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-2015 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_StyleChanged doesn't handle some changes too well
60 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
61 * linear in the number of items in the list, and this is
62 * unacceptable for large lists.
63 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
64 * binary search to calculate item index (e.g. DPA_Search()).
65 * This requires sorted state to be reliably tracked in item modifiers.
66 * -- we should keep an ordered array of coordinates in iconic mode.
67 * This would allow framing items (iterator_frameditems),
68 * and finding the nearest item (LVFI_NEARESTXY) a lot more efficiently.
75 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
80 * -- LVS_NOSCROLL (see Q137520)
84 * -- LVS_EX_BORDERSELECT
88 * -- LVS_EX_MULTIWORKAREAS
90 * -- LVS_EX_SIMPLESELECT
91 * -- LVS_EX_TWOCLICKACTIVATE
92 * -- LVS_EX_UNDERLINECOLD
93 * -- LVS_EX_UNDERLINEHOT
96 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
102 * -- LVM_ENABLEGROUPVIEW
103 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
104 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
105 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
106 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
107 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
108 * -- LVM_GETINSERTMARKRECT
109 * -- LVM_GETNUMBEROFWORKAREAS
110 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
111 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
112 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
113 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
114 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
115 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
116 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
117 * -- LVM_INSERTGROUPSORTED
118 * -- LVM_INSERTMARKHITTEST
119 * -- LVM_ISGROUPVIEWENABLED
121 * -- LVM_MOVEITEMTOGROUP
123 * -- LVM_SETTILEWIDTH
127 * -- ListView_GetHoverTime, ListView_SetHoverTime
128 * -- ListView_GetISearchString
129 * -- ListView_GetNumberOfWorkAreas
130 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
136 #include "comctl32.h"
140 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
142 typedef struct tagCOLUMN_INFO
144 RECT rcHeader
; /* tracks the header's rectangle */
145 INT fmt
; /* same as LVCOLUMN.fmt */
149 typedef struct tagITEMHDR
153 } ITEMHDR
, *LPITEMHDR
;
155 typedef struct tagSUBITEM_INFO
161 typedef struct tagITEM_ID ITEM_ID
;
163 typedef struct tagITEM_INFO
174 UINT id
; /* item id */
175 HDPA item
; /* link to item data */
178 typedef struct tagRANGE
184 typedef struct tagRANGES
189 typedef struct tagITERATOR
198 typedef struct tagDELAYED_ITEM_EDIT
204 typedef struct tagLISTVIEW_INFO
208 RECT rcList
; /* This rectangle is really the window
209 * client rectangle possibly reduced by the
210 * horizontal scroll bar and/or header - see
211 * LISTVIEW_UpdateSize. This rectangle offset
212 * by the LISTVIEW_GetOrigin value is in
213 * client coordinates */
215 /* notification window */
218 BOOL bDoChangeNotify
; /* send change notification messages? */
225 INT nItemCount
; /* the number of items in the list */
226 HDPA hdpaItems
; /* array ITEM_INFO pointers */
227 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
228 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
229 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
230 RANGES selectionRanges
;
231 INT nSelectionMark
; /* item to start next multiselection from */
233 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
236 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
237 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
240 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
245 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
249 DWORD dwStyle
; /* the cached window GWL_STYLE */
250 DWORD dwLvExStyle
; /* extended listview style */
251 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
257 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
260 HIMAGELIST himlNormal
;
261 HIMAGELIST himlSmall
;
262 HIMAGELIST himlState
;
267 POINT currIconPos
; /* this is the position next icon will be placed */
271 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
273 /* marquee selection */
274 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
276 RECT marqueeRect
; /* absolute coordinates of marquee selection */
277 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
278 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
281 BOOL bFocus
; /* control has focus */
283 RECT rcFocus
; /* focus bounds */
291 BOOL bDefaultBkColor
;
297 INT ntmHeight
; /* Some cached metrics of the font used */
298 INT ntmMaxCharWidth
; /* by the listview to draw items */
301 /* mouse operation */
304 POINT ptClickPos
; /* point where the user clicked */
305 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
310 /* keyboard operation */
311 DWORD lastKeyPressTimestamp
;
313 INT nSearchParamLength
;
314 WCHAR szSearchParam
[ MAX_PATH
];
317 BOOL bIsDrawing
; /* Drawing in progress */
318 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
319 BOOL redraw
; /* 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=%u, ", pScrollInfo
->cbSize
);
575 if (len
== -1) goto end
;
576 buf
+= len
; size
-= len
;
577 if (pScrollInfo
->fMask
& SIF_RANGE
)
578 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
580 if (len
== -1) goto end
;
581 buf
+= len
; size
-= len
;
582 if (pScrollInfo
->fMask
& SIF_PAGE
)
583 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
585 if (len
== -1) goto end
;
586 buf
+= len
; size
-= len
;
587 if (pScrollInfo
->fMask
& SIF_POS
)
588 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
590 if (len
== -1) goto end
;
591 buf
+= len
; size
-= len
;
592 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
593 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
595 if (len
== -1) goto end
;
599 buf
= text
+ strlen(text
);
601 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
605 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
607 if (!plvnm
) return "(null)";
608 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
609 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
610 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
611 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
614 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
616 char* buf
= debug_getbuf(), *text
= buf
;
617 int len
, size
= DEBUG_BUFFER_SIZE
;
619 if (lpLVItem
== NULL
) return "(null)";
620 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
621 if (len
== -1) goto end
;
622 buf
+= len
; size
-= len
;
623 if (lpLVItem
->mask
& LVIF_STATE
)
624 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
626 if (len
== -1) goto end
;
627 buf
+= len
; size
-= len
;
628 if (lpLVItem
->mask
& LVIF_TEXT
)
629 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
631 if (len
== -1) goto end
;
632 buf
+= len
; size
-= len
;
633 if (lpLVItem
->mask
& LVIF_IMAGE
)
634 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
636 if (len
== -1) goto end
;
637 buf
+= len
; size
-= len
;
638 if (lpLVItem
->mask
& LVIF_PARAM
)
639 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
641 if (len
== -1) goto end
;
642 buf
+= len
; size
-= len
;
643 if (lpLVItem
->mask
& LVIF_INDENT
)
644 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
646 if (len
== -1) goto end
;
650 buf
= text
+ strlen(text
);
652 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
656 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
658 char* buf
= debug_getbuf(), *text
= buf
;
659 int len
, size
= DEBUG_BUFFER_SIZE
;
661 if (lpColumn
== NULL
) return "(null)";
662 len
= snprintf(buf
, size
, "{");
663 if (len
== -1) goto end
;
664 buf
+= len
; size
-= len
;
665 if (lpColumn
->mask
& LVCF_SUBITEM
)
666 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
668 if (len
== -1) goto end
;
669 buf
+= len
; size
-= len
;
670 if (lpColumn
->mask
& LVCF_FMT
)
671 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
673 if (len
== -1) goto end
;
674 buf
+= len
; size
-= len
;
675 if (lpColumn
->mask
& LVCF_WIDTH
)
676 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
678 if (len
== -1) goto end
;
679 buf
+= len
; size
-= len
;
680 if (lpColumn
->mask
& LVCF_TEXT
)
681 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
683 if (len
== -1) goto end
;
684 buf
+= len
; size
-= len
;
685 if (lpColumn
->mask
& LVCF_IMAGE
)
686 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
688 if (len
== -1) goto end
;
689 buf
+= len
; size
-= len
;
690 if (lpColumn
->mask
& LVCF_ORDER
)
691 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
693 if (len
== -1) goto end
;
697 buf
= text
+ strlen(text
);
699 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
703 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
705 if (!lpht
) return "(null)";
707 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
708 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
711 /* Return the corresponding text for a given scroll value */
712 static inline LPCSTR
debugscrollcode(int nScrollCode
)
716 case SB_LINELEFT
: return "SB_LINELEFT";
717 case SB_LINERIGHT
: return "SB_LINERIGHT";
718 case SB_PAGELEFT
: return "SB_PAGELEFT";
719 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
720 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
721 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
722 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
723 case SB_INTERNAL
: return "SB_INTERNAL";
724 default: return "unknown";
729 /******** Notification functions ************************************/
731 static int get_ansi_notification(UINT unicodeNotificationCode
)
733 switch (unicodeNotificationCode
)
735 case LVN_BEGINLABELEDITA
:
736 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
737 case LVN_ENDLABELEDITA
:
738 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
739 case LVN_GETDISPINFOA
:
740 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
741 case LVN_SETDISPINFOA
:
742 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
743 case LVN_ODFINDITEMA
:
744 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
745 case LVN_GETINFOTIPA
:
746 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
747 /* header forwards */
749 case HDN_TRACKW
: return HDN_TRACKA
;
751 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
752 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
753 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
754 case HDN_ITEMCHANGINGA
:
755 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
756 case HDN_ITEMCHANGEDA
:
757 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
759 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
760 case HDN_DIVIDERDBLCLICKA
:
761 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
764 FIXME("unknown notification %x\n", unicodeNotificationCode
);
765 return unicodeNotificationCode
;
768 /* forwards header notifications to listview parent */
769 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
771 LPCWSTR text
= NULL
, filter
= NULL
;
773 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
775 /* on unicode format exit earlier */
776 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
777 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
780 /* header always supplies unicode notifications,
781 all we have to do is to convert strings to ANSI */
784 /* convert item text */
785 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
787 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
788 lpnmh
->pitem
->pszText
= NULL
;
789 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
791 /* convert filter text */
792 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
793 lpnmh
->pitem
->pvFilter
)
795 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
796 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= NULL
;
797 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
800 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
802 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
808 Free(lpnmh
->pitem
->pszText
);
809 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
813 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
814 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
820 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
824 TRACE("(code=%d)\n", code
);
826 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
827 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
829 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
831 TRACE(" <= %ld\n", result
);
836 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
839 HWND hwnd
= infoPtr
->hwndSelf
;
840 notify_hdr(infoPtr
, code
, &nmh
);
841 return IsWindow(hwnd
);
844 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
854 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
855 item
.iItem
= htInfo
->iItem
;
857 item
.stateMask
= (UINT
)-1;
858 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
859 nmia
.lParam
= item
.lParam
;
860 nmia
.uOldState
= item
.state
;
861 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
862 nmia
.uChanged
= LVIF_STATE
;
865 nmia
.iItem
= htInfo
->iItem
;
866 nmia
.iSubItem
= htInfo
->iSubItem
;
867 nmia
.ptAction
= htInfo
->pt
;
869 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
870 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
871 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
873 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
876 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
878 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
879 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
882 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
883 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
887 HWND hwnd
= infoPtr
->hwndSelf
;
890 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
891 ZeroMemory(&nmia
, sizeof(nmia
));
892 nmia
.iItem
= lvht
->iItem
;
893 nmia
.iSubItem
= lvht
->iSubItem
;
894 nmia
.ptAction
= lvht
->pt
;
895 item
.mask
= LVIF_PARAM
;
896 item
.iItem
= lvht
->iItem
;
898 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
899 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
900 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
903 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
907 HWND hwnd
= infoPtr
->hwndSelf
;
909 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
911 item
.mask
= LVIF_PARAM
;
914 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
915 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
916 return IsWindow(hwnd
);
920 Send notification. depends on dispinfoW having same
921 structure as dispinfoA.
922 infoPtr : listview struct
923 code : *Unicode* notification code
924 pdi : dispinfo structure (can be unicode or ansi)
925 isW : TRUE if dispinfo is Unicode
927 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
929 INT length
= 0, ret_length
;
930 LPWSTR buffer
= NULL
, ret_text
;
931 BOOL return_ansi
= FALSE
;
932 BOOL return_unicode
= FALSE
;
935 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
937 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
938 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
941 ret_length
= pdi
->item
.cchTextMax
;
942 ret_text
= pdi
->item
.pszText
;
944 if (return_unicode
|| return_ansi
)
946 if (code
!= LVN_GETDISPINFOW
)
948 length
= return_ansi
?
949 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
950 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
954 length
= pdi
->item
.cchTextMax
;
955 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
958 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
959 if (!buffer
) return FALSE
;
962 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
965 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
968 pdi
->item
.pszText
= buffer
;
969 pdi
->item
.cchTextMax
= length
;
972 if (infoPtr
->notifyFormat
== NFR_ANSI
)
973 code
= get_ansi_notification(code
);
975 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
976 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
977 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
979 if (return_ansi
|| return_unicode
)
981 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
983 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
985 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
987 strcpyW(ret_text
, pdi
->item
.pszText
);
989 else if (return_ansi
) /* note : pointer can be changed by app ! */
991 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
992 ret_length
, NULL
, NULL
);
995 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
996 ret_text
, ret_length
);
998 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
999 pdi
->item
.cchTextMax
= ret_length
;
1005 /* if dipsinfo holder changed notification code then convert */
1006 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1008 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1010 buffer
= Alloc(length
* sizeof(CHAR
));
1011 if (!buffer
) return FALSE
;
1013 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1014 ret_length
, NULL
, NULL
);
1016 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1023 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1024 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1026 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1027 lpnmlvcd
->nmcd
.hdc
= hdc
;
1028 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1029 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1030 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1031 if (!lplvItem
) return;
1032 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1033 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1034 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1035 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1036 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1037 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1040 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1042 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1045 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1046 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1047 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1048 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1049 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1050 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1054 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1056 COLORREF backcolor
, textcolor
;
1058 /* apparently, for selected items, we have to override the returned values */
1059 if (!SubItem
|| (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
1061 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1063 if (infoPtr
->bFocus
)
1065 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1066 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1068 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1070 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1071 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1076 backcolor
= lpnmlvcd
->clrTextBk
;
1077 textcolor
= lpnmlvcd
->clrText
;
1079 if (backcolor
== CLR_DEFAULT
)
1080 backcolor
= comctl32_color
.clrWindow
;
1081 if (textcolor
== CLR_DEFAULT
)
1082 textcolor
= comctl32_color
.clrWindowText
;
1084 /* Set the text attributes */
1085 if (backcolor
!= CLR_NONE
)
1087 SetBkMode(hdc
, OPAQUE
);
1088 SetBkColor(hdc
, backcolor
);
1091 SetBkMode(hdc
, TRANSPARENT
);
1092 SetTextColor(hdc
, textcolor
);
1095 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1097 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1100 /* returns TRUE when repaint needed, FALSE otherwise */
1101 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1103 MEASUREITEMSTRUCT mis
;
1104 mis
.CtlType
= ODT_LISTVIEW
;
1105 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1109 mis
.itemHeight
= infoPtr
->nItemHeight
;
1110 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1111 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1113 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1119 /******** Item iterator functions **********************************/
1121 static RANGES
ranges_create(int count
);
1122 static void ranges_destroy(RANGES ranges
);
1123 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1124 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1125 static void ranges_dump(RANGES ranges
);
1127 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1129 RANGE range
= { nItem
, nItem
+ 1 };
1131 return ranges_add(ranges
, range
);
1134 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1136 RANGE range
= { nItem
, nItem
+ 1 };
1138 return ranges_del(ranges
, range
);
1142 * ITERATOR DOCUMENTATION
1144 * The iterator functions allow for easy, and convenient iteration
1145 * over items of interest in the list. Typically, you create an
1146 * iterator, use it, and destroy it, as such:
1149 * iterator_xxxitems(&i, ...);
1150 * while (iterator_{prev,next}(&i)
1152 * //code which uses i.nItem
1154 * iterator_destroy(&i);
1156 * where xxx is either: framed, or visible.
1157 * Note that it is important that the code destroys the iterator
1158 * after it's done with it, as the creation of the iterator may
1159 * allocate memory, which thus needs to be freed.
1161 * You can iterate both forwards, and backwards through the list,
1162 * by using iterator_next or iterator_prev respectively.
1164 * Lower numbered items are draw on top of higher number items in
1165 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1166 * items may overlap). So, to test items, you should use
1168 * which lists the items top to bottom (in Z-order).
1169 * For drawing items, you should use
1171 * which lists the items bottom to top (in Z-order).
1172 * If you keep iterating over the items after the end-of-items
1173 * marker (-1) is returned, the iterator will start from the
1174 * beginning. Typically, you don't need to test for -1,
1175 * because iterator_{next,prev} will return TRUE if more items
1176 * are to be iterated over, or FALSE otherwise.
1178 * Note: the iterator is defined to be bidirectional. That is,
1179 * any number of prev followed by any number of next, or
1180 * five versa, should leave the iterator at the same item:
1181 * prev * n, next * n = next * n, prev * n
1183 * The iterator has a notion of an out-of-order, special item,
1184 * which sits at the start of the list. This is used in
1185 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1186 * which needs to be first, as it may overlap other items.
1188 * The code is a bit messy because we have:
1189 * - a special item to deal with
1190 * - simple range, or composite range
1192 * If you find bugs, or want to add features, please make sure you
1193 * always check/modify *both* iterator_prev, and iterator_next.
1197 * This function iterates through the items in increasing order,
1198 * but prefixed by the special item, then -1. That is:
1199 * special, 1, 2, 3, ..., n, -1.
1200 * Each item is listed only once.
1202 static inline BOOL
iterator_next(ITERATOR
* i
)
1206 i
->nItem
= i
->nSpecial
;
1207 if (i
->nItem
!= -1) return TRUE
;
1209 if (i
->nItem
== i
->nSpecial
)
1211 if (i
->ranges
) i
->index
= 0;
1217 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1218 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1223 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1224 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1227 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1229 i
->nItem
= i
->range
.lower
;
1230 if (i
->nItem
>= 0) goto testitem
;
1237 * This function iterates through the items in decreasing order,
1238 * followed by the special item, then -1. That is:
1239 * n, n-1, ..., 3, 2, 1, special, -1.
1240 * Each item is listed only once.
1242 static inline BOOL
iterator_prev(ITERATOR
* i
)
1249 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1252 if (i
->nItem
== i
->nSpecial
)
1260 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1261 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1267 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1270 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1272 i
->nItem
= i
->range
.upper
;
1273 if (i
->nItem
> 0) goto testitem
;
1275 return (i
->nItem
= i
->nSpecial
) != -1;
1278 static RANGE
iterator_range(const ITERATOR
*i
)
1282 if (!i
->ranges
) return i
->range
;
1284 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1286 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1287 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1289 else range
.lower
= range
.upper
= 0;
1295 * Releases resources associated with this iterator.
1297 static inline void iterator_destroy(const ITERATOR
*i
)
1299 ranges_destroy(i
->ranges
);
1303 * Create an empty iterator.
1305 static inline BOOL
iterator_empty(ITERATOR
* i
)
1307 ZeroMemory(i
, sizeof(*i
));
1308 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1313 * Create an iterator over a range.
1315 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1323 * Create an iterator over a bunch of ranges.
1324 * Please note that the iterator will take ownership of the ranges,
1325 * and will free them upon destruction.
1327 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1335 * Creates an iterator over the items which intersect frame.
1336 * Uses absolute coordinates rather than compensating for the current offset.
1338 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1340 RECT rcItem
, rcTemp
;
1342 /* in case we fail, we want to return an empty iterator */
1343 if (!iterator_empty(i
)) return FALSE
;
1345 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1347 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1351 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1353 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1354 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1355 i
->nSpecial
= infoPtr
->nFocusedItem
;
1357 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1358 /* to do better here, we need to have PosX, and PosY sorted */
1359 TRACE("building icon ranges:\n");
1360 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1362 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1363 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1364 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1365 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1366 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1367 ranges_additem(i
->ranges
, nItem
);
1371 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1375 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1376 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1378 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1379 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1380 if (range
.upper
<= range
.lower
) return TRUE
;
1381 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1382 TRACE(" report=%s\n", debugrange(&i
->range
));
1386 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1387 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1388 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1395 if (infoPtr
->nItemWidth
)
1397 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1398 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1402 nFirstCol
= max(frame
->left
, 0);
1403 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1406 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1408 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1409 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1411 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1413 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1414 TRACE("building list ranges:\n");
1415 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1417 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1418 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1419 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1420 TRACE(" list=%s\n", debugrange(&item_range
));
1421 ranges_add(i
->ranges
, item_range
);
1429 * Creates an iterator over the items which intersect lprc.
1431 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1436 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1438 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1439 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1441 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1445 * Creates an iterator over the items which intersect the visible region of hdc.
1447 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1449 POINT Origin
, Position
;
1450 RECT rcItem
, rcClip
;
1453 rgntype
= GetClipBox(hdc
, &rcClip
);
1454 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1455 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1456 if (rgntype
== SIMPLEREGION
) return TRUE
;
1458 /* first deal with the special item */
1459 if (i
->nSpecial
!= -1)
1461 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1462 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1465 /* if we can't deal with the region, we'll just go with the simple range */
1466 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1467 TRACE("building visible range:\n");
1468 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1470 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1471 if (!ranges_add(i
->ranges
, i
->range
))
1473 ranges_destroy(i
->ranges
);
1479 /* now delete the invisible items from the list */
1480 while(iterator_next(i
))
1482 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1483 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1484 rcItem
.top
= Position
.y
+ Origin
.y
;
1485 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1486 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1487 if (!RectVisible(hdc
, &rcItem
))
1488 ranges_delitem(i
->ranges
, i
->nItem
);
1490 /* the iterator should restart on the next iterator_next */
1496 /* Remove common elements from two iterators */
1497 /* Passed iterators have to point on the first elements */
1498 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1500 if(!iter1
->ranges
|| !iter2
->ranges
) {
1503 if(iter1
->ranges
|| iter2
->ranges
||
1504 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1505 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1506 ERR("result is not a one range iterator\n");
1510 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1513 lower
= iter1
->range
.lower
;
1514 upper
= iter1
->range
.upper
;
1516 if(lower
< iter2
->range
.lower
)
1517 iter1
->range
.upper
= iter2
->range
.lower
;
1518 else if(upper
> iter2
->range
.upper
)
1519 iter1
->range
.lower
= iter2
->range
.upper
;
1521 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1523 if(iter2
->range
.lower
< lower
)
1524 iter2
->range
.upper
= lower
;
1525 else if(iter2
->range
.upper
> upper
)
1526 iter2
->range
.lower
= upper
;
1528 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1533 iterator_next(iter1
);
1534 iterator_next(iter2
);
1537 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1540 if(iter1
->nItem
== iter2
->nItem
) {
1541 int delete = iter1
->nItem
;
1543 iterator_prev(iter1
);
1544 iterator_prev(iter2
);
1545 ranges_delitem(iter1
->ranges
, delete);
1546 ranges_delitem(iter2
->ranges
, delete);
1547 iterator_next(iter1
);
1548 iterator_next(iter2
);
1549 } else if(iter1
->nItem
> iter2
->nItem
)
1550 iterator_next(iter2
);
1552 iterator_next(iter1
);
1555 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1556 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1560 /******** Misc helper functions ************************************/
1562 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1563 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1565 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1566 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1569 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1571 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1572 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1575 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1577 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1578 if(state
== 1 || state
== 2)
1582 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1583 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1584 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1588 /* this should be called after window style got updated,
1589 it used to reset view state to match current window style */
1590 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1592 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1595 infoPtr
->uView
= LV_VIEW_ICON
;
1598 infoPtr
->uView
= LV_VIEW_DETAILS
;
1601 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1604 infoPtr
->uView
= LV_VIEW_LIST
;
1608 /* computes next item id value */
1609 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1611 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1615 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1616 return lpID
->id
+ 1;
1621 /******** Internal API functions ************************************/
1623 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1625 static COLUMN_INFO mainItem
;
1627 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1628 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1630 /* update cached column rectangles */
1631 if (infoPtr
->colRectsDirty
)
1634 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1637 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1638 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1639 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1641 Ptr
->colRectsDirty
= FALSE
;
1644 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1647 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1649 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1652 if (infoPtr
->hwndHeader
) return 0;
1654 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1656 /* setup creation flags */
1657 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1658 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1660 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1663 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1664 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1665 if (!infoPtr
->hwndHeader
) return -1;
1667 /* set header unicode format */
1668 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1670 /* set header font */
1671 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1673 /* set header image list */
1674 if (infoPtr
->himlSmall
)
1675 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1677 LISTVIEW_UpdateSize(infoPtr
);
1682 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1684 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1687 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1689 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1690 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1691 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1694 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1696 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1699 /* used to handle collapse main item column case */
1700 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1705 if (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
)
1707 DWORD dwOldBkColor
, dwOldTextColor
;
1709 dwOldBkColor
= SetBkColor(hdc
, RGB(255, 255, 255));
1710 dwOldTextColor
= SetBkColor(hdc
, RGB(0, 0, 0));
1711 Ret
= DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1712 SetBkColor(hdc
, dwOldBkColor
);
1713 SetBkColor(hdc
, dwOldTextColor
);
1717 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1718 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1722 /* Listview invalidation functions: use _only_ these functions to invalidate */
1724 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1726 return infoPtr
->redraw
;
1729 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1731 if(!is_redrawing(infoPtr
)) return;
1732 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1733 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1736 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1740 if(!is_redrawing(infoPtr
)) return;
1741 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1742 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1745 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1747 POINT Origin
, Position
;
1750 if(!is_redrawing(infoPtr
)) return;
1751 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1752 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1753 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1754 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1756 rcBox
.bottom
= infoPtr
->nItemHeight
;
1757 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1758 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1761 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1763 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1766 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1770 if(!is_redrawing(infoPtr
)) return;
1771 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1772 rcCol
.top
= infoPtr
->rcList
.top
;
1773 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1774 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1779 * Retrieves the number of items that can fit vertically in the client area.
1782 * [I] infoPtr : valid pointer to the listview structure
1785 * Number of items per row.
1787 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1789 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1791 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1796 * Retrieves the number of items that can fit horizontally in the client
1800 * [I] infoPtr : valid pointer to the listview structure
1803 * Number of items per column.
1805 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1807 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1809 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1813 /*************************************************************************
1814 * LISTVIEW_ProcessLetterKeys
1816 * Processes keyboard messages generated by pressing the letter keys
1818 * What this does is perform a case insensitive search from the
1819 * current position with the following quirks:
1820 * - If two chars or more are pressed in quick succession we search
1821 * for the corresponding string (e.g. 'abc').
1822 * - If there is a delay we wipe away the current search string and
1823 * restart with just that char.
1824 * - If the user keeps pressing the same character, whether slowly or
1825 * fast, so that the search string is entirely composed of this
1826 * character ('aaaaa' for instance), then we search for first item
1827 * that starting with that character.
1828 * - If the user types the above character in quick succession, then
1829 * we must also search for the corresponding string ('aaaaa'), and
1830 * go to that string if there is a match.
1833 * [I] hwnd : handle to the window
1834 * [I] charCode : the character code, the actual character
1835 * [I] keyData : key data
1843 * - The current implementation has a list of characters it will
1844 * accept and it ignores everything else. In particular it will
1845 * ignore accentuated characters which seems to match what
1846 * Windows does. But I'm not sure it makes sense to follow
1848 * - We don't sound a beep when the search fails.
1852 * TREEVIEW_ProcessLetterKeys
1854 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1856 WCHAR buffer
[MAX_PATH
];
1863 /* simple parameter checking */
1864 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1866 /* only allow the valid WM_CHARs through */
1867 if (!isalnumW(charCode
) &&
1868 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1869 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1870 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1871 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1872 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1873 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1874 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1875 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1876 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1879 /* update the search parameters */
1880 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1881 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1882 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1884 if (diff
>= 0 && diff
< KEY_DELAY
)
1886 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1887 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1889 if (infoPtr
->charCode
!= charCode
)
1890 infoPtr
->charCode
= charCode
= 0;
1894 infoPtr
->charCode
= charCode
;
1895 infoPtr
->szSearchParam
[0] = charCode
;
1896 infoPtr
->nSearchParamLength
= 1;
1899 /* should start from next after focused item, so next item that matches
1900 will be selected, if there isn't any and focused matches it will be selected
1901 on second search stage from beginning of the list */
1902 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1904 /* with some accumulated search data available start with current focus, otherwise
1905 it's excluded from search */
1906 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1907 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1912 /* let application handle this for virtual listview */
1913 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1917 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1918 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1919 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1920 nmlv
.iStart
= startidx
;
1922 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1924 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1928 int i
= startidx
, endidx
;
1930 /* and search from the current position */
1932 endidx
= infoPtr
->nItemCount
;
1934 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1937 /* start from first item if not found with >= startidx */
1938 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1944 for (i
= startidx
; i
< endidx
; i
++)
1947 item
.mask
= LVIF_TEXT
;
1950 item
.pszText
= buffer
;
1951 item
.cchTextMax
= MAX_PATH
;
1952 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1954 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1959 /* this is used to find first char match when search string is not available yet,
1960 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1961 already waiting for user to complete a string */
1962 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1964 /* this would work but we must keep looking for a longer match */
1969 if ( nItem
!= -1 || /* found something */
1970 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1971 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1977 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1982 /*************************************************************************
1983 * LISTVIEW_UpdateHeaderSize [Internal]
1985 * Function to resize the header control
1988 * [I] hwnd : handle to a window
1989 * [I] nNewScrollPos : scroll pos to set
1994 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1999 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
2001 if (!infoPtr
->hwndHeader
) return;
2003 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
2004 point
[0].x
= winRect
.left
;
2005 point
[0].y
= winRect
.top
;
2006 point
[1].x
= winRect
.right
;
2007 point
[1].y
= winRect
.bottom
;
2009 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
2010 point
[0].x
= -nNewScrollPos
;
2011 point
[1].x
+= nNewScrollPos
;
2013 SetWindowPos(infoPtr
->hwndHeader
,0,
2014 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
2015 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
2016 SWP_NOZORDER
| SWP_NOACTIVATE
);
2021 * Update the scrollbars. This functions should be called whenever
2022 * the content, size or view changes.
2025 * [I] infoPtr : valid pointer to the listview structure
2030 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2032 SCROLLINFO horzInfo
, vertInfo
;
2035 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2037 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2038 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2039 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2041 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2042 if (infoPtr
->uView
== LV_VIEW_LIST
)
2044 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2045 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2047 /* scroll by at least one column per page */
2048 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2049 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2051 if (infoPtr
->nItemWidth
)
2052 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2054 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2056 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2058 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2062 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2065 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2067 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2072 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2073 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2075 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2076 horzInfo
.nMax
= rcHeader
.right
;
2077 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2081 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2082 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2083 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2084 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2085 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2087 /* Setting the horizontal scroll can change the listview size
2088 * (and potentially everything else) so we need to recompute
2089 * everything again for the vertical scroll
2092 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2093 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2094 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2096 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2098 vertInfo
.nMax
= infoPtr
->nItemCount
;
2100 /* scroll by at least one page */
2101 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2102 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2104 if (infoPtr
->nItemHeight
> 0)
2105 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2107 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2111 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2114 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2115 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2116 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2117 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2118 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2120 /* Change of the range may have changed the scroll pos. If so move the content */
2121 if (dx
!= 0 || dy
!= 0)
2124 listRect
= infoPtr
->rcList
;
2125 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2126 SW_ERASE
| SW_INVALIDATE
);
2129 /* Update the Header Control */
2130 if (infoPtr
->hwndHeader
)
2132 horzInfo
.fMask
= SIF_POS
;
2133 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2134 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2141 * Shows/hides the focus rectangle.
2144 * [I] infoPtr : valid pointer to the listview structure
2145 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2150 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2154 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2156 if (infoPtr
->nFocusedItem
< 0) return;
2158 /* we need some gymnastics in ICON mode to handle large items */
2159 if (infoPtr
->uView
== LV_VIEW_ICON
)
2163 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2164 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2166 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2171 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2173 /* for some reason, owner draw should work only in report mode */
2174 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2179 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2180 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2182 item
.iItem
= infoPtr
->nFocusedItem
;
2184 item
.mask
= LVIF_PARAM
;
2185 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2187 ZeroMemory(&dis
, sizeof(dis
));
2188 dis
.CtlType
= ODT_LISTVIEW
;
2189 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2190 dis
.itemID
= item
.iItem
;
2191 dis
.itemAction
= ODA_FOCUS
;
2192 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2193 dis
.hwndItem
= infoPtr
->hwndSelf
;
2195 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2196 dis
.itemData
= item
.lParam
;
2198 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2200 SelectObject(hdc
, hOldFont
);
2204 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2207 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2211 * Invalidates all visible selected items.
2213 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2217 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2218 while(iterator_next(&i
))
2220 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2221 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2223 iterator_destroy(&i
);
2228 * DESCRIPTION: [INTERNAL]
2229 * Computes an item's (left,top) corner, relative to rcView.
2230 * That is, the position has NOT been made relative to the Origin.
2231 * This is deliberate, to avoid computing the Origin over, and
2232 * over again, when this function is called in a loop. Instead,
2233 * one can factor the computation of the Origin before the loop,
2234 * and offset the value returned by this function, on every iteration.
2237 * [I] infoPtr : valid pointer to the listview structure
2238 * [I] nItem : item number
2239 * [O] lpptOrig : item top, left corner
2244 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2246 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2248 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2250 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2251 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2253 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2255 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2256 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2257 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2259 else /* LV_VIEW_DETAILS */
2261 lpptPosition
->x
= REPORT_MARGINX
;
2262 /* item is always at zero indexed column */
2263 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2264 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2265 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2270 * DESCRIPTION: [INTERNAL]
2271 * Compute the rectangles of an item. This is to localize all
2272 * the computations in one place. If you are not interested in some
2273 * of these values, simply pass in a NULL -- the function is smart
2274 * enough to compute only what's necessary. The function computes
2275 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2276 * one, the BOX rectangle. This rectangle is very cheap to compute,
2277 * and is guaranteed to contain all the other rectangles. Computing
2278 * the ICON rect is also cheap, but all the others are potentially
2279 * expensive. This gives an easy and effective optimization when
2280 * searching (like point inclusion, or rectangle intersection):
2281 * first test against the BOX, and if TRUE, test against the desired
2283 * If the function does not have all the necessary information
2284 * to computed the requested rectangles, will crash with a
2285 * failed assertion. This is done so we catch all programming
2286 * errors, given that the function is called only from our code.
2288 * We have the following 'special' meanings for a few fields:
2289 * * If LVIS_FOCUSED is set, we assume the item has the focus
2290 * This is important in ICON mode, where it might get a larger
2291 * then usual rectangle
2293 * Please note that subitem support works only in REPORT mode.
2296 * [I] infoPtr : valid pointer to the listview structure
2297 * [I] lpLVItem : item to compute the measures for
2298 * [O] lprcBox : ptr to Box rectangle
2299 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2300 * [0] lprcSelectBox : ptr to select box rectangle
2301 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2302 * [O] lprcIcon : ptr to Icon rectangle
2303 * Same as LVM_GETITEMRECT with LVIR_ICON
2304 * [O] lprcStateIcon: ptr to State Icon rectangle
2305 * [O] lprcLabel : ptr to Label rectangle
2306 * Same as LVM_GETITEMRECT with LVIR_LABEL
2311 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2312 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2313 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2315 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2316 RECT Box
, SelectBox
, Icon
, Label
;
2317 COLUMN_INFO
*lpColumnInfo
= NULL
;
2318 SIZE labelSize
= { 0, 0 };
2320 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2322 /* Be smart and try to figure out the minimum we have to do */
2323 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2324 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2326 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2327 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2329 if (lprcSelectBox
) doSelectBox
= TRUE
;
2330 if (lprcLabel
) doLabel
= TRUE
;
2331 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2338 /************************************************************/
2339 /* compute the box rectangle (it should be cheap to do) */
2340 /************************************************************/
2341 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2342 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2344 if (lpLVItem
->iSubItem
)
2346 Box
= lpColumnInfo
->rcHeader
;
2351 Box
.right
= infoPtr
->nItemWidth
;
2354 Box
.bottom
= infoPtr
->nItemHeight
;
2356 /******************************************************************/
2357 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2358 /******************************************************************/
2361 LONG state_width
= 0;
2363 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2364 state_width
= infoPtr
->iconStateSize
.cx
;
2366 if (infoPtr
->uView
== LV_VIEW_ICON
)
2368 Icon
.left
= Box
.left
+ state_width
;
2369 if (infoPtr
->himlNormal
)
2370 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2371 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2372 Icon
.right
= Icon
.left
;
2373 Icon
.bottom
= Icon
.top
;
2374 if (infoPtr
->himlNormal
)
2376 Icon
.right
+= infoPtr
->iconSize
.cx
;
2377 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2380 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2382 Icon
.left
= Box
.left
+ state_width
;
2384 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2386 /* we need the indent in report mode */
2387 assert(lpLVItem
->mask
& LVIF_INDENT
);
2388 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2392 Icon
.right
= Icon
.left
;
2393 if (infoPtr
->himlSmall
&&
2394 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2395 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2396 Icon
.right
+= infoPtr
->iconSize
.cx
;
2397 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2399 if(lprcIcon
) *lprcIcon
= Icon
;
2400 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2402 /* TODO: is this correct? */
2405 lprcStateIcon
->left
= Icon
.left
- state_width
;
2406 lprcStateIcon
->right
= Icon
.left
;
2407 lprcStateIcon
->top
= Icon
.top
;
2408 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2409 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2412 else Icon
.right
= 0;
2414 /************************************************************/
2415 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2416 /************************************************************/
2419 /* calculate how far to the right can the label stretch */
2420 Label
.right
= Box
.right
;
2421 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2423 if (lpLVItem
->iSubItem
== 0)
2425 /* we need a zero based rect here */
2426 Label
= lpColumnInfo
->rcHeader
;
2427 OffsetRect(&Label
, -Label
.left
, 0);
2431 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2433 labelSize
.cx
= infoPtr
->nItemWidth
;
2434 labelSize
.cy
= infoPtr
->nItemHeight
;
2438 /* we need the text in non owner draw mode */
2439 assert(lpLVItem
->mask
& LVIF_TEXT
);
2440 if (is_text(lpLVItem
->pszText
))
2442 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2443 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2444 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2448 /* compute rough rectangle where the label will go */
2449 SetRectEmpty(&rcText
);
2450 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2451 rcText
.bottom
= infoPtr
->nItemHeight
;
2452 if (infoPtr
->uView
== LV_VIEW_ICON
)
2453 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2455 /* now figure out the flags */
2456 if (infoPtr
->uView
== LV_VIEW_ICON
)
2457 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2459 uFormat
= LV_SL_DT_FLAGS
;
2461 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2463 if (rcText
.right
!= rcText
.left
)
2464 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2466 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2468 SelectObject(hdc
, hOldFont
);
2469 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2473 if (infoPtr
->uView
== LV_VIEW_ICON
)
2475 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2476 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2477 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2478 Label
.right
= Label
.left
+ labelSize
.cx
;
2479 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2480 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2482 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2483 labelSize
.cy
/= infoPtr
->ntmHeight
;
2484 labelSize
.cy
= max(labelSize
.cy
, 1);
2485 labelSize
.cy
*= infoPtr
->ntmHeight
;
2487 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2489 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2491 Label
.left
= Icon
.right
;
2492 Label
.top
= Box
.top
;
2493 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2494 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2495 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2497 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2499 Label
.left
= Icon
.right
;
2500 Label
.top
= Box
.top
;
2501 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2502 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2505 if (lprcLabel
) *lprcLabel
= Label
;
2506 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2509 /************************************************************/
2510 /* compute SELECT bounding box */
2511 /************************************************************/
2514 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2516 SelectBox
.left
= Icon
.left
;
2517 SelectBox
.top
= Box
.top
;
2518 SelectBox
.bottom
= Box
.bottom
;
2521 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2523 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2527 UnionRect(&SelectBox
, &Icon
, &Label
);
2529 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2530 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2533 /* Fix the Box if necessary */
2536 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2537 else *lprcBox
= Box
;
2539 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2543 * DESCRIPTION: [INTERNAL]
2546 * [I] infoPtr : valid pointer to the listview structure
2547 * [I] nItem : item number
2548 * [O] lprcBox : ptr to Box rectangle
2553 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2555 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2556 POINT Position
, Origin
;
2559 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2560 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2562 /* Be smart and try to figure out the minimum we have to do */
2564 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2565 lvItem
.mask
|= LVIF_TEXT
;
2566 lvItem
.iItem
= nItem
;
2567 lvItem
.iSubItem
= 0;
2568 lvItem
.pszText
= szDispText
;
2569 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2570 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2571 if (infoPtr
->uView
== LV_VIEW_ICON
)
2573 lvItem
.mask
|= LVIF_STATE
;
2574 lvItem
.stateMask
= LVIS_FOCUSED
;
2575 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2577 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2579 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2580 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2582 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2585 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2588 /* LISTVIEW_MapIdToIndex helper */
2589 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2591 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2592 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2594 if (id1
->id
== id2
->id
) return 0;
2596 return (id1
->id
< id2
->id
) ? -1 : 1;
2601 * Returns the item index for id specified.
2604 * [I] infoPtr : valid pointer to the listview structure
2605 * [I] iID : item id to get index for
2608 * Item index, or -1 on failure.
2610 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2615 TRACE("iID=%d\n", iID
);
2617 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2618 if (infoPtr
->nItemCount
== 0) return -1;
2621 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2625 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2626 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2634 * Returns the item id for index given.
2637 * [I] infoPtr : valid pointer to the listview structure
2638 * [I] iItem : item index to get id for
2643 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2648 TRACE("iItem=%d\n", iItem
);
2650 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2651 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2653 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2654 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2656 return lpItem
->id
->id
;
2661 * Returns the current icon position, and advances it along the top.
2662 * The returned position is not offset by Origin.
2665 * [I] infoPtr : valid pointer to the listview structure
2666 * [O] lpPos : will get the current icon position
2671 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2673 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2675 *lpPos
= infoPtr
->currIconPos
;
2677 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2678 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2680 infoPtr
->currIconPos
.x
= 0;
2681 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2687 * Returns the current icon position, and advances it down the left edge.
2688 * The returned position is not offset by Origin.
2691 * [I] infoPtr : valid pointer to the listview structure
2692 * [O] lpPos : will get the current icon position
2697 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2699 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2701 *lpPos
= infoPtr
->currIconPos
;
2703 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2704 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2706 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2707 infoPtr
->currIconPos
.y
= 0;
2713 * Moves an icon to the specified position.
2714 * It takes care of invalidating the item, etc.
2717 * [I] infoPtr : valid pointer to the listview structure
2718 * [I] nItem : the item to move
2719 * [I] lpPos : the new icon position
2720 * [I] isNew : flags the item as being new
2726 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2732 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2733 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2735 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2736 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2739 /* Allocating a POINTER for every item is too resource intensive,
2740 * so we'll keep the (x,y) in different arrays */
2741 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2742 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2744 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2751 * Arranges listview items in icon display mode.
2754 * [I] infoPtr : valid pointer to the listview structure
2755 * [I] nAlignCode : alignment code
2761 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2763 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2767 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2769 TRACE("nAlignCode=%d\n", nAlignCode
);
2771 if (nAlignCode
== LVA_DEFAULT
)
2773 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2774 else nAlignCode
= LVA_ALIGNTOP
;
2779 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2780 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2781 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2782 default: return FALSE
;
2785 infoPtr
->bAutoarrange
= TRUE
;
2786 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2787 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2789 next_pos(infoPtr
, &pos
);
2790 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2798 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2799 * For LVS_REPORT always returns empty rectangle.
2802 * [I] infoPtr : valid pointer to the listview structure
2803 * [O] lprcView : bounding rectangle
2809 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2813 SetRectEmpty(lprcView
);
2815 switch (infoPtr
->uView
)
2818 case LV_VIEW_SMALLICON
:
2819 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2821 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2822 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2823 lprcView
->right
= max(lprcView
->right
, x
);
2824 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2826 if (infoPtr
->nItemCount
> 0)
2828 lprcView
->right
+= infoPtr
->nItemWidth
;
2829 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2834 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2835 x
= infoPtr
->nItemCount
/ y
;
2836 if (infoPtr
->nItemCount
% y
) x
++;
2837 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2838 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2845 * Retrieves the bounding rectangle of all the items.
2848 * [I] infoPtr : valid pointer to the listview structure
2849 * [O] lprcView : bounding rectangle
2855 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2859 TRACE("(lprcView=%p)\n", lprcView
);
2861 if (!lprcView
) return FALSE
;
2863 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2865 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2867 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2868 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2871 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2878 * Retrieves the subitem pointer associated with the subitem index.
2881 * [I] hdpaSubItems : DPA handle for a specific item
2882 * [I] nSubItem : index of subitem
2885 * SUCCESS : subitem pointer
2888 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2890 SUBITEM_INFO
*lpSubItem
;
2893 /* we should binary search here if need be */
2894 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2896 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2897 if (lpSubItem
->iSubItem
== nSubItem
)
2907 * Calculates the desired item width.
2910 * [I] infoPtr : valid pointer to the listview structure
2913 * The desired item width.
2915 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2919 TRACE("uView=%d\n", infoPtr
->uView
);
2921 if (infoPtr
->uView
== LV_VIEW_ICON
)
2922 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2923 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2925 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2930 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2931 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2933 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2934 nItemWidth
= rcHeader
.right
;
2937 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2939 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2943 lvItem
.mask
= LVIF_TEXT
;
2944 lvItem
.iSubItem
= 0;
2946 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2949 lvItem
.pszText
= szDispText
;
2950 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2951 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2952 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2956 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2957 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2959 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2967 * Calculates the desired item height.
2970 * [I] infoPtr : valid pointer to the listview structure
2973 * The desired item height.
2975 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2979 TRACE("uView=%d\n", infoPtr
->uView
);
2981 if (infoPtr
->uView
== LV_VIEW_ICON
)
2982 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2985 nItemHeight
= infoPtr
->ntmHeight
;
2986 if (infoPtr
->himlState
)
2987 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2988 if (infoPtr
->himlSmall
)
2989 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2990 nItemHeight
+= HEIGHT_PADDING
;
2991 if (infoPtr
->nMeasureItemHeight
> 0)
2992 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2995 return max(nItemHeight
, 1);
3000 * Updates the width, and height of an item.
3003 * [I] infoPtr : valid pointer to the listview structure
3008 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
3010 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
3011 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3017 * Retrieves and saves important text metrics info for the current
3021 * [I] infoPtr : valid pointer to the listview structure
3024 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3026 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3027 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3028 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3032 if (GetTextMetricsW(hdc
, &tm
))
3034 infoPtr
->ntmHeight
= tm
.tmHeight
;
3035 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3038 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3039 infoPtr
->nEllipsisWidth
= sz
.cx
;
3041 SelectObject(hdc
, hOldFont
);
3042 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3044 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3049 * A compare function for ranges
3052 * [I] range1 : pointer to range 1;
3053 * [I] range2 : pointer to range 2;
3057 * > 0 : if range 1 > range 2
3058 * < 0 : if range 2 > range 1
3059 * = 0 : if range intersects range 2
3061 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3065 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3067 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3072 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3077 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3079 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3084 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3086 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3087 ranges_dump(ranges
);
3088 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3090 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3091 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3092 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3094 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3095 assert (prev
->upper
<= curr
->lower
);
3096 assert (curr
->lower
< curr
->upper
);
3100 TRACE("--- Done checking---\n");
3103 static RANGES
ranges_create(int count
)
3105 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3106 if (!ranges
) return NULL
;
3107 ranges
->hdpa
= DPA_Create(count
);
3108 if (ranges
->hdpa
) return ranges
;
3113 static void ranges_clear(RANGES ranges
)
3117 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3118 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3119 DPA_DeleteAllPtrs(ranges
->hdpa
);
3123 static void ranges_destroy(RANGES ranges
)
3125 if (!ranges
) return;
3126 ranges_clear(ranges
);
3127 DPA_Destroy(ranges
->hdpa
);
3131 static RANGES
ranges_clone(RANGES ranges
)
3136 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3138 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3140 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3141 if (!newrng
) goto fail
;
3142 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3143 if (!DPA_SetPtr(clone
->hdpa
, i
, newrng
))
3152 TRACE ("clone failed\n");
3153 ranges_destroy(clone
);
3157 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3161 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3162 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3167 static void ranges_dump(RANGES ranges
)
3171 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3172 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3175 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3177 RANGE srchrng
= { nItem
, nItem
+ 1 };
3179 TRACE("(nItem=%d)\n", nItem
);
3180 ranges_check(ranges
, "before contain");
3181 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3184 static INT
ranges_itemcount(RANGES ranges
)
3188 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3190 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3191 count
+= sel
->upper
- sel
->lower
;
3197 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3199 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3202 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3203 if (index
== -1) return TRUE
;
3205 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3207 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3208 if (chkrng
->lower
>= nItem
)
3209 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3210 if (chkrng
->upper
> nItem
)
3211 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3216 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3221 TRACE("(%s)\n", debugrange(&range
));
3222 ranges_check(ranges
, "before add");
3224 /* try find overlapping regions first */
3225 srchrgn
.lower
= range
.lower
- 1;
3226 srchrgn
.upper
= range
.upper
+ 1;
3227 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3233 TRACE("Adding new range\n");
3235 /* create the brand new range to insert */
3236 newrgn
= Alloc(sizeof(RANGE
));
3237 if(!newrgn
) goto fail
;
3240 /* figure out where to insert it */
3241 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3242 TRACE("index=%d\n", index
);
3243 if (index
== -1) index
= 0;
3245 /* and get it over with */
3246 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3254 RANGE
*chkrgn
, *mrgrgn
;
3255 INT fromindex
, mergeindex
;
3257 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3258 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3260 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3261 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3263 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3265 /* merge now common ranges */
3267 srchrgn
.lower
= chkrgn
->lower
- 1;
3268 srchrgn
.upper
= chkrgn
->upper
+ 1;
3272 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3273 if (mergeindex
== -1) break;
3274 if (mergeindex
== index
)
3276 fromindex
= index
+ 1;
3280 TRACE("Merge with index %i\n", mergeindex
);
3282 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3283 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3284 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3286 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3287 if (mergeindex
< index
) index
--;
3291 ranges_check(ranges
, "after add");
3295 ranges_check(ranges
, "failed add");
3299 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3304 TRACE("(%s)\n", debugrange(&range
));
3305 ranges_check(ranges
, "before del");
3307 /* we don't use DPAS_SORTED here, since we need *
3308 * to find the first overlapping range */
3309 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3312 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3314 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3316 /* case 1: Same range */
3317 if ( (chkrgn
->upper
== range
.upper
) &&
3318 (chkrgn
->lower
== range
.lower
) )
3320 DPA_DeletePtr(ranges
->hdpa
, index
);
3324 /* case 2: engulf */
3325 else if ( (chkrgn
->upper
<= range
.upper
) &&
3326 (chkrgn
->lower
>= range
.lower
) )
3328 DPA_DeletePtr(ranges
->hdpa
, index
);
3331 /* case 3: overlap upper */
3332 else if ( (chkrgn
->upper
<= range
.upper
) &&
3333 (chkrgn
->lower
< range
.lower
) )
3335 chkrgn
->upper
= range
.lower
;
3337 /* case 4: overlap lower */
3338 else if ( (chkrgn
->upper
> range
.upper
) &&
3339 (chkrgn
->lower
>= range
.lower
) )
3341 chkrgn
->lower
= range
.upper
;
3344 /* case 5: fully internal */
3349 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3350 newrgn
->lower
= chkrgn
->lower
;
3351 newrgn
->upper
= range
.lower
;
3352 chkrgn
->lower
= range
.upper
;
3353 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3361 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3364 ranges_check(ranges
, "after del");
3368 ranges_check(ranges
, "failed del");
3374 * Removes all selection ranges
3377 * [I] infoPtr : valid pointer to the listview structure
3378 * [I] toSkip : item range to skip removing the selection
3384 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3393 lvItem
.stateMask
= LVIS_SELECTED
;
3395 /* need to clone the DPA because callbacks can change it */
3396 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3397 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3398 while(iterator_next(&i
))
3399 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3400 /* note that the iterator destructor will free the cloned range */
3401 iterator_destroy(&i
);
3406 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3410 if (!(toSkip
= ranges_create(1))) return FALSE
;
3411 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3412 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3413 ranges_destroy(toSkip
);
3417 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3419 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3424 * Retrieves the number of items that are marked as selected.
3427 * [I] infoPtr : valid pointer to the listview structure
3430 * Number of items selected.
3432 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3434 INT nSelectedCount
= 0;
3436 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3439 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3441 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3446 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3448 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3449 return nSelectedCount
;
3454 * Manages the item focus.
3457 * [I] infoPtr : valid pointer to the listview structure
3458 * [I] nItem : item index
3461 * TRUE : focused item changed
3462 * FALSE : focused item has NOT changed
3464 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3466 INT oldFocus
= infoPtr
->nFocusedItem
;
3469 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3471 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3472 lvItem
.stateMask
= LVIS_FOCUSED
;
3473 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3475 return oldFocus
!= infoPtr
->nFocusedItem
;
3478 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3480 if (nShiftItem
< nItem
) return nShiftItem
;
3482 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3484 if (direction
> 0) return nShiftItem
+ direction
;
3486 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3489 /* This function updates focus index.
3492 focus : current focus index
3493 item : index of item to be added/removed
3494 direction : add/remove flag
3496 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3498 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3500 infoPtr
->bDoChangeNotify
= FALSE
;
3501 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3502 if (focus
!= infoPtr
->nFocusedItem
)
3503 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3504 infoPtr
->bDoChangeNotify
= old_change
;
3509 * Updates the various indices after an item has been inserted or deleted.
3512 * [I] infoPtr : valid pointer to the listview structure
3513 * [I] nItem : item index
3514 * [I] direction : Direction of shift, +1 or -1.
3519 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3521 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3523 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3524 assert(abs(direction
) == 1);
3525 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3527 /* But we are not supposed to modify nHotItem! */
3532 * Adds a block of selections.
3535 * [I] infoPtr : valid pointer to the listview structure
3536 * [I] nItem : item index
3539 * Whether the window is still valid.
3541 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3543 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3544 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3545 HWND hwndSelf
= infoPtr
->hwndSelf
;
3546 NMLVODSTATECHANGE nmlv
;
3551 /* Temporarily disable change notification
3552 * If the control is LVS_OWNERDATA, we need to send
3553 * only one LVN_ODSTATECHANGED notification.
3554 * See MSDN documentation for LVN_ITEMCHANGED.
3556 bOldChange
= infoPtr
->bDoChangeNotify
;
3557 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3559 if (nFirst
== -1) nFirst
= nItem
;
3561 item
.state
= LVIS_SELECTED
;
3562 item
.stateMask
= LVIS_SELECTED
;
3564 for (i
= nFirst
; i
<= nLast
; i
++)
3565 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3567 ZeroMemory(&nmlv
, sizeof(nmlv
));
3568 nmlv
.iFrom
= nFirst
;
3571 nmlv
.uNewState
= item
.state
;
3573 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3574 if (!IsWindow(hwndSelf
))
3576 infoPtr
->bDoChangeNotify
= bOldChange
;
3583 * Sets a single group selection.
3586 * [I] infoPtr : valid pointer to the listview structure
3587 * [I] nItem : item index
3592 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3599 if (!(selection
= ranges_create(100))) return;
3601 item
.state
= LVIS_SELECTED
;
3602 item
.stateMask
= LVIS_SELECTED
;
3604 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3606 if (infoPtr
->nSelectionMark
== -1)
3608 infoPtr
->nSelectionMark
= nItem
;
3609 ranges_additem(selection
, nItem
);
3615 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3616 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3617 ranges_add(selection
, sel
);
3622 RECT rcItem
, rcSel
, rcSelMark
;
3625 rcItem
.left
= LVIR_BOUNDS
;
3626 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3627 ranges_destroy (selection
);
3630 rcSelMark
.left
= LVIR_BOUNDS
;
3631 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3632 ranges_destroy (selection
);
3635 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3636 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3637 while(iterator_next(&i
))
3639 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3640 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3642 iterator_destroy(&i
);
3645 /* disable per item notifications on LVS_OWNERDATA style
3646 FIXME: single LVN_ODSTATECHANGED should be used */
3647 bOldChange
= infoPtr
->bDoChangeNotify
;
3648 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3650 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3653 iterator_rangesitems(&i
, selection
);
3654 while(iterator_next(&i
))
3655 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3656 /* this will also destroy the selection */
3657 iterator_destroy(&i
);
3659 infoPtr
->bDoChangeNotify
= bOldChange
;
3661 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3666 * Sets a single selection.
3669 * [I] infoPtr : valid pointer to the listview structure
3670 * [I] nItem : item index
3675 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3679 TRACE("nItem=%d\n", nItem
);
3681 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3683 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3684 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3685 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3687 infoPtr
->nSelectionMark
= nItem
;
3692 * Set selection(s) with keyboard.
3695 * [I] infoPtr : valid pointer to the listview structure
3696 * [I] nItem : item index
3697 * [I] space : VK_SPACE code sent
3700 * SUCCESS : TRUE (needs to be repainted)
3701 * FAILURE : FALSE (nothing has changed)
3703 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3705 /* FIXME: pass in the state */
3706 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3707 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3708 BOOL bResult
= FALSE
;
3710 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3711 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3715 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3716 LISTVIEW_SetSelection(infoPtr
, nItem
);
3720 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3724 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3725 lvItem
.stateMask
= LVIS_SELECTED
;
3728 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3729 if (lvItem
.state
& LVIS_SELECTED
)
3730 infoPtr
->nSelectionMark
= nItem
;
3732 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3735 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3738 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3742 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3744 LVHITTESTINFO lvHitTestInfo
;
3746 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3747 lvHitTestInfo
.pt
.x
= pt
.x
;
3748 lvHitTestInfo
.pt
.y
= pt
.y
;
3750 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3752 lpLVItem
->mask
= LVIF_PARAM
;
3753 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3754 lpLVItem
->iSubItem
= 0;
3756 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3759 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3761 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3762 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3763 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3768 * Called when the mouse is being actively tracked and has hovered for a specified
3772 * [I] infoPtr : valid pointer to the listview structure
3773 * [I] fwKeys : key indicator
3774 * [I] x,y : mouse position
3777 * 0 if the message was processed, non-zero if there was an error
3780 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3781 * over the item for a certain period of time.
3784 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3788 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3790 if (LISTVIEW_IsHotTracking(infoPtr
))
3798 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3799 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3801 SetFocus(infoPtr
->hwndSelf
);
3807 #define SCROLL_LEFT 0x1
3808 #define SCROLL_RIGHT 0x2
3809 #define SCROLL_UP 0x4
3810 #define SCROLL_DOWN 0x8
3814 * Utility routine to draw and highlight items within a marquee selection rectangle.
3817 * [I] infoPtr : valid pointer to the listview structure
3818 * [I] coords_orig : original co-ordinates of the cursor
3819 * [I] coords_offs : offsetted coordinates of the cursor
3820 * [I] offset : offset amount
3821 * [I] scroll : Bitmask of which directions we should scroll, if at all
3826 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3827 const POINT
*coords_offs
, const POINT
*offset
,
3830 BOOL controlDown
= FALSE
;
3832 ITERATOR old_elems
, new_elems
;
3835 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3837 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3838 rect
.right
= coords_offs
->x
;
3842 rect
.left
= coords_offs
->x
;
3843 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3846 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3848 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3849 rect
.bottom
= coords_offs
->y
;
3853 rect
.top
= coords_offs
->y
;
3854 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3857 /* Cancel out the old marquee rectangle and draw the new one */
3858 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3860 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3861 the cursor is further away */
3863 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3864 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3866 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3867 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3869 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3870 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3872 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3873 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3875 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3877 infoPtr
->marqueeRect
= rect
;
3878 infoPtr
->marqueeDrawRect
= rect
;
3879 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3881 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3882 iterator_remove_common_items(&old_elems
, &new_elems
);
3884 /* Iterate over no longer selected items */
3885 while (iterator_next(&old_elems
))
3887 if (old_elems
.nItem
> -1)
3889 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3892 item
.state
= LVIS_SELECTED
;
3894 item
.stateMask
= LVIS_SELECTED
;
3896 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3899 iterator_destroy(&old_elems
);
3902 /* Iterate over newly selected items */
3903 if (GetKeyState(VK_CONTROL
) & 0x8000)
3906 while (iterator_next(&new_elems
))
3908 if (new_elems
.nItem
> -1)
3910 /* If CTRL is pressed, invert. If not, always select the item. */
3911 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3914 item
.state
= LVIS_SELECTED
;
3916 item
.stateMask
= LVIS_SELECTED
;
3918 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3921 iterator_destroy(&new_elems
);
3923 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3928 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3929 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3932 * [I] hwnd : Handle to the listview
3933 * [I] uMsg : WM_TIMER (ignored)
3934 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3935 * [I] dwTimer : The elapsed time (ignored)
3940 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3942 LISTVIEW_INFO
*infoPtr
;
3943 SCROLLINFO scrollInfo
;
3949 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3954 /* Get the current cursor position and convert to client coordinates */
3955 GetCursorPos(&coords_orig
);
3956 ScreenToClient(hWnd
, &coords_orig
);
3958 /* Ensure coordinates are within client bounds */
3959 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3960 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3963 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3965 /* Offset coordinates by the appropriate amount */
3966 coords_offs
.x
-= offset
.x
;
3967 coords_offs
.y
-= offset
.y
;
3969 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3970 scrollInfo
.fMask
= SIF_ALL
;
3972 /* Work out in which directions we can scroll */
3973 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3975 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3976 scroll
|= SCROLL_UP
;
3978 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3979 scroll
|= SCROLL_DOWN
;
3982 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3984 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3985 scroll
|= SCROLL_LEFT
;
3987 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3988 scroll
|= SCROLL_RIGHT
;
3991 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3992 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3993 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3994 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3996 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
4002 * Called whenever WM_MOUSEMOVE is received.
4005 * [I] infoPtr : valid pointer to the listview structure
4006 * [I] fwKeys : key indicator
4007 * [I] x,y : mouse position
4010 * 0 if the message is processed, non-zero if there was an error
4012 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4018 if (!(fwKeys
& MK_LBUTTON
))
4019 infoPtr
->bLButtonDown
= FALSE
;
4021 if (infoPtr
->bLButtonDown
)
4023 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4024 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4026 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4028 if (infoPtr
->bMarqueeSelect
)
4038 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4040 /* Ensure coordinates are within client bounds */
4041 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4042 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4044 /* Offset coordinates by the appropriate amount */
4045 coords_offs
.x
-= offset
.x
;
4046 coords_offs
.y
-= offset
.y
;
4048 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4049 move the mouse again */
4051 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4052 (y
>= infoPtr
->rcList
.bottom
))
4054 if (!infoPtr
->bScrolling
)
4056 infoPtr
->bScrolling
= TRUE
;
4057 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4062 infoPtr
->bScrolling
= FALSE
;
4063 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4066 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4074 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4076 /* reset item marker */
4077 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4078 infoPtr
->nLButtonDownItem
= -1;
4080 if (!PtInRect(&rect
, pt
))
4082 /* this path covers the following:
4083 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4084 2. change focus with keys
4085 3. move mouse over item from step 1 selects it and moves focus on it */
4086 if (infoPtr
->nLButtonDownItem
!= -1 &&
4087 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4091 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4092 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4094 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4095 infoPtr
->nLButtonDownItem
= -1;
4098 if (!infoPtr
->bDragging
)
4100 ht
.pt
= infoPtr
->ptClickPos
;
4101 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4103 /* If the click is outside the range of an item, begin a
4104 highlight. If not, begin an item drag. */
4109 /* If we're allowing multiple selections, send notification.
4110 If return value is non-zero, cancel. */
4111 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4113 /* Store the absolute coordinates of the click */
4115 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4117 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4118 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4120 /* Begin selection and capture mouse */
4121 infoPtr
->bMarqueeSelect
= TRUE
;
4122 SetCapture(infoPtr
->hwndSelf
);
4129 ZeroMemory(&nmlv
, sizeof(nmlv
));
4130 nmlv
.iItem
= ht
.iItem
;
4131 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4133 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4134 infoPtr
->bDragging
= TRUE
;
4142 /* see if we are supposed to be tracking mouse hovering */
4143 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4144 TRACKMOUSEEVENT trackinfo
;
4147 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4148 trackinfo
.dwFlags
= TME_QUERY
;
4150 /* see if we are already tracking this hwnd */
4151 _TrackMouseEvent(&trackinfo
);
4154 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
4157 if((trackinfo
.dwFlags
& flags
) != flags
|| trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4158 trackinfo
.dwFlags
= flags
;
4159 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4160 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4162 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4163 _TrackMouseEvent(&trackinfo
);
4172 * Tests whether the item is assignable to a list with style lStyle
4174 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4176 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4177 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4178 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4186 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4189 * [I] infoPtr : valid pointer to the listview structure
4190 * [I] lpLVItem : valid pointer to new item attributes
4191 * [I] isNew : the item being set is being inserted
4192 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4193 * [O] bChanged : will be set to TRUE if the item really changed
4199 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4205 /* stateMask is ignored for LVM_INSERTITEM */
4206 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4210 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4212 if (lpLVItem
->mask
== 0) return TRUE
;
4214 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4216 /* a virtual listview only stores selection and focus */
4217 if (lpLVItem
->mask
& ~LVIF_STATE
)
4223 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4224 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4228 /* we need to get the lParam and state of the item */
4229 item
.iItem
= lpLVItem
->iItem
;
4230 item
.iSubItem
= lpLVItem
->iSubItem
;
4231 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4232 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4236 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4238 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4239 /* determine what fields will change */
4240 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4241 uChanged
|= LVIF_STATE
;
4243 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4244 uChanged
|= LVIF_IMAGE
;
4246 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4247 uChanged
|= LVIF_PARAM
;
4249 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4250 uChanged
|= LVIF_INDENT
;
4252 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4253 uChanged
|= LVIF_TEXT
;
4255 TRACE("change mask=0x%x\n", uChanged
);
4257 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4258 nmlv
.iItem
= lpLVItem
->iItem
;
4259 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4260 nmlv
.uOldState
= item
.state
;
4261 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4262 nmlv
.lParam
= item
.lParam
;
4264 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4265 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4266 are enabled. Even nothing really changed we still need to send this,
4267 in this case uChanged mask is just set to passed item mask. */
4268 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4270 HWND hwndSelf
= infoPtr
->hwndSelf
;
4272 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4274 if (!IsWindow(hwndSelf
))
4278 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4279 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4280 /* this means we won't hit a focus change path later */
4281 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4283 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4284 infoPtr
->nFocusedItem
++;
4287 if (!uChanged
) return TRUE
;
4290 /* copy information */
4291 if (lpLVItem
->mask
& LVIF_TEXT
)
4292 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4294 if (lpLVItem
->mask
& LVIF_IMAGE
)
4295 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4297 if (lpLVItem
->mask
& LVIF_PARAM
)
4298 lpItem
->lParam
= lpLVItem
->lParam
;
4300 if (lpLVItem
->mask
& LVIF_INDENT
)
4301 lpItem
->iIndent
= lpLVItem
->iIndent
;
4303 if (uChanged
& LVIF_STATE
)
4305 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4307 lpItem
->state
&= ~stateMask
;
4308 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4310 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4312 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4313 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4315 else if (stateMask
& LVIS_SELECTED
)
4317 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4319 /* If we are asked to change focus, and we manage it, do it.
4320 It's important to have all new item data stored at this point,
4321 because changing existing focus could result in a redrawing operation,
4322 which in turn could ask for disp data, application should see all data
4323 for inserted item when processing LVN_GETDISPINFO.
4325 The way this works application will see nested item change notifications -
4326 changed item notifications interrupted by ones from item losing focus. */
4327 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4329 if (lpLVItem
->state
& LVIS_FOCUSED
)
4331 /* update selection mark */
4332 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4333 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4335 if (infoPtr
->nFocusedItem
!= -1)
4337 /* remove current focus */
4338 item
.mask
= LVIF_STATE
;
4340 item
.stateMask
= LVIS_FOCUSED
;
4342 /* recurse with redrawing an item */
4343 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4346 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4347 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4349 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4351 infoPtr
->nFocusedItem
= -1;
4356 /* if we're inserting the item, we're done */
4357 if (isNew
) return TRUE
;
4359 /* send LVN_ITEMCHANGED notification */
4360 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4361 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4368 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4371 * [I] infoPtr : valid pointer to the listview structure
4372 * [I] lpLVItem : valid pointer to new subitem attributes
4373 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4374 * [O] bChanged : will be set to TRUE if the item really changed
4380 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4383 SUBITEM_INFO
*lpSubItem
;
4385 /* we do not support subitems for virtual listviews */
4386 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4388 /* set subitem only if column is present */
4389 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4391 /* First do some sanity checks */
4392 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4393 particularly useful. We currently do not actually do anything with
4394 the flag on subitems.
4396 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4397 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4399 /* get the subitem structure, and create it if not there */
4400 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4401 assert (hdpaSubItems
);
4403 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4406 SUBITEM_INFO
*tmpSubItem
;
4409 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4410 if (!lpSubItem
) return FALSE
;
4411 /* we could binary search here, if need be...*/
4412 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4414 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4415 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4417 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4422 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4423 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4427 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4429 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4433 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4435 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4444 * Sets item attributes.
4447 * [I] infoPtr : valid pointer to the listview structure
4448 * [I] lpLVItem : new item attributes
4449 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4455 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4457 HWND hwndSelf
= infoPtr
->hwndSelf
;
4458 LPWSTR pszText
= NULL
;
4459 BOOL bResult
, bChanged
= FALSE
;
4462 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4464 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4467 /* Store old item area */
4468 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4470 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4471 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4473 pszText
= lpLVItem
->pszText
;
4474 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4477 /* actually set the fields */
4478 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4480 if (lpLVItem
->iSubItem
)
4481 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4483 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4484 if (!IsWindow(hwndSelf
))
4487 /* redraw item, if necessary */
4488 if (bChanged
&& !infoPtr
->bIsDrawing
)
4490 /* this little optimization eliminates some nasty flicker */
4491 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4492 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4493 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4494 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4497 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4498 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4504 textfreeT(lpLVItem
->pszText
, isW
);
4505 lpLVItem
->pszText
= pszText
;
4513 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4516 * [I] infoPtr : valid pointer to the listview structure
4521 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4524 SCROLLINFO scrollInfo
;
4526 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4527 scrollInfo
.fMask
= SIF_POS
;
4529 if (infoPtr
->uView
== LV_VIEW_LIST
)
4531 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4532 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4534 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4536 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4537 nItem
= scrollInfo
.nPos
;
4541 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4542 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4545 TRACE("nItem=%d\n", nItem
);
4553 * Erases the background of the given rectangle
4556 * [I] infoPtr : valid pointer to the listview structure
4557 * [I] hdc : device context handle
4558 * [I] lprcBox : clipping rectangle
4564 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4566 if (!infoPtr
->hBkBrush
) return FALSE
;
4568 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4570 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4573 /* Draw main item or subitem */
4574 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4576 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4577 const RECT
*background
;
4582 /* now check if we need to update the focus rectangle */
4583 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4584 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4586 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4587 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4588 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4589 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4590 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4591 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4592 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4593 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4594 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4596 /* FIXME: temporary hack */
4597 rcSelect
.left
= rcLabel
.left
;
4599 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4601 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4602 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4603 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4604 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4605 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4608 /* in icon mode, the label rect is really what we want to draw the
4610 /* in detail mode, we want to paint background for label rect when
4611 * item is not selected or listview has full row select; otherwise paint
4612 * background for text only */
4613 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4614 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4615 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4616 background
= &rcLabel
;
4618 background
= &rcSelect
;
4620 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4621 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4623 if (item
->state
& LVIS_FOCUSED
)
4625 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4627 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4629 /* we have to update left focus bound too if item isn't in leftmost column
4630 and reduce right box bound */
4631 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4635 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4637 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4638 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4639 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4641 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4642 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4645 rcSelect
.right
= rcBox
.right
;
4647 infoPtr
->rcFocus
= rcSelect
;
4650 infoPtr
->rcFocus
= rcLabel
;
4654 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4656 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4659 TRACE("stateimage=%d\n", stateimage
);
4660 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4665 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4666 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4670 TRACE("iImage=%d\n", item
->iImage
);
4672 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4673 style
= ILD_SELECTED
;
4677 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4678 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4679 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4680 style
| (item
->state
& LVIS_OVERLAYMASK
));
4683 /* Don't bother painting item being edited */
4684 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4686 /* figure out the text drawing flags */
4687 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4688 if (infoPtr
->uView
== LV_VIEW_ICON
)
4689 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4690 else if (item
->iSubItem
)
4692 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4694 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4695 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4696 default: format
|= DT_LEFT
;
4699 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4701 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4702 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4704 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4706 /* for GRIDLINES reduce the bottom so the text formats correctly */
4707 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4711 if ((!(item
->state
& LVIS_SELECTED
) || !infoPtr
->bFocus
) && (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTSHADOWTEXT
))
4712 DrawShadowText(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
, RGB(255, 255, 255), RGB(0, 0, 0), 2, 2);
4715 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4723 * [I] infoPtr : valid pointer to the listview structure
4724 * [I] hdc : device context handle
4725 * [I] nItem : item index
4726 * [I] nSubItem : subitem index
4727 * [I] pos : item position in client coordinates
4728 * [I] cdmode : custom draw mode
4734 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4736 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4737 static WCHAR callbackW
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4738 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4740 NMLVCUSTOMDRAW nmlvcd
;
4743 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4745 /* get information needed for drawing the item */
4746 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4747 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4748 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4749 lvItem
.iItem
= nItem
;
4750 lvItem
.iSubItem
= 0;
4753 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4754 lvItem
.pszText
= szDispText
;
4755 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4756 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4757 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4759 /* now check if we need to update the focus rectangle */
4760 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4761 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4763 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4764 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4766 /* Full custom draw stage sequence looks like this:
4771 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4772 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item itself
4773 - CDDS_ITEMPOSTPAINT
4778 - CDDS_ITEMPOSTPAINT
4781 /* fill in the custom draw structure */
4782 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4783 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4784 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4785 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4789 while (iterator_next(subitems
))
4791 DWORD subitemstage
= CDRF_DODEFAULT
;
4792 NMLVCUSTOMDRAW temp_nmlvcd
;
4794 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4795 if (subitems
->nItem
)
4797 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4798 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4799 lvItem
.iItem
= nItem
;
4800 lvItem
.iSubItem
= subitems
->nItem
;
4803 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4804 lvItem
.pszText
= szDispText
;
4805 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4806 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4807 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4808 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4809 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4811 /* update custom draw data */
4812 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4813 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4814 nmlvcd
.iSubItem
= subitems
->nItem
;
4817 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4818 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4821 * A selection should neither affect the colors in the post paint notification nor
4822 * affect the colors of the next drawn subitem. Copy the structure to prevent this.
4824 temp_nmlvcd
= nmlvcd
;
4825 prepaint_setup(infoPtr
, hdc
, &temp_nmlvcd
, subitems
->nItem
);
4827 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4828 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &temp_nmlvcd
, &pos
);
4830 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4831 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4836 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4837 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4841 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4843 nmlvcd
.iSubItem
= 0;
4844 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4852 * Draws listview items when in owner draw mode.
4855 * [I] infoPtr : valid pointer to the listview structure
4856 * [I] hdc : device context handle
4861 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4863 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4864 DWORD cditemmode
= CDRF_DODEFAULT
;
4865 NMLVCUSTOMDRAW nmlvcd
;
4866 POINT Origin
, Position
;
4872 ZeroMemory(&dis
, sizeof(dis
));
4874 /* Get scroll info once before loop */
4875 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4877 /* iterate through the invalidated rows */
4878 while(iterator_next(i
))
4880 item
.iItem
= i
->nItem
;
4882 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4883 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4884 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4886 dis
.CtlType
= ODT_LISTVIEW
;
4888 dis
.itemID
= item
.iItem
;
4889 dis
.itemAction
= ODA_DRAWENTIRE
;
4891 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4892 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4893 dis
.hwndItem
= infoPtr
->hwndSelf
;
4895 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4896 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4897 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4898 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4899 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4900 dis
.itemData
= item
.lParam
;
4902 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4905 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4906 * structure for the rest. of the paint cycle
4908 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4909 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4910 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4912 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4914 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4915 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4918 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4919 notify_postpaint(infoPtr
, &nmlvcd
);
4925 * Draws listview items when in report display mode.
4928 * [I] infoPtr : valid pointer to the listview structure
4929 * [I] hdc : device context handle
4930 * [I] cdmode : custom draw mode
4935 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4938 RECT rcClip
, rcItem
;
4946 /* figure out what to draw */
4947 rgntype
= GetClipBox(hdc
, &rcClip
);
4948 if (rgntype
== NULLREGION
) return;
4950 /* Get scroll info once before loop */
4951 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4953 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4955 /* narrow down the columns we need to paint */
4956 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4958 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4960 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4961 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4962 ranges_additem(colRanges
, index
);
4964 iterator_rangesitems(&j
, colRanges
);
4966 /* in full row select, we _have_ to draw the main item */
4967 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4970 /* iterate through the invalidated rows */
4971 while(iterator_next(i
))
4977 SelectObject(hdc
, infoPtr
->hFont
);
4978 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4979 Position
.x
= Origin
.x
;
4980 Position
.y
+= Origin
.y
;
4982 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4984 /* iterate through the invalidated columns */
4985 while(iterator_next(&j
))
4987 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4989 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4992 rcItem
.bottom
= infoPtr
->nItemHeight
;
4993 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4994 if (!RectVisible(hdc
, &rcItem
)) continue;
4997 ranges_additem(subitems
, j
.nItem
);
5000 iterator_rangesitems(&k
, subitems
);
5001 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
5002 iterator_destroy(&k
);
5004 iterator_destroy(&j
);
5009 * Draws the gridlines if necessary when in report display mode.
5012 * [I] infoPtr : valid pointer to the listview structure
5013 * [I] hdc : device context handle
5018 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
5024 RECT rcClip
, rcItem
= {0};
5032 /* figure out what to draw */
5033 rgntype
= GetClipBox(hdc
, &rcClip
);
5034 if (rgntype
== NULLREGION
) return;
5036 /* Get scroll info once before loop */
5037 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5039 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5041 /* narrow down the columns we need to paint */
5042 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5044 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5046 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5047 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5048 ranges_additem(colRanges
, index
);
5051 /* is right most vertical line visible? */
5052 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5054 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5055 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5056 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5059 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5061 hOldPen
= SelectObject ( hdc
, hPen
);
5063 /* draw the vertical lines for the columns */
5064 iterator_rangesitems(&j
, colRanges
);
5065 while(iterator_next(&j
))
5067 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5068 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5069 rcItem
.left
+= Origin
.x
;
5070 rcItem
.right
+= Origin
.x
;
5071 rcItem
.top
= infoPtr
->rcList
.top
;
5072 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5073 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5074 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5075 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5077 iterator_destroy(&j
);
5078 /* draw rightmost grid line if visible */
5081 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5082 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5083 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5085 rcItem
.right
+= Origin
.x
;
5087 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5088 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5091 /* draw the horizontal lines for the rows */
5092 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5093 rcItem
.left
= infoPtr
->rcList
.left
;
5094 rcItem
.right
= infoPtr
->rcList
.right
;
5095 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5097 rcItem
.bottom
= rcItem
.top
= y
;
5098 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5099 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5100 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5103 SelectObject( hdc
, hOldPen
);
5104 DeleteObject( hPen
);
5107 ranges_destroy(colRanges
);
5112 * Draws listview items when in list display mode.
5115 * [I] infoPtr : valid pointer to the listview structure
5116 * [I] hdc : device context handle
5117 * [I] cdmode : custom draw mode
5122 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5124 POINT Origin
, Position
;
5126 /* Get scroll info once before loop */
5127 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5129 while(iterator_prev(i
))
5131 SelectObject(hdc
, infoPtr
->hFont
);
5132 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5133 Position
.x
+= Origin
.x
;
5134 Position
.y
+= Origin
.y
;
5136 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5143 * Draws listview items.
5146 * [I] infoPtr : valid pointer to the listview structure
5147 * [I] hdc : device context handle
5148 * [I] prcErase : rect to be erased before refresh (may be NULL)
5153 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5155 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5156 NMLVCUSTOMDRAW nmlvcd
;
5163 HBITMAP hbmp
= NULL
;
5166 LISTVIEW_DUMP(infoPtr
);
5168 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5169 TRACE("double buffering\n");
5171 hdc
= CreateCompatibleDC(hdcOrig
);
5173 ERR("Failed to create DC for backbuffer\n");
5176 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5177 infoPtr
->rcList
.bottom
);
5179 ERR("Failed to create bitmap for backbuffer\n");
5184 SelectObject(hdc
, hbmp
);
5185 SelectObject(hdc
, infoPtr
->hFont
);
5187 if(GetClipBox(hdcOrig
, &rcClient
))
5188 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5190 /* Save dc values we're gonna trash while drawing
5191 * FIXME: Should be done in LISTVIEW_DrawItem() */
5192 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5193 oldBkMode
= GetBkMode(hdc
);
5194 oldBkColor
= GetBkColor(hdc
);
5195 oldTextColor
= GetTextColor(hdc
);
5198 infoPtr
->bIsDrawing
= TRUE
;
5201 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5202 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5203 /* If no erasing was done (usually because RedrawWindow was called
5204 * with RDW_INVALIDATE only) we need to copy the old contents into
5205 * the backbuffer before continuing. */
5206 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5207 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5208 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5209 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5212 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5213 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5214 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5215 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5217 /* nothing to draw */
5218 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5220 /* figure out what we need to draw */
5221 iterator_visibleitems(&i
, infoPtr
, hdc
);
5222 range
= iterator_range(&i
);
5224 /* send cache hint notification */
5225 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5229 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5230 nmlv
.iFrom
= range
.lower
;
5231 nmlv
.iTo
= range
.upper
- 1;
5232 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5235 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5236 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5239 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5240 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5241 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5242 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5244 /* if we have a focus rect and it's visible, draw it */
5245 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5246 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5247 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5249 iterator_destroy(&i
);
5252 /* For LVS_EX_GRIDLINES go and draw lines */
5253 /* This includes the case where there were *no* items */
5254 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5255 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5257 /* Draw marquee rectangle if appropriate */
5258 if (infoPtr
->bMarqueeSelect
)
5260 SetBkColor(hdc
, RGB(255, 255, 255));
5261 SetTextColor(hdc
, RGB(0, 0, 0));
5262 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5265 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5266 notify_postpaint(infoPtr
, &nmlvcd
);
5269 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5270 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5271 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5272 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5277 SelectObject(hdc
, hOldFont
);
5278 SetBkMode(hdc
, oldBkMode
);
5279 SetBkColor(hdc
, oldBkColor
);
5280 SetTextColor(hdc
, oldTextColor
);
5283 infoPtr
->bIsDrawing
= FALSE
;
5289 * Calculates the approximate width and height of a given number of items.
5292 * [I] infoPtr : valid pointer to the listview structure
5293 * [I] nItemCount : number of items
5294 * [I] wWidth : width
5295 * [I] wHeight : height
5298 * Returns a DWORD. The width in the low word and the height in high word.
5300 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5301 WORD wWidth
, WORD wHeight
)
5303 DWORD dwViewRect
= 0;
5305 if (nItemCount
== -1)
5306 nItemCount
= infoPtr
->nItemCount
;
5308 if (infoPtr
->uView
== LV_VIEW_LIST
)
5310 INT nItemCountPerColumn
= 1;
5311 INT nColumnCount
= 0;
5313 if (wHeight
== 0xFFFF)
5315 /* use current height */
5316 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5319 if (wHeight
< infoPtr
->nItemHeight
)
5320 wHeight
= infoPtr
->nItemHeight
;
5324 if (infoPtr
->nItemHeight
> 0)
5326 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5327 if (nItemCountPerColumn
== 0)
5328 nItemCountPerColumn
= 1;
5330 if (nItemCount
% nItemCountPerColumn
!= 0)
5331 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5333 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5337 /* Microsoft padding magic */
5338 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5339 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5341 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5343 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5347 if (infoPtr
->nItemCount
> 0)
5349 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5350 wWidth
= rcBox
.right
- rcBox
.left
;
5351 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5355 /* use current height and width */
5356 if (wHeight
== 0xffff)
5357 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5358 if (wWidth
== 0xffff)
5359 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5362 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5364 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5370 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5371 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5373 if (wWidth
== 0xffff)
5374 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5376 if (wWidth
< nItemWidth
)
5377 wWidth
= nItemWidth
;
5379 cols
= wWidth
/ nItemWidth
;
5380 if (cols
> nItemCount
)
5387 rows
= nItemCount
/ cols
;
5388 if (nItemCount
% cols
)
5394 wHeight
= (nItemHeight
* rows
)+2;
5395 wWidth
= (nItemWidth
* cols
)+2;
5397 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5399 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5400 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5407 * Cancel edit label with saving item text.
5410 * [I] infoPtr : valid pointer to the listview structure
5413 * Always returns TRUE.
5415 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5417 if (infoPtr
->hwndEdit
)
5419 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5420 HWND edit
= infoPtr
->hwndEdit
;
5422 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5423 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5431 * Create a drag image list for the specified item.
5434 * [I] infoPtr : valid pointer to the listview structure
5435 * [I] iItem : index of item
5436 * [O] lppt : Upper-left corner of the image
5439 * Returns a handle to the image list if successful, NULL otherwise.
5441 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5447 HBITMAP hbmp
, hOldbmp
;
5449 HIMAGELIST dragList
= 0;
5450 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5452 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5455 rcItem
.left
= LVIR_BOUNDS
;
5456 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5459 lppt
->x
= rcItem
.left
;
5460 lppt
->y
= rcItem
.top
;
5462 size
.cx
= rcItem
.right
- rcItem
.left
;
5463 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5465 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5466 hdc
= CreateCompatibleDC(hdcOrig
);
5467 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5468 hOldbmp
= SelectObject(hdc
, hbmp
);
5469 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5471 SetRect(&rcItem
, 0, 0, size
.cx
, size
.cy
);
5472 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5475 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5477 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5478 SelectObject(hdc
, hOldbmp
);
5479 ImageList_Add(dragList
, hbmp
, 0);
5482 SelectObject(hdc
, hOldbmp
);
5484 SelectObject(hdc
, hOldFont
);
5487 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5489 TRACE("ret=%p\n", dragList
);
5497 * Removes all listview items and subitems.
5500 * [I] infoPtr : valid pointer to the listview structure
5506 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5508 HDPA hdpaSubItems
= NULL
;
5509 BOOL suppress
= FALSE
;
5517 /* we do it directly, to avoid notifications */
5518 ranges_clear(infoPtr
->selectionRanges
);
5519 infoPtr
->nSelectionMark
= -1;
5520 infoPtr
->nFocusedItem
= -1;
5521 SetRectEmpty(&infoPtr
->rcFocus
);
5522 /* But we are supposed to leave nHotItem as is! */
5524 /* send LVN_DELETEALLITEMS notification */
5525 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5529 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5531 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5534 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5536 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5538 /* send LVN_DELETEITEM notification, if not suppressed
5539 and if it is not a virtual listview */
5540 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5541 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5542 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5543 /* free id struct */
5544 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5545 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5546 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5548 /* both item and subitem start with ITEMHDR header */
5549 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5551 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5552 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5555 DPA_Destroy(hdpaSubItems
);
5556 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5558 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5559 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5560 infoPtr
->nItemCount
--;
5565 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5566 LISTVIEW_UpdateScroll(infoPtr
);
5568 LISTVIEW_InvalidateList(infoPtr
);
5575 * Scrolls, and updates the columns, when a column is changing width.
5578 * [I] infoPtr : valid pointer to the listview structure
5579 * [I] nColumn : column to scroll
5580 * [I] dx : amount of scroll, in pixels
5585 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5587 COLUMN_INFO
*lpColumnInfo
;
5593 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5594 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5595 rcCol
= lpColumnInfo
->rcHeader
;
5596 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5597 rcCol
.left
= rcCol
.right
;
5599 /* adjust the other columns */
5600 hdi
.mask
= HDI_ORDER
;
5601 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5603 INT nOrder
= hdi
.iOrder
;
5604 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5606 hdi
.mask
= HDI_ORDER
;
5607 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5608 if (hdi
.iOrder
>= nOrder
) {
5609 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5610 lpColumnInfo
->rcHeader
.left
+= dx
;
5611 lpColumnInfo
->rcHeader
.right
+= dx
;
5616 /* do not update screen if not in report mode */
5617 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5619 /* Need to reset the item width when inserting a new column */
5620 infoPtr
->nItemWidth
+= dx
;
5622 LISTVIEW_UpdateScroll(infoPtr
);
5623 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5625 /* scroll to cover the deleted column, and invalidate for redraw */
5626 rcOld
= infoPtr
->rcList
;
5627 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5628 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5633 * Removes a column from the listview control.
5636 * [I] infoPtr : valid pointer to the listview structure
5637 * [I] nColumn : column index
5643 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5647 TRACE("nColumn=%d\n", nColumn
);
5649 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5652 /* While the MSDN specifically says that column zero should not be deleted,
5653 what actually happens is that the column itself is deleted but no items or subitems
5657 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5659 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5662 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5663 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5665 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5667 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5669 INT nItem
, nSubItem
, i
;
5671 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5673 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5676 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5678 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5679 if (lpSubItem
->iSubItem
== nColumn
)
5682 lpDelItem
= lpSubItem
;
5684 else if (lpSubItem
->iSubItem
> nColumn
)
5686 lpSubItem
->iSubItem
--;
5690 /* if we found our subitem, zap it */
5694 if (is_text(lpDelItem
->hdr
.pszText
))
5695 Free(lpDelItem
->hdr
.pszText
);
5700 /* free dpa memory */
5701 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5706 /* update the other column info */
5707 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5708 LISTVIEW_InvalidateList(infoPtr
);
5710 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5711 LISTVIEW_UpdateItemSize(infoPtr
);
5718 * Invalidates the listview after an item's insertion or deletion.
5721 * [I] infoPtr : valid pointer to the listview structure
5722 * [I] nItem : item index
5723 * [I] dir : -1 if deleting, 1 if inserting
5728 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5730 INT nPerCol
, nItemCol
, nItemRow
;
5734 /* if we don't refresh, what's the point of scrolling? */
5735 if (!is_redrawing(infoPtr
)) return;
5737 assert (abs(dir
) == 1);
5739 /* arrange icons if autoarrange is on */
5740 if (is_autoarrange(infoPtr
))
5742 BOOL arrange
= TRUE
;
5743 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5744 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5745 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5748 /* scrollbars need updating */
5749 LISTVIEW_UpdateScroll(infoPtr
);
5751 /* figure out the item's position */
5752 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5753 nPerCol
= infoPtr
->nItemCount
+ 1;
5754 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5755 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5756 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5759 nItemCol
= nItem
/ nPerCol
;
5760 nItemRow
= nItem
% nPerCol
;
5761 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5763 /* move the items below up a slot */
5764 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5765 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5766 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5767 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5768 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5769 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5770 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5772 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5773 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5776 /* report has only that column, so we're done */
5777 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5779 /* now for LISTs, we have to deal with the columns to the right */
5780 SetRect(&rcScroll
, (nItemCol
+ 1) * infoPtr
->nItemWidth
, 0,
5781 (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
,
5782 nPerCol
* infoPtr
->nItemHeight
);
5783 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5784 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5785 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5790 * Removes an item from the listview control.
5793 * [I] infoPtr : valid pointer to the listview structure
5794 * [I] nItem : item index
5800 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5803 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5804 INT focus
= infoPtr
->nFocusedItem
;
5806 TRACE("(nItem=%d)\n", nItem
);
5808 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5810 /* remove selection, and focus */
5812 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5813 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5815 /* send LVN_DELETEITEM notification. */
5816 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5818 /* we need to do this here, because we'll be deleting stuff */
5820 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5822 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5830 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5831 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5833 /* free id struct */
5834 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5835 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5836 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5838 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5840 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5841 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5844 DPA_Destroy(hdpaSubItems
);
5849 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5850 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5853 infoPtr
->nItemCount
--;
5854 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5855 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5857 /* now is the invalidation fun */
5859 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5866 * Callback implementation for editlabel control
5869 * [I] infoPtr : valid pointer to the listview structure
5870 * [I] storeText : store edit box text as item text
5871 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5877 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5879 HWND hwndSelf
= infoPtr
->hwndSelf
;
5880 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5881 NMLVDISPINFOW dispInfo
;
5882 INT editedItem
= infoPtr
->nEditLabelItem
;
5884 WCHAR
*pszText
= NULL
;
5889 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5893 if (!(pszText
= Alloc(len
* (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5897 GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
);
5899 GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
);
5903 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5905 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5906 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5907 dispInfo
.item
.iItem
= editedItem
;
5908 dispInfo
.item
.iSubItem
= 0;
5909 dispInfo
.item
.stateMask
= ~0;
5910 dispInfo
.item
.pszText
= szDispText
;
5911 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5912 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5919 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5922 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5923 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5924 textfreeT(tmp
, FALSE
);
5927 /* add the text from the edit in */
5928 dispInfo
.item
.mask
|= LVIF_TEXT
;
5929 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5930 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5932 /* Do we need to update the Item Text */
5933 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5935 infoPtr
->nEditLabelItem
= -1;
5936 infoPtr
->hwndEdit
= 0;
5938 if (!res
) goto cleanup
;
5940 if (!IsWindow(hwndSelf
))
5945 if (!pszText
) return TRUE
;
5952 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5954 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5955 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5956 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5958 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5964 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5965 dispInfo
.item
.mask
= LVIF_TEXT
;
5966 dispInfo
.item
.iItem
= editedItem
;
5967 dispInfo
.item
.iSubItem
= 0;
5968 dispInfo
.item
.pszText
= pszText
;
5969 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5970 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5980 * Subclassed edit control windproc function
5983 * [I] hwnd : the edit window handle
5984 * [I] uMsg : the message that is to be processed
5985 * [I] wParam : first message parameter
5986 * [I] lParam : second message parameter
5987 * [I] isW : TRUE if input is Unicode
5992 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5994 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5997 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5998 hwnd
, uMsg
, wParam
, lParam
, isW
);
6003 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
6007 WNDPROC editProc
= infoPtr
->EditWndProc
;
6008 infoPtr
->EditWndProc
= 0;
6009 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
6010 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6014 if (VK_ESCAPE
== (INT
)wParam
)
6019 else if (VK_RETURN
== (INT
)wParam
)
6023 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6027 if (infoPtr
->hwndEdit
)
6028 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
6030 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6036 * Subclassed edit control Unicode windproc function
6039 * [I] hwnd : the edit window handle
6040 * [I] uMsg : the message that is to be processed
6041 * [I] wParam : first message parameter
6042 * [I] lParam : second message parameter
6046 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6048 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6053 * Subclassed edit control ANSI windproc function
6056 * [I] hwnd : the edit window handle
6057 * [I] uMsg : the message that is to be processed
6058 * [I] wParam : first message parameter
6059 * [I] lParam : second message parameter
6063 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6065 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6070 * Creates a subclassed edit control
6073 * [I] infoPtr : valid pointer to the listview structure
6074 * [I] text : initial text for the edit
6075 * [I] style : the window style
6076 * [I] isW : TRUE if input is Unicode
6080 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6082 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6083 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6086 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6088 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6090 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6092 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6094 if (!hedit
) return 0;
6096 infoPtr
->EditWndProc
= (WNDPROC
)
6097 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6098 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6100 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6101 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6108 * Begin in place editing of specified list view item
6111 * [I] infoPtr : valid pointer to the listview structure
6112 * [I] nItem : item index
6113 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6119 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6121 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6122 HWND hwndSelf
= infoPtr
->hwndSelf
;
6123 NMLVDISPINFOW dispInfo
;
6124 HFONT hOldFont
= NULL
;
6130 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6132 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6134 /* remove existing edit box */
6135 if (infoPtr
->hwndEdit
)
6137 SetFocus(infoPtr
->hwndSelf
);
6138 infoPtr
->hwndEdit
= 0;
6141 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6143 infoPtr
->nEditLabelItem
= nItem
;
6145 LISTVIEW_SetSelection(infoPtr
, nItem
);
6146 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6147 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6149 rect
.left
= LVIR_LABEL
;
6150 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6152 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6153 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6154 dispInfo
.item
.iItem
= nItem
;
6155 dispInfo
.item
.iSubItem
= 0;
6156 dispInfo
.item
.stateMask
= ~0;
6157 dispInfo
.item
.pszText
= disptextW
;
6158 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6159 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6161 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6162 if (!infoPtr
->hwndEdit
) return 0;
6164 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6166 if (!IsWindow(hwndSelf
))
6168 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6169 infoPtr
->hwndEdit
= 0;
6173 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6175 /* position and display edit box */
6176 hdc
= GetDC(infoPtr
->hwndSelf
);
6178 /* select the font to get appropriate metric dimensions */
6180 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6182 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6183 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6184 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6186 /* get string length in pixels */
6187 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6189 /* add extra spacing for the next character */
6190 GetTextMetricsW(hdc
, &tm
);
6191 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6194 SelectObject(hdc
, hOldFont
);
6196 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6198 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6201 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6202 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6203 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6204 SetFocus(infoPtr
->hwndEdit
);
6205 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6206 return infoPtr
->hwndEdit
;
6212 * Ensures the specified item is visible, scrolling into view if necessary.
6215 * [I] infoPtr : valid pointer to the listview structure
6216 * [I] nItem : item index
6217 * [I] bPartial : partially or entirely visible
6223 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6225 INT nScrollPosHeight
= 0;
6226 INT nScrollPosWidth
= 0;
6227 INT nHorzAdjust
= 0;
6228 INT nVertAdjust
= 0;
6231 RECT rcItem
, rcTemp
;
6233 rcItem
.left
= LVIR_BOUNDS
;
6234 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6236 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6238 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6240 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6241 if (infoPtr
->uView
== LV_VIEW_LIST
)
6242 nScrollPosWidth
= infoPtr
->nItemWidth
;
6243 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6244 nScrollPosWidth
= 1;
6246 if (rcItem
.left
< infoPtr
->rcList
.left
)
6249 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6254 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6258 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6260 /* scroll up/down, but not in LVS_LIST mode */
6261 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6262 nScrollPosHeight
= infoPtr
->nItemHeight
;
6263 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6264 nScrollPosHeight
= 1;
6266 if (rcItem
.top
< infoPtr
->rcList
.top
)
6269 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6274 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6278 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6280 if (nScrollPosWidth
)
6282 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6283 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6284 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6287 if (nScrollPosHeight
)
6289 INT diff
= nVertDiff
/ nScrollPosHeight
;
6290 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6291 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6299 * Searches for an item with specific characteristics.
6302 * [I] hwnd : window handle
6303 * [I] nStart : base item index
6304 * [I] lpFindInfo : item information to look for
6307 * SUCCESS : index of item
6310 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6311 const LVFINDINFOW
*lpFindInfo
)
6313 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6314 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6315 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6316 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6317 POINT Position
, Destination
;
6320 /* Search in virtual listviews should be done by application, not by
6321 listview control, so we just send LVN_ODFINDITEMW and return the result */
6322 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6326 nmlv
.iStart
= nStart
;
6327 nmlv
.lvfi
= *lpFindInfo
;
6328 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6331 if (!lpFindInfo
|| nItem
< 0) return -1;
6334 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6335 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6337 lvItem
.mask
|= LVIF_TEXT
;
6338 lvItem
.pszText
= szDispText
;
6339 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6342 if (lpFindInfo
->flags
& LVFI_WRAP
)
6345 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6346 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6351 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6352 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6353 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6354 switch(lpFindInfo
->vkDirection
)
6356 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6357 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6358 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6359 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6360 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6361 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6362 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6364 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6365 Destination
.x
= rcArea
.right
;
6366 Destination
.y
= rcArea
.bottom
;
6368 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6372 else Destination
.x
= Destination
.y
= 0;
6374 /* if LVFI_PARAM is specified, all other flags are ignored */
6375 if (lpFindInfo
->flags
& LVFI_PARAM
)
6377 lvItem
.mask
|= LVIF_PARAM
;
6379 lvItem
.mask
&= ~LVIF_TEXT
;
6383 for (; nItem
< nLast
; nItem
++)
6385 lvItem
.iItem
= nItem
;
6386 lvItem
.iSubItem
= 0;
6387 lvItem
.pszText
= szDispText
;
6388 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6390 if (lvItem
.mask
& LVIF_PARAM
)
6392 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6398 if (lvItem
.mask
& LVIF_TEXT
)
6400 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6402 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6403 if (!p
|| p
!= lvItem
.pszText
) continue;
6407 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6411 if (!bNearest
) return nItem
;
6413 /* This is very inefficient. To do a good job here,
6414 * we need a sorted array of (x,y) item positions */
6415 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6417 /* compute the distance^2 to the destination */
6418 xdist
= Destination
.x
- Position
.x
;
6419 ydist
= Destination
.y
- Position
.y
;
6420 dist
= xdist
* xdist
+ ydist
* ydist
;
6422 /* remember the distance, and item if it's closer */
6426 nNearestItem
= nItem
;
6433 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6438 return nNearestItem
;
6443 * Searches for an item with specific characteristics.
6446 * [I] hwnd : window handle
6447 * [I] nStart : base item index
6448 * [I] lpFindInfo : item information to look for
6451 * SUCCESS : index of item
6454 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6455 const LVFINDINFOA
*lpFindInfo
)
6457 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6458 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6463 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6464 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6465 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6466 textfreeT(strW
, FALSE
);
6472 * Retrieves column attributes.
6475 * [I] infoPtr : valid pointer to the listview structure
6476 * [I] nColumn : column index
6477 * [IO] lpColumn : column information
6478 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6479 * otherwise it is in fact a LPLVCOLUMNA
6485 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6487 COLUMN_INFO
*lpColumnInfo
;
6490 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6491 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6493 /* initialize memory */
6494 ZeroMemory(&hdi
, sizeof(hdi
));
6496 if (lpColumn
->mask
& LVCF_TEXT
)
6498 hdi
.mask
|= HDI_TEXT
;
6499 hdi
.pszText
= lpColumn
->pszText
;
6500 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6503 if (lpColumn
->mask
& LVCF_IMAGE
)
6504 hdi
.mask
|= HDI_IMAGE
;
6506 if (lpColumn
->mask
& LVCF_ORDER
)
6507 hdi
.mask
|= HDI_ORDER
;
6509 if (lpColumn
->mask
& LVCF_SUBITEM
)
6510 hdi
.mask
|= HDI_LPARAM
;
6512 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6514 if (lpColumn
->mask
& LVCF_FMT
)
6515 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6517 if (lpColumn
->mask
& LVCF_WIDTH
)
6518 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6520 if (lpColumn
->mask
& LVCF_IMAGE
)
6521 lpColumn
->iImage
= hdi
.iImage
;
6523 if (lpColumn
->mask
& LVCF_ORDER
)
6524 lpColumn
->iOrder
= hdi
.iOrder
;
6526 if (lpColumn
->mask
& LVCF_SUBITEM
)
6527 lpColumn
->iSubItem
= hdi
.lParam
;
6529 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6530 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6535 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6537 if (!infoPtr
->hwndHeader
) return FALSE
;
6538 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6543 * Retrieves the column width.
6546 * [I] infoPtr : valid pointer to the listview structure
6547 * [I] int : column index
6550 * SUCCESS : column width
6553 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6555 INT nColumnWidth
= 0;
6558 TRACE("nColumn=%d\n", nColumn
);
6560 /* we have a 'column' in LIST and REPORT mode only */
6561 switch(infoPtr
->uView
)
6564 nColumnWidth
= infoPtr
->nItemWidth
;
6566 case LV_VIEW_DETAILS
:
6567 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6568 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6569 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6571 hdItem
.mask
= HDI_WIDTH
;
6572 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6574 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6577 nColumnWidth
= hdItem
.cxy
;
6581 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6582 return nColumnWidth
;
6587 * In list or report display mode, retrieves the number of items that can fit
6588 * vertically in the visible area. In icon or small icon display mode,
6589 * retrieves the total number of visible items.
6592 * [I] infoPtr : valid pointer to the listview structure
6595 * Number of fully visible items.
6597 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6599 switch (infoPtr
->uView
)
6602 case LV_VIEW_SMALLICON
:
6603 return infoPtr
->nItemCount
;
6604 case LV_VIEW_DETAILS
:
6605 return LISTVIEW_GetCountPerColumn(infoPtr
);
6607 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6615 * Retrieves an image list handle.
6618 * [I] infoPtr : valid pointer to the listview structure
6619 * [I] nImageList : image list identifier
6622 * SUCCESS : image list handle
6625 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6629 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6630 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6631 case LVSIL_STATE
: return infoPtr
->himlState
;
6632 case LVSIL_GROUPHEADER
:
6633 FIXME("LVSIL_GROUPHEADER not supported\n");
6636 WARN("got unknown imagelist index - %d\n", nImageList
);
6641 /* LISTVIEW_GetISearchString */
6645 * Retrieves item attributes.
6648 * [I] hwnd : window handle
6649 * [IO] lpLVItem : item info
6650 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6651 * if FALSE, then lpLVItem is a LPLVITEMA.
6654 * This is the internal 'GetItem' interface -- it tries to
6655 * be smart and avoid text copies, if possible, by modifying
6656 * lpLVItem->pszText to point to the text string. Please note
6657 * that this is not always possible (e.g. OWNERDATA), so on
6658 * entry you *must* supply valid values for pszText, and cchTextMax.
6659 * The only difference to the documented interface is that upon
6660 * return, you should use *only* the lpLVItem->pszText, rather than
6661 * the buffer pointer you provided on input. Most code already does
6662 * that, so it's not a problem.
6663 * For the two cases when the text must be copied (that is,
6664 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6670 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6672 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6673 NMLVDISPINFOW dispInfo
;
6679 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6681 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6684 if (lpLVItem
->mask
== 0) return TRUE
;
6685 TRACE("mask=%x\n", lpLVItem
->mask
);
6687 /* make a local copy */
6688 isubitem
= lpLVItem
->iSubItem
;
6690 /* a quick optimization if all we're asked is the focus state
6691 * these queries are worth optimising since they are common,
6692 * and can be answered in constant time, without the heavy accesses */
6693 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6694 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6696 lpLVItem
->state
= 0;
6697 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6698 lpLVItem
->state
|= LVIS_FOCUSED
;
6702 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6704 /* if the app stores all the data, handle it separately */
6705 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6707 dispInfo
.item
.state
= 0;
6709 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6710 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6711 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6713 UINT mask
= lpLVItem
->mask
;
6715 /* NOTE: copy only fields which we _know_ are initialized, some apps
6716 * depend on the uninitialized fields being 0 */
6717 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6718 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6719 dispInfo
.item
.iSubItem
= isubitem
;
6720 if (lpLVItem
->mask
& LVIF_TEXT
)
6722 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6724 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6727 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6728 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6731 if (lpLVItem
->mask
& LVIF_STATE
)
6732 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6733 /* could be zeroed on LVIF_NORECOMPUTE case */
6734 if (dispInfo
.item
.mask
)
6736 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6737 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6738 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6740 /* full size structure expected - _WIN32IE >= 0x560 */
6741 *lpLVItem
= dispInfo
.item
;
6743 else if (lpLVItem
->mask
& LVIF_INDENT
)
6745 /* indent member expected - _WIN32IE >= 0x300 */
6746 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6750 /* minimal structure expected */
6751 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6753 lpLVItem
->mask
= mask
;
6754 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6758 /* make sure lParam is zeroed out */
6759 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6761 /* callback marked pointer required here */
6762 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6763 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6765 /* we store only a little state, so if we're not asked, we're done */
6766 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6768 /* if focus is handled by us, report it */
6769 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6771 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6772 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6773 lpLVItem
->state
|= LVIS_FOCUSED
;
6776 /* and do the same for selection, if we handle it */
6777 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6779 lpLVItem
->state
&= ~LVIS_SELECTED
;
6780 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6781 lpLVItem
->state
|= LVIS_SELECTED
;
6787 /* find the item and subitem structures before we proceed */
6788 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6789 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6794 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6795 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6798 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6803 pItemHdr
= &lpItem
->hdr
;
6805 /* Do we need to query the state from the app? */
6806 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6808 dispInfo
.item
.mask
|= LVIF_STATE
;
6809 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6812 /* Do we need to enquire about the image? */
6813 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6814 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6816 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6817 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6820 /* Only items support indentation */
6821 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6824 dispInfo
.item
.mask
|= LVIF_INDENT
;
6825 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6828 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6829 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6830 !is_text(pItemHdr
->pszText
))
6832 dispInfo
.item
.mask
|= LVIF_TEXT
;
6833 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6834 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6835 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6836 *dispInfo
.item
.pszText
= '\0';
6839 /* If we don't have all the requested info, query the application */
6840 if (dispInfo
.item
.mask
)
6842 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6843 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6844 dispInfo
.item
.lParam
= lpItem
->lParam
;
6845 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6846 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6849 /* we should not store values for subitems */
6850 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6852 /* Now, handle the iImage field */
6853 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6855 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6856 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6857 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6859 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6861 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6862 lpLVItem
->iImage
= pItemHdr
->iImage
;
6864 lpLVItem
->iImage
= 0;
6867 /* The pszText field */
6868 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6870 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6871 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6873 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6875 else if (lpLVItem
->mask
& LVIF_TEXT
)
6877 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6878 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6879 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6882 /* Next is the lParam field */
6883 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6885 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6886 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6887 lpItem
->lParam
= dispInfo
.item
.lParam
;
6889 else if (lpLVItem
->mask
& LVIF_PARAM
)
6890 lpLVItem
->lParam
= lpItem
->lParam
;
6892 /* if this is a subitem, we're done */
6893 if (isubitem
) return TRUE
;
6895 /* ... the state field (this one is different due to uCallbackmask) */
6896 if (lpLVItem
->mask
& LVIF_STATE
)
6898 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6899 if (dispInfo
.item
.mask
& LVIF_STATE
)
6901 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6902 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6904 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6906 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6907 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6908 lpLVItem
->state
|= LVIS_FOCUSED
;
6910 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6912 lpLVItem
->state
&= ~LVIS_SELECTED
;
6913 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6914 lpLVItem
->state
|= LVIS_SELECTED
;
6918 /* and last, but not least, the indent field */
6919 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6921 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6922 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6923 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6925 else if (lpLVItem
->mask
& LVIF_INDENT
)
6927 lpLVItem
->iIndent
= lpItem
->iIndent
;
6935 * Retrieves item attributes.
6938 * [I] hwnd : window handle
6939 * [IO] lpLVItem : item info
6940 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6941 * if FALSE, then lpLVItem is a LPLVITEMA.
6944 * This is the external 'GetItem' interface -- it properly copies
6945 * the text in the provided buffer.
6951 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6956 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6959 pszText
= lpLVItem
->pszText
;
6960 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6961 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6963 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6964 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6966 pszText
= LPSTR_TEXTCALLBACKW
;
6968 lpLVItem
->pszText
= pszText
;
6976 * Retrieves the position (upper-left) of the listview control item.
6977 * Note that for LVS_ICON style, the upper-left is that of the icon
6978 * and not the bounding box.
6981 * [I] infoPtr : valid pointer to the listview structure
6982 * [I] nItem : item index
6983 * [O] lpptPosition : coordinate information
6989 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6993 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6995 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6997 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6998 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
7000 if (infoPtr
->uView
== LV_VIEW_ICON
)
7002 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
7003 lpptPosition
->y
+= ICON_TOP_PADDING
;
7005 lpptPosition
->x
+= Origin
.x
;
7006 lpptPosition
->y
+= Origin
.y
;
7008 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
7015 * Retrieves the bounding rectangle for a listview control item.
7018 * [I] infoPtr : valid pointer to the listview structure
7019 * [I] nItem : item index
7020 * [IO] lprc : bounding rectangle coordinates
7021 * lprc->left specifies the portion of the item for which the bounding
7022 * rectangle will be retrieved.
7024 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
7025 * including the icon and label.
7028 * * Experiment shows that native control returns:
7029 * * width = min (48, length of text line)
7030 * * .left = position.x - (width - iconsize.cx)/2
7031 * * .right = .left + width
7032 * * height = #lines of text * ntmHeight + icon height + 8
7033 * * .top = position.y - 2
7034 * * .bottom = .top + height
7035 * * separation between items .y = itemSpacing.cy - height
7036 * * .x = itemSpacing.cx - width
7037 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7040 * * Experiment shows that native control returns:
7041 * * width = iconSize.cx + 16
7042 * * .left = position.x - (width - iconsize.cx)/2
7043 * * .right = .left + width
7044 * * height = iconSize.cy + 4
7045 * * .top = position.y - 2
7046 * * .bottom = .top + height
7047 * * separation between items .y = itemSpacing.cy - height
7048 * * .x = itemSpacing.cx - width
7049 * LVIR_LABEL Returns the bounding rectangle of the item text.
7052 * * Experiment shows that native control returns:
7053 * * width = text length
7054 * * .left = position.x - width/2
7055 * * .right = .left + width
7056 * * height = ntmH * linecount + 2
7057 * * .top = position.y + iconSize.cy + 6
7058 * * .bottom = .top + height
7059 * * separation between items .y = itemSpacing.cy - height
7060 * * .x = itemSpacing.cx - width
7061 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7062 * rectangles, but excludes columns in report view.
7069 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7070 * upon whether the window has the focus currently and on whether the item
7071 * is the one with the focus. Ensure that the control's record of which
7072 * item has the focus agrees with the items' records.
7074 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7076 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7077 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7078 POINT Position
, Origin
;
7082 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7084 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7086 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7087 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7089 /* Be smart and try to figure out the minimum we have to do */
7090 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7091 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7092 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7093 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7094 oversizedBox
= TRUE
;
7096 /* get what we need from the item before hand, so we make
7097 * only one request. This can speed up things, if data
7098 * is stored on the app side */
7100 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7101 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7102 lvItem
.iItem
= nItem
;
7103 lvItem
.iSubItem
= 0;
7104 lvItem
.pszText
= szDispText
;
7105 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7106 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7107 /* we got the state already up, simulate it here, to avoid a reget */
7108 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7110 lvItem
.mask
|= LVIF_STATE
;
7111 lvItem
.stateMask
= LVIS_FOCUSED
;
7112 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7115 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7116 lprc
->left
= LVIR_BOUNDS
;
7122 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7126 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7130 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7133 case LVIR_SELECTBOUNDS
:
7134 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7138 WARN("Unknown value: %d\n", lprc
->left
);
7142 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7144 if (mode
!= LVIR_BOUNDS
)
7145 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7146 Position
.y
+ Origin
.y
);
7148 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7151 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7153 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7160 * Retrieves the spacing between listview control items.
7163 * [I] infoPtr : valid pointer to the listview structure
7164 * [IO] lprc : rectangle to receive the output
7165 * on input, lprc->top = nSubItem
7166 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7168 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7169 * not only those of the first column.
7175 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7177 RECT rect
= { 0, 0, 0, 0 };
7181 if (!lprc
) return FALSE
;
7183 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7184 /* Subitem of '0' means item itself, and this works for all control view modes */
7186 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7188 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7190 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7191 /* this works for any item index, no matter if it exists or not */
7192 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7194 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7197 rect
.bottom
= infoPtr
->nItemHeight
;
7201 /* Native implementation is broken for this case and garbage is left for left and right fields,
7202 we zero them to get predictable output */
7203 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7204 lprc
->bottom
= infoPtr
->nItemHeight
;
7205 OffsetRect(lprc
, origin
.x
, y
);
7206 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7214 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7215 if (infoPtr
->himlSmall
)
7216 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7218 rect
.right
= rect
.left
;
7220 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7228 ERR("Unknown bounds=%d\n", lprc
->left
);
7232 OffsetRect(&rect
, origin
.x
, y
);
7234 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7241 * Retrieves the spacing between listview control items.
7244 * [I] infoPtr : valid pointer to the listview structure
7245 * [I] bSmall : flag for small or large icon
7248 * Horizontal + vertical spacing
7250 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7256 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7260 if (infoPtr
->uView
== LV_VIEW_ICON
)
7261 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7263 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7270 * Retrieves the state of a listview control item.
7273 * [I] infoPtr : valid pointer to the listview structure
7274 * [I] nItem : item index
7275 * [I] uMask : state mask
7278 * State specified by the mask.
7280 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7284 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7286 lvItem
.iItem
= nItem
;
7287 lvItem
.iSubItem
= 0;
7288 lvItem
.mask
= LVIF_STATE
;
7289 lvItem
.stateMask
= uMask
;
7290 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7292 return lvItem
.state
& uMask
;
7297 * Retrieves the text of a listview control item or subitem.
7300 * [I] hwnd : window handle
7301 * [I] nItem : item index
7302 * [IO] lpLVItem : item information
7303 * [I] isW : TRUE if lpLVItem is Unicode
7306 * SUCCESS : string length
7309 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7311 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7313 lpLVItem
->mask
= LVIF_TEXT
;
7314 lpLVItem
->iItem
= nItem
;
7315 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7317 return textlenT(lpLVItem
->pszText
, isW
);
7322 * Searches for an item based on properties + relationships.
7325 * [I] infoPtr : valid pointer to the listview structure
7326 * [I] nItem : item index
7327 * [I] uFlags : relationship flag
7330 * SUCCESS : item index
7333 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7336 LVFINDINFOW lvFindInfo
;
7337 INT nCountPerColumn
;
7341 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7342 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7344 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7346 if (uFlags
& LVNI_CUT
)
7349 if (uFlags
& LVNI_DROPHILITED
)
7350 uMask
|= LVIS_DROPHILITED
;
7352 if (uFlags
& LVNI_FOCUSED
)
7353 uMask
|= LVIS_FOCUSED
;
7355 if (uFlags
& LVNI_SELECTED
)
7356 uMask
|= LVIS_SELECTED
;
7358 /* if we're asked for the focused item, that's only one,
7359 * so it's worth optimizing */
7360 if (uFlags
& LVNI_FOCUSED
)
7362 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7363 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7366 if (uFlags
& LVNI_ABOVE
)
7368 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7373 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7379 /* Special case for autoarrange - move 'til the top of a list */
7380 if (is_autoarrange(infoPtr
))
7382 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7383 while (nItem
- nCountPerRow
>= 0)
7385 nItem
-= nCountPerRow
;
7386 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7391 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7392 lvFindInfo
.vkDirection
= VK_UP
;
7393 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7394 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7396 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7401 else if (uFlags
& LVNI_BELOW
)
7403 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7405 while (nItem
< infoPtr
->nItemCount
)
7408 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7414 /* Special case for autoarrange - move 'til the bottom of a list */
7415 if (is_autoarrange(infoPtr
))
7417 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7418 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7420 nItem
+= nCountPerRow
;
7421 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7426 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7427 lvFindInfo
.vkDirection
= VK_DOWN
;
7428 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7429 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7431 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7436 else if (uFlags
& LVNI_TOLEFT
)
7438 if (infoPtr
->uView
== LV_VIEW_LIST
)
7440 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7441 while (nItem
- nCountPerColumn
>= 0)
7443 nItem
-= nCountPerColumn
;
7444 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7448 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7450 /* Special case for autoarrange - move 'til the beginning of a row */
7451 if (is_autoarrange(infoPtr
))
7453 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7454 while (nItem
% nCountPerRow
> 0)
7457 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7462 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7463 lvFindInfo
.vkDirection
= VK_LEFT
;
7464 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7465 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7467 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7472 else if (uFlags
& LVNI_TORIGHT
)
7474 if (infoPtr
->uView
== LV_VIEW_LIST
)
7476 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7477 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7479 nItem
+= nCountPerColumn
;
7480 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7484 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7486 /* Special case for autoarrange - move 'til the end of a row */
7487 if (is_autoarrange(infoPtr
))
7489 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7490 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7493 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7498 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7499 lvFindInfo
.vkDirection
= VK_RIGHT
;
7500 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7501 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7503 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7512 /* search by index */
7513 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7515 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7523 /* LISTVIEW_GetNumberOfWorkAreas */
7527 * Retrieves the origin coordinates when in icon or small icon display mode.
7530 * [I] infoPtr : valid pointer to the listview structure
7531 * [O] lpptOrigin : coordinate information
7536 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7538 INT nHorzPos
= 0, nVertPos
= 0;
7539 SCROLLINFO scrollInfo
;
7541 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7542 scrollInfo
.fMask
= SIF_POS
;
7544 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7545 nHorzPos
= scrollInfo
.nPos
;
7546 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7547 nVertPos
= scrollInfo
.nPos
;
7549 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7551 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7552 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7553 if (infoPtr
->uView
== LV_VIEW_LIST
)
7554 nHorzPos
*= infoPtr
->nItemWidth
;
7555 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7556 nVertPos
*= infoPtr
->nItemHeight
;
7558 lpptOrigin
->x
-= nHorzPos
;
7559 lpptOrigin
->y
-= nVertPos
;
7561 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7566 * Retrieves the width of a string.
7569 * [I] hwnd : window handle
7570 * [I] lpszText : text string to process
7571 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7574 * SUCCESS : string width (in pixels)
7577 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7582 if (is_text(lpszText
))
7584 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7585 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7586 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7589 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7591 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7592 SelectObject(hdc
, hOldFont
);
7593 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7595 return stringSize
.cx
;
7600 * Determines which listview item is located at the specified position.
7603 * [I] infoPtr : valid pointer to the listview structure
7604 * [IO] lpht : hit test information
7605 * [I] subitem : fill out iSubItem.
7606 * [I] select : return the index only if the hit selects the item
7609 * (mm 20001022): We must not allow iSubItem to be touched, for
7610 * an app might pass only a structure with space up to iItem!
7611 * (MS Office 97 does that for instance in the file open dialog)
7614 * SUCCESS : item index
7617 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7619 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7620 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7621 POINT Origin
, Position
, opt
;
7627 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7631 if (subitem
) lpht
->iSubItem
= 0;
7633 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7635 /* set whole list relation flags */
7636 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7638 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7639 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7640 lpht
->flags
|= LVHT_TOLEFT
;
7642 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7643 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7647 if (infoPtr
->rcList
.bottom
< opt
.y
)
7648 lpht
->flags
|= LVHT_BELOW
;
7652 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7653 lpht
->flags
|= LVHT_TOLEFT
;
7654 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7655 lpht
->flags
|= LVHT_TORIGHT
;
7657 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7658 lpht
->flags
|= LVHT_ABOVE
;
7659 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7660 lpht
->flags
|= LVHT_BELOW
;
7663 /* even if item is invalid try to find subitem */
7664 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7669 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7671 lpht
->iSubItem
= -1;
7672 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7674 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7676 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7682 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7684 /* if we're outside horizontal columns bounds there's nothing to test further */
7685 if (lpht
->iSubItem
== -1)
7688 lpht
->flags
= LVHT_NOWHERE
;
7693 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7694 if (lpht
->flags
) return -1;
7696 lpht
->flags
|= LVHT_NOWHERE
;
7698 /* first deal with the large items */
7699 rcSearch
.left
= lpht
->pt
.x
;
7700 rcSearch
.top
= lpht
->pt
.y
;
7701 rcSearch
.right
= rcSearch
.left
+ 1;
7702 rcSearch
.bottom
= rcSearch
.top
+ 1;
7704 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7705 iterator_next(&i
); /* go to first item in the sequence */
7707 iterator_destroy(&i
);
7709 TRACE("lpht->iItem=%d\n", iItem
);
7710 if (iItem
== -1) return -1;
7712 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7713 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7714 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7715 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7716 lvItem
.iItem
= iItem
;
7717 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7718 lvItem
.pszText
= szDispText
;
7719 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7720 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7721 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7723 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7724 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7725 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7727 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7728 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7730 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7732 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7735 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7736 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7740 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7741 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7743 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7744 if (!PtInRect(&rcBounds
, opt
)) return -1;
7746 /* That's a special case - row rectangle is used as item rectangle and
7747 returned flags contain all item parts. */
7748 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7750 if (PtInRect(&rcIcon
, opt
))
7751 lpht
->flags
|= LVHT_ONITEMICON
;
7752 else if (PtInRect(&rcLabel
, opt
))
7753 lpht
->flags
|= LVHT_ONITEMLABEL
;
7754 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7755 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7756 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7758 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7760 if (lpht
->flags
& LVHT_ONITEM
)
7761 lpht
->flags
&= ~LVHT_NOWHERE
;
7762 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7764 if (select
&& !is_fullrow
)
7766 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7768 /* get main item bounds */
7769 lvItem
.iSubItem
= 0;
7770 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7771 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7772 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7774 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7776 return lpht
->iItem
= iItem
;
7781 * Inserts a new item in the listview control.
7784 * [I] infoPtr : valid pointer to the listview structure
7785 * [I] lpLVItem : item information
7786 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7789 * SUCCESS : new item index
7792 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7799 BOOL is_sorted
, has_changed
;
7801 HWND hwndSelf
= infoPtr
->hwndSelf
;
7803 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7805 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7807 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7808 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7810 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7812 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7814 /* insert item in listview control data structure */
7815 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7816 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7818 /* link with id struct */
7819 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7821 lpID
->item
= hdpaSubItems
;
7822 lpID
->id
= get_next_itemid(infoPtr
);
7823 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7825 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7826 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7828 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7830 /* calculate new item index */
7837 while (i
< infoPtr
->nItemCount
)
7839 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7840 item_s
= DPA_GetPtr(hItem
, 0);
7842 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7843 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7845 if (cmpv
>= 0) break;
7851 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7853 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7854 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7855 if (nItem
== -1) goto fail
;
7856 infoPtr
->nItemCount
++;
7858 /* shift indices first so they don't get tangled */
7859 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7861 /* set the item attributes */
7862 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7864 /* full size structure expected - _WIN32IE >= 0x560 */
7867 else if (lpLVItem
->mask
& LVIF_INDENT
)
7869 /* indent member expected - _WIN32IE >= 0x300 */
7870 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7874 /* minimal structure expected */
7875 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7878 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7880 if (item
.mask
& LVIF_STATE
)
7882 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7883 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7884 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7888 item
.mask
|= LVIF_STATE
;
7889 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7890 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7894 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7896 /* make room for the position, if we are in the right mode */
7897 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7899 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7901 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7903 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7908 /* send LVN_INSERTITEM notification */
7909 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7911 nmlv
.lParam
= lpItem
->lParam
;
7912 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7913 if (!IsWindow(hwndSelf
))
7916 /* align items (set position of each item) */
7917 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7921 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7922 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7924 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7926 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7929 /* now is the invalidation fun */
7930 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7934 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7935 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7936 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7937 infoPtr
->nItemCount
--;
7939 DPA_DeletePtr(hdpaSubItems
, 0);
7940 DPA_Destroy (hdpaSubItems
);
7947 * Checks item visibility.
7950 * [I] infoPtr : valid pointer to the listview structure
7951 * [I] nFirst : item index to check for
7954 * Item visible : TRUE
7955 * Item invisible or failure : FALSE
7957 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7959 POINT Origin
, Position
;
7964 TRACE("nItem=%d\n", nItem
);
7966 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7968 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7969 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7970 rcItem
.left
= Position
.x
+ Origin
.x
;
7971 rcItem
.top
= Position
.y
+ Origin
.y
;
7972 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7973 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7975 hdc
= GetDC(infoPtr
->hwndSelf
);
7976 if (!hdc
) return FALSE
;
7977 ret
= RectVisible(hdc
, &rcItem
);
7978 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7985 * Redraws a range of items.
7988 * [I] infoPtr : valid pointer to the listview structure
7989 * [I] nFirst : first item
7990 * [I] nLast : last item
7996 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
8000 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
8001 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
8004 for (i
= nFirst
; i
<= nLast
; i
++)
8005 LISTVIEW_InvalidateItem(infoPtr
, i
);
8012 * Scroll the content of a listview.
8015 * [I] infoPtr : valid pointer to the listview structure
8016 * [I] dx : horizontal scroll amount in pixels
8017 * [I] dy : vertical scroll amount in pixels
8024 * If the control is in report view (LV_VIEW_DETAILS) the control can
8025 * be scrolled only in line increments. "dy" will be rounded to the
8026 * nearest number of pixels that are a whole line. Ex: if line height
8027 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
8028 * is passed, then the scroll will be 0. (per MSDN 7/2002)
8030 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8032 switch(infoPtr
->uView
) {
8033 case LV_VIEW_DETAILS
:
8034 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
8035 dy
/= infoPtr
->nItemHeight
;
8038 if (dy
!= 0) return FALSE
;
8044 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8045 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8052 * Sets the background color.
8055 * [I] infoPtr : valid pointer to the listview structure
8056 * [I] color : background color
8062 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8064 TRACE("(color=%x)\n", color
);
8067 infoPtr
->bDefaultBkColor
= FALSE
;
8069 if(infoPtr
->clrBk
!= color
) {
8070 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8071 infoPtr
->clrBk
= color
;
8072 if (color
== CLR_NONE
)
8073 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8076 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8077 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8084 /* LISTVIEW_SetBkImage */
8086 /*** Helper for {Insert,Set}ColumnT *only* */
8087 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8088 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8090 if (lpColumn
->mask
& LVCF_FMT
)
8092 /* format member is valid */
8093 lphdi
->mask
|= HDI_FORMAT
;
8095 /* set text alignment (leftmost column must be left-aligned) */
8096 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8097 lphdi
->fmt
|= HDF_LEFT
;
8098 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8099 lphdi
->fmt
|= HDF_RIGHT
;
8100 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8101 lphdi
->fmt
|= HDF_CENTER
;
8103 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8104 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8106 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8108 lphdi
->fmt
|= HDF_IMAGE
;
8109 lphdi
->iImage
= I_IMAGECALLBACK
;
8112 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8113 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8116 if (lpColumn
->mask
& LVCF_WIDTH
)
8118 lphdi
->mask
|= HDI_WIDTH
;
8119 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8121 /* make it fill the remainder of the controls width */
8125 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8127 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8128 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8131 /* retrieve the layout of the header */
8132 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8133 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8135 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8138 lphdi
->cxy
= lpColumn
->cx
;
8141 if (lpColumn
->mask
& LVCF_TEXT
)
8143 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8144 lphdi
->fmt
|= HDF_STRING
;
8145 lphdi
->pszText
= lpColumn
->pszText
;
8146 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8149 if (lpColumn
->mask
& LVCF_IMAGE
)
8151 lphdi
->mask
|= HDI_IMAGE
;
8152 lphdi
->iImage
= lpColumn
->iImage
;
8155 if (lpColumn
->mask
& LVCF_ORDER
)
8157 lphdi
->mask
|= HDI_ORDER
;
8158 lphdi
->iOrder
= lpColumn
->iOrder
;
8165 * Inserts a new column.
8168 * [I] infoPtr : valid pointer to the listview structure
8169 * [I] nColumn : column index
8170 * [I] lpColumn : column information
8171 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8174 * SUCCESS : new column index
8177 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8178 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8180 COLUMN_INFO
*lpColumnInfo
;
8184 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8186 if (!lpColumn
|| nColumn
< 0) return -1;
8187 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8189 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8190 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8193 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8194 * (can be seen in SPY) otherwise column never gets added.
8196 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8197 hdi
.mask
|= HDI_WIDTH
;
8202 * when the iSubItem is available Windows copies it to the header lParam. It seems
8203 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8205 if (lpColumn
->mask
& LVCF_SUBITEM
)
8207 hdi
.mask
|= HDI_LPARAM
;
8208 hdi
.lParam
= lpColumn
->iSubItem
;
8211 /* create header if not present */
8212 LISTVIEW_CreateHeader(infoPtr
);
8213 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8214 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8216 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8219 /* insert item in header control */
8220 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8221 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8222 nColumn
, (LPARAM
)&hdi
);
8223 if (nNewColumn
== -1) return -1;
8224 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8226 /* create our own column info */
8227 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8228 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8230 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8231 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8232 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8235 /* now we have to actually adjust the data */
8236 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8238 SUBITEM_INFO
*lpSubItem
;
8244 item
.iSubItem
= nNewColumn
;
8245 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8246 item
.iImage
= I_IMAGECALLBACK
;
8247 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8249 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8251 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8252 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8254 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8255 if (lpSubItem
->iSubItem
>= nNewColumn
)
8256 lpSubItem
->iSubItem
++;
8259 /* add new subitem for each item */
8261 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8265 /* make space for the new column */
8266 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8267 LISTVIEW_UpdateItemSize(infoPtr
);
8272 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8275 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8283 * Sets the attributes of a header item.
8286 * [I] infoPtr : valid pointer to the listview structure
8287 * [I] nColumn : column index
8288 * [I] lpColumn : column attributes
8289 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8295 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8296 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8298 HDITEMW hdi
, hdiget
;
8301 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8303 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8305 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8306 if (lpColumn
->mask
& LVCF_FMT
)
8308 hdi
.mask
|= HDI_FORMAT
;
8309 hdiget
.mask
= HDI_FORMAT
;
8310 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8311 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8313 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8315 /* set header item attributes */
8316 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8317 if (!bResult
) return FALSE
;
8319 if (lpColumn
->mask
& LVCF_FMT
)
8321 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8322 INT oldFmt
= lpColumnInfo
->fmt
;
8324 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8325 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8327 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8331 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8332 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8339 * Sets the column order array
8342 * [I] infoPtr : valid pointer to the listview structure
8343 * [I] iCount : number of elements in column order array
8344 * [I] lpiArray : pointer to column order array
8350 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8352 if (!infoPtr
->hwndHeader
) return FALSE
;
8353 infoPtr
->colRectsDirty
= TRUE
;
8354 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8359 * Sets the width of a column
8362 * [I] infoPtr : valid pointer to the listview structure
8363 * [I] nColumn : column index
8364 * [I] cx : column width
8370 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8372 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8376 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8378 /* set column width only if in report or list mode */
8379 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8381 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8382 with _USEHEADER being the lowest */
8383 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8384 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8386 /* resize all columns if in LV_VIEW_LIST mode */
8387 if(infoPtr
->uView
== LV_VIEW_LIST
)
8389 infoPtr
->nItemWidth
= cx
;
8390 LISTVIEW_InvalidateList(infoPtr
);
8394 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8396 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8401 lvItem
.mask
= LVIF_TEXT
;
8403 lvItem
.iSubItem
= nColumn
;
8404 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8405 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8407 lvItem
.pszText
= szDispText
;
8408 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8409 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8410 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8412 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8413 max_cx
+= infoPtr
->iconSize
.cx
;
8414 max_cx
+= TRAILING_LABEL_PADDING
;
8417 /* autosize based on listview items width */
8418 if(cx
== LVSCW_AUTOSIZE
)
8420 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8422 /* if iCol is the last column make it fill the remainder of the controls width */
8423 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8428 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8429 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8431 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8435 /* Despite what the MS docs say, if this is not the last
8436 column, then MS resizes the column to the width of the
8437 largest text string in the column, including headers
8438 and items. This is different from LVSCW_AUTOSIZE in that
8439 LVSCW_AUTOSIZE ignores the header string length. */
8442 /* retrieve header text */
8443 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8444 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8445 hdi
.pszText
= szDispText
;
8446 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8448 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8449 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8450 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8451 INT bitmap_margin
= 0;
8454 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8455 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8457 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8458 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8460 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8462 INT icon_cx
, icon_cy
;
8464 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8465 cx
+= icon_cx
+ 2*bitmap_margin
;
8467 else if (hdi
.fmt
& HDF_BITMAP
)
8471 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8472 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8475 SelectObject(hdc
, old_font
);
8476 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8478 cx
= max (cx
, max_cx
);
8482 if (cx
< 0) return FALSE
;
8484 /* call header to update the column change */
8485 hdi
.mask
= HDI_WIDTH
;
8486 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8487 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8488 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8492 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8495 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8498 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8500 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8501 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8504 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8505 ILC_COLOR
| ILC_MASK
, 2, 2);
8506 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8507 hdc
= CreateCompatibleDC(hdc_wnd
);
8508 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8509 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8510 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8512 SetRect(&rc
, 0, 0, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8513 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8514 FillRect(hdc
, &rc
, hbr_white
);
8515 InflateRect(&rc
, -2, -2);
8516 FillRect(hdc
, &rc
, hbr_black
);
8518 SelectObject(hdc
, hbm_im
);
8519 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8520 SelectObject(hdc
, hbm_orig
);
8521 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8523 SelectObject(hdc
, hbm_im
);
8524 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8525 SelectObject(hdc
, hbm_orig
);
8526 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8528 DeleteObject(hbm_mask
);
8529 DeleteObject(hbm_im
);
8537 * Sets the extended listview style.
8540 * [I] infoPtr : valid pointer to the listview structure
8542 * [I] dwStyle : style
8545 * SUCCESS : previous style
8548 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8550 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8552 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8556 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8558 infoPtr
->dwLvExStyle
= ex_style
;
8560 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8562 HIMAGELIST himl
= 0;
8563 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8566 item
.mask
= LVIF_STATE
;
8567 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8568 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8569 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8571 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8572 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8573 ImageList_Destroy(infoPtr
->himlState
);
8575 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8576 /* checkbox list replaces previous custom list or... */
8577 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8578 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8579 /* ...previous was checkbox list */
8580 (old_ex_style
& LVS_EX_CHECKBOXES
))
8581 ImageList_Destroy(himl
);
8584 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8588 /* if not already created */
8589 LISTVIEW_CreateHeader(infoPtr
);
8591 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8592 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8593 style
|= HDS_DRAGDROP
;
8595 style
&= ~HDS_DRAGDROP
;
8596 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8599 /* GRIDLINES adds decoration at top so changes sizes */
8600 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8602 LISTVIEW_CreateHeader(infoPtr
);
8603 LISTVIEW_UpdateSize(infoPtr
);
8606 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8608 LISTVIEW_CreateHeader(infoPtr
);
8611 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8613 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8614 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8617 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8619 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8620 LISTVIEW_CreateHeader(infoPtr
);
8622 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8623 LISTVIEW_UpdateSize(infoPtr
);
8624 LISTVIEW_UpdateScroll(infoPtr
);
8627 LISTVIEW_InvalidateList(infoPtr
);
8628 return old_ex_style
;
8633 * Sets the new hot cursor used during hot tracking and hover selection.
8636 * [I] infoPtr : valid pointer to the listview structure
8637 * [I] hCursor : the new hot cursor handle
8640 * Returns the previous hot cursor
8642 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8644 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8646 infoPtr
->hHotCursor
= hCursor
;
8654 * Sets the hot item index.
8657 * [I] infoPtr : valid pointer to the listview structure
8658 * [I] iIndex : index
8661 * SUCCESS : previous hot item index
8662 * FAILURE : -1 (no hot item)
8664 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8666 INT iOldIndex
= infoPtr
->nHotItem
;
8668 infoPtr
->nHotItem
= iIndex
;
8676 * Sets the amount of time the cursor must hover over an item before it is selected.
8679 * [I] infoPtr : valid pointer to the listview structure
8680 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8683 * Returns the previous hover time
8685 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8687 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8689 infoPtr
->dwHoverTime
= dwHoverTime
;
8691 return oldHoverTime
;
8696 * Sets spacing for icons of LVS_ICON style.
8699 * [I] infoPtr : valid pointer to the listview structure
8700 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8701 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8704 * MAKELONG(oldcx, oldcy)
8706 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8708 INT iconWidth
= 0, iconHeight
= 0;
8709 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8711 TRACE("requested=(%d,%d)\n", cx
, cy
);
8713 /* set to defaults, if instructed to */
8714 if (cx
== -1 && cy
== -1)
8716 infoPtr
->autoSpacing
= TRUE
;
8717 if (infoPtr
->himlNormal
)
8718 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8719 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8720 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8723 infoPtr
->autoSpacing
= FALSE
;
8725 /* if 0 then keep width */
8727 infoPtr
->iconSpacing
.cx
= cx
;
8729 /* if 0 then keep height */
8731 infoPtr
->iconSpacing
.cy
= cy
;
8733 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8734 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8735 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8736 infoPtr
->ntmHeight
);
8738 /* these depend on the iconSpacing */
8739 LISTVIEW_UpdateItemSize(infoPtr
);
8744 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL is_small
)
8748 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8755 size
->cx
= GetSystemMetrics(is_small
? SM_CXSMICON
: SM_CXICON
);
8756 size
->cy
= GetSystemMetrics(is_small
? SM_CYSMICON
: SM_CYICON
);
8765 * [I] infoPtr : valid pointer to the listview structure
8766 * [I] nType : image list type
8767 * [I] himl : image list handle
8770 * SUCCESS : old image list
8773 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8775 INT oldHeight
= infoPtr
->nItemHeight
;
8776 HIMAGELIST himlOld
= 0;
8778 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8783 himlOld
= infoPtr
->himlNormal
;
8784 infoPtr
->himlNormal
= himl
;
8785 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8786 if (infoPtr
->autoSpacing
)
8787 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8791 himlOld
= infoPtr
->himlSmall
;
8792 infoPtr
->himlSmall
= himl
;
8793 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8794 if (infoPtr
->hwndHeader
)
8795 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8799 himlOld
= infoPtr
->himlState
;
8800 infoPtr
->himlState
= himl
;
8801 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8802 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8806 ERR("Unknown icon type=%d\n", nType
);
8810 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8811 if (infoPtr
->nItemHeight
!= oldHeight
)
8812 LISTVIEW_UpdateScroll(infoPtr
);
8819 * Preallocates memory (does *not* set the actual count of items !)
8822 * [I] infoPtr : valid pointer to the listview structure
8823 * [I] nItems : item count (projected number of items to allocate)
8824 * [I] dwFlags : update flags
8830 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8832 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8834 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8836 INT nOldCount
= infoPtr
->nItemCount
;
8837 infoPtr
->nItemCount
= nItems
;
8839 if (nItems
< nOldCount
)
8841 RANGE range
= { nItems
, nOldCount
};
8842 ranges_del(infoPtr
->selectionRanges
, range
);
8843 if (infoPtr
->nFocusedItem
>= nItems
)
8845 LISTVIEW_SetItemFocus(infoPtr
, -1);
8846 SetRectEmpty(&infoPtr
->rcFocus
);
8850 LISTVIEW_UpdateScroll(infoPtr
);
8852 /* the flags are valid only in ownerdata report and list modes */
8853 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8855 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8856 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8858 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8859 LISTVIEW_InvalidateList(infoPtr
);
8866 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8867 nFrom
= min(nOldCount
, nItems
);
8868 nTo
= max(nOldCount
, nItems
);
8870 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8872 SetRect(&rcErase
, 0, nFrom
* infoPtr
->nItemHeight
, infoPtr
->nItemWidth
,
8873 nTo
* infoPtr
->nItemHeight
);
8874 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8875 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8876 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8878 else /* LV_VIEW_LIST */
8880 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8882 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8883 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8884 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8885 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8886 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8887 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8888 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8890 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8892 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8893 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8894 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8895 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8896 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8902 /* According to MSDN for non-LVS_OWNERDATA this is just
8903 * a performance issue. The control allocates its internal
8904 * data structures for the number of items specified. It
8905 * cuts down on the number of memory allocations. Therefore
8906 * we will just issue a WARN here
8908 WARN("for non-ownerdata performance option not implemented.\n");
8916 * Sets the position of an item.
8919 * [I] infoPtr : valid pointer to the listview structure
8920 * [I] nItem : item index
8921 * [I] pt : coordinate
8927 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8931 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8933 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8934 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8937 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8939 /* This point value seems to be an undocumented feature.
8940 * The best guess is that it means either at the origin,
8941 * or at true beginning of the list. I will assume the origin. */
8942 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8945 if (infoPtr
->uView
== LV_VIEW_ICON
)
8947 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8948 Pt
.y
-= ICON_TOP_PADDING
;
8953 infoPtr
->bAutoarrange
= FALSE
;
8955 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8960 * Sets the state of one or many items.
8963 * [I] infoPtr : valid pointer to the listview structure
8964 * [I] nItem : item index
8965 * [I] item : item or subitem info
8971 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8976 if (!item
) return FALSE
;
8978 lvItem
.iItem
= nItem
;
8979 lvItem
.iSubItem
= 0;
8980 lvItem
.mask
= LVIF_STATE
;
8981 lvItem
.state
= item
->state
;
8982 lvItem
.stateMask
= item
->stateMask
;
8983 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8990 /* special case optimization for recurring attempt to deselect all */
8991 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8994 /* select all isn't allowed in LVS_SINGLESEL */
8995 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8998 /* focus all isn't allowed */
8999 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
9001 notify
= infoPtr
->bDoChangeNotify
;
9002 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9004 infoPtr
->bDoChangeNotify
= FALSE
;
9005 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
9006 oldstate
|= LVIS_SELECTED
;
9007 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
9010 /* apply to all items */
9011 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
9012 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
9014 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9018 infoPtr
->bDoChangeNotify
= notify
;
9022 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
9023 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
9024 nmlv
.uChanged
= LVIF_STATE
;
9025 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
9028 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
9032 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9039 * Sets the text of an item or subitem.
9042 * [I] hwnd : window handle
9043 * [I] nItem : item index
9044 * [I] lpLVItem : item or subitem info
9045 * [I] isW : TRUE if input is Unicode
9051 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9055 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9056 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9058 lvItem
.iItem
= nItem
;
9059 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9060 lvItem
.mask
= LVIF_TEXT
;
9061 lvItem
.pszText
= lpLVItem
->pszText
;
9062 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9064 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9066 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9071 * Set item index that marks the start of a multiple selection.
9074 * [I] infoPtr : valid pointer to the listview structure
9075 * [I] nIndex : index
9078 * Index number or -1 if there is no selection mark.
9080 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9082 INT nOldIndex
= infoPtr
->nSelectionMark
;
9084 TRACE("(nIndex=%d)\n", nIndex
);
9086 if (nIndex
>= -1 && nIndex
< infoPtr
->nItemCount
)
9087 infoPtr
->nSelectionMark
= nIndex
;
9094 * Sets the text background color.
9097 * [I] infoPtr : valid pointer to the listview structure
9098 * [I] color : text background color
9104 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9106 TRACE("(color=%x)\n", color
);
9108 infoPtr
->clrTextBk
= color
;
9114 * Sets the text foreground color.
9117 * [I] infoPtr : valid pointer to the listview structure
9118 * [I] color : text color
9124 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9126 TRACE("(color=%x)\n", color
);
9128 infoPtr
->clrText
= color
;
9134 * Sets new ToolTip window to ListView control.
9137 * [I] infoPtr : valid pointer to the listview structure
9138 * [I] hwndNewToolTip : handle to new ToolTip
9143 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9145 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9146 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9147 return hwndOldToolTip
;
9152 * sets the Unicode character format flag for the control
9154 * [I] infoPtr :valid pointer to the listview structure
9155 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9158 * Old Unicode Format
9160 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9162 SHORT rc
= infoPtr
->notifyFormat
;
9163 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9164 return rc
== NFR_UNICODE
;
9169 * sets the control view mode
9171 * [I] infoPtr :valid pointer to the listview structure
9172 * [I] nView :new view mode value
9178 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9182 if (infoPtr
->uView
== nView
) return 1;
9184 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9185 if (nView
== LV_VIEW_TILE
)
9187 FIXME("View LV_VIEW_TILE unimplemented\n");
9191 infoPtr
->uView
= nView
;
9193 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9194 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9196 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9197 SetRectEmpty(&infoPtr
->rcFocus
);
9199 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9200 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9205 case LV_VIEW_SMALLICON
:
9206 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9208 case LV_VIEW_DETAILS
:
9213 LISTVIEW_CreateHeader( infoPtr
);
9215 hl
.prc
= &infoPtr
->rcList
;
9217 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9218 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9219 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9226 LISTVIEW_UpdateItemSize(infoPtr
);
9227 LISTVIEW_UpdateSize(infoPtr
);
9228 LISTVIEW_UpdateScroll(infoPtr
);
9229 LISTVIEW_InvalidateList(infoPtr
);
9231 TRACE("nView=%d\n", nView
);
9236 /* LISTVIEW_SetWorkAreas */
9240 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9243 * [I] first : pointer to first ITEM_INFO to compare
9244 * [I] second : pointer to second ITEM_INFO to compare
9245 * [I] lParam : HWND of control
9248 * if first comes before second : negative
9249 * if first comes after second : positive
9250 * if first and second are equivalent : zero
9252 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9254 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9255 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9256 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9258 /* Forward the call to the client defined callback */
9259 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9264 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9267 * [I] first : pointer to first ITEM_INFO to compare
9268 * [I] second : pointer to second ITEM_INFO to compare
9269 * [I] lParam : HWND of control
9272 * if first comes before second : negative
9273 * if first comes after second : positive
9274 * if first and second are equivalent : zero
9276 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9278 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9279 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9280 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9282 /* Forward the call to the client defined callback */
9283 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9288 * Sorts the listview items.
9291 * [I] infoPtr : valid pointer to the listview structure
9292 * [I] pfnCompare : application-defined value
9293 * [I] lParamSort : pointer to comparison callback
9294 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9300 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9301 LPARAM lParamSort
, BOOL IsEx
)
9305 LPVOID selectionMarkItem
= NULL
;
9306 LPVOID focusedItem
= NULL
;
9309 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9311 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9313 if (!pfnCompare
) return FALSE
;
9314 if (!infoPtr
->hdpaItems
) return FALSE
;
9316 /* if there are 0 or 1 items, there is no need to sort */
9317 if (infoPtr
->nItemCount
< 2) return TRUE
;
9319 /* clear selection */
9320 ranges_clear(infoPtr
->selectionRanges
);
9322 /* save selection mark and focused item */
9323 if (infoPtr
->nSelectionMark
>= 0)
9324 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9325 if (infoPtr
->nFocusedItem
>= 0)
9326 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9328 infoPtr
->pfnCompare
= pfnCompare
;
9329 infoPtr
->lParamSort
= lParamSort
;
9331 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9333 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9335 /* restore selection ranges */
9336 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9338 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9339 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9341 if (lpItem
->state
& LVIS_SELECTED
)
9342 ranges_additem(infoPtr
->selectionRanges
, i
);
9344 /* restore selection mark and focused item */
9345 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9346 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9348 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9350 /* refresh the display */
9351 LISTVIEW_InvalidateList(infoPtr
);
9357 * Update theme handle after a theme change.
9360 * [I] infoPtr : valid pointer to the listview structure
9364 * FAILURE : something else
9366 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9368 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9369 CloseThemeData(theme
);
9370 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9376 * Updates an items or rearranges the listview control.
9379 * [I] infoPtr : valid pointer to the listview structure
9380 * [I] nItem : item index
9386 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9388 TRACE("(nItem=%d)\n", nItem
);
9390 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9392 /* rearrange with default alignment style */
9393 if (is_autoarrange(infoPtr
))
9394 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9396 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9403 * Draw the track line at the place defined in the infoPtr structure.
9404 * The line is drawn with a XOR pen so drawing the line for the second time
9405 * in the same place erases the line.
9408 * [I] infoPtr : valid pointer to the listview structure
9414 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9418 if (infoPtr
->xTrackLine
== -1)
9421 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9423 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9424 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9425 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9431 * Called when an edit control should be displayed. This function is called after
9432 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9435 * [I] hwnd : Handle to the listview
9436 * [I] uMsg : WM_TIMER (ignored)
9437 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9438 * [I] dwTimer : The elapsed time (ignored)
9443 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9445 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9446 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9448 KillTimer(hwnd
, idEvent
);
9449 editItem
->fEnabled
= FALSE
;
9450 /* check if the item is still selected */
9451 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9452 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9457 * Creates the listview control - the WM_NCCREATE phase.
9460 * [I] hwnd : window handle
9461 * [I] lpcs : the create parameters
9467 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9469 LISTVIEW_INFO
*infoPtr
;
9472 TRACE("(lpcs=%p)\n", lpcs
);
9474 /* initialize info pointer */
9475 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9476 if (!infoPtr
) return FALSE
;
9478 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9480 infoPtr
->hwndSelf
= hwnd
;
9481 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9482 map_style_view(infoPtr
);
9483 /* determine the type of structures to use */
9484 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9485 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9487 /* initialize color information */
9488 infoPtr
->clrBk
= CLR_NONE
;
9489 infoPtr
->clrText
= CLR_DEFAULT
;
9490 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9491 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9493 infoPtr
->bDefaultBkColor
= TRUE
;
9496 /* set default values */
9497 infoPtr
->nFocusedItem
= -1;
9498 infoPtr
->nSelectionMark
= -1;
9499 infoPtr
->nHotItem
= -1;
9500 infoPtr
->redraw
= TRUE
;
9501 infoPtr
->bNoItemMetrics
= TRUE
;
9502 infoPtr
->bDoChangeNotify
= TRUE
;
9503 infoPtr
->autoSpacing
= TRUE
;
9504 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9505 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9506 infoPtr
->nEditLabelItem
= -1;
9507 infoPtr
->nLButtonDownItem
= -1;
9508 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9509 infoPtr
->cWheelRemainder
= 0;
9510 infoPtr
->nMeasureItemHeight
= 0;
9511 infoPtr
->xTrackLine
= -1; /* no track line */
9512 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9513 infoPtr
->iVersion
= COMCTL32_VERSION
;
9514 infoPtr
->colRectsDirty
= FALSE
;
9516 /* get default font (icon title) */
9517 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9518 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9519 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9520 LISTVIEW_SaveTextMetrics(infoPtr
);
9522 /* allocate memory for the data structure */
9523 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9524 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9525 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9526 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9527 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9528 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9532 DestroyWindow(infoPtr
->hwndHeader
);
9533 ranges_destroy(infoPtr
->selectionRanges
);
9534 DPA_Destroy(infoPtr
->hdpaItems
);
9535 DPA_Destroy(infoPtr
->hdpaItemIds
);
9536 DPA_Destroy(infoPtr
->hdpaPosX
);
9537 DPA_Destroy(infoPtr
->hdpaPosY
);
9538 DPA_Destroy(infoPtr
->hdpaColumns
);
9545 * Creates the listview control - the WM_CREATE phase. Most of the data is
9546 * already set up in LISTVIEW_NCCreate
9549 * [I] hwnd : window handle
9550 * [I] lpcs : the create parameters
9556 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9558 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9560 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9562 infoPtr
->dwStyle
= lpcs
->style
;
9563 map_style_view(infoPtr
);
9565 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9566 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9567 /* on error defaulting to ANSI notifications */
9568 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9569 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9571 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9573 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9576 infoPtr
->hwndHeader
= 0;
9578 /* init item size to avoid division by 0 */
9579 LISTVIEW_UpdateItemSize (infoPtr
);
9580 LISTVIEW_UpdateSize (infoPtr
);
9582 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9584 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9586 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9588 LISTVIEW_UpdateScroll(infoPtr
);
9589 /* send WM_MEASUREITEM notification */
9590 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9593 OpenThemeData(hwnd
, themeClass
);
9595 /* initialize the icon sizes */
9596 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9597 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9603 * Destroys the listview control.
9606 * [I] infoPtr : valid pointer to the listview structure
9612 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9614 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9615 CloseThemeData(theme
);
9617 /* delete all items */
9618 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9625 * Enables the listview control.
9628 * [I] infoPtr : valid pointer to the listview structure
9629 * [I] bEnable : specifies whether to enable or disable the window
9635 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9637 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9638 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9644 * Erases the background of the listview control.
9647 * [I] infoPtr : valid pointer to the listview structure
9648 * [I] hdc : device context handle
9654 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9658 TRACE("(hdc=%p)\n", hdc
);
9660 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9662 if (infoPtr
->clrBk
== CLR_NONE
)
9664 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9665 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9666 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9668 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9671 /* for double buffered controls we need to do this during refresh */
9672 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9674 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9680 * Helper function for LISTVIEW_[HV]Scroll *only*.
9681 * Performs vertical/horizontal scrolling by a give amount.
9684 * [I] infoPtr : valid pointer to the listview structure
9685 * [I] dx : amount of horizontal scroll
9686 * [I] dy : amount of vertical scroll
9688 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9690 /* now we can scroll the list */
9691 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9692 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9693 /* if we have focus, adjust rect */
9694 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9695 UpdateWindow(infoPtr
->hwndSelf
);
9700 * Performs vertical scrolling.
9703 * [I] infoPtr : valid pointer to the listview structure
9704 * [I] nScrollCode : scroll code
9705 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9706 * [I] hScrollWnd : scrollbar control window handle
9712 * SB_LINEUP/SB_LINEDOWN:
9713 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9714 * for LVS_REPORT is 1 line
9715 * for LVS_LIST cannot occur
9718 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9721 INT nOldScrollPos
, nNewScrollPos
;
9722 SCROLLINFO scrollInfo
;
9725 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9726 debugscrollcode(nScrollCode
), nScrollDiff
);
9728 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9730 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9731 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9733 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9735 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9737 nOldScrollPos
= scrollInfo
.nPos
;
9738 switch (nScrollCode
)
9744 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9748 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9752 nScrollDiff
= -scrollInfo
.nPage
;
9756 nScrollDiff
= scrollInfo
.nPage
;
9759 case SB_THUMBPOSITION
:
9761 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9768 /* quit right away if pos isn't changing */
9769 if (nScrollDiff
== 0) return 0;
9771 /* calculate new position, and handle overflows */
9772 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9773 if (nScrollDiff
> 0) {
9774 if (nNewScrollPos
< nOldScrollPos
||
9775 nNewScrollPos
> scrollInfo
.nMax
)
9776 nNewScrollPos
= scrollInfo
.nMax
;
9778 if (nNewScrollPos
> nOldScrollPos
||
9779 nNewScrollPos
< scrollInfo
.nMin
)
9780 nNewScrollPos
= scrollInfo
.nMin
;
9783 /* set the new position, and reread in case it changed */
9784 scrollInfo
.fMask
= SIF_POS
;
9785 scrollInfo
.nPos
= nNewScrollPos
;
9786 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9788 /* carry on only if it really changed */
9789 if (nNewScrollPos
== nOldScrollPos
) return 0;
9791 /* now adjust to client coordinates */
9792 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9793 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9795 /* and scroll the window */
9796 scroll_list(infoPtr
, 0, nScrollDiff
);
9803 * Performs horizontal scrolling.
9806 * [I] infoPtr : valid pointer to the listview structure
9807 * [I] nScrollCode : scroll code
9808 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9809 * [I] hScrollWnd : scrollbar control window handle
9815 * SB_LINELEFT/SB_LINERIGHT:
9816 * for LVS_ICON, LVS_SMALLICON 1 pixel
9817 * for LVS_REPORT is 1 pixel
9818 * for LVS_LIST is 1 column --> which is a 1 because the
9819 * scroll is based on columns not pixels
9822 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9825 INT nOldScrollPos
, nNewScrollPos
;
9826 SCROLLINFO scrollInfo
;
9829 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9830 debugscrollcode(nScrollCode
), nScrollDiff
);
9832 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9834 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9835 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9837 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9839 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9841 nOldScrollPos
= scrollInfo
.nPos
;
9843 switch (nScrollCode
)
9849 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9853 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9857 nScrollDiff
= -scrollInfo
.nPage
;
9861 nScrollDiff
= scrollInfo
.nPage
;
9864 case SB_THUMBPOSITION
:
9866 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9873 /* quit right away if pos isn't changing */
9874 if (nScrollDiff
== 0) return 0;
9876 /* calculate new position, and handle overflows */
9877 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9878 if (nScrollDiff
> 0) {
9879 if (nNewScrollPos
< nOldScrollPos
||
9880 nNewScrollPos
> scrollInfo
.nMax
)
9881 nNewScrollPos
= scrollInfo
.nMax
;
9883 if (nNewScrollPos
> nOldScrollPos
||
9884 nNewScrollPos
< scrollInfo
.nMin
)
9885 nNewScrollPos
= scrollInfo
.nMin
;
9888 /* set the new position, and reread in case it changed */
9889 scrollInfo
.fMask
= SIF_POS
;
9890 scrollInfo
.nPos
= nNewScrollPos
;
9891 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9893 /* carry on only if it really changed */
9894 if (nNewScrollPos
== nOldScrollPos
) return 0;
9896 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9898 /* now adjust to client coordinates */
9899 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9900 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9902 /* and scroll the window */
9903 scroll_list(infoPtr
, nScrollDiff
, 0);
9908 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9910 UINT pulScrollLines
= 3;
9912 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9914 switch(infoPtr
->uView
)
9917 case LV_VIEW_SMALLICON
:
9919 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9920 * should be fixed in the future.
9922 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9923 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9926 case LV_VIEW_DETAILS
:
9927 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9929 /* if scrolling changes direction, ignore left overs */
9930 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9931 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9932 infoPtr
->cWheelRemainder
+= wheelDelta
;
9934 infoPtr
->cWheelRemainder
= wheelDelta
;
9935 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9938 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9939 cLineScroll
= pulScrollLines
* (float)infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9940 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
9941 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9946 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9957 * [I] infoPtr : valid pointer to the listview structure
9958 * [I] nVirtualKey : virtual key
9959 * [I] lKeyData : key data
9964 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9966 HWND hwndSelf
= infoPtr
->hwndSelf
;
9968 NMLVKEYDOWN nmKeyDown
;
9970 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9972 /* send LVN_KEYDOWN notification */
9973 nmKeyDown
.wVKey
= nVirtualKey
;
9974 nmKeyDown
.flags
= 0;
9975 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9976 if (!IsWindow(hwndSelf
))
9979 switch (nVirtualKey
)
9982 nItem
= infoPtr
->nFocusedItem
;
9983 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9984 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9988 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9990 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9991 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9996 if (infoPtr
->nItemCount
> 0)
10001 if (infoPtr
->nItemCount
> 0)
10002 nItem
= infoPtr
->nItemCount
- 1;
10006 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
10010 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
10014 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
10018 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
10022 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10024 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10025 if (infoPtr
->nFocusedItem
== topidx
)
10026 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
10031 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
10032 * LISTVIEW_GetCountPerRow(infoPtr
);
10033 if(nItem
< 0) nItem
= 0;
10037 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10039 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10040 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10041 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10042 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10044 nItem
= topidx
+ cnt
- 1;
10047 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10048 * LISTVIEW_GetCountPerRow(infoPtr
);
10049 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10053 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10054 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10064 * [I] infoPtr : valid pointer to the listview structure
10069 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10073 /* drop any left over scroll amount */
10074 infoPtr
->cWheelRemainder
= 0;
10076 /* if we did not have the focus, there's nothing more to do */
10077 if (!infoPtr
->bFocus
) return 0;
10079 /* send NM_KILLFOCUS notification */
10080 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10082 /* if we have a focus rectangle, get rid of it */
10083 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10085 /* if have a marquee selection, stop it */
10086 if (infoPtr
->bMarqueeSelect
)
10088 /* Remove the marquee rectangle and release our mouse capture */
10089 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10092 SetRectEmpty(&infoPtr
->marqueeRect
);
10094 infoPtr
->bMarqueeSelect
= FALSE
;
10095 infoPtr
->bScrolling
= FALSE
;
10096 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10099 /* set window focus flag */
10100 infoPtr
->bFocus
= FALSE
;
10102 /* invalidate the selected items before resetting focus flag */
10103 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10110 * Processes double click messages (left mouse button).
10113 * [I] infoPtr : valid pointer to the listview structure
10114 * [I] wKey : key flag
10115 * [I] x,y : mouse coordinate
10120 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10122 LVHITTESTINFO htInfo
;
10124 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10126 /* Cancel the item edition if any */
10127 if (infoPtr
->itemEdit
.fEnabled
)
10129 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10130 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10133 /* send NM_RELEASEDCAPTURE notification */
10134 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10139 /* send NM_DBLCLK notification */
10140 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10141 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10143 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10144 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10149 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10154 r
.top
= r
.bottom
= pt
.y
;
10155 r
.left
= r
.right
= pt
.x
;
10157 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10159 SetCapture(infoPtr
->hwndSelf
);
10163 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10165 if (msg
.message
== WM_MOUSEMOVE
)
10167 pt
.x
= (short)LOWORD(msg
.lParam
);
10168 pt
.y
= (short)HIWORD(msg
.lParam
);
10169 if (PtInRect(&r
, pt
))
10177 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10178 msg
.message
<= WM_RBUTTONDBLCLK
)
10183 DispatchMessageW(&msg
);
10186 if (GetCapture() != infoPtr
->hwndSelf
)
10197 * Processes mouse down messages (left mouse button).
10200 * infoPtr [I ] valid pointer to the listview structure
10201 * wKey [I ] key flag
10202 * x,y [I ] mouse coordinate
10207 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10209 LVHITTESTINFO lvHitTestInfo
;
10210 static BOOL bGroupSelect
= TRUE
;
10211 POINT pt
= { x
, y
};
10214 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10216 /* send NM_RELEASEDCAPTURE notification */
10217 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10219 /* set left button down flag and record the click position */
10220 infoPtr
->bLButtonDown
= TRUE
;
10221 infoPtr
->ptClickPos
= pt
;
10222 infoPtr
->bDragging
= FALSE
;
10223 infoPtr
->bMarqueeSelect
= FALSE
;
10224 infoPtr
->bScrolling
= FALSE
;
10226 lvHitTestInfo
.pt
.x
= x
;
10227 lvHitTestInfo
.pt
.y
= y
;
10229 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10230 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10231 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10233 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10235 toggle_checkbox_state(infoPtr
, nItem
);
10239 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10241 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10242 infoPtr
->nEditLabelItem
= nItem
;
10244 LISTVIEW_SetSelection(infoPtr
, nItem
);
10248 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10252 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10253 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10254 infoPtr
->nSelectionMark
= nItem
;
10260 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10261 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10263 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10264 infoPtr
->nSelectionMark
= nItem
;
10267 else if (wKey
& MK_CONTROL
)
10271 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10273 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10274 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10275 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10276 infoPtr
->nSelectionMark
= nItem
;
10278 else if (wKey
& MK_SHIFT
)
10280 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10284 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10286 infoPtr
->nEditLabelItem
= nItem
;
10287 infoPtr
->nLButtonDownItem
= nItem
;
10289 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10292 /* set selection (clears other pre-existing selections) */
10293 LISTVIEW_SetSelection(infoPtr
, nItem
);
10297 if (!infoPtr
->bFocus
)
10298 SetFocus(infoPtr
->hwndSelf
);
10300 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10301 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10305 if (!infoPtr
->bFocus
)
10306 SetFocus(infoPtr
->hwndSelf
);
10308 /* remove all selections */
10309 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10310 LISTVIEW_DeselectAll(infoPtr
);
10319 * Processes mouse up messages (left mouse button).
10322 * infoPtr [I ] valid pointer to the listview structure
10323 * wKey [I ] key flag
10324 * x,y [I ] mouse coordinate
10329 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10331 LVHITTESTINFO lvHitTestInfo
;
10333 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10335 if (!infoPtr
->bLButtonDown
) return 0;
10337 lvHitTestInfo
.pt
.x
= x
;
10338 lvHitTestInfo
.pt
.y
= y
;
10340 /* send NM_CLICK notification */
10341 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10342 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10344 /* set left button flag */
10345 infoPtr
->bLButtonDown
= FALSE
;
10347 /* set a single selection, reset others */
10348 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10349 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10350 infoPtr
->nLButtonDownItem
= -1;
10352 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10354 /* Remove the marquee rectangle and release our mouse capture */
10355 if (infoPtr
->bMarqueeSelect
)
10357 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10361 SetRectEmpty(&infoPtr
->marqueeRect
);
10362 SetRectEmpty(&infoPtr
->marqueeDrawRect
);
10364 infoPtr
->bDragging
= FALSE
;
10365 infoPtr
->bMarqueeSelect
= FALSE
;
10366 infoPtr
->bScrolling
= FALSE
;
10368 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10372 /* if we clicked on a selected item, edit the label */
10373 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10375 /* we want to make sure the user doesn't want to do a double click. So we will
10376 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10378 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10379 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10380 SetTimer(infoPtr
->hwndSelf
,
10381 (UINT_PTR
)&infoPtr
->itemEdit
,
10382 GetDoubleClickTime(),
10383 LISTVIEW_DelayedEditItem
);
10391 * Destroys the listview control (called after WM_DESTROY).
10394 * [I] infoPtr : valid pointer to the listview structure
10399 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10405 /* destroy data structure */
10406 DPA_Destroy(infoPtr
->hdpaItems
);
10407 DPA_Destroy(infoPtr
->hdpaItemIds
);
10408 DPA_Destroy(infoPtr
->hdpaPosX
);
10409 DPA_Destroy(infoPtr
->hdpaPosY
);
10411 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10412 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10413 DPA_Destroy(infoPtr
->hdpaColumns
);
10414 ranges_destroy(infoPtr
->selectionRanges
);
10416 /* destroy image lists */
10417 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10419 ImageList_Destroy(infoPtr
->himlNormal
);
10420 ImageList_Destroy(infoPtr
->himlSmall
);
10421 ImageList_Destroy(infoPtr
->himlState
);
10424 /* destroy font, bkgnd brush */
10425 infoPtr
->hFont
= 0;
10426 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10427 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10429 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10431 /* free listview info pointer*/
10439 * Handles notifications.
10442 * [I] infoPtr : valid pointer to the listview structure
10443 * [I] lpnmhdr : notification information
10448 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10452 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10454 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10456 /* remember: HDN_LAST < HDN_FIRST */
10457 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10458 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10460 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10462 switch (lpnmhdr
->code
)
10467 COLUMN_INFO
*lpColumnInfo
;
10471 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10474 /* remove the old line (if any) */
10475 LISTVIEW_DrawTrackLine(infoPtr
);
10477 /* compute & draw the new line */
10478 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10479 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10480 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10481 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10482 LISTVIEW_DrawTrackLine(infoPtr
);
10483 return notify_forward_header(infoPtr
, lpnmh
);
10486 case HDN_ENDTRACKA
:
10487 case HDN_ENDTRACKW
:
10488 /* remove the track line (if any) */
10489 LISTVIEW_DrawTrackLine(infoPtr
);
10490 infoPtr
->xTrackLine
= -1;
10491 return notify_forward_header(infoPtr
, lpnmh
);
10493 case HDN_BEGINDRAG
:
10494 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10495 return notify_forward_header(infoPtr
, lpnmh
);
10498 infoPtr
->colRectsDirty
= TRUE
;
10499 LISTVIEW_InvalidateList(infoPtr
);
10500 return notify_forward_header(infoPtr
, lpnmh
);
10502 case HDN_ITEMCHANGEDW
:
10503 case HDN_ITEMCHANGEDA
:
10505 COLUMN_INFO
*lpColumnInfo
;
10509 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10511 hdi
.mask
= HDI_WIDTH
;
10512 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10516 cxy
= lpnmh
->pitem
->cxy
;
10518 /* determine how much we change since the last know position */
10519 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10520 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10523 lpColumnInfo
->rcHeader
.right
+= dx
;
10525 hdi
.mask
= HDI_ORDER
;
10526 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10528 /* not the rightmost one */
10529 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10531 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10532 hdi
.iOrder
+ 1, 0);
10533 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10537 /* only needs to update the scrolls */
10538 infoPtr
->nItemWidth
+= dx
;
10539 LISTVIEW_UpdateScroll(infoPtr
);
10541 LISTVIEW_UpdateItemSize(infoPtr
);
10542 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10545 RECT rcCol
= lpColumnInfo
->rcHeader
;
10547 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10548 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10550 rcCol
.top
= infoPtr
->rcList
.top
;
10551 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10553 /* resizing left-aligned columns leaves most of the left side untouched */
10554 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10556 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10559 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10562 /* when shrinking the last column clear the now unused field */
10563 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10569 /* deal with right from rightmost column area */
10570 right
.left
= rcCol
.right
;
10571 right
.top
= rcCol
.top
;
10572 right
.bottom
= rcCol
.bottom
;
10573 right
.right
= infoPtr
->rcList
.right
;
10575 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10578 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10584 case HDN_ITEMCLICKW
:
10585 case HDN_ITEMCLICKA
:
10587 /* Handle sorting by Header Column */
10590 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10592 nmlv
.iSubItem
= lpnmh
->iItem
;
10593 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10594 return notify_forward_header(infoPtr
, lpnmh
);
10597 case HDN_DIVIDERDBLCLICKW
:
10598 case HDN_DIVIDERDBLCLICKA
:
10599 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10600 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10601 split needed for that */
10602 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10603 return notify_forward_header(infoPtr
, lpnmh
);
10610 * Paint non-client area of control.
10613 * [I] infoPtr : valid pointer to the listview structureof the sender
10614 * [I] region : update region
10617 * TRUE - frame was painted
10618 * FALSE - call default window proc
10620 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10622 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10626 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10627 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10630 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10632 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10634 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10635 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10636 if (region
!= (HRGN
)1)
10637 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10638 OffsetRect(&r
, -r
.left
, -r
.top
);
10640 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10641 OffsetRect(&r
, -r
.left
, -r
.top
);
10643 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10644 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10645 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10646 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10648 /* Call default proc to get the scrollbars etc. painted */
10649 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10656 * Determines the type of structure to use.
10659 * [I] infoPtr : valid pointer to the listview structureof the sender
10660 * [I] hwndFrom : listview window handle
10661 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10666 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10668 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10670 if (nCommand
== NF_REQUERY
)
10671 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10673 return infoPtr
->notifyFormat
;
10678 * Paints/Repaints the listview control. Internal use.
10681 * [I] infoPtr : valid pointer to the listview structure
10682 * [I] hdc : device context handle
10687 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10689 TRACE("(hdc=%p)\n", hdc
);
10691 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10693 infoPtr
->bNoItemMetrics
= FALSE
;
10694 LISTVIEW_UpdateItemSize(infoPtr
);
10695 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10696 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10697 LISTVIEW_UpdateScroll(infoPtr
);
10700 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10703 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10708 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10709 if (!hdc
) return 1;
10710 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10711 EndPaint(infoPtr
->hwndSelf
, &ps
);
10719 * Paints/Repaints the listview control, WM_PAINT handler.
10722 * [I] infoPtr : valid pointer to the listview structure
10723 * [I] hdc : device context handle
10728 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10730 TRACE("(hdc=%p)\n", hdc
);
10732 if (!is_redrawing(infoPtr
))
10733 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10735 return LISTVIEW_Paint(infoPtr
, hdc
);
10740 * Paints/Repaints the listview control.
10743 * [I] infoPtr : valid pointer to the listview structure
10744 * [I] hdc : device context handle
10745 * [I] options : drawing options
10750 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10752 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10754 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10757 if (options
& PRF_ERASEBKGND
)
10758 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10760 if (options
& PRF_CLIENT
)
10761 LISTVIEW_Paint(infoPtr
, hdc
);
10769 * Processes double click messages (right mouse button).
10772 * [I] infoPtr : valid pointer to the listview structure
10773 * [I] wKey : key flag
10774 * [I] x,y : mouse coordinate
10779 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10781 LVHITTESTINFO lvHitTestInfo
;
10783 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10785 /* send NM_RELEASEDCAPTURE notification */
10786 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10788 /* send NM_RDBLCLK notification */
10789 lvHitTestInfo
.pt
.x
= x
;
10790 lvHitTestInfo
.pt
.y
= y
;
10791 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10792 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10799 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10802 * [I] infoPtr : valid pointer to the listview structure
10803 * [I] wKey : key flag
10804 * [I] x, y : mouse coordinate
10809 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10814 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10816 /* send NM_RELEASEDCAPTURE notification */
10817 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10819 /* determine the index of the selected item */
10822 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10824 /* make sure the listview control window has the focus */
10825 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10827 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10829 LISTVIEW_SetItemFocus(infoPtr
, item
);
10830 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10831 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10832 LISTVIEW_SetSelection(infoPtr
, item
);
10835 LISTVIEW_DeselectAll(infoPtr
);
10837 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10839 if (ht
.iItem
!= -1)
10843 memset(&nmlv
, 0, sizeof(nmlv
));
10844 nmlv
.iItem
= ht
.iItem
;
10845 nmlv
.ptAction
= ht
.pt
;
10847 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10852 SetFocus(infoPtr
->hwndSelf
);
10856 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10858 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10860 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10861 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10862 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10874 * [I] infoPtr : valid pointer to the listview structure
10875 * [I] hwnd : window handle of window containing the cursor
10876 * [I] nHittest : hit-test code
10877 * [I] wMouseMsg : ideintifier of the mouse message
10880 * TRUE if cursor is set
10883 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10885 LVHITTESTINFO lvHitTestInfo
;
10887 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10889 if (!infoPtr
->hHotCursor
) goto forward
;
10891 GetCursorPos(&lvHitTestInfo
.pt
);
10892 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10894 SetCursor(infoPtr
->hHotCursor
);
10900 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10908 * [I] infoPtr : valid pointer to the listview structure
10909 * [I] hwndLoseFocus : handle of previously focused window
10914 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10916 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10918 /* if we have the focus already, there's nothing to do */
10919 if (infoPtr
->bFocus
) return 0;
10921 /* send NM_SETFOCUS notification */
10922 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10924 /* set window focus flag */
10925 infoPtr
->bFocus
= TRUE
;
10927 /* put the focus rect back on */
10928 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10930 /* redraw all visible selected items */
10931 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10941 * [I] infoPtr : valid pointer to the listview structure
10942 * [I] fRedraw : font handle
10943 * [I] fRedraw : redraw flag
10948 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10950 HFONT oldFont
= infoPtr
->hFont
;
10951 INT oldHeight
= infoPtr
->nItemHeight
;
10953 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10955 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10956 if (infoPtr
->hFont
== oldFont
) return 0;
10958 LISTVIEW_SaveTextMetrics(infoPtr
);
10960 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10962 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10964 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10965 LISTVIEW_UpdateSize(infoPtr
);
10966 LISTVIEW_UpdateScroll(infoPtr
);
10968 else if (infoPtr
->nItemHeight
!= oldHeight
)
10969 LISTVIEW_UpdateScroll(infoPtr
);
10971 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10978 * Message handling for WM_SETREDRAW.
10979 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10982 * [I] infoPtr : valid pointer to the listview structure
10983 * [I] redraw: state of redraw flag
10988 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL redraw
)
10990 TRACE("old=%d, new=%d\n", infoPtr
->redraw
, redraw
);
10992 if (infoPtr
->redraw
== !!redraw
)
10995 if (!(infoPtr
->redraw
= !!redraw
))
10998 if (is_autoarrange(infoPtr
))
10999 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11000 LISTVIEW_UpdateScroll(infoPtr
);
11002 /* despite what the WM_SETREDRAW docs says, apps expect us
11003 * to invalidate the listview here... stupid! */
11004 LISTVIEW_InvalidateList(infoPtr
);
11011 * Resizes the listview control. This function processes WM_SIZE
11012 * messages. At this time, the width and height are not used.
11015 * [I] infoPtr : valid pointer to the listview structure
11016 * [I] Width : new width
11017 * [I] Height : new height
11022 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
11024 RECT rcOld
= infoPtr
->rcList
;
11026 TRACE("(width=%d, height=%d)\n", Width
, Height
);
11028 LISTVIEW_UpdateSize(infoPtr
);
11029 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
11031 /* do not bother with display related stuff if we're not redrawing */
11032 if (!is_redrawing(infoPtr
)) return 0;
11034 if (is_autoarrange(infoPtr
))
11035 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11037 LISTVIEW_UpdateScroll(infoPtr
);
11039 /* refresh all only for lists whose height changed significantly */
11040 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11041 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11042 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11043 LISTVIEW_InvalidateList(infoPtr
);
11050 * Sets the size information.
11053 * [I] infoPtr : valid pointer to the listview structure
11058 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11060 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11062 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11064 if (infoPtr
->uView
== LV_VIEW_LIST
)
11066 /* Apparently the "LIST" style is supposed to have the same
11067 * number of items in a column even if there is no scroll bar.
11068 * Since if a scroll bar already exists then the bottom is already
11069 * reduced, only reduce if the scroll bar does not currently exist.
11070 * The "2" is there to mimic the native control. I think it may be
11071 * related to either padding or edges. (GLA 7/2002)
11073 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11074 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11075 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11078 /* if control created invisible header isn't created */
11079 if (infoPtr
->hwndHeader
)
11084 hl
.prc
= &infoPtr
->rcList
;
11086 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11087 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11089 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11090 wp
.flags
|= SWP_SHOWWINDOW
;
11093 wp
.flags
|= SWP_HIDEWINDOW
;
11097 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11098 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11100 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11102 /* extra padding for grid */
11103 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11104 infoPtr
->rcList
.top
+= 2;
11106 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11111 * Processes WM_STYLECHANGED messages.
11114 * [I] infoPtr : valid pointer to the listview structure
11115 * [I] wStyleType : window style type (normal or extended)
11116 * [I] lpss : window style information
11121 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11122 const STYLESTRUCT
*lpss
)
11124 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11125 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11128 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11129 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11131 if (wStyleType
!= GWL_STYLE
) return 0;
11133 infoPtr
->dwStyle
= lpss
->styleNew
;
11135 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11136 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11137 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11139 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11140 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11141 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11143 if (uNewView
!= uOldView
)
11147 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11148 changing style updates current view only when view bits change. */
11149 map_style_view(infoPtr
);
11150 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11151 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11153 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11154 SetRectEmpty(&infoPtr
->rcFocus
);
11156 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11157 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11159 if (uNewView
== LVS_REPORT
)
11164 LISTVIEW_CreateHeader( infoPtr
);
11166 hl
.prc
= &infoPtr
->rcList
;
11168 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11169 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11170 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11171 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11174 LISTVIEW_UpdateItemSize(infoPtr
);
11177 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11179 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11181 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11183 /* Turn off the header control */
11184 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11185 TRACE("Hide header control, was 0x%08x\n", style
);
11186 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11188 /* Turn on the header control */
11189 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11191 TRACE("Show header control, was 0x%08x\n", style
);
11192 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11198 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11199 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11200 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11202 /* update the size of the client area */
11203 LISTVIEW_UpdateSize(infoPtr
);
11205 /* add scrollbars if needed */
11206 LISTVIEW_UpdateScroll(infoPtr
);
11208 /* invalidate client area + erase background */
11209 LISTVIEW_InvalidateList(infoPtr
);
11216 * Processes WM_STYLECHANGING messages.
11219 * [I] wStyleType : window style type (normal or extended)
11220 * [I0] lpss : window style information
11225 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11228 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11229 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11231 /* don't forward LVS_OWNERDATA only if not already set to */
11232 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11234 if (lpss
->styleOld
& LVS_OWNERDATA
)
11235 lpss
->styleNew
|= LVS_OWNERDATA
;
11237 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11245 * Processes WM_SHOWWINDOW messages.
11248 * [I] infoPtr : valid pointer to the listview structure
11249 * [I] bShown : window is being shown (FALSE when hidden)
11250 * [I] iStatus : window show status
11255 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11257 /* header delayed creation */
11258 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11260 LISTVIEW_CreateHeader(infoPtr
);
11262 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11263 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11266 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11271 * Processes CCM_GETVERSION messages.
11274 * [I] infoPtr : valid pointer to the listview structure
11279 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11281 return infoPtr
->iVersion
;
11286 * Processes CCM_SETVERSION messages.
11289 * [I] infoPtr : valid pointer to the listview structure
11290 * [I] iVersion : version to be set
11293 * -1 when requested version is greater than DLL version;
11294 * previous version otherwise
11296 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11298 INT iOldVersion
= infoPtr
->iVersion
;
11300 if (iVersion
> COMCTL32_VERSION
)
11303 infoPtr
->iVersion
= iVersion
;
11305 TRACE("new version %d\n", iVersion
);
11307 return iOldVersion
;
11312 * Window procedure of the listview control.
11315 static LRESULT WINAPI
11316 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11318 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11320 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11322 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11323 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11327 case LVM_APPROXIMATEVIEWRECT
:
11328 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11329 LOWORD(lParam
), HIWORD(lParam
));
11331 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11333 case LVM_CANCELEDITLABEL
:
11334 return LISTVIEW_CancelEditLabel(infoPtr
);
11336 case LVM_CREATEDRAGIMAGE
:
11337 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11339 case LVM_DELETEALLITEMS
:
11340 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11342 case LVM_DELETECOLUMN
:
11343 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11345 case LVM_DELETEITEM
:
11346 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11348 case LVM_EDITLABELA
:
11349 case LVM_EDITLABELW
:
11350 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11351 uMsg
== LVM_EDITLABELW
);
11352 /* case LVM_ENABLEGROUPVIEW: */
11354 case LVM_ENSUREVISIBLE
:
11355 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11357 case LVM_FINDITEMW
:
11358 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11360 case LVM_FINDITEMA
:
11361 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11363 case LVM_GETBKCOLOR
:
11364 return infoPtr
->clrBk
;
11366 /* case LVM_GETBKIMAGE: */
11368 case LVM_GETCALLBACKMASK
:
11369 return infoPtr
->uCallbackMask
;
11371 case LVM_GETCOLUMNA
:
11372 case LVM_GETCOLUMNW
:
11373 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11374 uMsg
== LVM_GETCOLUMNW
);
11376 case LVM_GETCOLUMNORDERARRAY
:
11377 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11379 case LVM_GETCOLUMNWIDTH
:
11380 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11382 case LVM_GETCOUNTPERPAGE
:
11383 return LISTVIEW_GetCountPerPage(infoPtr
);
11385 case LVM_GETEDITCONTROL
:
11386 return (LRESULT
)infoPtr
->hwndEdit
;
11388 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11389 return infoPtr
->dwLvExStyle
;
11391 /* case LVM_GETGROUPINFO: */
11393 /* case LVM_GETGROUPMETRICS: */
11395 case LVM_GETHEADER
:
11396 return (LRESULT
)infoPtr
->hwndHeader
;
11398 case LVM_GETHOTCURSOR
:
11399 return (LRESULT
)infoPtr
->hHotCursor
;
11401 case LVM_GETHOTITEM
:
11402 return infoPtr
->nHotItem
;
11404 case LVM_GETHOVERTIME
:
11405 return infoPtr
->dwHoverTime
;
11407 case LVM_GETIMAGELIST
:
11408 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11410 /* case LVM_GETINSERTMARK: */
11412 /* case LVM_GETINSERTMARKCOLOR: */
11414 /* case LVM_GETINSERTMARKRECT: */
11416 case LVM_GETISEARCHSTRINGA
:
11417 case LVM_GETISEARCHSTRINGW
:
11418 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11423 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11425 case LVM_GETITEMCOUNT
:
11426 return infoPtr
->nItemCount
;
11428 case LVM_GETITEMPOSITION
:
11429 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11431 case LVM_GETITEMRECT
:
11432 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11434 case LVM_GETITEMSPACING
:
11435 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11437 case LVM_GETITEMSTATE
:
11438 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11440 case LVM_GETITEMTEXTA
:
11441 case LVM_GETITEMTEXTW
:
11442 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11443 uMsg
== LVM_GETITEMTEXTW
);
11445 case LVM_GETNEXTITEM
:
11446 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11448 case LVM_GETNUMBEROFWORKAREAS
:
11449 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11452 case LVM_GETORIGIN
:
11453 if (!lParam
) return FALSE
;
11454 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11455 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11456 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11459 /* case LVM_GETOUTLINECOLOR: */
11461 /* case LVM_GETSELECTEDCOLUMN: */
11463 case LVM_GETSELECTEDCOUNT
:
11464 return LISTVIEW_GetSelectedCount(infoPtr
);
11466 case LVM_GETSELECTIONMARK
:
11467 return infoPtr
->nSelectionMark
;
11469 case LVM_GETSTRINGWIDTHA
:
11470 case LVM_GETSTRINGWIDTHW
:
11471 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11472 uMsg
== LVM_GETSTRINGWIDTHW
);
11474 case LVM_GETSUBITEMRECT
:
11475 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11477 case LVM_GETTEXTBKCOLOR
:
11478 return infoPtr
->clrTextBk
;
11480 case LVM_GETTEXTCOLOR
:
11481 return infoPtr
->clrText
;
11483 /* case LVM_GETTILEINFO: */
11485 /* case LVM_GETTILEVIEWINFO: */
11487 case LVM_GETTOOLTIPS
:
11488 if( !infoPtr
->hwndToolTip
)
11489 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11490 return (LRESULT
)infoPtr
->hwndToolTip
;
11492 case LVM_GETTOPINDEX
:
11493 return LISTVIEW_GetTopIndex(infoPtr
);
11495 case LVM_GETUNICODEFORMAT
:
11496 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11499 return infoPtr
->uView
;
11501 case LVM_GETVIEWRECT
:
11502 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11504 case LVM_GETWORKAREAS
:
11505 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11508 /* case LVM_HASGROUP: */
11511 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11513 case LVM_INSERTCOLUMNA
:
11514 case LVM_INSERTCOLUMNW
:
11515 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11516 uMsg
== LVM_INSERTCOLUMNW
);
11518 /* case LVM_INSERTGROUP: */
11520 /* case LVM_INSERTGROUPSORTED: */
11522 case LVM_INSERTITEMA
:
11523 case LVM_INSERTITEMW
:
11524 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11526 /* case LVM_INSERTMARKHITTEST: */
11528 /* case LVM_ISGROUPVIEWENABLED: */
11530 case LVM_ISITEMVISIBLE
:
11531 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11533 case LVM_MAPIDTOINDEX
:
11534 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11536 case LVM_MAPINDEXTOID
:
11537 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11539 /* case LVM_MOVEGROUP: */
11541 /* case LVM_MOVEITEMTOGROUP: */
11543 case LVM_REDRAWITEMS
:
11544 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11546 /* case LVM_REMOVEALLGROUPS: */
11548 /* case LVM_REMOVEGROUP: */
11551 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11553 case LVM_SETBKCOLOR
:
11554 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11556 /* case LVM_SETBKIMAGE: */
11558 case LVM_SETCALLBACKMASK
:
11559 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11562 case LVM_SETCOLUMNA
:
11563 case LVM_SETCOLUMNW
:
11564 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11565 uMsg
== LVM_SETCOLUMNW
);
11567 case LVM_SETCOLUMNORDERARRAY
:
11568 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11570 case LVM_SETCOLUMNWIDTH
:
11571 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11573 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11574 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11576 /* case LVM_SETGROUPINFO: */
11578 /* case LVM_SETGROUPMETRICS: */
11580 case LVM_SETHOTCURSOR
:
11581 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11583 case LVM_SETHOTITEM
:
11584 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11586 case LVM_SETHOVERTIME
:
11587 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11589 case LVM_SETICONSPACING
:
11591 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11592 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11594 case LVM_SETIMAGELIST
:
11595 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11597 /* case LVM_SETINFOTIP: */
11599 /* case LVM_SETINSERTMARK: */
11601 /* case LVM_SETINSERTMARKCOLOR: */
11606 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11607 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11610 case LVM_SETITEMCOUNT
:
11611 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11613 case LVM_SETITEMPOSITION
:
11616 pt
.x
= (short)LOWORD(lParam
);
11617 pt
.y
= (short)HIWORD(lParam
);
11618 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11621 case LVM_SETITEMPOSITION32
:
11622 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11624 case LVM_SETITEMSTATE
:
11625 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11627 case LVM_SETITEMTEXTA
:
11628 case LVM_SETITEMTEXTW
:
11629 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11630 uMsg
== LVM_SETITEMTEXTW
);
11632 /* case LVM_SETOUTLINECOLOR: */
11634 /* case LVM_SETSELECTEDCOLUMN: */
11636 case LVM_SETSELECTIONMARK
:
11637 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11639 case LVM_SETTEXTBKCOLOR
:
11640 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11642 case LVM_SETTEXTCOLOR
:
11643 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11645 /* case LVM_SETTILEINFO: */
11647 /* case LVM_SETTILEVIEWINFO: */
11649 /* case LVM_SETTILEWIDTH: */
11651 case LVM_SETTOOLTIPS
:
11652 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11654 case LVM_SETUNICODEFORMAT
:
11655 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11658 return LISTVIEW_SetView(infoPtr
, wParam
);
11660 /* case LVM_SETWORKAREAS: */
11662 /* case LVM_SORTGROUPS: */
11664 case LVM_SORTITEMS
:
11665 case LVM_SORTITEMSEX
:
11666 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11667 uMsg
== LVM_SORTITEMSEX
);
11668 case LVM_SUBITEMHITTEST
:
11669 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11672 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11674 case CCM_GETVERSION
:
11675 return LISTVIEW_GetVersion(infoPtr
);
11677 case CCM_SETVERSION
:
11678 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11681 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11684 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11687 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11690 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11693 return LISTVIEW_Destroy(infoPtr
);
11696 return LISTVIEW_Enable(infoPtr
);
11698 case WM_ERASEBKGND
:
11699 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11701 case WM_GETDLGCODE
:
11702 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11705 return (LRESULT
)infoPtr
->hFont
;
11708 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11711 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11714 return LISTVIEW_KillFocus(infoPtr
);
11716 case WM_LBUTTONDBLCLK
:
11717 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11719 case WM_LBUTTONDOWN
:
11720 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11723 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11726 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11728 case WM_MOUSEHOVER
:
11729 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11732 return LISTVIEW_NCDestroy(infoPtr
);
11735 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11738 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11740 case WM_NOTIFYFORMAT
:
11741 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11743 case WM_PRINTCLIENT
:
11744 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11747 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11749 case WM_RBUTTONDBLCLK
:
11750 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11752 case WM_RBUTTONDOWN
:
11753 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11756 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11759 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11762 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11765 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11767 case WM_SHOWWINDOW
:
11768 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11770 case WM_STYLECHANGED
:
11771 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11773 case WM_STYLECHANGING
:
11774 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11776 case WM_SYSCOLORCHANGE
:
11777 COMCTL32_RefreshSysColors();
11779 if (infoPtr
->bDefaultBkColor
)
11781 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
11782 infoPtr
->bDefaultBkColor
= TRUE
;
11783 LISTVIEW_InvalidateList(infoPtr
);
11788 /* case WM_TIMER: */
11789 case WM_THEMECHANGED
:
11790 return LISTVIEW_ThemeChanged(infoPtr
);
11793 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11795 case WM_MOUSEWHEEL
:
11796 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11797 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11798 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11800 case WM_WINDOWPOSCHANGED
:
11801 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11803 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11804 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11806 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11808 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11810 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11812 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11814 /* case WM_WININICHANGE: */
11817 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11818 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11820 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11827 * Registers the window class.
11835 void LISTVIEW_Register(void)
11837 WNDCLASSW wndClass
;
11839 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11840 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11841 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11842 wndClass
.cbClsExtra
= 0;
11843 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11844 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11845 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11846 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11847 RegisterClassW(&wndClass
);
11852 * Unregisters the window class.
11860 void LISTVIEW_Unregister(void)
11862 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11867 * Handle any WM_COMMAND messages
11870 * [I] infoPtr : valid pointer to the listview structure
11871 * [I] wParam : the first message parameter
11872 * [I] lParam : the second message parameter
11877 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11880 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11882 if (!infoPtr
->hwndEdit
) return 0;
11884 switch (HIWORD(wParam
))
11889 * Adjust the edit window size
11891 WCHAR buffer
[1024];
11892 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11893 HFONT hFont
, hOldFont
= 0;
11897 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11898 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11899 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11901 /* Select font to get the right dimension of the string */
11902 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11905 hOldFont
= SelectObject(hdc
, hFont
);
11908 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11910 TEXTMETRICW textMetric
;
11912 /* Add Extra spacing for the next character */
11913 GetTextMetricsW(hdc
, &textMetric
);
11914 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11916 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11917 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11920 SelectObject(hdc
, hOldFont
);
11922 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11928 LISTVIEW_CancelEditLabel(infoPtr
);
11933 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);