4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1999 Luc Tourangeau
6 * Copyright 2000 Jason Mawdsley
7 * Copyright 2001 CodeWeavers Inc.
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009-2013 Nikolay Sivov
10 * Copyright 2009 Owen Rudge for CodeWeavers
11 * Copyright 2012-2013 Daniel Jelinski
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 * This code was audited for completeness against the documented features
30 * of Comctl32.dll version 6.0 on May. 20, 2005, by James Hawkins.
32 * Unless otherwise noted, we believe this code to be complete, as per
33 * the specification mentioned above.
34 * If you discover missing features, or bugs, please note them below.
38 * Default Message Processing
39 * -- WM_CREATE: create the icon and small icon image lists at this point only if
40 * the LVS_SHAREIMAGELISTS style is not specified.
41 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
42 * or small icon and the LVS_AUTOARRANGE style is specified.
47 * -- Hot item handling, mouse hovering
48 * -- Workareas support
53 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
54 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
55 * -- LVA_SNAPTOGRID not implemented
56 * -- LISTVIEW_ApproximateViewRect partially implemented
57 * -- LISTVIEW_SetColumnWidth ignores header images & bitmap
58 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
61 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
62 * linear in the number of items in the list, and this is
63 * unacceptable for large lists.
64 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
65 * binary search to calculate item index (e.g. DPA_Search()).
66 * This requires sorted state to be reliably tracked in item modifiers.
67 * -- we should keep an ordered array of coordinates in iconic mode
68 * this would allow to frame items (iterator_frameditems),
69 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
76 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
81 * -- LVS_NOSCROLL (see Q137520)
85 * -- LVS_EX_BORDERSELECT
89 * -- LVS_EX_MULTIWORKAREAS
91 * -- LVS_EX_SIMPLESELECT
92 * -- LVS_EX_TWOCLICKACTIVATE
93 * -- LVS_EX_UNDERLINECOLD
94 * -- LVS_EX_UNDERLINEHOT
97 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
103 * -- LVM_ENABLEGROUPVIEW
104 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
105 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
106 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
107 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
108 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
109 * -- LVM_GETINSERTMARKRECT
110 * -- LVM_GETNUMBEROFWORKAREAS
111 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
112 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
113 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
114 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
115 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
116 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
117 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
118 * -- LVM_INSERTGROUPSORTED
119 * -- LVM_INSERTMARKHITTEST
120 * -- LVM_ISGROUPVIEWENABLED
122 * -- LVM_MOVEITEMTOGROUP
124 * -- LVM_SETTILEWIDTH
128 * -- ListView_GetHoverTime, ListView_SetHoverTime
129 * -- ListView_GetISearchString
130 * -- ListView_GetNumberOfWorkAreas
131 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
139 #include "comctl32.h"
141 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
143 typedef struct tagCOLUMN_INFO
145 RECT rcHeader
; /* tracks the header's rectangle */
146 INT fmt
; /* same as LVCOLUMN.fmt */
150 typedef struct tagITEMHDR
154 } ITEMHDR
, *LPITEMHDR
;
156 typedef struct tagSUBITEM_INFO
162 typedef struct tagITEM_ID ITEM_ID
;
164 typedef struct tagITEM_INFO
175 UINT id
; /* item id */
176 HDPA item
; /* link to item data */
179 typedef struct tagRANGE
185 typedef struct tagRANGES
190 typedef struct tagITERATOR
199 typedef struct tagDELAYED_ITEM_EDIT
205 typedef struct tagLISTVIEW_INFO
209 RECT rcList
; /* This rectangle is really the window
210 * client rectangle possibly reduced by the
211 * horizontal scroll bar and/or header - see
212 * LISTVIEW_UpdateSize. This rectangle offset
213 * by the LISTVIEW_GetOrigin value is in
214 * client coordinates */
216 /* notification window */
219 BOOL bDoChangeNotify
; /* send change notification messages? */
226 INT nItemCount
; /* the number of items in the list */
227 HDPA hdpaItems
; /* array ITEM_INFO pointers */
228 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
229 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
230 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
231 RANGES selectionRanges
;
232 INT nSelectionMark
; /* item to start next multiselection from */
234 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
237 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
238 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
241 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
246 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
250 DWORD dwStyle
; /* the cached window GWL_STYLE */
251 DWORD dwLvExStyle
; /* extended listview style */
252 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
258 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
261 HIMAGELIST himlNormal
;
262 HIMAGELIST himlSmall
;
263 HIMAGELIST himlState
;
268 POINT currIconPos
; /* this is the position next icon will be placed */
272 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
274 /* marquee selection */
275 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
277 RECT marqueeRect
; /* absolute coordinates of marquee selection */
278 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
279 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
282 BOOL bFocus
; /* control has focus */
284 RECT rcFocus
; /* focus bounds */
291 BOOL bDefaultBkColor
;
296 INT ntmHeight
; /* Some cached metrics of the font used */
297 INT ntmMaxCharWidth
; /* by the listview to draw items */
300 /* mouse operation */
303 POINT ptClickPos
; /* point where the user clicked */
304 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
309 /* keyboard operation */
310 DWORD lastKeyPressTimestamp
;
312 INT nSearchParamLength
;
313 WCHAR szSearchParam
[ MAX_PATH
];
316 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
317 BOOL bIsDrawing
; /* Drawing in progress */
318 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
319 BOOL bRedraw
; /* WM_SETREDRAW switch */
322 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
328 /* How many we debug buffer to allocate */
329 #define DEBUG_BUFFERS 20
330 /* The size of a single debug buffer */
331 #define DEBUG_BUFFER_SIZE 256
333 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
334 #define SB_INTERNAL -1
336 /* maximum size of a label */
337 #define DISP_TEXT_SIZE 260
339 /* padding for items in list and small icon display modes */
340 #define WIDTH_PADDING 12
342 /* padding for items in list, report and small icon display modes */
343 #define HEIGHT_PADDING 1
345 /* offset of items in report display mode */
346 #define REPORT_MARGINX 2
348 /* padding for icon in large icon display mode
349 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
350 * that HITTEST will see.
351 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
352 * ICON_TOP_PADDING - sum of the two above.
353 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
354 * LABEL_HOR_PADDING - between text and sides of box
355 * LABEL_VERT_PADDING - between bottom of text and end of box
357 * ICON_LR_PADDING - additional width above icon size.
358 * ICON_LR_HALF - half of the above value
360 #define ICON_TOP_PADDING_NOTHITABLE 2
361 #define ICON_TOP_PADDING_HITABLE 2
362 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
363 #define ICON_BOTTOM_PADDING 4
364 #define LABEL_HOR_PADDING 5
365 #define LABEL_VERT_PADDING 7
366 #define ICON_LR_PADDING 16
367 #define ICON_LR_HALF (ICON_LR_PADDING/2)
369 /* default label width for items in list and small icon display modes */
370 #define DEFAULT_LABEL_WIDTH 40
371 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
372 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
374 /* default column width for items in list display mode */
375 #define DEFAULT_COLUMN_WIDTH 128
377 /* Size of "line" scroll for V & H scrolls */
378 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
380 /* Padding between image and label */
381 #define IMAGE_PADDING 2
383 /* Padding behind the label */
384 #define TRAILING_LABEL_PADDING 12
385 #define TRAILING_HEADER_PADDING 11
387 /* Border for the icon caption */
388 #define CAPTION_BORDER 2
390 /* Standard DrawText flags */
391 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
392 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
393 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
395 /* Image index from state */
396 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
398 /* The time in milliseconds to reset the search in the list */
399 #define KEY_DELAY 450
401 /* Dump the LISTVIEW_INFO structure to the debug channel */
402 #define LISTVIEW_DUMP(iP) do { \
403 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
404 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
405 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
406 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
407 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
408 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
409 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
410 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
411 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
412 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
415 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
418 * forward declarations
420 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
421 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
422 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
423 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
424 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
425 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
426 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
427 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
428 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
429 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
430 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
431 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
432 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
433 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
434 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
435 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
436 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
437 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
438 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
439 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
441 /******** Text handling functions *************************************/
443 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
444 * text string. The string may be ANSI or Unicode, in which case
445 * the boolean isW tells us the type of the string.
447 * The name of the function tell what type of strings it expects:
448 * W: Unicode, T: ANSI/Unicode - function of isW
451 static inline BOOL
is_text(LPCWSTR text
)
453 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
456 static inline int textlenT(LPCWSTR text
, BOOL isW
)
458 return !is_text(text
) ? 0 :
459 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
462 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
465 if (isSrcW
) lstrcpynW(dest
, src
, max
);
466 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
468 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
469 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
472 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
474 LPWSTR wstr
= (LPWSTR
)text
;
476 if (!isW
&& is_text(text
))
478 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
479 wstr
= Alloc(len
* sizeof(WCHAR
));
480 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
482 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
486 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
488 if (!isW
&& is_text(wstr
)) Free (wstr
);
492 * dest is a pointer to a Unicode string
493 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
495 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
499 if (src
== LPSTR_TEXTCALLBACKW
)
501 if (is_text(*dest
)) Free(*dest
);
502 *dest
= LPSTR_TEXTCALLBACKW
;
506 LPWSTR pszText
= textdupTtoW(src
, isW
);
507 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
508 bResult
= Str_SetPtrW(dest
, pszText
);
509 textfreeT(pszText
, isW
);
515 * compares a Unicode to a Unicode/ANSI text string
517 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
519 if (!aw
) return bt
? -1 : 0;
521 if (aw
== LPSTR_TEXTCALLBACKW
)
522 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
523 if (bt
!= LPSTR_TEXTCALLBACKW
)
525 LPWSTR bw
= textdupTtoW(bt
, isW
);
526 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
534 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
536 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
537 return CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
) - CSTR_EQUAL
;
540 /******** Debugging functions *****************************************/
542 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
544 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
545 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
548 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
550 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
551 n
= min(textlenT(text
, isW
), n
);
552 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
555 static char* debug_getbuf(void)
557 static int index
= 0;
558 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
559 return buffers
[index
++ % DEBUG_BUFFERS
];
562 static inline const char* debugrange(const RANGE
*lprng
)
564 if (!lprng
) return "(null)";
565 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
568 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
570 char* buf
= debug_getbuf(), *text
= buf
;
571 int len
, size
= DEBUG_BUFFER_SIZE
;
573 if (pScrollInfo
== NULL
) return "(null)";
574 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
575 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
576 if (pScrollInfo
->fMask
& SIF_RANGE
)
577 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
579 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
580 if (pScrollInfo
->fMask
& SIF_PAGE
)
581 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
583 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
584 if (pScrollInfo
->fMask
& SIF_POS
)
585 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
587 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
588 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
589 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
591 if (len
== -1) goto end
; buf
+= len
;
594 buf
= text
+ strlen(text
);
596 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
600 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
602 if (!plvnm
) return "(null)";
603 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
604 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
605 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
606 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
609 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
611 char* buf
= debug_getbuf(), *text
= buf
;
612 int len
, size
= DEBUG_BUFFER_SIZE
;
614 if (lpLVItem
== NULL
) return "(null)";
615 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
616 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
617 if (lpLVItem
->mask
& LVIF_STATE
)
618 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
620 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
621 if (lpLVItem
->mask
& LVIF_TEXT
)
622 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
624 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
625 if (lpLVItem
->mask
& LVIF_IMAGE
)
626 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
628 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
629 if (lpLVItem
->mask
& LVIF_PARAM
)
630 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
632 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
633 if (lpLVItem
->mask
& LVIF_INDENT
)
634 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
636 if (len
== -1) goto end
; buf
+= len
;
639 buf
= text
+ strlen(text
);
641 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
645 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
647 char* buf
= debug_getbuf(), *text
= buf
;
648 int len
, size
= DEBUG_BUFFER_SIZE
;
650 if (lpColumn
== NULL
) return "(null)";
651 len
= snprintf(buf
, size
, "{");
652 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
653 if (lpColumn
->mask
& LVCF_SUBITEM
)
654 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
656 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
657 if (lpColumn
->mask
& LVCF_FMT
)
658 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
660 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
661 if (lpColumn
->mask
& LVCF_WIDTH
)
662 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
664 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
665 if (lpColumn
->mask
& LVCF_TEXT
)
666 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
668 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
669 if (lpColumn
->mask
& LVCF_IMAGE
)
670 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
672 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
673 if (lpColumn
->mask
& LVCF_ORDER
)
674 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
676 if (len
== -1) goto end
; buf
+= len
;
679 buf
= text
+ strlen(text
);
681 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
685 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
687 if (!lpht
) return "(null)";
689 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
690 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
693 /* Return the corresponding text for a given scroll value */
694 static inline LPCSTR
debugscrollcode(int nScrollCode
)
698 case SB_LINELEFT
: return "SB_LINELEFT";
699 case SB_LINERIGHT
: return "SB_LINERIGHT";
700 case SB_PAGELEFT
: return "SB_PAGELEFT";
701 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
702 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
703 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
704 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
705 case SB_INTERNAL
: return "SB_INTERNAL";
706 default: return "unknown";
711 /******** Notification functions ************************************/
713 static int get_ansi_notification(UINT unicodeNotificationCode
)
715 switch (unicodeNotificationCode
)
717 case LVN_BEGINLABELEDITA
:
718 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
719 case LVN_ENDLABELEDITA
:
720 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
721 case LVN_GETDISPINFOA
:
722 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
723 case LVN_SETDISPINFOA
:
724 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
725 case LVN_ODFINDITEMA
:
726 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
727 case LVN_GETINFOTIPA
:
728 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
729 /* header forwards */
731 case HDN_TRACKW
: return HDN_TRACKA
;
733 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
734 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
735 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
736 case HDN_ITEMCHANGINGA
:
737 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
738 case HDN_ITEMCHANGEDA
:
739 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
741 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
742 case HDN_DIVIDERDBLCLICKA
:
743 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
746 FIXME("unknown notification %x\n", unicodeNotificationCode
);
747 return unicodeNotificationCode
;
750 /* forwards header notifications to listview parent */
751 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
753 LPCWSTR text
= NULL
, filter
= NULL
;
755 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
757 /* on unicode format exit earlier */
758 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
759 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
762 /* header always supplies unicode notifications,
763 all we have to do is to convert strings to ANSI */
766 /* convert item text */
767 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
769 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
770 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
772 /* convert filter text */
773 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
774 lpnmh
->pitem
->pvFilter
)
776 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
777 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
780 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
782 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
788 Free(lpnmh
->pitem
->pszText
);
789 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
793 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
794 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
800 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
804 TRACE("(code=%d)\n", code
);
806 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
807 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
809 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
811 TRACE(" <= %ld\n", result
);
816 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
819 HWND hwnd
= infoPtr
->hwndSelf
;
820 notify_hdr(infoPtr
, code
, &nmh
);
821 return IsWindow(hwnd
);
824 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
835 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
836 item
.iItem
= htInfo
->iItem
;
838 item
.stateMask
= (UINT
)-1;
839 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
840 nmia
.lParam
= item
.lParam
;
841 nmia
.uOldState
= item
.state
;
842 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
843 nmia
.uChanged
= LVIF_STATE
;
846 nmia
.iItem
= htInfo
->iItem
;
847 nmia
.iSubItem
= htInfo
->iSubItem
;
848 nmia
.ptAction
= htInfo
->pt
;
850 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
851 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
852 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
854 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
857 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
859 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
860 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
863 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
864 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
868 HWND hwnd
= infoPtr
->hwndSelf
;
871 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
872 ZeroMemory(&nmia
, sizeof(nmia
));
873 nmia
.iItem
= lvht
->iItem
;
874 nmia
.iSubItem
= lvht
->iSubItem
;
875 nmia
.ptAction
= lvht
->pt
;
876 item
.mask
= LVIF_PARAM
;
877 item
.iItem
= lvht
->iItem
;
879 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
880 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
881 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
884 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
888 HWND hwnd
= infoPtr
->hwndSelf
;
890 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
892 item
.mask
= LVIF_PARAM
;
895 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
896 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
897 return IsWindow(hwnd
);
901 Send notification. depends on dispinfoW having same
902 structure as dispinfoA.
903 infoPtr : listview struct
904 code : *Unicode* notification code
905 pdi : dispinfo structure (can be unicode or ansi)
906 isW : TRUE if dispinfo is Unicode
908 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
910 INT length
= 0, ret_length
;
911 LPWSTR buffer
= NULL
, ret_text
;
912 BOOL return_ansi
= FALSE
;
913 BOOL return_unicode
= FALSE
;
916 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
918 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
919 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
922 ret_length
= pdi
->item
.cchTextMax
;
923 ret_text
= pdi
->item
.pszText
;
925 if (return_unicode
|| return_ansi
)
927 if (code
!= LVN_GETDISPINFOW
)
929 length
= return_ansi
?
930 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
931 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
935 length
= pdi
->item
.cchTextMax
;
936 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
939 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
940 if (!buffer
) return FALSE
;
943 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
946 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
949 pdi
->item
.pszText
= buffer
;
950 pdi
->item
.cchTextMax
= length
;
953 if (infoPtr
->notifyFormat
== NFR_ANSI
)
954 code
= get_ansi_notification(code
);
956 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
957 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
958 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
960 if (return_ansi
|| return_unicode
)
962 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
964 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
966 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
968 strcpyW(ret_text
, pdi
->item
.pszText
);
970 else if (return_ansi
) /* note : pointer can be changed by app ! */
972 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
973 ret_length
, NULL
, NULL
);
976 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
977 ret_text
, ret_length
);
979 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
980 pdi
->item
.cchTextMax
= ret_length
;
986 /* if dipsinfo holder changed notification code then convert */
987 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
989 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
991 buffer
= Alloc(length
* sizeof(CHAR
));
992 if (!buffer
) return FALSE
;
994 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
995 ret_length
, NULL
, NULL
);
997 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1004 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1005 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1007 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1008 lpnmlvcd
->nmcd
.hdc
= hdc
;
1009 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1010 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1011 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1012 if (!lplvItem
) return;
1013 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1014 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1015 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1016 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1017 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1018 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1021 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1023 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1026 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1027 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1028 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1029 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1030 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1031 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1035 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1037 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
1038 lpnmlvcd
->clrTextBk
= comctl32_color
.clrWindow
;
1039 if (lpnmlvcd
->clrText
== CLR_DEFAULT
)
1040 lpnmlvcd
->clrText
= comctl32_color
.clrWindowText
;
1042 /* apparently, for selected items, we have to override the returned values */
1045 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1047 if (infoPtr
->bFocus
)
1049 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1050 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1052 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1054 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1055 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1060 /* Set the text attributes */
1061 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
1063 SetBkMode(hdc
, OPAQUE
);
1064 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
1067 SetBkMode(hdc
, TRANSPARENT
);
1068 SetTextColor(hdc
, lpnmlvcd
->clrText
);
1071 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1073 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1076 /* returns TRUE when repaint needed, FALSE otherwise */
1077 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1079 MEASUREITEMSTRUCT mis
;
1080 mis
.CtlType
= ODT_LISTVIEW
;
1081 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1085 mis
.itemHeight
= infoPtr
->nItemHeight
;
1086 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1087 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1089 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1095 /******** Item iterator functions **********************************/
1097 static RANGES
ranges_create(int count
);
1098 static void ranges_destroy(RANGES ranges
);
1099 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1100 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1101 static void ranges_dump(RANGES ranges
);
1103 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1105 RANGE range
= { nItem
, nItem
+ 1 };
1107 return ranges_add(ranges
, range
);
1110 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1112 RANGE range
= { nItem
, nItem
+ 1 };
1114 return ranges_del(ranges
, range
);
1118 * ITERATOR DOCUMENTATION
1120 * The iterator functions allow for easy, and convenient iteration
1121 * over items of interest in the list. Typically, you create a
1122 * iterator, use it, and destroy it, as such:
1125 * iterator_xxxitems(&i, ...);
1126 * while (iterator_{prev,next}(&i)
1128 * //code which uses i.nItem
1130 * iterator_destroy(&i);
1132 * where xxx is either: framed, or visible.
1133 * Note that it is important that the code destroys the iterator
1134 * after it's done with it, as the creation of the iterator may
1135 * allocate memory, which thus needs to be freed.
1137 * You can iterate both forwards, and backwards through the list,
1138 * by using iterator_next or iterator_prev respectively.
1140 * Lower numbered items are draw on top of higher number items in
1141 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1142 * items may overlap). So, to test items, you should use
1144 * which lists the items top to bottom (in Z-order).
1145 * For drawing items, you should use
1147 * which lists the items bottom to top (in Z-order).
1148 * If you keep iterating over the items after the end-of-items
1149 * marker (-1) is returned, the iterator will start from the
1150 * beginning. Typically, you don't need to test for -1,
1151 * because iterator_{next,prev} will return TRUE if more items
1152 * are to be iterated over, or FALSE otherwise.
1154 * Note: the iterator is defined to be bidirectional. That is,
1155 * any number of prev followed by any number of next, or
1156 * five versa, should leave the iterator at the same item:
1157 * prev * n, next * n = next * n, prev * n
1159 * The iterator has a notion of an out-of-order, special item,
1160 * which sits at the start of the list. This is used in
1161 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1162 * which needs to be first, as it may overlap other items.
1164 * The code is a bit messy because we have:
1165 * - a special item to deal with
1166 * - simple range, or composite range
1168 * If you find bugs, or want to add features, please make sure you
1169 * always check/modify *both* iterator_prev, and iterator_next.
1173 * This function iterates through the items in increasing order,
1174 * but prefixed by the special item, then -1. That is:
1175 * special, 1, 2, 3, ..., n, -1.
1176 * Each item is listed only once.
1178 static inline BOOL
iterator_next(ITERATOR
* i
)
1182 i
->nItem
= i
->nSpecial
;
1183 if (i
->nItem
!= -1) return TRUE
;
1185 if (i
->nItem
== i
->nSpecial
)
1187 if (i
->ranges
) i
->index
= 0;
1193 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1194 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1199 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1200 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1203 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1205 i
->nItem
= i
->range
.lower
;
1206 if (i
->nItem
>= 0) goto testitem
;
1213 * This function iterates through the items in decreasing order,
1214 * followed by the special item, then -1. That is:
1215 * n, n-1, ..., 3, 2, 1, special, -1.
1216 * Each item is listed only once.
1218 static inline BOOL
iterator_prev(ITERATOR
* i
)
1225 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1228 if (i
->nItem
== i
->nSpecial
)
1236 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1237 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1243 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1246 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1248 i
->nItem
= i
->range
.upper
;
1249 if (i
->nItem
> 0) goto testitem
;
1251 return (i
->nItem
= i
->nSpecial
) != -1;
1254 static RANGE
iterator_range(const ITERATOR
*i
)
1258 if (!i
->ranges
) return i
->range
;
1260 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1262 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1263 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1265 else range
.lower
= range
.upper
= 0;
1271 * Releases resources associated with this iterator.
1273 static inline void iterator_destroy(const ITERATOR
*i
)
1275 ranges_destroy(i
->ranges
);
1279 * Create an empty iterator.
1281 static inline BOOL
iterator_empty(ITERATOR
* i
)
1283 ZeroMemory(i
, sizeof(*i
));
1284 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1289 * Create an iterator over a range.
1291 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1299 * Create an iterator over a bunch of ranges.
1300 * Please note that the iterator will take ownership of the ranges,
1301 * and will free them upon destruction.
1303 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1311 * Creates an iterator over the items which intersect frame.
1312 * Uses absolute coordinates rather than compensating for the current offset.
1314 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1316 RECT rcItem
, rcTemp
;
1318 /* in case we fail, we want to return an empty iterator */
1319 if (!iterator_empty(i
)) return FALSE
;
1321 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1323 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1327 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1329 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1330 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1331 i
->nSpecial
= infoPtr
->nFocusedItem
;
1333 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1334 /* to do better here, we need to have PosX, and PosY sorted */
1335 TRACE("building icon ranges:\n");
1336 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1338 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1339 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1340 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1341 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1342 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1343 ranges_additem(i
->ranges
, nItem
);
1347 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1351 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1352 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1354 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1355 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1356 if (range
.upper
<= range
.lower
) return TRUE
;
1357 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1358 TRACE(" report=%s\n", debugrange(&i
->range
));
1362 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1363 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1364 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1371 if (infoPtr
->nItemWidth
)
1373 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1374 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1378 nFirstCol
= max(frame
->left
, 0);
1379 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1382 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1384 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1385 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1387 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1389 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1390 TRACE("building list ranges:\n");
1391 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1393 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1394 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1395 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1396 TRACE(" list=%s\n", debugrange(&item_range
));
1397 ranges_add(i
->ranges
, item_range
);
1405 * Creates an iterator over the items which intersect lprc.
1407 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1412 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1414 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1415 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1417 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1421 * Creates an iterator over the items which intersect the visible region of hdc.
1423 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1425 POINT Origin
, Position
;
1426 RECT rcItem
, rcClip
;
1429 rgntype
= GetClipBox(hdc
, &rcClip
);
1430 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1431 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1432 if (rgntype
== SIMPLEREGION
) return TRUE
;
1434 /* first deal with the special item */
1435 if (i
->nSpecial
!= -1)
1437 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1438 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1441 /* if we can't deal with the region, we'll just go with the simple range */
1442 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1443 TRACE("building visible range:\n");
1444 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1446 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1447 if (!ranges_add(i
->ranges
, i
->range
))
1449 ranges_destroy(i
->ranges
);
1455 /* now delete the invisible items from the list */
1456 while(iterator_next(i
))
1458 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1459 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1460 rcItem
.top
= Position
.y
+ Origin
.y
;
1461 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1462 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1463 if (!RectVisible(hdc
, &rcItem
))
1464 ranges_delitem(i
->ranges
, i
->nItem
);
1466 /* the iterator should restart on the next iterator_next */
1472 /* Remove common elements from two iterators */
1473 /* Passed iterators have to point on the first elements */
1474 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1476 if(!iter1
->ranges
|| !iter2
->ranges
) {
1479 if(iter1
->ranges
|| iter2
->ranges
||
1480 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1481 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1482 ERR("result is not a one range iterator\n");
1486 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1489 lower
= iter1
->range
.lower
;
1490 upper
= iter1
->range
.upper
;
1492 if(lower
< iter2
->range
.lower
)
1493 iter1
->range
.upper
= iter2
->range
.lower
;
1494 else if(upper
> iter2
->range
.upper
)
1495 iter1
->range
.lower
= iter2
->range
.upper
;
1497 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1499 if(iter2
->range
.lower
< lower
)
1500 iter2
->range
.upper
= lower
;
1501 else if(iter2
->range
.upper
> upper
)
1502 iter2
->range
.lower
= upper
;
1504 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1509 iterator_next(iter1
);
1510 iterator_next(iter2
);
1513 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1516 if(iter1
->nItem
== iter2
->nItem
) {
1517 int delete = iter1
->nItem
;
1519 iterator_prev(iter1
);
1520 iterator_prev(iter2
);
1521 ranges_delitem(iter1
->ranges
, delete);
1522 ranges_delitem(iter2
->ranges
, delete);
1523 iterator_next(iter1
);
1524 iterator_next(iter2
);
1525 } else if(iter1
->nItem
> iter2
->nItem
)
1526 iterator_next(iter2
);
1528 iterator_next(iter1
);
1531 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1532 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1536 /******** Misc helper functions ************************************/
1538 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1539 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1541 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1542 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1545 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1547 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1548 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1551 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1553 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1554 if(state
== 1 || state
== 2)
1558 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1559 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1560 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1564 /* this should be called after window style got updated,
1565 it used to reset view state to match current window style */
1566 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1568 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1571 infoPtr
->uView
= LV_VIEW_ICON
;
1574 infoPtr
->uView
= LV_VIEW_DETAILS
;
1577 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1580 infoPtr
->uView
= LV_VIEW_LIST
;
1584 /* computes next item id value */
1585 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1587 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1591 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1592 return lpID
->id
+ 1;
1597 /******** Internal API functions ************************************/
1599 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1601 static COLUMN_INFO mainItem
;
1603 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1604 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1606 /* update cached column rectangles */
1607 if (infoPtr
->colRectsDirty
)
1610 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1613 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1614 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1615 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1617 Ptr
->colRectsDirty
= FALSE
;
1620 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1623 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1625 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1628 if (infoPtr
->hwndHeader
) return 0;
1630 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1632 /* setup creation flags */
1633 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1634 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1636 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1639 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1640 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1641 if (!infoPtr
->hwndHeader
) return -1;
1643 /* set header unicode format */
1644 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1646 /* set header font */
1647 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1649 /* set header image list */
1650 if (infoPtr
->himlSmall
)
1651 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1653 LISTVIEW_UpdateSize(infoPtr
);
1658 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1660 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1663 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1665 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1666 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1667 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1670 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1672 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1675 /* used to handle collapse main item column case */
1676 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1680 if (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
)
1682 DWORD dwOldBkColor
, dwOldTextColor
;
1684 dwOldBkColor
= SetBkColor(hdc
, RGB(255, 255, 255));
1685 dwOldTextColor
= SetBkColor(hdc
, RGB(0, 0, 0));
1686 Ret
= DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1687 SetBkColor(hdc
, dwOldBkColor
);
1688 SetBkColor(hdc
, dwOldTextColor
);
1693 /* Listview invalidation functions: use _only_ these functions to invalidate */
1695 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1697 return infoPtr
->bRedraw
;
1700 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1702 if(!is_redrawing(infoPtr
)) return;
1703 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1704 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1707 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1711 if(!is_redrawing(infoPtr
)) return;
1712 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1713 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1716 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1718 POINT Origin
, Position
;
1721 if(!is_redrawing(infoPtr
)) return;
1722 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1723 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1724 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1725 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1727 rcBox
.bottom
= infoPtr
->nItemHeight
;
1728 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1729 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1732 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1734 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1737 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1741 if(!is_redrawing(infoPtr
)) return;
1742 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1743 rcCol
.top
= infoPtr
->rcList
.top
;
1744 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1745 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1750 * Retrieves the number of items that can fit vertically in the client area.
1753 * [I] infoPtr : valid pointer to the listview structure
1756 * Number of items per row.
1758 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1760 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1762 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1767 * Retrieves the number of items that can fit horizontally in the client
1771 * [I] infoPtr : valid pointer to the listview structure
1774 * Number of items per column.
1776 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1778 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1780 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1784 /*************************************************************************
1785 * LISTVIEW_ProcessLetterKeys
1787 * Processes keyboard messages generated by pressing the letter keys
1789 * What this does is perform a case insensitive search from the
1790 * current position with the following quirks:
1791 * - If two chars or more are pressed in quick succession we search
1792 * for the corresponding string (e.g. 'abc').
1793 * - If there is a delay we wipe away the current search string and
1794 * restart with just that char.
1795 * - If the user keeps pressing the same character, whether slowly or
1796 * fast, so that the search string is entirely composed of this
1797 * character ('aaaaa' for instance), then we search for first item
1798 * that starting with that character.
1799 * - If the user types the above character in quick succession, then
1800 * we must also search for the corresponding string ('aaaaa'), and
1801 * go to that string if there is a match.
1804 * [I] hwnd : handle to the window
1805 * [I] charCode : the character code, the actual character
1806 * [I] keyData : key data
1814 * - The current implementation has a list of characters it will
1815 * accept and it ignores everything else. In particular it will
1816 * ignore accentuated characters which seems to match what
1817 * Windows does. But I'm not sure it makes sense to follow
1819 * - We don't sound a beep when the search fails.
1823 * TREEVIEW_ProcessLetterKeys
1825 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1827 WCHAR buffer
[MAX_PATH
];
1834 /* simple parameter checking */
1835 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1837 /* only allow the valid WM_CHARs through */
1838 if (!isalnumW(charCode
) &&
1839 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1840 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1841 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1842 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1843 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1844 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1845 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1846 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1847 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1850 /* update the search parameters */
1851 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1852 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1853 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1855 if (diff
>= 0 && diff
< KEY_DELAY
)
1857 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1858 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1860 if (infoPtr
->charCode
!= charCode
)
1861 infoPtr
->charCode
= charCode
= 0;
1865 infoPtr
->charCode
= charCode
;
1866 infoPtr
->szSearchParam
[0] = charCode
;
1867 infoPtr
->nSearchParamLength
= 1;
1870 /* should start from next after focused item, so next item that matches
1871 will be selected, if there isn't any and focused matches it will be selected
1872 on second search stage from beginning of the list */
1873 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1875 /* with some accumulated search data available start with current focus, otherwise
1876 it's excluded from search */
1877 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1878 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1883 /* let application handle this for virtual listview */
1884 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1888 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1889 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1890 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1891 nmlv
.iStart
= startidx
;
1893 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1895 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1899 int i
= startidx
, endidx
;
1901 /* and search from the current position */
1903 endidx
= infoPtr
->nItemCount
;
1905 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1908 /* start from first item if not found with >= startidx */
1909 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1915 for (i
= startidx
; i
< endidx
; i
++)
1918 item
.mask
= LVIF_TEXT
;
1921 item
.pszText
= buffer
;
1922 item
.cchTextMax
= MAX_PATH
;
1923 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1925 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1930 /* this is used to find first char match when search string is not available yet,
1931 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1932 already waiting for user to complete a string */
1933 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1935 /* this would work but we must keep looking for a longer match */
1940 if ( nItem
!= -1 || /* found something */
1941 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1942 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1948 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1953 /*************************************************************************
1954 * LISTVIEW_UpdateHeaderSize [Internal]
1956 * Function to resize the header control
1959 * [I] hwnd : handle to a window
1960 * [I] nNewScrollPos : scroll pos to set
1965 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1970 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1972 if (!infoPtr
->hwndHeader
) return;
1974 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1975 point
[0].x
= winRect
.left
;
1976 point
[0].y
= winRect
.top
;
1977 point
[1].x
= winRect
.right
;
1978 point
[1].y
= winRect
.bottom
;
1980 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1981 point
[0].x
= -nNewScrollPos
;
1982 point
[1].x
+= nNewScrollPos
;
1984 SetWindowPos(infoPtr
->hwndHeader
,0,
1985 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1986 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1987 SWP_NOZORDER
| SWP_NOACTIVATE
);
1992 * Update the scrollbars. This functions should be called whenever
1993 * the content, size or view changes.
1996 * [I] infoPtr : valid pointer to the listview structure
2001 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2003 SCROLLINFO horzInfo
, vertInfo
;
2006 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2008 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2009 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2010 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2012 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2013 if (infoPtr
->uView
== LV_VIEW_LIST
)
2015 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2016 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2018 /* scroll by at least one column per page */
2019 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2020 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2022 if (infoPtr
->nItemWidth
)
2023 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2025 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2027 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2029 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2033 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2036 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2038 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2043 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2044 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2046 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2047 horzInfo
.nMax
= rcHeader
.right
;
2048 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2052 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2053 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2054 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2055 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2056 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2058 /* Setting the horizontal scroll can change the listview size
2059 * (and potentially everything else) so we need to recompute
2060 * everything again for the vertical scroll
2063 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2064 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2065 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2067 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2069 vertInfo
.nMax
= infoPtr
->nItemCount
;
2071 /* scroll by at least one page */
2072 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2073 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2075 if (infoPtr
->nItemHeight
> 0)
2076 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2078 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2082 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2085 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2086 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2087 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2088 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2089 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2091 /* Change of the range may have changed the scroll pos. If so move the content */
2092 if (dx
!= 0 || dy
!= 0)
2095 listRect
= infoPtr
->rcList
;
2096 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2097 SW_ERASE
| SW_INVALIDATE
);
2100 /* Update the Header Control */
2101 if (infoPtr
->hwndHeader
)
2103 horzInfo
.fMask
= SIF_POS
;
2104 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2105 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2112 * Shows/hides the focus rectangle.
2115 * [I] infoPtr : valid pointer to the listview structure
2116 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2121 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2125 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2127 if (infoPtr
->nFocusedItem
< 0) return;
2129 /* we need some gymnastics in ICON mode to handle large items */
2130 if (infoPtr
->uView
== LV_VIEW_ICON
)
2134 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2135 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2137 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2142 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2144 /* for some reason, owner draw should work only in report mode */
2145 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2150 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2151 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2153 item
.iItem
= infoPtr
->nFocusedItem
;
2155 item
.mask
= LVIF_PARAM
;
2156 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2158 ZeroMemory(&dis
, sizeof(dis
));
2159 dis
.CtlType
= ODT_LISTVIEW
;
2160 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2161 dis
.itemID
= item
.iItem
;
2162 dis
.itemAction
= ODA_FOCUS
;
2163 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2164 dis
.hwndItem
= infoPtr
->hwndSelf
;
2166 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2167 dis
.itemData
= item
.lParam
;
2169 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2171 SelectObject(hdc
, hOldFont
);
2175 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2178 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2182 * Invalidates all visible selected items.
2184 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2188 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2189 while(iterator_next(&i
))
2191 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2192 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2194 iterator_destroy(&i
);
2199 * DESCRIPTION: [INTERNAL]
2200 * Computes an item's (left,top) corner, relative to rcView.
2201 * That is, the position has NOT been made relative to the Origin.
2202 * This is deliberate, to avoid computing the Origin over, and
2203 * over again, when this function is called in a loop. Instead,
2204 * one can factor the computation of the Origin before the loop,
2205 * and offset the value returned by this function, on every iteration.
2208 * [I] infoPtr : valid pointer to the listview structure
2209 * [I] nItem : item number
2210 * [O] lpptOrig : item top, left corner
2215 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2217 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2219 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2221 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2222 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2224 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2226 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2227 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2228 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2230 else /* LV_VIEW_DETAILS */
2232 lpptPosition
->x
= REPORT_MARGINX
;
2233 /* item is always at zero indexed column */
2234 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2235 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2236 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2241 * DESCRIPTION: [INTERNAL]
2242 * Compute the rectangles of an item. This is to localize all
2243 * the computations in one place. If you are not interested in some
2244 * of these values, simply pass in a NULL -- the function is smart
2245 * enough to compute only what's necessary. The function computes
2246 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2247 * one, the BOX rectangle. This rectangle is very cheap to compute,
2248 * and is guaranteed to contain all the other rectangles. Computing
2249 * the ICON rect is also cheap, but all the others are potentially
2250 * expensive. This gives an easy and effective optimization when
2251 * searching (like point inclusion, or rectangle intersection):
2252 * first test against the BOX, and if TRUE, test against the desired
2254 * If the function does not have all the necessary information
2255 * to computed the requested rectangles, will crash with a
2256 * failed assertion. This is done so we catch all programming
2257 * errors, given that the function is called only from our code.
2259 * We have the following 'special' meanings for a few fields:
2260 * * If LVIS_FOCUSED is set, we assume the item has the focus
2261 * This is important in ICON mode, where it might get a larger
2262 * then usual rectangle
2264 * Please note that subitem support works only in REPORT mode.
2267 * [I] infoPtr : valid pointer to the listview structure
2268 * [I] lpLVItem : item to compute the measures for
2269 * [O] lprcBox : ptr to Box rectangle
2270 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2271 * [0] lprcSelectBox : ptr to select box rectangle
2272 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2273 * [O] lprcIcon : ptr to Icon rectangle
2274 * Same as LVM_GETITEMRECT with LVIR_ICON
2275 * [O] lprcStateIcon: ptr to State Icon rectangle
2276 * [O] lprcLabel : ptr to Label rectangle
2277 * Same as LVM_GETITEMRECT with LVIR_LABEL
2282 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2283 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2284 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2286 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2287 RECT Box
, SelectBox
, Icon
, Label
;
2288 COLUMN_INFO
*lpColumnInfo
= NULL
;
2289 SIZE labelSize
= { 0, 0 };
2291 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2293 /* Be smart and try to figure out the minimum we have to do */
2294 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2295 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2297 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2298 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2300 if (lprcSelectBox
) doSelectBox
= TRUE
;
2301 if (lprcLabel
) doLabel
= TRUE
;
2302 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2309 /************************************************************/
2310 /* compute the box rectangle (it should be cheap to do) */
2311 /************************************************************/
2312 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2313 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2315 if (lpLVItem
->iSubItem
)
2317 Box
= lpColumnInfo
->rcHeader
;
2322 Box
.right
= infoPtr
->nItemWidth
;
2325 Box
.bottom
= infoPtr
->nItemHeight
;
2327 /******************************************************************/
2328 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2329 /******************************************************************/
2332 LONG state_width
= 0;
2334 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2335 state_width
= infoPtr
->iconStateSize
.cx
;
2337 if (infoPtr
->uView
== LV_VIEW_ICON
)
2339 Icon
.left
= Box
.left
+ state_width
;
2340 if (infoPtr
->himlNormal
)
2341 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2342 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2343 Icon
.right
= Icon
.left
;
2344 Icon
.bottom
= Icon
.top
;
2345 if (infoPtr
->himlNormal
)
2347 Icon
.right
+= infoPtr
->iconSize
.cx
;
2348 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2351 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2353 Icon
.left
= Box
.left
+ state_width
;
2355 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2357 /* we need the indent in report mode */
2358 assert(lpLVItem
->mask
& LVIF_INDENT
);
2359 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2363 Icon
.right
= Icon
.left
;
2364 if (infoPtr
->himlSmall
&&
2365 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2366 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2367 Icon
.right
+= infoPtr
->iconSize
.cx
;
2368 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2370 if(lprcIcon
) *lprcIcon
= Icon
;
2371 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2373 /* TODO: is this correct? */
2376 lprcStateIcon
->left
= Icon
.left
- state_width
;
2377 lprcStateIcon
->right
= Icon
.left
;
2378 lprcStateIcon
->top
= Icon
.top
;
2379 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2380 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2383 else Icon
.right
= 0;
2385 /************************************************************/
2386 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2387 /************************************************************/
2390 /* calculate how far to the right can the label stretch */
2391 Label
.right
= Box
.right
;
2392 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2394 if (lpLVItem
->iSubItem
== 0)
2396 /* we need a zero based rect here */
2397 Label
= lpColumnInfo
->rcHeader
;
2398 OffsetRect(&Label
, -Label
.left
, 0);
2402 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2404 labelSize
.cx
= infoPtr
->nItemWidth
;
2405 labelSize
.cy
= infoPtr
->nItemHeight
;
2409 /* we need the text in non owner draw mode */
2410 assert(lpLVItem
->mask
& LVIF_TEXT
);
2411 if (is_text(lpLVItem
->pszText
))
2413 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2414 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2415 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2419 /* compute rough rectangle where the label will go */
2420 SetRectEmpty(&rcText
);
2421 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2422 rcText
.bottom
= infoPtr
->nItemHeight
;
2423 if (infoPtr
->uView
== LV_VIEW_ICON
)
2424 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2426 /* now figure out the flags */
2427 if (infoPtr
->uView
== LV_VIEW_ICON
)
2428 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2430 uFormat
= LV_SL_DT_FLAGS
;
2432 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2434 if (rcText
.right
!= rcText
.left
)
2435 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2437 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2439 SelectObject(hdc
, hOldFont
);
2440 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2444 if (infoPtr
->uView
== LV_VIEW_ICON
)
2446 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2447 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2448 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2449 Label
.right
= Label
.left
+ labelSize
.cx
;
2450 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2451 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2453 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2454 labelSize
.cy
/= infoPtr
->ntmHeight
;
2455 labelSize
.cy
= max(labelSize
.cy
, 1);
2456 labelSize
.cy
*= infoPtr
->ntmHeight
;
2458 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2460 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2462 Label
.left
= Icon
.right
;
2463 Label
.top
= Box
.top
;
2464 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2465 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2466 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2468 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2470 Label
.left
= Icon
.right
;
2471 Label
.top
= Box
.top
;
2472 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2473 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2476 if (lprcLabel
) *lprcLabel
= Label
;
2477 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2480 /************************************************************/
2481 /* compute SELECT bounding box */
2482 /************************************************************/
2485 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2487 SelectBox
.left
= Icon
.left
;
2488 SelectBox
.top
= Box
.top
;
2489 SelectBox
.bottom
= Box
.bottom
;
2492 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2494 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2498 UnionRect(&SelectBox
, &Icon
, &Label
);
2500 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2501 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2504 /* Fix the Box if necessary */
2507 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2508 else *lprcBox
= Box
;
2510 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2514 * DESCRIPTION: [INTERNAL]
2517 * [I] infoPtr : valid pointer to the listview structure
2518 * [I] nItem : item number
2519 * [O] lprcBox : ptr to Box rectangle
2524 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2526 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2527 POINT Position
, Origin
;
2530 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2531 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2533 /* Be smart and try to figure out the minimum we have to do */
2535 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2536 lvItem
.mask
|= LVIF_TEXT
;
2537 lvItem
.iItem
= nItem
;
2538 lvItem
.iSubItem
= 0;
2539 lvItem
.pszText
= szDispText
;
2540 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2541 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2542 if (infoPtr
->uView
== LV_VIEW_ICON
)
2544 lvItem
.mask
|= LVIF_STATE
;
2545 lvItem
.stateMask
= LVIS_FOCUSED
;
2546 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2548 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2550 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2551 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2553 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2556 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2559 /* LISTVIEW_MapIdToIndex helper */
2560 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2562 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2563 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2565 if (id1
->id
== id2
->id
) return 0;
2567 return (id1
->id
< id2
->id
) ? -1 : 1;
2572 * Returns the item index for id specified.
2575 * [I] infoPtr : valid pointer to the listview structure
2576 * [I] iID : item id to get index for
2579 * Item index, or -1 on failure.
2581 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2586 TRACE("iID=%d\n", iID
);
2588 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2589 if (infoPtr
->nItemCount
== 0) return -1;
2592 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2596 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2597 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2605 * Returns the item id for index given.
2608 * [I] infoPtr : valid pointer to the listview structure
2609 * [I] iItem : item index to get id for
2614 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2619 TRACE("iItem=%d\n", iItem
);
2621 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2622 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2624 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2625 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2627 return lpItem
->id
->id
;
2632 * Returns the current icon position, and advances it along the top.
2633 * The returned position is not offset by Origin.
2636 * [I] infoPtr : valid pointer to the listview structure
2637 * [O] lpPos : will get the current icon position
2642 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2644 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2646 *lpPos
= infoPtr
->currIconPos
;
2648 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2649 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2651 infoPtr
->currIconPos
.x
= 0;
2652 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2658 * Returns the current icon position, and advances it down the left edge.
2659 * The returned position is not offset by Origin.
2662 * [I] infoPtr : valid pointer to the listview structure
2663 * [O] lpPos : will get the current icon position
2668 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2670 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2672 *lpPos
= infoPtr
->currIconPos
;
2674 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2675 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2677 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2678 infoPtr
->currIconPos
.y
= 0;
2684 * Moves an icon to the specified position.
2685 * It takes care of invalidating the item, etc.
2688 * [I] infoPtr : valid pointer to the listview structure
2689 * [I] nItem : the item to move
2690 * [I] lpPos : the new icon position
2691 * [I] isNew : flags the item as being new
2697 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2703 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2704 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2706 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2707 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2710 /* Allocating a POINTER for every item is too resource intensive,
2711 * so we'll keep the (x,y) in different arrays */
2712 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2713 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2715 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2722 * Arranges listview items in icon display mode.
2725 * [I] infoPtr : valid pointer to the listview structure
2726 * [I] nAlignCode : alignment code
2732 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2734 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2738 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2740 TRACE("nAlignCode=%d\n", nAlignCode
);
2742 if (nAlignCode
== LVA_DEFAULT
)
2744 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2745 else nAlignCode
= LVA_ALIGNTOP
;
2750 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2751 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2752 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2753 default: return FALSE
;
2756 infoPtr
->bAutoarrange
= TRUE
;
2757 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2758 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2760 next_pos(infoPtr
, &pos
);
2761 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2769 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2770 * For LVS_REPORT always returns empty rectangle.
2773 * [I] infoPtr : valid pointer to the listview structure
2774 * [O] lprcView : bounding rectangle
2780 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2784 SetRectEmpty(lprcView
);
2786 switch (infoPtr
->uView
)
2789 case LV_VIEW_SMALLICON
:
2790 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2792 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2793 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2794 lprcView
->right
= max(lprcView
->right
, x
);
2795 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2797 if (infoPtr
->nItemCount
> 0)
2799 lprcView
->right
+= infoPtr
->nItemWidth
;
2800 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2805 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2806 x
= infoPtr
->nItemCount
/ y
;
2807 if (infoPtr
->nItemCount
% y
) x
++;
2808 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2809 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2816 * Retrieves the bounding rectangle of all the items.
2819 * [I] infoPtr : valid pointer to the listview structure
2820 * [O] lprcView : bounding rectangle
2826 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2830 TRACE("(lprcView=%p)\n", lprcView
);
2832 if (!lprcView
) return FALSE
;
2834 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2836 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2838 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2839 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2842 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2849 * Retrieves the subitem pointer associated with the subitem index.
2852 * [I] hdpaSubItems : DPA handle for a specific item
2853 * [I] nSubItem : index of subitem
2856 * SUCCESS : subitem pointer
2859 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2861 SUBITEM_INFO
*lpSubItem
;
2864 /* we should binary search here if need be */
2865 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2867 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2868 if (lpSubItem
->iSubItem
== nSubItem
)
2878 * Calculates the desired item width.
2881 * [I] infoPtr : valid pointer to the listview structure
2884 * The desired item width.
2886 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2890 TRACE("uView=%d\n", infoPtr
->uView
);
2892 if (infoPtr
->uView
== LV_VIEW_ICON
)
2893 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2894 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2896 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2901 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2902 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2904 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2905 nItemWidth
= rcHeader
.right
;
2908 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2910 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2914 lvItem
.mask
= LVIF_TEXT
;
2915 lvItem
.iSubItem
= 0;
2917 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2920 lvItem
.pszText
= szDispText
;
2921 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2922 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2923 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2927 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2928 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2930 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2938 * Calculates the desired item height.
2941 * [I] infoPtr : valid pointer to the listview structure
2944 * The desired item height.
2946 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2950 TRACE("uView=%d\n", infoPtr
->uView
);
2952 if (infoPtr
->uView
== LV_VIEW_ICON
)
2953 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2956 nItemHeight
= infoPtr
->ntmHeight
;
2957 if (infoPtr
->himlState
)
2958 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2959 if (infoPtr
->himlSmall
)
2960 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2961 nItemHeight
+= HEIGHT_PADDING
;
2962 if (infoPtr
->nMeasureItemHeight
> 0)
2963 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2966 return max(nItemHeight
, 1);
2971 * Updates the width, and height of an item.
2974 * [I] infoPtr : valid pointer to the listview structure
2979 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2981 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2982 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2988 * Retrieves and saves important text metrics info for the current
2992 * [I] infoPtr : valid pointer to the listview structure
2995 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2997 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2998 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2999 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3003 if (GetTextMetricsW(hdc
, &tm
))
3005 infoPtr
->ntmHeight
= tm
.tmHeight
;
3006 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3009 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3010 infoPtr
->nEllipsisWidth
= sz
.cx
;
3012 SelectObject(hdc
, hOldFont
);
3013 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3015 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3020 * A compare function for ranges
3023 * [I] range1 : pointer to range 1;
3024 * [I] range2 : pointer to range 2;
3028 * > 0 : if range 1 > range 2
3029 * < 0 : if range 2 > range 1
3030 * = 0 : if range intersects range 2
3032 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3036 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3038 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3043 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3048 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3050 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3055 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3057 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3058 ranges_dump(ranges
);
3059 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3061 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3062 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3063 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3065 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3066 assert (prev
->upper
<= curr
->lower
);
3067 assert (curr
->lower
< curr
->upper
);
3071 TRACE("--- Done checking---\n");
3074 static RANGES
ranges_create(int count
)
3076 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3077 if (!ranges
) return NULL
;
3078 ranges
->hdpa
= DPA_Create(count
);
3079 if (ranges
->hdpa
) return ranges
;
3084 static void ranges_clear(RANGES ranges
)
3088 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3089 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3090 DPA_DeleteAllPtrs(ranges
->hdpa
);
3094 static void ranges_destroy(RANGES ranges
)
3096 if (!ranges
) return;
3097 ranges_clear(ranges
);
3098 DPA_Destroy(ranges
->hdpa
);
3102 static RANGES
ranges_clone(RANGES ranges
)
3107 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3109 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3111 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3112 if (!newrng
) goto fail
;
3113 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3114 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
3119 TRACE ("clone failed\n");
3120 ranges_destroy(clone
);
3124 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3128 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3129 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3134 static void ranges_dump(RANGES ranges
)
3138 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3139 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3142 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3144 RANGE srchrng
= { nItem
, nItem
+ 1 };
3146 TRACE("(nItem=%d)\n", nItem
);
3147 ranges_check(ranges
, "before contain");
3148 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3151 static INT
ranges_itemcount(RANGES ranges
)
3155 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3157 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3158 count
+= sel
->upper
- sel
->lower
;
3164 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3166 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3169 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3170 if (index
== -1) return TRUE
;
3172 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3174 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3175 if (chkrng
->lower
>= nItem
)
3176 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3177 if (chkrng
->upper
> nItem
)
3178 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3183 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3188 TRACE("(%s)\n", debugrange(&range
));
3189 ranges_check(ranges
, "before add");
3191 /* try find overlapping regions first */
3192 srchrgn
.lower
= range
.lower
- 1;
3193 srchrgn
.upper
= range
.upper
+ 1;
3194 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3200 TRACE("Adding new range\n");
3202 /* create the brand new range to insert */
3203 newrgn
= Alloc(sizeof(RANGE
));
3204 if(!newrgn
) goto fail
;
3207 /* figure out where to insert it */
3208 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3209 TRACE("index=%d\n", index
);
3210 if (index
== -1) index
= 0;
3212 /* and get it over with */
3213 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3221 RANGE
*chkrgn
, *mrgrgn
;
3222 INT fromindex
, mergeindex
;
3224 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3225 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3227 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3228 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3230 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3232 /* merge now common ranges */
3234 srchrgn
.lower
= chkrgn
->lower
- 1;
3235 srchrgn
.upper
= chkrgn
->upper
+ 1;
3239 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3240 if (mergeindex
== -1) break;
3241 if (mergeindex
== index
)
3243 fromindex
= index
+ 1;
3247 TRACE("Merge with index %i\n", mergeindex
);
3249 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3250 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3251 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3253 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3254 if (mergeindex
< index
) index
--;
3258 ranges_check(ranges
, "after add");
3262 ranges_check(ranges
, "failed add");
3266 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3271 TRACE("(%s)\n", debugrange(&range
));
3272 ranges_check(ranges
, "before del");
3274 /* we don't use DPAS_SORTED here, since we need *
3275 * to find the first overlapping range */
3276 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3279 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3281 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3283 /* case 1: Same range */
3284 if ( (chkrgn
->upper
== range
.upper
) &&
3285 (chkrgn
->lower
== range
.lower
) )
3287 DPA_DeletePtr(ranges
->hdpa
, index
);
3291 /* case 2: engulf */
3292 else if ( (chkrgn
->upper
<= range
.upper
) &&
3293 (chkrgn
->lower
>= range
.lower
) )
3295 DPA_DeletePtr(ranges
->hdpa
, index
);
3298 /* case 3: overlap upper */
3299 else if ( (chkrgn
->upper
<= range
.upper
) &&
3300 (chkrgn
->lower
< range
.lower
) )
3302 chkrgn
->upper
= range
.lower
;
3304 /* case 4: overlap lower */
3305 else if ( (chkrgn
->upper
> range
.upper
) &&
3306 (chkrgn
->lower
>= range
.lower
) )
3308 chkrgn
->lower
= range
.upper
;
3311 /* case 5: fully internal */
3316 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3317 newrgn
->lower
= chkrgn
->lower
;
3318 newrgn
->upper
= range
.lower
;
3319 chkrgn
->lower
= range
.upper
;
3320 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3328 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3331 ranges_check(ranges
, "after del");
3335 ranges_check(ranges
, "failed del");
3341 * Removes all selection ranges
3344 * [I] infoPtr : valid pointer to the listview structure
3345 * [I] toSkip : item range to skip removing the selection
3351 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3360 lvItem
.stateMask
= LVIS_SELECTED
;
3362 /* need to clone the DPA because callbacks can change it */
3363 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3364 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3365 while(iterator_next(&i
))
3366 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3367 /* note that the iterator destructor will free the cloned range */
3368 iterator_destroy(&i
);
3373 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3377 if (!(toSkip
= ranges_create(1))) return FALSE
;
3378 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3379 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3380 ranges_destroy(toSkip
);
3384 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3386 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3391 * Retrieves the number of items that are marked as selected.
3394 * [I] infoPtr : valid pointer to the listview structure
3397 * Number of items selected.
3399 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3401 INT nSelectedCount
= 0;
3403 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3406 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3408 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3413 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3415 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3416 return nSelectedCount
;
3421 * Manages the item focus.
3424 * [I] infoPtr : valid pointer to the listview structure
3425 * [I] nItem : item index
3428 * TRUE : focused item changed
3429 * FALSE : focused item has NOT changed
3431 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3433 INT oldFocus
= infoPtr
->nFocusedItem
;
3436 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3438 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3439 lvItem
.stateMask
= LVIS_FOCUSED
;
3440 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3442 return oldFocus
!= infoPtr
->nFocusedItem
;
3445 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3447 if (nShiftItem
< nItem
) return nShiftItem
;
3449 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3451 if (direction
> 0) return nShiftItem
+ direction
;
3453 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3456 /* This function updates focus index.
3459 focus : current focus index
3460 item : index of item to be added/removed
3461 direction : add/remove flag
3463 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3465 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3467 infoPtr
->bDoChangeNotify
= FALSE
;
3468 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3469 if (focus
!= infoPtr
->nFocusedItem
)
3470 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3471 infoPtr
->bDoChangeNotify
= old_change
;
3476 * Updates the various indices after an item has been inserted or deleted.
3479 * [I] infoPtr : valid pointer to the listview structure
3480 * [I] nItem : item index
3481 * [I] direction : Direction of shift, +1 or -1.
3486 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3488 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3490 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3491 assert(abs(direction
) == 1);
3492 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3494 /* But we are not supposed to modify nHotItem! */
3499 * Adds a block of selections.
3502 * [I] infoPtr : valid pointer to the listview structure
3503 * [I] nItem : item index
3506 * Whether the window is still valid.
3508 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3510 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3511 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3512 HWND hwndSelf
= infoPtr
->hwndSelf
;
3513 NMLVODSTATECHANGE nmlv
;
3518 /* Temporarily disable change notification
3519 * If the control is LVS_OWNERDATA, we need to send
3520 * only one LVN_ODSTATECHANGED notification.
3521 * See MSDN documentation for LVN_ITEMCHANGED.
3523 bOldChange
= infoPtr
->bDoChangeNotify
;
3524 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3526 if (nFirst
== -1) nFirst
= nItem
;
3528 item
.state
= LVIS_SELECTED
;
3529 item
.stateMask
= LVIS_SELECTED
;
3531 for (i
= nFirst
; i
<= nLast
; i
++)
3532 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3534 ZeroMemory(&nmlv
, sizeof(nmlv
));
3535 nmlv
.iFrom
= nFirst
;
3538 nmlv
.uNewState
= item
.state
;
3540 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3541 if (!IsWindow(hwndSelf
))
3543 infoPtr
->bDoChangeNotify
= bOldChange
;
3550 * Sets a single group selection.
3553 * [I] infoPtr : valid pointer to the listview structure
3554 * [I] nItem : item index
3559 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3566 if (!(selection
= ranges_create(100))) return;
3568 item
.state
= LVIS_SELECTED
;
3569 item
.stateMask
= LVIS_SELECTED
;
3571 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3573 if (infoPtr
->nSelectionMark
== -1)
3575 infoPtr
->nSelectionMark
= nItem
;
3576 ranges_additem(selection
, nItem
);
3582 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3583 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3584 ranges_add(selection
, sel
);
3589 RECT rcItem
, rcSel
, rcSelMark
;
3592 rcItem
.left
= LVIR_BOUNDS
;
3593 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3594 ranges_destroy (selection
);
3597 rcSelMark
.left
= LVIR_BOUNDS
;
3598 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3599 ranges_destroy (selection
);
3602 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3603 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3604 while(iterator_next(&i
))
3606 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3607 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3609 iterator_destroy(&i
);
3612 /* disable per item notifications on LVS_OWNERDATA style
3613 FIXME: single LVN_ODSTATECHANGED should be used */
3614 bOldChange
= infoPtr
->bDoChangeNotify
;
3615 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3617 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3620 iterator_rangesitems(&i
, selection
);
3621 while(iterator_next(&i
))
3622 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3623 /* this will also destroy the selection */
3624 iterator_destroy(&i
);
3626 infoPtr
->bDoChangeNotify
= bOldChange
;
3628 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3633 * Sets a single selection.
3636 * [I] infoPtr : valid pointer to the listview structure
3637 * [I] nItem : item index
3642 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3646 TRACE("nItem=%d\n", nItem
);
3648 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3650 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3651 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3652 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3654 infoPtr
->nSelectionMark
= nItem
;
3659 * Set selection(s) with keyboard.
3662 * [I] infoPtr : valid pointer to the listview structure
3663 * [I] nItem : item index
3664 * [I] space : VK_SPACE code sent
3667 * SUCCESS : TRUE (needs to be repainted)
3668 * FAILURE : FALSE (nothing has changed)
3670 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3672 /* FIXME: pass in the state */
3673 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
3674 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
3675 BOOL bResult
= FALSE
;
3677 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3678 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3682 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3683 LISTVIEW_SetSelection(infoPtr
, nItem
);
3687 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3691 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3692 lvItem
.stateMask
= LVIS_SELECTED
;
3695 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3696 if (lvItem
.state
& LVIS_SELECTED
)
3697 infoPtr
->nSelectionMark
= nItem
;
3699 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3702 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3705 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3709 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3711 LVHITTESTINFO lvHitTestInfo
;
3713 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3714 lvHitTestInfo
.pt
.x
= pt
.x
;
3715 lvHitTestInfo
.pt
.y
= pt
.y
;
3717 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3719 lpLVItem
->mask
= LVIF_PARAM
;
3720 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3721 lpLVItem
->iSubItem
= 0;
3723 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3726 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3728 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3729 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3730 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3735 * Called when the mouse is being actively tracked and has hovered for a specified
3739 * [I] infoPtr : valid pointer to the listview structure
3740 * [I] fwKeys : key indicator
3741 * [I] x,y : mouse position
3744 * 0 if the message was processed, non-zero if there was an error
3747 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3748 * over the item for a certain period of time.
3751 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3755 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3757 if (LISTVIEW_IsHotTracking(infoPtr
))
3765 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3766 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3768 SetFocus(infoPtr
->hwndSelf
);
3774 #define SCROLL_LEFT 0x1
3775 #define SCROLL_RIGHT 0x2
3776 #define SCROLL_UP 0x4
3777 #define SCROLL_DOWN 0x8
3781 * Utility routine to draw and highlight items within a marquee selection rectangle.
3784 * [I] infoPtr : valid pointer to the listview structure
3785 * [I] coords_orig : original co-ordinates of the cursor
3786 * [I] coords_offs : offsetted coordinates of the cursor
3787 * [I] offset : offset amount
3788 * [I] scroll : Bitmask of which directions we should scroll, if at all
3793 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3794 const POINT
*coords_offs
, const POINT
*offset
,
3797 BOOL controlDown
= FALSE
;
3799 ITERATOR old_elems
, new_elems
;
3802 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3804 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3805 rect
.right
= coords_offs
->x
;
3809 rect
.left
= coords_offs
->x
;
3810 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3813 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3815 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3816 rect
.bottom
= coords_offs
->y
;
3820 rect
.top
= coords_offs
->y
;
3821 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3824 /* Cancel out the old marquee rectangle and draw the new one */
3825 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3827 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3828 the cursor is further away */
3830 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3831 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3833 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3834 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3836 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3837 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3839 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3840 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3842 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3844 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3846 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3847 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3849 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3850 iterator_remove_common_items(&old_elems
, &new_elems
);
3852 /* Iterate over no longer selected items */
3853 while (iterator_next(&old_elems
))
3855 if (old_elems
.nItem
> -1)
3857 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3860 item
.state
= LVIS_SELECTED
;
3862 item
.stateMask
= LVIS_SELECTED
;
3864 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3867 iterator_destroy(&old_elems
);
3870 /* Iterate over newly selected items */
3871 if (GetKeyState(VK_CONTROL
) & 0x8000)
3874 while (iterator_next(&new_elems
))
3876 if (new_elems
.nItem
> -1)
3878 /* If CTRL is pressed, invert. If not, always select the item. */
3879 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3882 item
.state
= LVIS_SELECTED
;
3884 item
.stateMask
= LVIS_SELECTED
;
3886 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3889 iterator_destroy(&new_elems
);
3891 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3896 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3897 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3900 * [I] hwnd : Handle to the listview
3901 * [I] uMsg : WM_TIMER (ignored)
3902 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3903 * [I] dwTimer : The elapsed time (ignored)
3908 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3910 LISTVIEW_INFO
*infoPtr
;
3911 SCROLLINFO scrollInfo
;
3917 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3922 /* Get the current cursor position and convert to client coordinates */
3923 GetCursorPos(&coords_orig
);
3924 ScreenToClient(hWnd
, &coords_orig
);
3926 /* Ensure coordinates are within client bounds */
3927 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3928 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3931 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3933 /* Offset coordinates by the appropriate amount */
3934 coords_offs
.x
-= offset
.x
;
3935 coords_offs
.y
-= offset
.y
;
3937 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3938 scrollInfo
.fMask
= SIF_ALL
;
3940 /* Work out in which directions we can scroll */
3941 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3943 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3944 scroll
|= SCROLL_UP
;
3946 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3947 scroll
|= SCROLL_DOWN
;
3950 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3952 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3953 scroll
|= SCROLL_LEFT
;
3955 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3956 scroll
|= SCROLL_RIGHT
;
3959 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3960 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3961 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3962 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3964 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3970 * Called whenever WM_MOUSEMOVE is received.
3973 * [I] infoPtr : valid pointer to the listview structure
3974 * [I] fwKeys : key indicator
3975 * [I] x,y : mouse position
3978 * 0 if the message is processed, non-zero if there was an error
3980 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3986 if (!(fwKeys
& MK_LBUTTON
))
3987 infoPtr
->bLButtonDown
= FALSE
;
3989 if (infoPtr
->bLButtonDown
)
3991 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
3992 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
3994 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
3997 if (infoPtr
->bLButtonDown
)
3999 if (infoPtr
->bMarqueeSelect
)
4009 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4011 /* Ensure coordinates are within client bounds */
4012 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4013 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4015 /* Offset coordinates by the appropriate amount */
4016 coords_offs
.x
-= offset
.x
;
4017 coords_offs
.y
-= offset
.y
;
4019 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4020 move the mouse again */
4022 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4023 (y
>= infoPtr
->rcList
.bottom
))
4025 if (!infoPtr
->bScrolling
)
4027 infoPtr
->bScrolling
= TRUE
;
4028 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4033 infoPtr
->bScrolling
= FALSE
;
4034 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4037 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4045 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4047 /* reset item marker */
4048 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4049 infoPtr
->nLButtonDownItem
= -1;
4051 if (!PtInRect(&rect
, pt
))
4053 /* this path covers the following:
4054 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4055 2. change focus with keys
4056 3. move mouse over item from step 1 selects it and moves focus on it */
4057 if (infoPtr
->nLButtonDownItem
!= -1 &&
4058 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4062 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4063 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4065 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4066 infoPtr
->nLButtonDownItem
= -1;
4069 if (!infoPtr
->bDragging
)
4071 ht
.pt
= infoPtr
->ptClickPos
;
4072 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4074 /* If the click is outside the range of an item, begin a
4075 highlight. If not, begin an item drag. */
4080 /* If we're allowing multiple selections, send notification.
4081 If return value is non-zero, cancel. */
4082 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4084 /* Store the absolute coordinates of the click */
4086 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4088 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4089 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4091 /* Begin selection and capture mouse */
4092 infoPtr
->bMarqueeSelect
= TRUE
;
4093 SetCapture(infoPtr
->hwndSelf
);
4100 ZeroMemory(&nmlv
, sizeof(nmlv
));
4101 nmlv
.iItem
= ht
.iItem
;
4102 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4104 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4105 infoPtr
->bDragging
= TRUE
;
4113 /* see if we are supposed to be tracking mouse hovering */
4114 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4115 TRACKMOUSEEVENT trackinfo
;
4117 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4118 trackinfo
.dwFlags
= TME_QUERY
;
4120 /* see if we are already tracking this hwnd */
4121 _TrackMouseEvent(&trackinfo
);
4123 if(!(trackinfo
.dwFlags
& TME_HOVER
) || trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4124 trackinfo
.dwFlags
= TME_HOVER
;
4125 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4126 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4128 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4129 _TrackMouseEvent(&trackinfo
);
4138 * Tests whether the item is assignable to a list with style lStyle
4140 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4142 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4143 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4144 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4152 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4155 * [I] infoPtr : valid pointer to the listview structure
4156 * [I] lpLVItem : valid pointer to new item attributes
4157 * [I] isNew : the item being set is being inserted
4158 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4159 * [O] bChanged : will be set to TRUE if the item really changed
4165 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4171 /* stateMask is ignored for LVM_INSERTITEM */
4172 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4176 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4178 if (lpLVItem
->mask
== 0) return TRUE
;
4180 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4182 /* a virtual listview only stores selection and focus */
4183 if (lpLVItem
->mask
& ~LVIF_STATE
)
4189 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4190 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4194 /* we need to get the lParam and state of the item */
4195 item
.iItem
= lpLVItem
->iItem
;
4196 item
.iSubItem
= lpLVItem
->iSubItem
;
4197 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4198 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4202 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4204 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4205 /* determine what fields will change */
4206 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4207 uChanged
|= LVIF_STATE
;
4209 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4210 uChanged
|= LVIF_IMAGE
;
4212 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4213 uChanged
|= LVIF_PARAM
;
4215 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4216 uChanged
|= LVIF_INDENT
;
4218 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4219 uChanged
|= LVIF_TEXT
;
4221 TRACE("change mask=0x%x\n", uChanged
);
4223 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4224 nmlv
.iItem
= lpLVItem
->iItem
;
4225 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4226 nmlv
.uOldState
= item
.state
;
4227 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4228 nmlv
.lParam
= item
.lParam
;
4230 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4231 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4232 are enabled. Even nothing really changed we still need to send this,
4233 in this case uChanged mask is just set to passed item mask. */
4234 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4236 HWND hwndSelf
= infoPtr
->hwndSelf
;
4238 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4240 if (!IsWindow(hwndSelf
))
4244 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4245 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4246 /* this means we won't hit a focus change path later */
4247 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4249 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4250 infoPtr
->nFocusedItem
++;
4253 if (!uChanged
) return TRUE
;
4256 /* copy information */
4257 if (lpLVItem
->mask
& LVIF_TEXT
)
4258 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4260 if (lpLVItem
->mask
& LVIF_IMAGE
)
4261 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4263 if (lpLVItem
->mask
& LVIF_PARAM
)
4264 lpItem
->lParam
= lpLVItem
->lParam
;
4266 if (lpLVItem
->mask
& LVIF_INDENT
)
4267 lpItem
->iIndent
= lpLVItem
->iIndent
;
4269 if (uChanged
& LVIF_STATE
)
4271 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4273 lpItem
->state
&= ~stateMask
;
4274 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4276 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4278 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4279 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4281 else if (stateMask
& LVIS_SELECTED
)
4283 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4285 /* If we are asked to change focus, and we manage it, do it.
4286 It's important to have all new item data stored at this point,
4287 because changing existing focus could result in a redrawing operation,
4288 which in turn could ask for disp data, application should see all data
4289 for inserted item when processing LVN_GETDISPINFO.
4291 The way this works application will see nested item change notifications -
4292 changed item notifications interrupted by ones from item losing focus. */
4293 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4295 if (lpLVItem
->state
& LVIS_FOCUSED
)
4297 /* update selection mark */
4298 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4299 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4301 if (infoPtr
->nFocusedItem
!= -1)
4303 /* remove current focus */
4304 item
.mask
= LVIF_STATE
;
4306 item
.stateMask
= LVIS_FOCUSED
;
4308 /* recurse with redrawing an item */
4309 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4312 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4313 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4315 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4317 infoPtr
->nFocusedItem
= -1;
4322 /* if we're inserting the item, we're done */
4323 if (isNew
) return TRUE
;
4325 /* send LVN_ITEMCHANGED notification */
4326 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4327 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4334 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4337 * [I] infoPtr : valid pointer to the listview structure
4338 * [I] lpLVItem : valid pointer to new subitem attributes
4339 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4340 * [O] bChanged : will be set to TRUE if the item really changed
4346 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4349 SUBITEM_INFO
*lpSubItem
;
4351 /* we do not support subitems for virtual listviews */
4352 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4354 /* set subitem only if column is present */
4355 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4357 /* First do some sanity checks */
4358 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4359 particularly useful. We currently do not actually do anything with
4360 the flag on subitems.
4362 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4363 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4365 /* get the subitem structure, and create it if not there */
4366 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4367 assert (hdpaSubItems
);
4369 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4372 SUBITEM_INFO
*tmpSubItem
;
4375 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4376 if (!lpSubItem
) return FALSE
;
4377 /* we could binary search here, if need be...*/
4378 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4380 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4381 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4383 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4388 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4389 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4393 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4395 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4399 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4401 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4410 * Sets item attributes.
4413 * [I] infoPtr : valid pointer to the listview structure
4414 * [I] lpLVItem : new item attributes
4415 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4421 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4423 HWND hwndSelf
= infoPtr
->hwndSelf
;
4424 LPWSTR pszText
= NULL
;
4425 BOOL bResult
, bChanged
= FALSE
;
4428 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4430 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4433 /* Store old item area */
4434 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4436 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4437 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4439 pszText
= lpLVItem
->pszText
;
4440 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4443 /* actually set the fields */
4444 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4446 if (lpLVItem
->iSubItem
)
4447 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4449 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4450 if (!IsWindow(hwndSelf
))
4453 /* redraw item, if necessary */
4454 if (bChanged
&& !infoPtr
->bIsDrawing
)
4456 /* this little optimization eliminates some nasty flicker */
4457 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4458 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4459 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4460 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4463 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4464 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4470 textfreeT(lpLVItem
->pszText
, isW
);
4471 lpLVItem
->pszText
= pszText
;
4479 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4482 * [I] infoPtr : valid pointer to the listview structure
4487 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4490 SCROLLINFO scrollInfo
;
4492 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4493 scrollInfo
.fMask
= SIF_POS
;
4495 if (infoPtr
->uView
== LV_VIEW_LIST
)
4497 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4498 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4500 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4502 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4503 nItem
= scrollInfo
.nPos
;
4507 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4508 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4511 TRACE("nItem=%d\n", nItem
);
4519 * Erases the background of the given rectangle
4522 * [I] infoPtr : valid pointer to the listview structure
4523 * [I] hdc : device context handle
4524 * [I] lprcBox : clipping rectangle
4530 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4532 if (!infoPtr
->hBkBrush
) return FALSE
;
4534 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4536 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4544 * [I] infoPtr : valid pointer to the listview structure
4545 * [I] hdc : device context handle
4546 * [I] nItem : item index
4547 * [I] nSubItem : subitem index
4548 * [I] pos : item position in client coordinates
4549 * [I] cdmode : custom draw mode
4555 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
4558 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4559 static WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4560 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4562 RECT rcSelect
, rcBox
, rcIcon
, rcLabel
, rcStateIcon
;
4563 NMLVCUSTOMDRAW nmlvcd
;
4567 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, wine_dbgstr_point(&pos
));
4569 /* get information needed for drawing the item */
4570 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
4571 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
;
4572 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4573 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4574 lvItem
.iItem
= nItem
;
4575 lvItem
.iSubItem
= nSubItem
;
4578 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4579 lvItem
.pszText
= szDispText
;
4580 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4581 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4582 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4583 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
4584 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4586 /* now check if we need to update the focus rectangle */
4587 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4589 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4590 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4591 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4592 OffsetRect(&rcSelect
, pos
.x
, pos
.y
);
4593 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
4594 OffsetRect(&rcStateIcon
, pos
.x
, pos
.y
);
4595 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
4596 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4597 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4598 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4600 /* fill in the custom draw structure */
4601 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4603 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
4604 if (cdmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4605 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4606 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4607 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
4608 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4609 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
4610 if (nSubItem
== 0 && (cdsubitemmode
& CDRF_NOTIFYITEMDRAW
) != 0)
4612 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4613 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4615 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4616 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4617 else if ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) == FALSE
)
4618 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4620 /* FIXME: temporary hack */
4621 rcSelect
.left
= rcLabel
.left
;
4623 /* in icon mode, the label rect is really what we want to draw the
4625 /* in detail mode, we want to paint background for label rect when
4626 * item is not selected or listview has full row select; otherwise paint
4627 * background for text only */
4628 if (infoPtr
->uView
== LV_VIEW_ICON
||
4629 (infoPtr
->uView
== LV_VIEW_DETAILS
&&
4630 (!(lvItem
.state
& LVIS_SELECTED
) ||
4631 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) != 0)))
4634 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
4635 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, NULL
, 0, NULL
);
4637 if(nSubItem
== 0 && infoPtr
->nFocusedItem
== nItem
)
4639 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4641 /* we have to update left focus bound too if item isn't in leftmost column
4642 and reduce right box bound */
4643 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4647 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4649 INT Originx
= pos
.x
- LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
4650 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4651 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4653 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, index
)->rcHeader
.right
+ Originx
;
4654 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4658 rcSelect
.right
= rcBox
.right
;
4661 /* store new focus rectangle */
4662 infoPtr
->rcFocus
= rcSelect
;
4666 if (infoPtr
->himlState
&& STATEIMAGEINDEX(lvItem
.state
) && (nSubItem
== 0))
4668 UINT uStateImage
= STATEIMAGEINDEX(lvItem
.state
);
4671 TRACE("uStateImage=%d\n", uStateImage
);
4672 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
,
4673 rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4678 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4679 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4683 TRACE("iImage=%d\n", lvItem
.iImage
);
4685 if (lvItem
.state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4686 style
= ILD_SELECTED
;
4690 ImageList_DrawEx(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
4691 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4692 lvItem
.state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4693 style
| (lvItem
.state
& LVIS_OVERLAYMASK
));
4696 /* Don't bother painting item being edited */
4697 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
4699 /* figure out the text drawing flags */
4700 uFormat
= (infoPtr
->uView
== LV_VIEW_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4701 if (infoPtr
->uView
== LV_VIEW_ICON
)
4702 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4705 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4707 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
4708 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
4709 default: uFormat
|= DT_LEFT
;
4712 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
4714 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4715 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4717 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4719 /* for GRIDLINES reduce the bottom so the text formats correctly */
4720 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4723 if ((!(lvItem
.state
& LVIS_SELECTED
) || !infoPtr
->bFocus
) && (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTSHADOWTEXT
))
4724 DrawShadowText(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
, RGB(255, 255, 255), RGB(0, 0, 0), 2, 2);
4726 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
4729 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4730 notify_postpaint(infoPtr
, &nmlvcd
);
4736 * Draws listview items when in owner draw mode.
4739 * [I] infoPtr : valid pointer to the listview structure
4740 * [I] hdc : device context handle
4745 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4747 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4748 DWORD cditemmode
= CDRF_DODEFAULT
;
4749 NMLVCUSTOMDRAW nmlvcd
;
4750 POINT Origin
, Position
;
4756 ZeroMemory(&dis
, sizeof(dis
));
4758 /* Get scroll info once before loop */
4759 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4761 /* iterate through the invalidated rows */
4762 while(iterator_next(i
))
4764 item
.iItem
= i
->nItem
;
4766 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4767 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4768 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4770 dis
.CtlType
= ODT_LISTVIEW
;
4772 dis
.itemID
= item
.iItem
;
4773 dis
.itemAction
= ODA_DRAWENTIRE
;
4775 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4776 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4777 dis
.hwndItem
= infoPtr
->hwndSelf
;
4779 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4780 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4781 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4782 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4783 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4784 dis
.itemData
= item
.lParam
;
4786 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4789 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4790 * structure for the rest. of the paint cycle
4792 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4793 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4794 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4796 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4798 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4799 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4802 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4803 notify_postpaint(infoPtr
, &nmlvcd
);
4809 * Draws listview items when in report display mode.
4812 * [I] infoPtr : valid pointer to the listview structure
4813 * [I] hdc : device context handle
4814 * [I] cdmode : custom draw mode
4819 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4822 RECT rcClip
, rcItem
;
4823 POINT Origin
, Position
;
4830 /* figure out what to draw */
4831 rgntype
= GetClipBox(hdc
, &rcClip
);
4832 if (rgntype
== NULLREGION
) return;
4834 /* Get scroll info once before loop */
4835 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4837 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4839 /* narrow down the columns we need to paint */
4840 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4842 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4844 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4845 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4846 ranges_additem(colRanges
, index
);
4848 iterator_rangesitems(&j
, colRanges
);
4850 /* in full row select, we _have_ to draw the main item */
4851 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4854 /* iterate through the invalidated rows */
4855 while(iterator_next(i
))
4857 SelectObject(hdc
, infoPtr
->hFont
);
4858 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4859 Position
.y
+= Origin
.y
;
4861 /* iterate through the invalidated columns */
4862 while(iterator_next(&j
))
4864 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4865 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4867 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4870 rcItem
.bottom
= infoPtr
->nItemHeight
;
4871 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4872 if (!RectVisible(hdc
, &rcItem
)) continue;
4875 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
4878 iterator_destroy(&j
);
4883 * Draws the gridlines if necessary when in report display mode.
4886 * [I] infoPtr : valid pointer to the listview structure
4887 * [I] hdc : device context handle
4892 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4898 RECT rcClip
, rcItem
= {0};
4906 /* figure out what to draw */
4907 rgntype
= GetClipBox(hdc
, &rcClip
);
4908 if (rgntype
== NULLREGION
) return;
4910 /* Get scroll info once before loop */
4911 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4913 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4915 /* narrow down the columns we need to paint */
4916 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4918 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4920 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4921 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4922 ranges_additem(colRanges
, index
);
4925 /* is right most vertical line visible? */
4926 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4928 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4929 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4930 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
4933 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
4935 hOldPen
= SelectObject ( hdc
, hPen
);
4937 /* draw the vertical lines for the columns */
4938 iterator_rangesitems(&j
, colRanges
);
4939 while(iterator_next(&j
))
4941 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4942 if (rcItem
.left
== 0) continue; /* skip leftmost column */
4943 rcItem
.left
+= Origin
.x
;
4944 rcItem
.right
+= Origin
.x
;
4945 rcItem
.top
= infoPtr
->rcList
.top
;
4946 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
4947 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
4948 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4949 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
4951 iterator_destroy(&j
);
4952 /* draw rightmost grid line if visible */
4955 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4956 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4957 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4959 rcItem
.right
+= Origin
.x
;
4961 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
4962 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
4965 /* draw the horizontal lines for the rows */
4966 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
4967 rcItem
.left
= infoPtr
->rcList
.left
;
4968 rcItem
.right
= infoPtr
->rcList
.right
;
4969 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
4971 rcItem
.bottom
= rcItem
.top
= y
;
4972 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
4973 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4974 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
4977 SelectObject( hdc
, hOldPen
);
4978 DeleteObject( hPen
);
4981 ranges_destroy(colRanges
);
4986 * Draws listview items when in list display mode.
4989 * [I] infoPtr : valid pointer to the listview structure
4990 * [I] hdc : device context handle
4991 * [I] cdmode : custom draw mode
4996 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4998 POINT Origin
, Position
;
5000 /* Get scroll info once before loop */
5001 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5003 while(iterator_prev(i
))
5005 SelectObject(hdc
, infoPtr
->hFont
);
5006 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5007 Position
.x
+= Origin
.x
;
5008 Position
.y
+= Origin
.y
;
5010 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
5017 * Draws listview items.
5020 * [I] infoPtr : valid pointer to the listview structure
5021 * [I] hdc : device context handle
5022 * [I] prcErase : rect to be erased before refresh (may be NULL)
5027 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5029 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5030 NMLVCUSTOMDRAW nmlvcd
;
5037 HBITMAP hbmp
= NULL
;
5040 LISTVIEW_DUMP(infoPtr
);
5042 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5043 TRACE("double buffering\n");
5045 hdc
= CreateCompatibleDC(hdcOrig
);
5047 ERR("Failed to create DC for backbuffer\n");
5050 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5051 infoPtr
->rcList
.bottom
);
5053 ERR("Failed to create bitmap for backbuffer\n");
5058 SelectObject(hdc
, hbmp
);
5059 SelectObject(hdc
, infoPtr
->hFont
);
5061 if(GetClipBox(hdcOrig
, &rcClient
))
5062 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5064 /* Save dc values we're gonna trash while drawing
5065 * FIXME: Should be done in LISTVIEW_DrawItem() */
5066 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5067 oldBkMode
= GetBkMode(hdc
);
5068 oldBkColor
= GetBkColor(hdc
);
5069 oldTextColor
= GetTextColor(hdc
);
5072 infoPtr
->bIsDrawing
= TRUE
;
5075 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5076 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5077 /* If no erasing was done (usually because RedrawWindow was called
5078 * with RDW_INVALIDATE only) we need to copy the old contents into
5079 * the backbuffer before continuing. */
5080 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5081 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5082 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5083 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5086 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
5088 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5089 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5090 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5091 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5093 /* nothing to draw */
5094 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5096 /* figure out what we need to draw */
5097 iterator_visibleitems(&i
, infoPtr
, hdc
);
5098 range
= iterator_range(&i
);
5100 /* send cache hint notification */
5101 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5105 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5106 nmlv
.iFrom
= range
.lower
;
5107 nmlv
.iTo
= range
.upper
- 1;
5108 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5111 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5112 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5115 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5116 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5117 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5118 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5120 /* if we have a focus rect and it's visible, draw it */
5121 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5122 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5123 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5125 iterator_destroy(&i
);
5128 /* For LVS_EX_GRIDLINES go and draw lines */
5129 /* This includes the case where there were *no* items */
5130 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5131 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5133 /* Draw marquee rectangle if appropriate */
5134 if (infoPtr
->bMarqueeSelect
)
5136 SetBkColor(hdc
, RGB(255, 255, 255));
5137 SetTextColor(hdc
, RGB(0, 0, 0));
5138 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5141 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5142 notify_postpaint(infoPtr
, &nmlvcd
);
5145 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5146 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5147 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5148 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5153 SelectObject(hdc
, hOldFont
);
5154 SetBkMode(hdc
, oldBkMode
);
5155 SetBkColor(hdc
, oldBkColor
);
5156 SetTextColor(hdc
, oldTextColor
);
5159 infoPtr
->bIsDrawing
= FALSE
;
5165 * Calculates the approximate width and height of a given number of items.
5168 * [I] infoPtr : valid pointer to the listview structure
5169 * [I] nItemCount : number of items
5170 * [I] wWidth : width
5171 * [I] wHeight : height
5174 * Returns a DWORD. The width in the low word and the height in high word.
5176 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5177 WORD wWidth
, WORD wHeight
)
5179 DWORD dwViewRect
= 0;
5181 if (nItemCount
== -1)
5182 nItemCount
= infoPtr
->nItemCount
;
5184 if (infoPtr
->uView
== LV_VIEW_LIST
)
5186 INT nItemCountPerColumn
= 1;
5187 INT nColumnCount
= 0;
5189 if (wHeight
== 0xFFFF)
5191 /* use current height */
5192 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5195 if (wHeight
< infoPtr
->nItemHeight
)
5196 wHeight
= infoPtr
->nItemHeight
;
5200 if (infoPtr
->nItemHeight
> 0)
5202 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5203 if (nItemCountPerColumn
== 0)
5204 nItemCountPerColumn
= 1;
5206 if (nItemCount
% nItemCountPerColumn
!= 0)
5207 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5209 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5213 /* Microsoft padding magic */
5214 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5215 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5217 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5219 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5223 if (infoPtr
->nItemCount
> 0)
5225 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5226 wWidth
= rcBox
.right
- rcBox
.left
;
5227 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5231 /* use current height and width */
5232 if (wHeight
== 0xffff)
5233 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5234 if (wWidth
== 0xffff)
5235 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5238 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5240 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5246 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5247 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5249 if (wWidth
== 0xffff)
5250 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5252 if (wWidth
< nItemWidth
)
5253 wWidth
= nItemWidth
;
5255 cols
= wWidth
/ nItemWidth
;
5256 if (cols
> nItemCount
)
5263 rows
= nItemCount
/ cols
;
5264 if (nItemCount
% cols
)
5270 wHeight
= (nItemHeight
* rows
)+2;
5271 wWidth
= (nItemWidth
* cols
)+2;
5273 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5275 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5276 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5283 * Cancel edit label with saving item text.
5286 * [I] infoPtr : valid pointer to the listview structure
5289 * Always returns TRUE.
5291 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5293 if (infoPtr
->hwndEdit
)
5295 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5296 HWND edit
= infoPtr
->hwndEdit
;
5298 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5299 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5307 * Create a drag image list for the specified item.
5310 * [I] infoPtr : valid pointer to the listview structure
5311 * [I] iItem : index of item
5312 * [O] lppt : Upper-left corner of the image
5315 * Returns a handle to the image list if successful, NULL otherwise.
5317 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5323 HBITMAP hbmp
, hOldbmp
;
5325 HIMAGELIST dragList
= 0;
5326 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5328 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5331 rcItem
.left
= LVIR_BOUNDS
;
5332 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5335 lppt
->x
= rcItem
.left
;
5336 lppt
->y
= rcItem
.top
;
5338 size
.cx
= rcItem
.right
- rcItem
.left
;
5339 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5341 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5342 hdc
= CreateCompatibleDC(hdcOrig
);
5343 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5344 hOldbmp
= SelectObject(hdc
, hbmp
);
5345 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5347 rcItem
.left
= rcItem
.top
= 0;
5348 rcItem
.right
= size
.cx
;
5349 rcItem
.bottom
= size
.cy
;
5350 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5353 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
5355 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5356 SelectObject(hdc
, hOldbmp
);
5357 ImageList_Add(dragList
, hbmp
, 0);
5360 SelectObject(hdc
, hOldbmp
);
5362 SelectObject(hdc
, hOldFont
);
5365 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5367 TRACE("ret=%p\n", dragList
);
5375 * Removes all listview items and subitems.
5378 * [I] infoPtr : valid pointer to the listview structure
5384 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5387 HDPA hdpaSubItems
= NULL
;
5396 /* we do it directly, to avoid notifications */
5397 ranges_clear(infoPtr
->selectionRanges
);
5398 infoPtr
->nSelectionMark
= -1;
5399 infoPtr
->nFocusedItem
= -1;
5400 SetRectEmpty(&infoPtr
->rcFocus
);
5401 /* But we are supposed to leave nHotItem as is! */
5404 /* send LVN_DELETEALLITEMS notification */
5405 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
5407 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5409 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5411 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5413 /* send LVN_DELETEITEM notification, if not suppressed
5414 and if it is not a virtual listview */
5415 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
5416 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5417 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5418 /* free id struct */
5419 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5420 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5421 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5423 /* both item and subitem start with ITEMHDR header */
5424 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5426 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5427 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5430 DPA_Destroy(hdpaSubItems
);
5431 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5433 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5434 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5435 infoPtr
->nItemCount
--;
5440 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5441 LISTVIEW_UpdateScroll(infoPtr
);
5443 LISTVIEW_InvalidateList(infoPtr
);
5450 * Scrolls, and updates the columns, when a column is changing width.
5453 * [I] infoPtr : valid pointer to the listview structure
5454 * [I] nColumn : column to scroll
5455 * [I] dx : amount of scroll, in pixels
5460 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5462 COLUMN_INFO
*lpColumnInfo
;
5468 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5469 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5470 rcCol
= lpColumnInfo
->rcHeader
;
5471 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5472 rcCol
.left
= rcCol
.right
;
5474 /* adjust the other columns */
5475 hdi
.mask
= HDI_ORDER
;
5476 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5478 INT nOrder
= hdi
.iOrder
;
5479 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5481 hdi
.mask
= HDI_ORDER
;
5482 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5483 if (hdi
.iOrder
>= nOrder
) {
5484 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5485 lpColumnInfo
->rcHeader
.left
+= dx
;
5486 lpColumnInfo
->rcHeader
.right
+= dx
;
5491 /* do not update screen if not in report mode */
5492 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5494 /* Need to reset the item width when inserting a new column */
5495 infoPtr
->nItemWidth
+= dx
;
5497 LISTVIEW_UpdateScroll(infoPtr
);
5498 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5500 /* scroll to cover the deleted column, and invalidate for redraw */
5501 rcOld
= infoPtr
->rcList
;
5502 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5503 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5508 * Removes a column from the listview control.
5511 * [I] infoPtr : valid pointer to the listview structure
5512 * [I] nColumn : column index
5518 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5522 TRACE("nColumn=%d\n", nColumn
);
5524 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5525 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5527 /* While the MSDN specifically says that column zero should not be deleted,
5528 what actually happens is that the column itself is deleted but no items or subitems
5532 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5534 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5537 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5538 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5540 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5542 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5544 INT nItem
, nSubItem
, i
;
5546 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5548 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5551 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5553 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5554 if (lpSubItem
->iSubItem
== nColumn
)
5557 lpDelItem
= lpSubItem
;
5559 else if (lpSubItem
->iSubItem
> nColumn
)
5561 lpSubItem
->iSubItem
--;
5565 /* if we found our subitem, zap it */
5569 if (is_text(lpDelItem
->hdr
.pszText
))
5570 Free(lpDelItem
->hdr
.pszText
);
5575 /* free dpa memory */
5576 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5581 /* update the other column info */
5582 LISTVIEW_UpdateItemSize(infoPtr
);
5583 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5584 LISTVIEW_InvalidateList(infoPtr
);
5586 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5593 * Invalidates the listview after an item's insertion or deletion.
5596 * [I] infoPtr : valid pointer to the listview structure
5597 * [I] nItem : item index
5598 * [I] dir : -1 if deleting, 1 if inserting
5603 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5605 INT nPerCol
, nItemCol
, nItemRow
;
5609 /* if we don't refresh, what's the point of scrolling? */
5610 if (!is_redrawing(infoPtr
)) return;
5612 assert (abs(dir
) == 1);
5614 /* arrange icons if autoarrange is on */
5615 if (is_autoarrange(infoPtr
))
5617 BOOL arrange
= TRUE
;
5618 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5619 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5620 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5623 /* scrollbars need updating */
5624 LISTVIEW_UpdateScroll(infoPtr
);
5626 /* figure out the item's position */
5627 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5628 nPerCol
= infoPtr
->nItemCount
+ 1;
5629 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5630 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5631 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5634 nItemCol
= nItem
/ nPerCol
;
5635 nItemRow
= nItem
% nPerCol
;
5636 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5638 /* move the items below up a slot */
5639 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5640 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5641 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5642 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5643 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5644 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5645 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5647 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5648 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5651 /* report has only that column, so we're done */
5652 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5654 /* now for LISTs, we have to deal with the columns to the right */
5655 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5657 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5658 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5659 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5660 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5661 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5666 * Removes an item from the listview control.
5669 * [I] infoPtr : valid pointer to the listview structure
5670 * [I] nItem : item index
5676 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5679 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5680 INT focus
= infoPtr
->nFocusedItem
;
5682 TRACE("(nItem=%d)\n", nItem
);
5684 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5686 /* remove selection, and focus */
5688 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5689 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5691 /* send LVN_DELETEITEM notification. */
5692 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5694 /* we need to do this here, because we'll be deleting stuff */
5696 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5698 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5706 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5707 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5709 /* free id struct */
5710 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5711 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5712 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5714 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5716 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5717 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5720 DPA_Destroy(hdpaSubItems
);
5725 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5726 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5729 infoPtr
->nItemCount
--;
5730 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5731 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5733 /* now is the invalidation fun */
5735 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5742 * Callback implementation for editlabel control
5745 * [I] infoPtr : valid pointer to the listview structure
5746 * [I] storeText : store edit box text as item text
5747 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5753 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5755 HWND hwndSelf
= infoPtr
->hwndSelf
;
5756 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5757 NMLVDISPINFOW dispInfo
;
5758 INT editedItem
= infoPtr
->nEditLabelItem
;
5760 WCHAR
*pszText
= NULL
;
5765 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5769 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5771 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5772 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5777 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5779 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5780 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5781 dispInfo
.item
.iItem
= editedItem
;
5782 dispInfo
.item
.iSubItem
= 0;
5783 dispInfo
.item
.stateMask
= ~0;
5784 dispInfo
.item
.pszText
= szDispText
;
5785 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5786 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5793 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5796 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5797 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5798 textfreeT(tmp
, FALSE
);
5801 /* add the text from the edit in */
5802 dispInfo
.item
.mask
|= LVIF_TEXT
;
5803 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5804 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5806 /* Do we need to update the Item Text */
5807 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5809 infoPtr
->nEditLabelItem
= -1;
5810 infoPtr
->hwndEdit
= 0;
5812 if (!res
) goto cleanup
;
5814 if (!IsWindow(hwndSelf
))
5819 if (!pszText
) return TRUE
;
5826 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5828 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5829 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5830 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5832 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5838 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5839 dispInfo
.item
.mask
= LVIF_TEXT
;
5840 dispInfo
.item
.iItem
= editedItem
;
5841 dispInfo
.item
.iSubItem
= 0;
5842 dispInfo
.item
.pszText
= pszText
;
5843 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5844 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5854 * Subclassed edit control windproc function
5857 * [I] hwnd : the edit window handle
5858 * [I] uMsg : the message that is to be processed
5859 * [I] wParam : first message parameter
5860 * [I] lParam : second message parameter
5861 * [I] isW : TRUE if input is Unicode
5866 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5868 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5871 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5872 hwnd
, uMsg
, wParam
, lParam
, isW
);
5877 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5881 WNDPROC editProc
= infoPtr
->EditWndProc
;
5882 infoPtr
->EditWndProc
= 0;
5883 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5884 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5888 if (VK_ESCAPE
== (INT
)wParam
)
5893 else if (VK_RETURN
== (INT
)wParam
)
5897 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5901 if (infoPtr
->hwndEdit
)
5902 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
5904 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
5910 * Subclassed edit control Unicode windproc function
5913 * [I] hwnd : the edit window handle
5914 * [I] uMsg : the message that is to be processed
5915 * [I] wParam : first message parameter
5916 * [I] lParam : second message parameter
5920 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5922 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
5927 * Subclassed edit control ANSI windproc function
5930 * [I] hwnd : the edit window handle
5931 * [I] uMsg : the message that is to be processed
5932 * [I] wParam : first message parameter
5933 * [I] lParam : second message parameter
5937 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5939 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
5944 * Creates a subclassed edit control
5947 * [I] infoPtr : valid pointer to the listview structure
5948 * [I] text : initial text for the edit
5949 * [I] style : the window style
5950 * [I] isW : TRUE if input is Unicode
5954 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
5956 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
5957 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
5960 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
5962 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
5964 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5966 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5968 if (!hedit
) return 0;
5970 infoPtr
->EditWndProc
= (WNDPROC
)
5971 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
5972 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
5974 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
5975 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
5982 * Begin in place editing of specified list view item
5985 * [I] infoPtr : valid pointer to the listview structure
5986 * [I] nItem : item index
5987 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
5993 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
5995 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
5996 HWND hwndSelf
= infoPtr
->hwndSelf
;
5997 NMLVDISPINFOW dispInfo
;
5998 HFONT hOldFont
= NULL
;
6004 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6006 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6008 /* remove existing edit box */
6009 if (infoPtr
->hwndEdit
)
6011 SetFocus(infoPtr
->hwndSelf
);
6012 infoPtr
->hwndEdit
= 0;
6015 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6017 infoPtr
->nEditLabelItem
= nItem
;
6019 LISTVIEW_SetSelection(infoPtr
, nItem
);
6020 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6021 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6023 rect
.left
= LVIR_LABEL
;
6024 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6026 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6027 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6028 dispInfo
.item
.iItem
= nItem
;
6029 dispInfo
.item
.iSubItem
= 0;
6030 dispInfo
.item
.stateMask
= ~0;
6031 dispInfo
.item
.pszText
= disptextW
;
6032 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6033 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6035 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6036 if (!infoPtr
->hwndEdit
) return 0;
6038 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6040 if (!IsWindow(hwndSelf
))
6042 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6043 infoPtr
->hwndEdit
= 0;
6047 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6049 /* position and display edit box */
6050 hdc
= GetDC(infoPtr
->hwndSelf
);
6052 /* select the font to get appropriate metric dimensions */
6054 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6056 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6057 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6058 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6060 /* get string length in pixels */
6061 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6063 /* add extra spacing for the next character */
6064 GetTextMetricsW(hdc
, &tm
);
6065 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6068 SelectObject(hdc
, hOldFont
);
6070 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6072 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6075 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6076 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6077 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6078 SetFocus(infoPtr
->hwndEdit
);
6079 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6080 return infoPtr
->hwndEdit
;
6086 * Ensures the specified item is visible, scrolling into view if necessary.
6089 * [I] infoPtr : valid pointer to the listview structure
6090 * [I] nItem : item index
6091 * [I] bPartial : partially or entirely visible
6097 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6099 INT nScrollPosHeight
= 0;
6100 INT nScrollPosWidth
= 0;
6101 INT nHorzAdjust
= 0;
6102 INT nVertAdjust
= 0;
6105 RECT rcItem
, rcTemp
;
6107 rcItem
.left
= LVIR_BOUNDS
;
6108 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6110 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6112 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6114 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6115 if (infoPtr
->uView
== LV_VIEW_LIST
)
6116 nScrollPosWidth
= infoPtr
->nItemWidth
;
6117 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6118 nScrollPosWidth
= 1;
6120 if (rcItem
.left
< infoPtr
->rcList
.left
)
6123 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6128 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6132 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6134 /* scroll up/down, but not in LVS_LIST mode */
6135 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6136 nScrollPosHeight
= infoPtr
->nItemHeight
;
6137 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6138 nScrollPosHeight
= 1;
6140 if (rcItem
.top
< infoPtr
->rcList
.top
)
6143 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6148 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6152 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6154 if (nScrollPosWidth
)
6156 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6157 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6158 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6161 if (nScrollPosHeight
)
6163 INT diff
= nVertDiff
/ nScrollPosHeight
;
6164 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6165 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6173 * Searches for an item with specific characteristics.
6176 * [I] hwnd : window handle
6177 * [I] nStart : base item index
6178 * [I] lpFindInfo : item information to look for
6181 * SUCCESS : index of item
6184 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6185 const LVFINDINFOW
*lpFindInfo
)
6187 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6188 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6189 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6190 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6191 POINT Position
, Destination
;
6194 /* Search in virtual listviews should be done by application, not by
6195 listview control, so we just send LVN_ODFINDITEMW and return the result */
6196 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6200 nmlv
.iStart
= nStart
;
6201 nmlv
.lvfi
= *lpFindInfo
;
6202 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6205 if (!lpFindInfo
|| nItem
< 0) return -1;
6208 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6209 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6211 lvItem
.mask
|= LVIF_TEXT
;
6212 lvItem
.pszText
= szDispText
;
6213 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6216 if (lpFindInfo
->flags
& LVFI_WRAP
)
6219 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6220 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6225 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6226 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6227 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6228 switch(lpFindInfo
->vkDirection
)
6230 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6231 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6232 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6233 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6234 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6235 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6236 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6238 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6239 Destination
.x
= rcArea
.right
;
6240 Destination
.y
= rcArea
.bottom
;
6242 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6246 else Destination
.x
= Destination
.y
= 0;
6248 /* if LVFI_PARAM is specified, all other flags are ignored */
6249 if (lpFindInfo
->flags
& LVFI_PARAM
)
6251 lvItem
.mask
|= LVIF_PARAM
;
6253 lvItem
.mask
&= ~LVIF_TEXT
;
6257 for (; nItem
< nLast
; nItem
++)
6259 lvItem
.iItem
= nItem
;
6260 lvItem
.iSubItem
= 0;
6261 lvItem
.pszText
= szDispText
;
6262 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6264 if (lvItem
.mask
& LVIF_PARAM
)
6266 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6272 if (lvItem
.mask
& LVIF_TEXT
)
6274 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6276 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6277 if (!p
|| p
!= lvItem
.pszText
) continue;
6281 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6285 if (!bNearest
) return nItem
;
6287 /* This is very inefficient. To do a good job here,
6288 * we need a sorted array of (x,y) item positions */
6289 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6291 /* compute the distance^2 to the destination */
6292 xdist
= Destination
.x
- Position
.x
;
6293 ydist
= Destination
.y
- Position
.y
;
6294 dist
= xdist
* xdist
+ ydist
* ydist
;
6296 /* remember the distance, and item if it's closer */
6300 nNearestItem
= nItem
;
6307 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6312 return nNearestItem
;
6317 * Searches for an item with specific characteristics.
6320 * [I] hwnd : window handle
6321 * [I] nStart : base item index
6322 * [I] lpFindInfo : item information to look for
6325 * SUCCESS : index of item
6328 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6329 const LVFINDINFOA
*lpFindInfo
)
6331 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6332 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6337 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6338 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6339 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6340 textfreeT(strW
, FALSE
);
6346 * Retrieves column attributes.
6349 * [I] infoPtr : valid pointer to the listview structure
6350 * [I] nColumn : column index
6351 * [IO] lpColumn : column information
6352 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6353 * otherwise it is in fact a LPLVCOLUMNA
6359 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6361 COLUMN_INFO
*lpColumnInfo
;
6364 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6365 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6367 /* initialize memory */
6368 ZeroMemory(&hdi
, sizeof(hdi
));
6370 if (lpColumn
->mask
& LVCF_TEXT
)
6372 hdi
.mask
|= HDI_TEXT
;
6373 hdi
.pszText
= lpColumn
->pszText
;
6374 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6377 if (lpColumn
->mask
& LVCF_IMAGE
)
6378 hdi
.mask
|= HDI_IMAGE
;
6380 if (lpColumn
->mask
& LVCF_ORDER
)
6381 hdi
.mask
|= HDI_ORDER
;
6383 if (lpColumn
->mask
& LVCF_SUBITEM
)
6384 hdi
.mask
|= HDI_LPARAM
;
6386 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6388 if (lpColumn
->mask
& LVCF_FMT
)
6389 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6391 if (lpColumn
->mask
& LVCF_WIDTH
)
6392 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6394 if (lpColumn
->mask
& LVCF_IMAGE
)
6395 lpColumn
->iImage
= hdi
.iImage
;
6397 if (lpColumn
->mask
& LVCF_ORDER
)
6398 lpColumn
->iOrder
= hdi
.iOrder
;
6400 if (lpColumn
->mask
& LVCF_SUBITEM
)
6401 lpColumn
->iSubItem
= hdi
.lParam
;
6403 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6404 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6410 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6412 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
6417 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6422 * Retrieves the column width.
6425 * [I] infoPtr : valid pointer to the listview structure
6426 * [I] int : column index
6429 * SUCCESS : column width
6432 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6434 INT nColumnWidth
= 0;
6437 TRACE("nColumn=%d\n", nColumn
);
6439 /* we have a 'column' in LIST and REPORT mode only */
6440 switch(infoPtr
->uView
)
6443 nColumnWidth
= infoPtr
->nItemWidth
;
6445 case LV_VIEW_DETAILS
:
6446 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6447 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6448 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6450 * TODO: should we do the same in LVM_GETCOLUMN?
6452 hdItem
.mask
= HDI_WIDTH
;
6453 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6455 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6458 nColumnWidth
= hdItem
.cxy
;
6462 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6463 return nColumnWidth
;
6468 * In list or report display mode, retrieves the number of items that can fit
6469 * vertically in the visible area. In icon or small icon display mode,
6470 * retrieves the total number of visible items.
6473 * [I] infoPtr : valid pointer to the listview structure
6476 * Number of fully visible items.
6478 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6480 switch (infoPtr
->uView
)
6483 case LV_VIEW_SMALLICON
:
6484 return infoPtr
->nItemCount
;
6485 case LV_VIEW_DETAILS
:
6486 return LISTVIEW_GetCountPerColumn(infoPtr
);
6488 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6496 * Retrieves an image list handle.
6499 * [I] infoPtr : valid pointer to the listview structure
6500 * [I] nImageList : image list identifier
6503 * SUCCESS : image list handle
6506 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6510 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6511 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6512 case LVSIL_STATE
: return infoPtr
->himlState
;
6513 case LVSIL_GROUPHEADER
:
6514 FIXME("LVSIL_GROUPHEADER not supported\n");
6517 WARN("got unknown imagelist index - %d\n", nImageList
);
6522 /* LISTVIEW_GetISearchString */
6526 * Retrieves item attributes.
6529 * [I] hwnd : window handle
6530 * [IO] lpLVItem : item info
6531 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6532 * if FALSE, then lpLVItem is a LPLVITEMA.
6535 * This is the internal 'GetItem' interface -- it tries to
6536 * be smart and avoid text copies, if possible, by modifying
6537 * lpLVItem->pszText to point to the text string. Please note
6538 * that this is not always possible (e.g. OWNERDATA), so on
6539 * entry you *must* supply valid values for pszText, and cchTextMax.
6540 * The only difference to the documented interface is that upon
6541 * return, you should use *only* the lpLVItem->pszText, rather than
6542 * the buffer pointer you provided on input. Most code already does
6543 * that, so it's not a problem.
6544 * For the two cases when the text must be copied (that is,
6545 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6551 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6553 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6554 NMLVDISPINFOW dispInfo
;
6560 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6562 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6565 if (lpLVItem
->mask
== 0) return TRUE
;
6566 TRACE("mask=%x\n", lpLVItem
->mask
);
6568 /* make a local copy */
6569 isubitem
= lpLVItem
->iSubItem
;
6571 /* a quick optimization if all we're asked is the focus state
6572 * these queries are worth optimising since they are common,
6573 * and can be answered in constant time, without the heavy accesses */
6574 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6575 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6577 lpLVItem
->state
= 0;
6578 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6579 lpLVItem
->state
|= LVIS_FOCUSED
;
6583 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6585 /* if the app stores all the data, handle it separately */
6586 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6588 dispInfo
.item
.state
= 0;
6590 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6591 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6592 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6594 UINT mask
= lpLVItem
->mask
;
6596 /* NOTE: copy only fields which we _know_ are initialized, some apps
6597 * depend on the uninitialized fields being 0 */
6598 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6599 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6600 dispInfo
.item
.iSubItem
= isubitem
;
6601 if (lpLVItem
->mask
& LVIF_TEXT
)
6603 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6605 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6608 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6609 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6612 if (lpLVItem
->mask
& LVIF_STATE
)
6613 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6614 /* could be zeroed on LVIF_NORECOMPUTE case */
6615 if (dispInfo
.item
.mask
)
6617 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6618 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6619 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6621 /* full size structure expected - _WIN32IE >= 0x560 */
6622 *lpLVItem
= dispInfo
.item
;
6624 else if (lpLVItem
->mask
& LVIF_INDENT
)
6626 /* indent member expected - _WIN32IE >= 0x300 */
6627 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6631 /* minimal structure expected */
6632 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6634 lpLVItem
->mask
= mask
;
6635 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6639 /* make sure lParam is zeroed out */
6640 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6642 /* callback marked pointer required here */
6643 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6644 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6646 /* we store only a little state, so if we're not asked, we're done */
6647 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6649 /* if focus is handled by us, report it */
6650 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6652 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6653 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6654 lpLVItem
->state
|= LVIS_FOCUSED
;
6657 /* and do the same for selection, if we handle it */
6658 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6660 lpLVItem
->state
&= ~LVIS_SELECTED
;
6661 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6662 lpLVItem
->state
|= LVIS_SELECTED
;
6668 /* find the item and subitem structures before we proceed */
6669 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6670 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6675 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6676 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6679 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6684 pItemHdr
= &lpItem
->hdr
;
6686 /* Do we need to query the state from the app? */
6687 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6689 dispInfo
.item
.mask
|= LVIF_STATE
;
6690 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6693 /* Do we need to enquire about the image? */
6694 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6695 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6697 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6698 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6701 /* Only items support indentation */
6702 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6705 dispInfo
.item
.mask
|= LVIF_INDENT
;
6706 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6709 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6710 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6711 !is_text(pItemHdr
->pszText
))
6713 dispInfo
.item
.mask
|= LVIF_TEXT
;
6714 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6715 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6716 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6717 *dispInfo
.item
.pszText
= '\0';
6720 /* If we don't have all the requested info, query the application */
6721 if (dispInfo
.item
.mask
)
6723 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6724 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6725 dispInfo
.item
.lParam
= lpItem
->lParam
;
6726 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6727 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6730 /* we should not store values for subitems */
6731 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6733 /* Now, handle the iImage field */
6734 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6736 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6737 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6738 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6740 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6742 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6743 lpLVItem
->iImage
= pItemHdr
->iImage
;
6745 lpLVItem
->iImage
= 0;
6748 /* The pszText field */
6749 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6751 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6752 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6754 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6756 else if (lpLVItem
->mask
& LVIF_TEXT
)
6758 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6759 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6760 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6763 /* Next is the lParam field */
6764 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6766 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6767 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6768 lpItem
->lParam
= dispInfo
.item
.lParam
;
6770 else if (lpLVItem
->mask
& LVIF_PARAM
)
6771 lpLVItem
->lParam
= lpItem
->lParam
;
6773 /* if this is a subitem, we're done */
6774 if (isubitem
) return TRUE
;
6776 /* ... the state field (this one is different due to uCallbackmask) */
6777 if (lpLVItem
->mask
& LVIF_STATE
)
6779 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6780 if (dispInfo
.item
.mask
& LVIF_STATE
)
6782 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6783 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6785 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6787 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6788 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6789 lpLVItem
->state
|= LVIS_FOCUSED
;
6791 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6793 lpLVItem
->state
&= ~LVIS_SELECTED
;
6794 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6795 lpLVItem
->state
|= LVIS_SELECTED
;
6799 /* and last, but not least, the indent field */
6800 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6802 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6803 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6804 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6806 else if (lpLVItem
->mask
& LVIF_INDENT
)
6808 lpLVItem
->iIndent
= lpItem
->iIndent
;
6816 * Retrieves item attributes.
6819 * [I] hwnd : window handle
6820 * [IO] lpLVItem : item info
6821 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6822 * if FALSE, then lpLVItem is a LPLVITEMA.
6825 * This is the external 'GetItem' interface -- it properly copies
6826 * the text in the provided buffer.
6832 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6837 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6840 pszText
= lpLVItem
->pszText
;
6841 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6842 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6844 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6845 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6847 pszText
= LPSTR_TEXTCALLBACKW
;
6849 lpLVItem
->pszText
= pszText
;
6857 * Retrieves the position (upper-left) of the listview control item.
6858 * Note that for LVS_ICON style, the upper-left is that of the icon
6859 * and not the bounding box.
6862 * [I] infoPtr : valid pointer to the listview structure
6863 * [I] nItem : item index
6864 * [O] lpptPosition : coordinate information
6870 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6874 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6876 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6878 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6879 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6881 if (infoPtr
->uView
== LV_VIEW_ICON
)
6883 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6884 lpptPosition
->y
+= ICON_TOP_PADDING
;
6886 lpptPosition
->x
+= Origin
.x
;
6887 lpptPosition
->y
+= Origin
.y
;
6889 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6896 * Retrieves the bounding rectangle for a listview control item.
6899 * [I] infoPtr : valid pointer to the listview structure
6900 * [I] nItem : item index
6901 * [IO] lprc : bounding rectangle coordinates
6902 * lprc->left specifies the portion of the item for which the bounding
6903 * rectangle will be retrieved.
6905 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6906 * including the icon and label.
6909 * * Experiment shows that native control returns:
6910 * * width = min (48, length of text line)
6911 * * .left = position.x - (width - iconsize.cx)/2
6912 * * .right = .left + width
6913 * * height = #lines of text * ntmHeight + icon height + 8
6914 * * .top = position.y - 2
6915 * * .bottom = .top + height
6916 * * separation between items .y = itemSpacing.cy - height
6917 * * .x = itemSpacing.cx - width
6918 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
6921 * * Experiment shows that native control returns:
6922 * * width = iconSize.cx + 16
6923 * * .left = position.x - (width - iconsize.cx)/2
6924 * * .right = .left + width
6925 * * height = iconSize.cy + 4
6926 * * .top = position.y - 2
6927 * * .bottom = .top + height
6928 * * separation between items .y = itemSpacing.cy - height
6929 * * .x = itemSpacing.cx - width
6930 * LVIR_LABEL Returns the bounding rectangle of the item text.
6933 * * Experiment shows that native control returns:
6934 * * width = text length
6935 * * .left = position.x - width/2
6936 * * .right = .left + width
6937 * * height = ntmH * linecount + 2
6938 * * .top = position.y + iconSize.cy + 6
6939 * * .bottom = .top + height
6940 * * separation between items .y = itemSpacing.cy - height
6941 * * .x = itemSpacing.cx - width
6942 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
6943 * rectangles, but excludes columns in report view.
6950 * Note that the bounding rectangle of the label in the LVS_ICON view depends
6951 * upon whether the window has the focus currently and on whether the item
6952 * is the one with the focus. Ensure that the control's record of which
6953 * item has the focus agrees with the items' records.
6955 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6957 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6958 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
6959 POINT Position
, Origin
;
6963 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
6965 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6967 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6968 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6970 /* Be smart and try to figure out the minimum we have to do */
6971 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
6972 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
6973 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
6974 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
6975 oversizedBox
= TRUE
;
6977 /* get what we need from the item before hand, so we make
6978 * only one request. This can speed up things, if data
6979 * is stored on the app side */
6981 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6982 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
6983 lvItem
.iItem
= nItem
;
6984 lvItem
.iSubItem
= 0;
6985 lvItem
.pszText
= szDispText
;
6986 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6987 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6988 /* we got the state already up, simulate it here, to avoid a reget */
6989 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
6991 lvItem
.mask
|= LVIF_STATE
;
6992 lvItem
.stateMask
= LVIS_FOCUSED
;
6993 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
6996 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
6997 lprc
->left
= LVIR_BOUNDS
;
7003 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7007 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7011 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7014 case LVIR_SELECTBOUNDS
:
7015 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7019 WARN("Unknown value: %d\n", lprc
->left
);
7023 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7025 if (mode
!= LVIR_BOUNDS
)
7026 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7027 Position
.y
+ Origin
.y
);
7029 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7032 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7034 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7041 * Retrieves the spacing between listview control items.
7044 * [I] infoPtr : valid pointer to the listview structure
7045 * [IO] lprc : rectangle to receive the output
7046 * on input, lprc->top = nSubItem
7047 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7049 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7050 * not only those of the first column.
7056 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7058 RECT rect
= { 0, 0, 0, 0 };
7062 if (!lprc
) return FALSE
;
7064 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7065 /* Subitem of '0' means item itself, and this works for all control view modes */
7067 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7069 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7071 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7072 /* this works for any item index, no matter if it exists or not */
7073 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7075 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7078 rect
.bottom
= infoPtr
->nItemHeight
;
7082 /* Native implementation is broken for this case and garbage is left for left and right fields,
7083 we zero them to get predictable output */
7084 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7085 lprc
->bottom
= infoPtr
->nItemHeight
;
7086 OffsetRect(lprc
, origin
.x
, y
);
7087 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7095 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7096 if (infoPtr
->himlSmall
)
7097 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7099 rect
.right
= rect
.left
;
7101 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7109 ERR("Unknown bounds=%d\n", lprc
->left
);
7113 OffsetRect(&rect
, origin
.x
, y
);
7115 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7122 * Retrieves the spacing between listview control items.
7125 * [I] infoPtr : valid pointer to the listview structure
7126 * [I] bSmall : flag for small or large icon
7129 * Horizontal + vertical spacing
7131 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7137 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7141 if (infoPtr
->uView
== LV_VIEW_ICON
)
7142 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7144 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7151 * Retrieves the state of a listview control item.
7154 * [I] infoPtr : valid pointer to the listview structure
7155 * [I] nItem : item index
7156 * [I] uMask : state mask
7159 * State specified by the mask.
7161 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7165 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7167 lvItem
.iItem
= nItem
;
7168 lvItem
.iSubItem
= 0;
7169 lvItem
.mask
= LVIF_STATE
;
7170 lvItem
.stateMask
= uMask
;
7171 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7173 return lvItem
.state
& uMask
;
7178 * Retrieves the text of a listview control item or subitem.
7181 * [I] hwnd : window handle
7182 * [I] nItem : item index
7183 * [IO] lpLVItem : item information
7184 * [I] isW : TRUE if lpLVItem is Unicode
7187 * SUCCESS : string length
7190 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7192 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7194 lpLVItem
->mask
= LVIF_TEXT
;
7195 lpLVItem
->iItem
= nItem
;
7196 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7198 return textlenT(lpLVItem
->pszText
, isW
);
7203 * Searches for an item based on properties + relationships.
7206 * [I] infoPtr : valid pointer to the listview structure
7207 * [I] nItem : item index
7208 * [I] uFlags : relationship flag
7211 * SUCCESS : item index
7214 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7217 LVFINDINFOW lvFindInfo
;
7218 INT nCountPerColumn
;
7222 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7223 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7225 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7227 if (uFlags
& LVNI_CUT
)
7230 if (uFlags
& LVNI_DROPHILITED
)
7231 uMask
|= LVIS_DROPHILITED
;
7233 if (uFlags
& LVNI_FOCUSED
)
7234 uMask
|= LVIS_FOCUSED
;
7236 if (uFlags
& LVNI_SELECTED
)
7237 uMask
|= LVIS_SELECTED
;
7239 /* if we're asked for the focused item, that's only one,
7240 * so it's worth optimizing */
7241 if (uFlags
& LVNI_FOCUSED
)
7243 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7244 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7247 if (uFlags
& LVNI_ABOVE
)
7249 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7254 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7260 /* Special case for autoarrange - move 'til the top of a list */
7261 if (is_autoarrange(infoPtr
))
7263 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7264 while (nItem
- nCountPerRow
>= 0)
7266 nItem
-= nCountPerRow
;
7267 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7272 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7273 lvFindInfo
.vkDirection
= VK_UP
;
7274 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7275 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7277 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7282 else if (uFlags
& LVNI_BELOW
)
7284 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7286 while (nItem
< infoPtr
->nItemCount
)
7289 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7295 /* Special case for autoarrange - move 'til the bottom of a list */
7296 if (is_autoarrange(infoPtr
))
7298 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7299 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7301 nItem
+= nCountPerRow
;
7302 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7307 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7308 lvFindInfo
.vkDirection
= VK_DOWN
;
7309 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7310 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7312 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7317 else if (uFlags
& LVNI_TOLEFT
)
7319 if (infoPtr
->uView
== LV_VIEW_LIST
)
7321 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7322 while (nItem
- nCountPerColumn
>= 0)
7324 nItem
-= nCountPerColumn
;
7325 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7329 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7331 /* Special case for autoarrange - move 'til the beginning of a row */
7332 if (is_autoarrange(infoPtr
))
7334 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7335 while (nItem
% nCountPerRow
> 0)
7338 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7343 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7344 lvFindInfo
.vkDirection
= VK_LEFT
;
7345 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7346 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7348 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7353 else if (uFlags
& LVNI_TORIGHT
)
7355 if (infoPtr
->uView
== LV_VIEW_LIST
)
7357 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7358 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7360 nItem
+= nCountPerColumn
;
7361 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7365 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7367 /* Special case for autoarrange - move 'til the end of a row */
7368 if (is_autoarrange(infoPtr
))
7370 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7371 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7374 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7379 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7380 lvFindInfo
.vkDirection
= VK_RIGHT
;
7381 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7382 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7384 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7393 /* search by index */
7394 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7396 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7404 /* LISTVIEW_GetNumberOfWorkAreas */
7408 * Retrieves the origin coordinates when in icon or small icon display mode.
7411 * [I] infoPtr : valid pointer to the listview structure
7412 * [O] lpptOrigin : coordinate information
7417 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7419 INT nHorzPos
= 0, nVertPos
= 0;
7420 SCROLLINFO scrollInfo
;
7422 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7423 scrollInfo
.fMask
= SIF_POS
;
7425 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7426 nHorzPos
= scrollInfo
.nPos
;
7427 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7428 nVertPos
= scrollInfo
.nPos
;
7430 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7432 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7433 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7434 if (infoPtr
->uView
== LV_VIEW_LIST
)
7435 nHorzPos
*= infoPtr
->nItemWidth
;
7436 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7437 nVertPos
*= infoPtr
->nItemHeight
;
7439 lpptOrigin
->x
-= nHorzPos
;
7440 lpptOrigin
->y
-= nVertPos
;
7442 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7447 * Retrieves the width of a string.
7450 * [I] hwnd : window handle
7451 * [I] lpszText : text string to process
7452 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7455 * SUCCESS : string width (in pixels)
7458 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7463 if (is_text(lpszText
))
7465 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7466 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7467 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7470 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7472 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7473 SelectObject(hdc
, hOldFont
);
7474 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7476 return stringSize
.cx
;
7481 * Determines which listview item is located at the specified position.
7484 * [I] infoPtr : valid pointer to the listview structure
7485 * [IO] lpht : hit test information
7486 * [I] subitem : fill out iSubItem.
7487 * [I] select : return the index only if the hit selects the item
7490 * (mm 20001022): We must not allow iSubItem to be touched, for
7491 * an app might pass only a structure with space up to iItem!
7492 * (MS Office 97 does that for instance in the file open dialog)
7495 * SUCCESS : item index
7498 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7500 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7501 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7502 POINT Origin
, Position
, opt
;
7507 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7511 if (subitem
) lpht
->iSubItem
= 0;
7513 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7515 /* set whole list relation flags */
7516 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7518 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7519 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7520 lpht
->flags
|= LVHT_TOLEFT
;
7522 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7523 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7527 if (infoPtr
->rcList
.bottom
< opt
.y
)
7528 lpht
->flags
|= LVHT_BELOW
;
7532 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7533 lpht
->flags
|= LVHT_TOLEFT
;
7534 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7535 lpht
->flags
|= LVHT_TORIGHT
;
7537 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7538 lpht
->flags
|= LVHT_ABOVE
;
7539 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7540 lpht
->flags
|= LVHT_BELOW
;
7543 /* even if item is invalid try to find subitem */
7544 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7549 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7551 lpht
->iSubItem
= -1;
7552 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7554 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7556 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7562 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7564 /* if we're outside horizontal columns bounds there's nothing to test further */
7565 if (lpht
->iSubItem
== -1)
7568 lpht
->flags
= LVHT_NOWHERE
;
7573 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7574 if (lpht
->flags
) return -1;
7576 lpht
->flags
|= LVHT_NOWHERE
;
7578 /* first deal with the large items */
7579 rcSearch
.left
= lpht
->pt
.x
;
7580 rcSearch
.top
= lpht
->pt
.y
;
7581 rcSearch
.right
= rcSearch
.left
+ 1;
7582 rcSearch
.bottom
= rcSearch
.top
+ 1;
7584 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7585 iterator_next(&i
); /* go to first item in the sequence */
7587 iterator_destroy(&i
);
7589 TRACE("lpht->iItem=%d\n", iItem
);
7590 if (iItem
== -1) return -1;
7592 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7593 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7594 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7595 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7596 lvItem
.iItem
= iItem
;
7597 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7598 lvItem
.pszText
= szDispText
;
7599 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7600 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7601 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7603 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7604 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7605 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7607 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7608 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7610 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7612 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7615 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7616 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7620 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7621 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7623 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7624 if (!PtInRect(&rcBounds
, opt
)) return -1;
7626 if (PtInRect(&rcIcon
, opt
))
7627 lpht
->flags
|= LVHT_ONITEMICON
;
7628 else if (PtInRect(&rcLabel
, opt
))
7629 lpht
->flags
|= LVHT_ONITEMLABEL
;
7630 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7631 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7632 /* special case for LVS_EX_FULLROWSELECT */
7633 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
7634 !(lpht
->flags
& LVHT_ONITEM
))
7636 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7638 if (lpht
->flags
& LVHT_ONITEM
)
7639 lpht
->flags
&= ~LVHT_NOWHERE
;
7640 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7642 if (select
&& !(infoPtr
->uView
== LV_VIEW_DETAILS
&&
7643 ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) ||
7644 (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
))))
7646 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7648 /* get main item bounds */
7649 lvItem
.iSubItem
= 0;
7650 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7651 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7652 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7654 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7656 return lpht
->iItem
= iItem
;
7661 * Inserts a new item in the listview control.
7664 * [I] infoPtr : valid pointer to the listview structure
7665 * [I] lpLVItem : item information
7666 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7669 * SUCCESS : new item index
7672 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7679 BOOL is_sorted
, has_changed
;
7681 HWND hwndSelf
= infoPtr
->hwndSelf
;
7683 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7685 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7687 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7688 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7690 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7692 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7694 /* insert item in listview control data structure */
7695 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7696 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7698 /* link with id struct */
7699 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7701 lpID
->item
= hdpaSubItems
;
7702 lpID
->id
= get_next_itemid(infoPtr
);
7703 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7705 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7706 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7708 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7710 /* calculate new item index */
7717 while (i
< infoPtr
->nItemCount
)
7719 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7720 item_s
= DPA_GetPtr(hItem
, 0);
7722 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7723 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7725 if (cmpv
>= 0) break;
7731 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7733 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7734 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7735 if (nItem
== -1) goto fail
;
7736 infoPtr
->nItemCount
++;
7738 /* shift indices first so they don't get tangled */
7739 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7741 /* set the item attributes */
7742 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7744 /* full size structure expected - _WIN32IE >= 0x560 */
7747 else if (lpLVItem
->mask
& LVIF_INDENT
)
7749 /* indent member expected - _WIN32IE >= 0x300 */
7750 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7754 /* minimal structure expected */
7755 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7758 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7760 item
.mask
|= LVIF_STATE
;
7761 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7762 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7763 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7766 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7768 /* make room for the position, if we are in the right mode */
7769 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7771 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7773 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7775 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7780 /* send LVN_INSERTITEM notification */
7781 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7783 nmlv
.lParam
= lpItem
->lParam
;
7784 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7785 if (!IsWindow(hwndSelf
))
7788 /* align items (set position of each item) */
7789 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7793 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7794 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7796 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7798 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7801 /* now is the invalidation fun */
7802 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7806 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7807 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7808 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7809 infoPtr
->nItemCount
--;
7811 DPA_DeletePtr(hdpaSubItems
, 0);
7812 DPA_Destroy (hdpaSubItems
);
7819 * Checks item visibility.
7822 * [I] infoPtr : valid pointer to the listview structure
7823 * [I] nFirst : item index to check for
7826 * Item visible : TRUE
7827 * Item invisible or failure : FALSE
7829 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7831 POINT Origin
, Position
;
7836 TRACE("nItem=%d\n", nItem
);
7838 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7840 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7841 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7842 rcItem
.left
= Position
.x
+ Origin
.x
;
7843 rcItem
.top
= Position
.y
+ Origin
.y
;
7844 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7845 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7847 hdc
= GetDC(infoPtr
->hwndSelf
);
7848 if (!hdc
) return FALSE
;
7849 ret
= RectVisible(hdc
, &rcItem
);
7850 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7857 * Redraws a range of items.
7860 * [I] infoPtr : valid pointer to the listview structure
7861 * [I] nFirst : first item
7862 * [I] nLast : last item
7868 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7872 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7873 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7876 for (i
= nFirst
; i
<= nLast
; i
++)
7877 LISTVIEW_InvalidateItem(infoPtr
, i
);
7884 * Scroll the content of a listview.
7887 * [I] infoPtr : valid pointer to the listview structure
7888 * [I] dx : horizontal scroll amount in pixels
7889 * [I] dy : vertical scroll amount in pixels
7896 * If the control is in report view (LV_VIEW_DETAILS) the control can
7897 * be scrolled only in line increments. "dy" will be rounded to the
7898 * nearest number of pixels that are a whole line. Ex: if line height
7899 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7900 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7902 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7904 switch(infoPtr
->uView
) {
7905 case LV_VIEW_DETAILS
:
7906 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7907 dy
/= infoPtr
->nItemHeight
;
7910 if (dy
!= 0) return FALSE
;
7916 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
7917 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
7924 * Sets the background color.
7927 * [I] infoPtr : valid pointer to the listview structure
7928 * [I] color : background color
7934 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
7936 TRACE("(color=%x)\n", color
);
7938 infoPtr
->bDefaultBkColor
= FALSE
;
7939 if(infoPtr
->clrBk
!= color
) {
7940 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7941 infoPtr
->clrBk
= color
;
7942 if (color
== CLR_NONE
)
7943 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
7946 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
7947 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
7954 /* LISTVIEW_SetBkImage */
7956 /*** Helper for {Insert,Set}ColumnT *only* */
7957 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
7958 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7960 if (lpColumn
->mask
& LVCF_FMT
)
7962 /* format member is valid */
7963 lphdi
->mask
|= HDI_FORMAT
;
7965 /* set text alignment (leftmost column must be left-aligned) */
7966 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
7967 lphdi
->fmt
|= HDF_LEFT
;
7968 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
7969 lphdi
->fmt
|= HDF_RIGHT
;
7970 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
7971 lphdi
->fmt
|= HDF_CENTER
;
7973 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
7974 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
7976 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
7978 lphdi
->fmt
|= HDF_IMAGE
;
7979 lphdi
->iImage
= I_IMAGECALLBACK
;
7982 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
7983 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
7986 if (lpColumn
->mask
& LVCF_WIDTH
)
7988 lphdi
->mask
|= HDI_WIDTH
;
7989 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
7991 /* make it fill the remainder of the controls width */
7995 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
7997 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
7998 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8001 /* retrieve the layout of the header */
8002 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8003 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8005 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8008 lphdi
->cxy
= lpColumn
->cx
;
8011 if (lpColumn
->mask
& LVCF_TEXT
)
8013 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8014 lphdi
->fmt
|= HDF_STRING
;
8015 lphdi
->pszText
= lpColumn
->pszText
;
8016 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8019 if (lpColumn
->mask
& LVCF_IMAGE
)
8021 lphdi
->mask
|= HDI_IMAGE
;
8022 lphdi
->iImage
= lpColumn
->iImage
;
8025 if (lpColumn
->mask
& LVCF_ORDER
)
8027 lphdi
->mask
|= HDI_ORDER
;
8028 lphdi
->iOrder
= lpColumn
->iOrder
;
8035 * Inserts a new column.
8038 * [I] infoPtr : valid pointer to the listview structure
8039 * [I] nColumn : column index
8040 * [I] lpColumn : column information
8041 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8044 * SUCCESS : new column index
8047 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8048 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8050 COLUMN_INFO
*lpColumnInfo
;
8054 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8056 if (!lpColumn
|| nColumn
< 0) return -1;
8057 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8059 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8060 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8063 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8064 * (can be seen in SPY) otherwise column never gets added.
8066 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8067 hdi
.mask
|= HDI_WIDTH
;
8072 * when the iSubItem is available Windows copies it to the header lParam. It seems
8073 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8075 if (lpColumn
->mask
& LVCF_SUBITEM
)
8077 hdi
.mask
|= HDI_LPARAM
;
8078 hdi
.lParam
= lpColumn
->iSubItem
;
8081 /* create header if not present */
8082 LISTVIEW_CreateHeader(infoPtr
);
8083 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8084 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8086 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8089 /* insert item in header control */
8090 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8091 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8092 nColumn
, (LPARAM
)&hdi
);
8093 if (nNewColumn
== -1) return -1;
8094 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8096 /* create our own column info */
8097 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8098 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8100 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8101 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8102 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8105 /* now we have to actually adjust the data */
8106 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8108 SUBITEM_INFO
*lpSubItem
;
8114 item
.iSubItem
= nNewColumn
;
8115 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8116 item
.iImage
= I_IMAGECALLBACK
;
8117 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8119 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8121 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8122 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8124 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8125 if (lpSubItem
->iSubItem
>= nNewColumn
)
8126 lpSubItem
->iSubItem
++;
8129 /* add new subitem for each item */
8131 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8135 /* make space for the new column */
8136 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8137 LISTVIEW_UpdateItemSize(infoPtr
);
8142 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8145 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8153 * Sets the attributes of a header item.
8156 * [I] infoPtr : valid pointer to the listview structure
8157 * [I] nColumn : column index
8158 * [I] lpColumn : column attributes
8159 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8165 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8166 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8168 HDITEMW hdi
, hdiget
;
8171 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8173 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8175 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8176 if (lpColumn
->mask
& LVCF_FMT
)
8178 hdi
.mask
|= HDI_FORMAT
;
8179 hdiget
.mask
= HDI_FORMAT
;
8180 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8181 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8183 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8185 /* set header item attributes */
8186 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8187 if (!bResult
) return FALSE
;
8189 if (lpColumn
->mask
& LVCF_FMT
)
8191 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8192 INT oldFmt
= lpColumnInfo
->fmt
;
8194 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8195 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8197 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8201 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8202 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8209 * Sets the column order array
8212 * [I] infoPtr : valid pointer to the listview structure
8213 * [I] iCount : number of elements in column order array
8214 * [I] lpiArray : pointer to column order array
8220 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8222 TRACE("iCount %d lpiArray %p\n", iCount
, lpiArray
);
8224 if (!lpiArray
|| !IsWindow(infoPtr
->hwndHeader
)) return FALSE
;
8226 infoPtr
->colRectsDirty
= TRUE
;
8228 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8233 * Sets the width of a column
8236 * [I] infoPtr : valid pointer to the listview structure
8237 * [I] nColumn : column index
8238 * [I] cx : column width
8244 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8246 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8250 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
8252 /* set column width only if in report or list mode */
8253 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8255 /* take care of invalid cx values */
8256 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
8257 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
8259 /* resize all columns if in LV_VIEW_LIST mode */
8260 if(infoPtr
->uView
== LV_VIEW_LIST
)
8262 infoPtr
->nItemWidth
= cx
;
8263 LISTVIEW_InvalidateList(infoPtr
);
8267 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8269 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8274 lvItem
.mask
= LVIF_TEXT
;
8276 lvItem
.iSubItem
= nColumn
;
8277 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8278 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8280 lvItem
.pszText
= szDispText
;
8281 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8282 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8283 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8285 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8286 max_cx
+= infoPtr
->iconSize
.cx
;
8287 max_cx
+= TRAILING_LABEL_PADDING
;
8290 /* autosize based on listview items width */
8291 if(cx
== LVSCW_AUTOSIZE
)
8293 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8295 /* if iCol is the last column make it fill the remainder of the controls width */
8296 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8301 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8302 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8304 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8308 /* Despite what the MS docs say, if this is not the last
8309 column, then MS resizes the column to the width of the
8310 largest text string in the column, including headers
8311 and items. This is different from LVSCW_AUTOSIZE in that
8312 LVSCW_AUTOSIZE ignores the header string length. */
8315 /* retrieve header text */
8316 hdi
.mask
= HDI_TEXT
;
8317 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8318 hdi
.pszText
= szDispText
;
8319 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8321 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8322 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8325 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8326 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8327 /* FIXME: Take into account the header image, if one is present */
8328 SelectObject(hdc
, old_font
);
8329 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8331 cx
= max (cx
, max_cx
);
8335 if (cx
< 0) return FALSE
;
8337 /* call header to update the column change */
8338 hdi
.mask
= HDI_WIDTH
;
8339 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8340 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8341 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8345 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8348 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8351 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8353 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8354 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8357 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8358 ILC_COLOR
| ILC_MASK
, 2, 2);
8359 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8360 hdc
= CreateCompatibleDC(hdc_wnd
);
8361 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8362 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8363 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8365 rc
.left
= rc
.top
= 0;
8366 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
8367 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
8369 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8370 FillRect(hdc
, &rc
, hbr_white
);
8371 InflateRect(&rc
, -2, -2);
8372 FillRect(hdc
, &rc
, hbr_black
);
8374 SelectObject(hdc
, hbm_im
);
8375 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8376 SelectObject(hdc
, hbm_orig
);
8377 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8379 SelectObject(hdc
, hbm_im
);
8380 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8381 SelectObject(hdc
, hbm_orig
);
8382 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8384 DeleteObject(hbm_mask
);
8385 DeleteObject(hbm_im
);
8393 * Sets the extended listview style.
8396 * [I] infoPtr : valid pointer to the listview structure
8398 * [I] dwStyle : style
8401 * SUCCESS : previous style
8404 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8406 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8408 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8412 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8414 infoPtr
->dwLvExStyle
= ex_style
;
8416 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8418 HIMAGELIST himl
= 0;
8419 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8422 item
.mask
= LVIF_STATE
;
8423 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8424 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8425 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8427 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8428 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8429 ImageList_Destroy(infoPtr
->himlState
);
8431 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8432 /* checkbox list replaces previous custom list or... */
8433 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8434 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8435 /* ...previous was checkbox list */
8436 (old_ex_style
& LVS_EX_CHECKBOXES
))
8437 ImageList_Destroy(himl
);
8440 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8444 /* if not already created */
8445 LISTVIEW_CreateHeader(infoPtr
);
8447 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8448 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8449 style
|= HDS_DRAGDROP
;
8451 style
&= ~HDS_DRAGDROP
;
8452 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8455 /* GRIDLINES adds decoration at top so changes sizes */
8456 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8458 LISTVIEW_CreateHeader(infoPtr
);
8459 LISTVIEW_UpdateSize(infoPtr
);
8462 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8464 LISTVIEW_CreateHeader(infoPtr
);
8467 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8469 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8470 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8473 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8475 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8476 LISTVIEW_CreateHeader(infoPtr
);
8478 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8479 LISTVIEW_UpdateSize(infoPtr
);
8480 LISTVIEW_UpdateScroll(infoPtr
);
8483 LISTVIEW_InvalidateList(infoPtr
);
8484 return old_ex_style
;
8489 * Sets the new hot cursor used during hot tracking and hover selection.
8492 * [I] infoPtr : valid pointer to the listview structure
8493 * [I] hCursor : the new hot cursor handle
8496 * Returns the previous hot cursor
8498 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8500 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8502 infoPtr
->hHotCursor
= hCursor
;
8510 * Sets the hot item index.
8513 * [I] infoPtr : valid pointer to the listview structure
8514 * [I] iIndex : index
8517 * SUCCESS : previous hot item index
8518 * FAILURE : -1 (no hot item)
8520 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8522 INT iOldIndex
= infoPtr
->nHotItem
;
8524 infoPtr
->nHotItem
= iIndex
;
8532 * Sets the amount of time the cursor must hover over an item before it is selected.
8535 * [I] infoPtr : valid pointer to the listview structure
8536 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8539 * Returns the previous hover time
8541 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8543 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8545 infoPtr
->dwHoverTime
= dwHoverTime
;
8547 return oldHoverTime
;
8552 * Sets spacing for icons of LVS_ICON style.
8555 * [I] infoPtr : valid pointer to the listview structure
8556 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8557 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8560 * MAKELONG(oldcx, oldcy)
8562 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8564 INT iconWidth
= 0, iconHeight
= 0;
8565 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8567 TRACE("requested=(%d,%d)\n", cx
, cy
);
8569 /* set to defaults, if instructed to */
8570 if (cx
== -1 && cy
== -1)
8572 infoPtr
->autoSpacing
= TRUE
;
8573 if (infoPtr
->himlNormal
)
8574 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8575 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8576 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8579 infoPtr
->autoSpacing
= FALSE
;
8581 /* if 0 then keep width */
8583 infoPtr
->iconSpacing
.cx
= cx
;
8585 /* if 0 then keep height */
8587 infoPtr
->iconSpacing
.cy
= cy
;
8589 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8590 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8591 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8592 infoPtr
->ntmHeight
);
8594 /* these depend on the iconSpacing */
8595 LISTVIEW_UpdateItemSize(infoPtr
);
8600 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8604 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8611 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8612 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8621 * [I] infoPtr : valid pointer to the listview structure
8622 * [I] nType : image list type
8623 * [I] himl : image list handle
8626 * SUCCESS : old image list
8629 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8631 INT oldHeight
= infoPtr
->nItemHeight
;
8632 HIMAGELIST himlOld
= 0;
8634 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
8639 himlOld
= infoPtr
->himlNormal
;
8640 infoPtr
->himlNormal
= himl
;
8641 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8642 if (infoPtr
->autoSpacing
)
8643 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8647 himlOld
= infoPtr
->himlSmall
;
8648 infoPtr
->himlSmall
= himl
;
8649 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8650 if (infoPtr
->hwndHeader
)
8651 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8655 himlOld
= infoPtr
->himlState
;
8656 infoPtr
->himlState
= himl
;
8657 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8658 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8662 ERR("Unknown icon type=%d\n", nType
);
8666 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8667 if (infoPtr
->nItemHeight
!= oldHeight
)
8668 LISTVIEW_UpdateScroll(infoPtr
);
8675 * Preallocates memory (does *not* set the actual count of items !)
8678 * [I] infoPtr : valid pointer to the listview structure
8679 * [I] nItems : item count (projected number of items to allocate)
8680 * [I] dwFlags : update flags
8686 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8688 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8690 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8692 INT nOldCount
= infoPtr
->nItemCount
;
8694 if (nItems
< nOldCount
)
8696 RANGE range
= { nItems
, nOldCount
};
8697 ranges_del(infoPtr
->selectionRanges
, range
);
8698 if (infoPtr
->nFocusedItem
>= nItems
)
8700 LISTVIEW_SetItemFocus(infoPtr
, -1);
8701 SetRectEmpty(&infoPtr
->rcFocus
);
8705 infoPtr
->nItemCount
= nItems
;
8706 LISTVIEW_UpdateScroll(infoPtr
);
8708 /* the flags are valid only in ownerdata report and list modes */
8709 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8711 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8712 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8714 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8715 LISTVIEW_InvalidateList(infoPtr
);
8722 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8723 nFrom
= min(nOldCount
, nItems
);
8724 nTo
= max(nOldCount
, nItems
);
8726 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8729 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8730 rcErase
.right
= infoPtr
->nItemWidth
;
8731 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8732 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8733 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8734 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8736 else /* LV_VIEW_LIST */
8738 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8740 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8741 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8742 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8743 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8744 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8745 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8746 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8748 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8750 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8751 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8752 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8753 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8754 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8760 /* According to MSDN for non-LVS_OWNERDATA this is just
8761 * a performance issue. The control allocates its internal
8762 * data structures for the number of items specified. It
8763 * cuts down on the number of memory allocations. Therefore
8764 * we will just issue a WARN here
8766 WARN("for non-ownerdata performance option not implemented.\n");
8774 * Sets the position of an item.
8777 * [I] infoPtr : valid pointer to the listview structure
8778 * [I] nItem : item index
8779 * [I] pt : coordinate
8785 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8789 TRACE("(nItem=%d, pt=%s\n", nItem
, wine_dbgstr_point(pt
));
8791 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8792 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8795 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8797 /* This point value seems to be an undocumented feature.
8798 * The best guess is that it means either at the origin,
8799 * or at true beginning of the list. I will assume the origin. */
8800 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8803 if (infoPtr
->uView
== LV_VIEW_ICON
)
8805 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8806 Pt
.y
-= ICON_TOP_PADDING
;
8811 infoPtr
->bAutoarrange
= FALSE
;
8813 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8818 * Sets the state of one or many items.
8821 * [I] infoPtr : valid pointer to the listview structure
8822 * [I] nItem : item index
8823 * [I] item : item or subitem info
8829 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8834 if (!item
) return FALSE
;
8836 lvItem
.iItem
= nItem
;
8837 lvItem
.iSubItem
= 0;
8838 lvItem
.mask
= LVIF_STATE
;
8839 lvItem
.state
= item
->state
;
8840 lvItem
.stateMask
= item
->stateMask
;
8841 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8848 /* special case optimization for recurring attempt to deselect all */
8849 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8852 /* select all isn't allowed in LVS_SINGLESEL */
8853 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8856 /* focus all isn't allowed */
8857 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8859 notify
= infoPtr
->bDoChangeNotify
;
8860 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8862 infoPtr
->bDoChangeNotify
= FALSE
;
8863 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8864 oldstate
|= LVIS_SELECTED
;
8865 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
8868 /* apply to all items */
8869 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8870 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
8872 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8876 infoPtr
->bDoChangeNotify
= notify
;
8880 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
8881 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
8882 nmlv
.uChanged
= LVIF_STATE
;
8883 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
8886 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
8890 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8897 * Sets the text of an item or subitem.
8900 * [I] hwnd : window handle
8901 * [I] nItem : item index
8902 * [I] lpLVItem : item or subitem info
8903 * [I] isW : TRUE if input is Unicode
8909 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
8913 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
8914 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
8916 lvItem
.iItem
= nItem
;
8917 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
8918 lvItem
.mask
= LVIF_TEXT
;
8919 lvItem
.pszText
= lpLVItem
->pszText
;
8920 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
8922 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
8924 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
8929 * Set item index that marks the start of a multiple selection.
8932 * [I] infoPtr : valid pointer to the listview structure
8933 * [I] nIndex : index
8936 * Index number or -1 if there is no selection mark.
8938 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
8940 INT nOldIndex
= infoPtr
->nSelectionMark
;
8942 TRACE("(nIndex=%d)\n", nIndex
);
8944 infoPtr
->nSelectionMark
= nIndex
;
8951 * Sets the text background color.
8954 * [I] infoPtr : valid pointer to the listview structure
8955 * [I] color : text background color
8961 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8963 TRACE("(color=%x)\n", color
);
8965 infoPtr
->clrTextBk
= color
;
8971 * Sets the text foreground color.
8974 * [I] infoPtr : valid pointer to the listview structure
8975 * [I] color : text color
8981 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8983 TRACE("(color=%x)\n", color
);
8985 infoPtr
->clrText
= color
;
8991 * Sets new ToolTip window to ListView control.
8994 * [I] infoPtr : valid pointer to the listview structure
8995 * [I] hwndNewToolTip : handle to new ToolTip
9000 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9002 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9003 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9004 return hwndOldToolTip
;
9009 * sets the Unicode character format flag for the control
9011 * [I] infoPtr :valid pointer to the listview structure
9012 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9015 * Old Unicode Format
9017 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9019 SHORT rc
= infoPtr
->notifyFormat
;
9020 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9021 return rc
== NFR_UNICODE
;
9026 * sets the control view mode
9028 * [I] infoPtr :valid pointer to the listview structure
9029 * [I] nView :new view mode value
9035 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9039 if (infoPtr
->uView
== nView
) return 1;
9041 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9042 if (nView
== LV_VIEW_TILE
)
9044 FIXME("View LV_VIEW_TILE unimplemented\n");
9048 infoPtr
->uView
= nView
;
9050 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9051 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9053 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9054 SetRectEmpty(&infoPtr
->rcFocus
);
9056 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9057 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9062 case LV_VIEW_SMALLICON
:
9063 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9065 case LV_VIEW_DETAILS
:
9070 LISTVIEW_CreateHeader( infoPtr
);
9072 hl
.prc
= &infoPtr
->rcList
;
9074 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9075 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9076 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9083 LISTVIEW_UpdateItemSize(infoPtr
);
9084 LISTVIEW_UpdateSize(infoPtr
);
9085 LISTVIEW_UpdateScroll(infoPtr
);
9086 LISTVIEW_InvalidateList(infoPtr
);
9088 TRACE("nView=%d\n", nView
);
9093 /* LISTVIEW_SetWorkAreas */
9097 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9100 * [I] first : pointer to first ITEM_INFO to compare
9101 * [I] second : pointer to second ITEM_INFO to compare
9102 * [I] lParam : HWND of control
9105 * if first comes before second : negative
9106 * if first comes after second : positive
9107 * if first and second are equivalent : zero
9109 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9111 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9112 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9113 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9115 /* Forward the call to the client defined callback */
9116 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9121 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9124 * [I] first : pointer to first ITEM_INFO to compare
9125 * [I] second : pointer to second ITEM_INFO to compare
9126 * [I] lParam : HWND of control
9129 * if first comes before second : negative
9130 * if first comes after second : positive
9131 * if first and second are equivalent : zero
9133 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9135 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9136 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9137 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9139 /* Forward the call to the client defined callback */
9140 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9145 * Sorts the listview items.
9148 * [I] infoPtr : valid pointer to the listview structure
9149 * [I] pfnCompare : application-defined value
9150 * [I] lParamSort : pointer to comparison callback
9151 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9157 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9158 LPARAM lParamSort
, BOOL IsEx
)
9162 LPVOID selectionMarkItem
= NULL
;
9163 LPVOID focusedItem
= NULL
;
9166 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9168 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9170 if (!pfnCompare
) return FALSE
;
9171 if (!infoPtr
->hdpaItems
) return FALSE
;
9173 /* if there are 0 or 1 items, there is no need to sort */
9174 if (infoPtr
->nItemCount
< 2) return TRUE
;
9176 /* clear selection */
9177 ranges_clear(infoPtr
->selectionRanges
);
9179 /* save selection mark and focused item */
9180 if (infoPtr
->nSelectionMark
>= 0)
9181 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9182 if (infoPtr
->nFocusedItem
>= 0)
9183 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9185 infoPtr
->pfnCompare
= pfnCompare
;
9186 infoPtr
->lParamSort
= lParamSort
;
9188 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9190 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9192 /* restore selection ranges */
9193 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9195 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9196 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9198 if (lpItem
->state
& LVIS_SELECTED
)
9199 ranges_additem(infoPtr
->selectionRanges
, i
);
9201 /* restore selection mark and focused item */
9202 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9203 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9205 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9207 /* refresh the display */
9208 LISTVIEW_InvalidateList(infoPtr
);
9214 * Update theme handle after a theme change.
9217 * [I] infoPtr : valid pointer to the listview structure
9221 * FAILURE : something else
9223 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9225 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9226 CloseThemeData(theme
);
9227 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9233 * Updates an items or rearranges the listview control.
9236 * [I] infoPtr : valid pointer to the listview structure
9237 * [I] nItem : item index
9243 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9245 TRACE("(nItem=%d)\n", nItem
);
9247 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9249 /* rearrange with default alignment style */
9250 if (is_autoarrange(infoPtr
))
9251 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9253 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9260 * Draw the track line at the place defined in the infoPtr structure.
9261 * The line is drawn with a XOR pen so drawing the line for the second time
9262 * in the same place erases the line.
9265 * [I] infoPtr : valid pointer to the listview structure
9271 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9275 if (infoPtr
->xTrackLine
== -1)
9278 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9280 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9281 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9282 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9288 * Called when an edit control should be displayed. This function is called after
9289 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9292 * [I] hwnd : Handle to the listview
9293 * [I] uMsg : WM_TIMER (ignored)
9294 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9295 * [I] dwTimer : The elapsed time (ignored)
9300 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9302 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9303 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9305 KillTimer(hwnd
, idEvent
);
9306 editItem
->fEnabled
= FALSE
;
9307 /* check if the item is still selected */
9308 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9309 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9314 * Creates the listview control - the WM_NCCREATE phase.
9317 * [I] hwnd : window handle
9318 * [I] lpcs : the create parameters
9324 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9326 LISTVIEW_INFO
*infoPtr
;
9329 TRACE("(lpcs=%p)\n", lpcs
);
9331 /* initialize info pointer */
9332 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9333 if (!infoPtr
) return FALSE
;
9335 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9337 infoPtr
->hwndSelf
= hwnd
;
9338 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9339 map_style_view(infoPtr
);
9340 /* determine the type of structures to use */
9341 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9342 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9344 /* initialize color information */
9345 infoPtr
->clrBk
= CLR_NONE
;
9346 infoPtr
->clrText
= CLR_DEFAULT
;
9347 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9348 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9349 infoPtr
->bDefaultBkColor
= TRUE
;
9351 /* set default values */
9352 infoPtr
->nFocusedItem
= -1;
9353 infoPtr
->nSelectionMark
= -1;
9354 infoPtr
->nHotItem
= -1;
9355 infoPtr
->bRedraw
= TRUE
;
9356 infoPtr
->bNoItemMetrics
= TRUE
;
9357 infoPtr
->bDoChangeNotify
= TRUE
;
9358 infoPtr
->autoSpacing
= TRUE
;
9359 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9360 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9361 infoPtr
->nEditLabelItem
= -1;
9362 infoPtr
->nLButtonDownItem
= -1;
9363 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9364 infoPtr
->cWheelRemainder
= 0;
9365 infoPtr
->nMeasureItemHeight
= 0;
9366 infoPtr
->xTrackLine
= -1; /* no track line */
9367 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9368 infoPtr
->iVersion
= COMCTL32_VERSION
;
9369 infoPtr
->colRectsDirty
= FALSE
;
9371 /* get default font (icon title) */
9372 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9373 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9374 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9375 LISTVIEW_SaveTextMetrics(infoPtr
);
9377 /* allocate memory for the data structure */
9378 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9379 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9380 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9381 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9382 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9383 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9387 DestroyWindow(infoPtr
->hwndHeader
);
9388 ranges_destroy(infoPtr
->selectionRanges
);
9389 DPA_Destroy(infoPtr
->hdpaItems
);
9390 DPA_Destroy(infoPtr
->hdpaItemIds
);
9391 DPA_Destroy(infoPtr
->hdpaPosX
);
9392 DPA_Destroy(infoPtr
->hdpaPosY
);
9393 DPA_Destroy(infoPtr
->hdpaColumns
);
9400 * Creates the listview control - the WM_CREATE phase. Most of the data is
9401 * already set up in LISTVIEW_NCCreate
9404 * [I] hwnd : window handle
9405 * [I] lpcs : the create parameters
9411 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9413 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9415 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9417 infoPtr
->dwStyle
= lpcs
->style
;
9418 map_style_view(infoPtr
);
9420 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9421 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9422 /* on error defaulting to ANSI notifications */
9423 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9424 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9426 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9428 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9431 infoPtr
->hwndHeader
= 0;
9433 /* init item size to avoid division by 0 */
9434 LISTVIEW_UpdateItemSize (infoPtr
);
9435 LISTVIEW_UpdateSize (infoPtr
);
9437 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9439 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9441 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9443 LISTVIEW_UpdateScroll(infoPtr
);
9444 /* send WM_MEASUREITEM notification */
9445 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9448 OpenThemeData(hwnd
, themeClass
);
9450 /* initialize the icon sizes */
9451 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9452 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9458 * Destroys the listview control.
9461 * [I] infoPtr : valid pointer to the listview structure
9467 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9469 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9470 CloseThemeData(theme
);
9472 /* delete all items */
9473 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9480 * Enables the listview control.
9483 * [I] infoPtr : valid pointer to the listview structure
9484 * [I] bEnable : specifies whether to enable or disable the window
9490 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9492 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9493 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9499 * Erases the background of the listview control.
9502 * [I] infoPtr : valid pointer to the listview structure
9503 * [I] hdc : device context handle
9509 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9513 TRACE("(hdc=%p)\n", hdc
);
9515 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9517 if (infoPtr
->clrBk
== CLR_NONE
)
9519 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9520 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9521 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9523 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9526 /* for double buffered controls we need to do this during refresh */
9527 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9529 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9535 * Helper function for LISTVIEW_[HV]Scroll *only*.
9536 * Performs vertical/horizontal scrolling by a give amount.
9539 * [I] infoPtr : valid pointer to the listview structure
9540 * [I] dx : amount of horizontal scroll
9541 * [I] dy : amount of vertical scroll
9543 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9545 /* now we can scroll the list */
9546 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9547 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9548 /* if we have focus, adjust rect */
9549 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9550 UpdateWindow(infoPtr
->hwndSelf
);
9555 * Performs vertical scrolling.
9558 * [I] infoPtr : valid pointer to the listview structure
9559 * [I] nScrollCode : scroll code
9560 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9561 * [I] hScrollWnd : scrollbar control window handle
9567 * SB_LINEUP/SB_LINEDOWN:
9568 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9569 * for LVS_REPORT is 1 line
9570 * for LVS_LIST cannot occur
9573 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9576 INT nOldScrollPos
, nNewScrollPos
;
9577 SCROLLINFO scrollInfo
;
9580 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9581 debugscrollcode(nScrollCode
), nScrollDiff
);
9583 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9585 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9586 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9588 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9590 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9592 nOldScrollPos
= scrollInfo
.nPos
;
9593 switch (nScrollCode
)
9599 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9603 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9607 nScrollDiff
= -scrollInfo
.nPage
;
9611 nScrollDiff
= scrollInfo
.nPage
;
9614 case SB_THUMBPOSITION
:
9616 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9623 /* quit right away if pos isn't changing */
9624 if (nScrollDiff
== 0) return 0;
9626 /* calculate new position, and handle overflows */
9627 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9628 if (nScrollDiff
> 0) {
9629 if (nNewScrollPos
< nOldScrollPos
||
9630 nNewScrollPos
> scrollInfo
.nMax
)
9631 nNewScrollPos
= scrollInfo
.nMax
;
9633 if (nNewScrollPos
> nOldScrollPos
||
9634 nNewScrollPos
< scrollInfo
.nMin
)
9635 nNewScrollPos
= scrollInfo
.nMin
;
9638 /* set the new position, and reread in case it changed */
9639 scrollInfo
.fMask
= SIF_POS
;
9640 scrollInfo
.nPos
= nNewScrollPos
;
9641 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9643 /* carry on only if it really changed */
9644 if (nNewScrollPos
== nOldScrollPos
) return 0;
9646 /* now adjust to client coordinates */
9647 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9648 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9650 /* and scroll the window */
9651 scroll_list(infoPtr
, 0, nScrollDiff
);
9658 * Performs horizontal scrolling.
9661 * [I] infoPtr : valid pointer to the listview structure
9662 * [I] nScrollCode : scroll code
9663 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9664 * [I] hScrollWnd : scrollbar control window handle
9670 * SB_LINELEFT/SB_LINERIGHT:
9671 * for LVS_ICON, LVS_SMALLICON 1 pixel
9672 * for LVS_REPORT is 1 pixel
9673 * for LVS_LIST is 1 column --> which is a 1 because the
9674 * scroll is based on columns not pixels
9677 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9680 INT nOldScrollPos
, nNewScrollPos
;
9681 SCROLLINFO scrollInfo
;
9684 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9685 debugscrollcode(nScrollCode
), nScrollDiff
);
9687 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9689 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9690 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9692 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9694 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9696 nOldScrollPos
= scrollInfo
.nPos
;
9698 switch (nScrollCode
)
9704 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9708 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9712 nScrollDiff
= -scrollInfo
.nPage
;
9716 nScrollDiff
= scrollInfo
.nPage
;
9719 case SB_THUMBPOSITION
:
9721 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9728 /* quit right away if pos isn't changing */
9729 if (nScrollDiff
== 0) return 0;
9731 /* calculate new position, and handle overflows */
9732 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9733 if (nScrollDiff
> 0) {
9734 if (nNewScrollPos
< nOldScrollPos
||
9735 nNewScrollPos
> scrollInfo
.nMax
)
9736 nNewScrollPos
= scrollInfo
.nMax
;
9738 if (nNewScrollPos
> nOldScrollPos
||
9739 nNewScrollPos
< scrollInfo
.nMin
)
9740 nNewScrollPos
= scrollInfo
.nMin
;
9743 /* set the new position, and reread in case it changed */
9744 scrollInfo
.fMask
= SIF_POS
;
9745 scrollInfo
.nPos
= nNewScrollPos
;
9746 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9748 /* carry on only if it really changed */
9749 if (nNewScrollPos
== nOldScrollPos
) return 0;
9751 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9753 /* now adjust to client coordinates */
9754 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9755 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9757 /* and scroll the window */
9758 scroll_list(infoPtr
, nScrollDiff
, 0);
9763 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9765 UINT pulScrollLines
= 3;
9767 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9769 switch(infoPtr
->uView
)
9772 case LV_VIEW_SMALLICON
:
9774 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9775 * should be fixed in the future.
9777 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9778 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9781 case LV_VIEW_DETAILS
:
9782 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9784 /* if scrolling changes direction, ignore left overs */
9785 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9786 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9787 infoPtr
->cWheelRemainder
+= wheelDelta
;
9789 infoPtr
->cWheelRemainder
= wheelDelta
;
9790 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9793 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9794 cLineScroll
= pulScrollLines
* (float)infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9795 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
9796 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9801 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9812 * [I] infoPtr : valid pointer to the listview structure
9813 * [I] nVirtualKey : virtual key
9814 * [I] lKeyData : key data
9819 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9821 HWND hwndSelf
= infoPtr
->hwndSelf
;
9823 NMLVKEYDOWN nmKeyDown
;
9825 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9827 /* send LVN_KEYDOWN notification */
9828 nmKeyDown
.wVKey
= nVirtualKey
;
9829 nmKeyDown
.flags
= 0;
9830 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9831 if (!IsWindow(hwndSelf
))
9834 switch (nVirtualKey
)
9837 nItem
= infoPtr
->nFocusedItem
;
9838 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9839 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9843 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9845 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9846 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9851 if (infoPtr
->nItemCount
> 0)
9856 if (infoPtr
->nItemCount
> 0)
9857 nItem
= infoPtr
->nItemCount
- 1;
9861 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9865 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9869 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9873 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9877 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9879 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9880 if (infoPtr
->nFocusedItem
== topidx
)
9881 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9886 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9887 * LISTVIEW_GetCountPerRow(infoPtr
);
9888 if(nItem
< 0) nItem
= 0;
9892 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9894 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9895 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9896 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9897 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9899 nItem
= topidx
+ cnt
- 1;
9902 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9903 * LISTVIEW_GetCountPerRow(infoPtr
);
9904 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9908 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9909 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
9919 * [I] infoPtr : valid pointer to the listview structure
9924 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
9928 /* drop any left over scroll amount */
9929 infoPtr
->cWheelRemainder
= 0;
9931 /* if we did not have the focus, there's nothing more to do */
9932 if (!infoPtr
->bFocus
) return 0;
9934 /* send NM_KILLFOCUS notification */
9935 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
9937 /* if we have a focus rectangle, get rid of it */
9938 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
9940 /* if have a marquee selection, stop it */
9941 if (infoPtr
->bMarqueeSelect
)
9943 /* Remove the marquee rectangle and release our mouse capture */
9944 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
9947 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
9949 infoPtr
->bMarqueeSelect
= FALSE
;
9950 infoPtr
->bScrolling
= FALSE
;
9951 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
9954 /* set window focus flag */
9955 infoPtr
->bFocus
= FALSE
;
9957 /* invalidate the selected items before resetting focus flag */
9958 LISTVIEW_InvalidateSelectedItems(infoPtr
);
9965 * Processes double click messages (left mouse button).
9968 * [I] infoPtr : valid pointer to the listview structure
9969 * [I] wKey : key flag
9970 * [I] x,y : mouse coordinate
9975 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9977 LVHITTESTINFO htInfo
;
9979 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
9981 /* Cancel the item edition if any */
9982 if (infoPtr
->itemEdit
.fEnabled
)
9984 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
9985 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9988 /* send NM_RELEASEDCAPTURE notification */
9989 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9994 /* send NM_DBLCLK notification */
9995 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
9996 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
9998 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
9999 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10004 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10009 r
.top
= r
.bottom
= pt
.y
;
10010 r
.left
= r
.right
= pt
.x
;
10012 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10014 SetCapture(infoPtr
->hwndSelf
);
10018 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10020 if (msg
.message
== WM_MOUSEMOVE
)
10022 pt
.x
= (short)LOWORD(msg
.lParam
);
10023 pt
.y
= (short)HIWORD(msg
.lParam
);
10024 if (PtInRect(&r
, pt
))
10032 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10033 msg
.message
<= WM_RBUTTONDBLCLK
)
10038 DispatchMessageW(&msg
);
10041 if (GetCapture() != infoPtr
->hwndSelf
)
10052 * Processes mouse down messages (left mouse button).
10055 * infoPtr [I ] valid pointer to the listview structure
10056 * wKey [I ] key flag
10057 * x,y [I ] mouse coordinate
10062 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10064 LVHITTESTINFO lvHitTestInfo
;
10065 static BOOL bGroupSelect
= TRUE
;
10066 POINT pt
= { x
, y
};
10069 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10071 /* send NM_RELEASEDCAPTURE notification */
10072 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10074 /* set left button down flag and record the click position */
10075 infoPtr
->bLButtonDown
= TRUE
;
10076 infoPtr
->ptClickPos
= pt
;
10077 infoPtr
->bDragging
= FALSE
;
10078 infoPtr
->bMarqueeSelect
= FALSE
;
10079 infoPtr
->bScrolling
= FALSE
;
10081 lvHitTestInfo
.pt
.x
= x
;
10082 lvHitTestInfo
.pt
.y
= y
;
10084 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10085 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10086 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10088 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10090 toggle_checkbox_state(infoPtr
, nItem
);
10094 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10096 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10097 infoPtr
->nEditLabelItem
= nItem
;
10099 LISTVIEW_SetSelection(infoPtr
, nItem
);
10103 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10107 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10108 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10109 infoPtr
->nSelectionMark
= nItem
;
10115 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10116 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10118 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10119 infoPtr
->nSelectionMark
= nItem
;
10122 else if (wKey
& MK_CONTROL
)
10126 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10128 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10129 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10130 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10131 infoPtr
->nSelectionMark
= nItem
;
10133 else if (wKey
& MK_SHIFT
)
10135 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10139 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10141 infoPtr
->nEditLabelItem
= nItem
;
10142 infoPtr
->nLButtonDownItem
= nItem
;
10144 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10147 /* set selection (clears other pre-existing selections) */
10148 LISTVIEW_SetSelection(infoPtr
, nItem
);
10152 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10153 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10157 if (!infoPtr
->bFocus
)
10158 SetFocus(infoPtr
->hwndSelf
);
10160 /* remove all selections */
10161 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10162 LISTVIEW_DeselectAll(infoPtr
);
10171 * Processes mouse up messages (left mouse button).
10174 * infoPtr [I ] valid pointer to the listview structure
10175 * wKey [I ] key flag
10176 * x,y [I ] mouse coordinate
10181 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10183 LVHITTESTINFO lvHitTestInfo
;
10185 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10187 if (!infoPtr
->bLButtonDown
) return 0;
10189 lvHitTestInfo
.pt
.x
= x
;
10190 lvHitTestInfo
.pt
.y
= y
;
10192 /* send NM_CLICK notification */
10193 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10194 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10196 /* set left button flag */
10197 infoPtr
->bLButtonDown
= FALSE
;
10199 /* set a single selection, reset others */
10200 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10201 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10202 infoPtr
->nLButtonDownItem
= -1;
10204 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10206 /* Remove the marquee rectangle and release our mouse capture */
10207 if (infoPtr
->bMarqueeSelect
)
10209 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10213 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10214 SetRect(&infoPtr
->marqueeDrawRect
, 0, 0, 0, 0);
10216 infoPtr
->bDragging
= FALSE
;
10217 infoPtr
->bMarqueeSelect
= FALSE
;
10218 infoPtr
->bScrolling
= FALSE
;
10220 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10224 /* if we clicked on a selected item, edit the label */
10225 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10227 /* we want to make sure the user doesn't want to do a double click. So we will
10228 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10230 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10231 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10232 SetTimer(infoPtr
->hwndSelf
,
10233 (UINT_PTR
)&infoPtr
->itemEdit
,
10234 GetDoubleClickTime(),
10235 LISTVIEW_DelayedEditItem
);
10238 if (!infoPtr
->bFocus
)
10239 SetFocus(infoPtr
->hwndSelf
);
10246 * Destroys the listview control (called after WM_DESTROY).
10249 * [I] infoPtr : valid pointer to the listview structure
10254 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10260 /* destroy data structure */
10261 DPA_Destroy(infoPtr
->hdpaItems
);
10262 DPA_Destroy(infoPtr
->hdpaItemIds
);
10263 DPA_Destroy(infoPtr
->hdpaPosX
);
10264 DPA_Destroy(infoPtr
->hdpaPosY
);
10266 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10267 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10268 DPA_Destroy(infoPtr
->hdpaColumns
);
10269 ranges_destroy(infoPtr
->selectionRanges
);
10271 /* destroy image lists */
10272 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10274 ImageList_Destroy(infoPtr
->himlNormal
);
10275 ImageList_Destroy(infoPtr
->himlSmall
);
10276 ImageList_Destroy(infoPtr
->himlState
);
10279 /* destroy font, bkgnd brush */
10280 infoPtr
->hFont
= 0;
10281 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10282 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10284 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10286 /* free listview info pointer*/
10294 * Handles notifications.
10297 * [I] infoPtr : valid pointer to the listview structure
10298 * [I] lpnmhdr : notification information
10303 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10307 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10309 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10311 /* remember: HDN_LAST < HDN_FIRST */
10312 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10313 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10315 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10317 switch (lpnmhdr
->code
)
10322 COLUMN_INFO
*lpColumnInfo
;
10326 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10329 /* remove the old line (if any) */
10330 LISTVIEW_DrawTrackLine(infoPtr
);
10332 /* compute & draw the new line */
10333 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10334 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10335 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10336 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10337 LISTVIEW_DrawTrackLine(infoPtr
);
10338 return notify_forward_header(infoPtr
, lpnmh
);
10341 case HDN_ENDTRACKA
:
10342 case HDN_ENDTRACKW
:
10343 /* remove the track line (if any) */
10344 LISTVIEW_DrawTrackLine(infoPtr
);
10345 infoPtr
->xTrackLine
= -1;
10346 return notify_forward_header(infoPtr
, lpnmh
);
10348 case HDN_BEGINDRAG
:
10349 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10350 return notify_forward_header(infoPtr
, lpnmh
);
10353 infoPtr
->colRectsDirty
= TRUE
;
10354 LISTVIEW_InvalidateList(infoPtr
);
10355 return notify_forward_header(infoPtr
, lpnmh
);
10357 case HDN_ITEMCHANGEDW
:
10358 case HDN_ITEMCHANGEDA
:
10360 COLUMN_INFO
*lpColumnInfo
;
10364 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10366 hdi
.mask
= HDI_WIDTH
;
10367 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10371 cxy
= lpnmh
->pitem
->cxy
;
10373 /* determine how much we change since the last know position */
10374 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10375 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10378 lpColumnInfo
->rcHeader
.right
+= dx
;
10380 hdi
.mask
= HDI_ORDER
;
10381 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10383 /* not the rightmost one */
10384 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10386 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10387 hdi
.iOrder
+ 1, 0);
10388 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10392 /* only needs to update the scrolls */
10393 infoPtr
->nItemWidth
+= dx
;
10394 LISTVIEW_UpdateScroll(infoPtr
);
10396 LISTVIEW_UpdateItemSize(infoPtr
);
10397 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10400 RECT rcCol
= lpColumnInfo
->rcHeader
;
10402 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10403 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10405 rcCol
.top
= infoPtr
->rcList
.top
;
10406 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10408 /* resizing left-aligned columns leaves most of the left side untouched */
10409 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10411 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10414 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10417 /* when shrinking the last column clear the now unused field */
10418 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10424 /* deal with right from rightmost column area */
10425 right
.left
= rcCol
.right
;
10426 right
.top
= rcCol
.top
;
10427 right
.bottom
= rcCol
.bottom
;
10428 right
.right
= infoPtr
->rcList
.right
;
10430 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10433 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10439 case HDN_ITEMCLICKW
:
10440 case HDN_ITEMCLICKA
:
10442 /* Handle sorting by Header Column */
10445 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10447 nmlv
.iSubItem
= lpnmh
->iItem
;
10448 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10449 return notify_forward_header(infoPtr
, lpnmh
);
10452 case HDN_DIVIDERDBLCLICKW
:
10453 case HDN_DIVIDERDBLCLICKA
:
10454 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10455 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10456 split needed for that */
10457 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10458 return notify_forward_header(infoPtr
, lpnmh
);
10465 * Paint non-client area of control.
10468 * [I] infoPtr : valid pointer to the listview structureof the sender
10469 * [I] region : update region
10472 * TRUE - frame was painted
10473 * FALSE - call default window proc
10475 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10477 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10481 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10482 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10485 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10487 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10489 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10490 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10491 if (region
!= (HRGN
)1)
10492 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10493 OffsetRect(&r
, -r
.left
, -r
.top
);
10495 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10496 OffsetRect(&r
, -r
.left
, -r
.top
);
10498 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10499 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10500 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10501 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10503 /* Call default proc to get the scrollbars etc. painted */
10504 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10511 * Determines the type of structure to use.
10514 * [I] infoPtr : valid pointer to the listview structureof the sender
10515 * [I] hwndFrom : listview window handle
10516 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10521 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10523 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10525 if (nCommand
== NF_REQUERY
)
10526 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10528 return infoPtr
->notifyFormat
;
10533 * Paints/Repaints the listview control. Internal use.
10536 * [I] infoPtr : valid pointer to the listview structure
10537 * [I] hdc : device context handle
10542 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10544 TRACE("(hdc=%p)\n", hdc
);
10546 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10548 infoPtr
->bNoItemMetrics
= FALSE
;
10549 LISTVIEW_UpdateItemSize(infoPtr
);
10550 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10551 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10552 LISTVIEW_UpdateScroll(infoPtr
);
10555 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10558 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10563 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10564 if (!hdc
) return 1;
10565 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10566 EndPaint(infoPtr
->hwndSelf
, &ps
);
10574 * Paints/Repaints the listview control, WM_PAINT handler.
10577 * [I] infoPtr : valid pointer to the listview structure
10578 * [I] hdc : device context handle
10583 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10585 TRACE("(hdc=%p)\n", hdc
);
10587 if (!is_redrawing(infoPtr
))
10588 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10590 return LISTVIEW_Paint(infoPtr
, hdc
);
10595 * Paints/Repaints the listview control.
10598 * [I] infoPtr : valid pointer to the listview structure
10599 * [I] hdc : device context handle
10600 * [I] options : drawing options
10605 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10607 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10609 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10612 if (options
& PRF_ERASEBKGND
)
10613 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10615 if (options
& PRF_CLIENT
)
10616 LISTVIEW_Paint(infoPtr
, hdc
);
10624 * Processes double click messages (right mouse button).
10627 * [I] infoPtr : valid pointer to the listview structure
10628 * [I] wKey : key flag
10629 * [I] x,y : mouse coordinate
10634 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10636 LVHITTESTINFO lvHitTestInfo
;
10638 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10640 /* send NM_RELEASEDCAPTURE notification */
10641 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10643 /* send NM_RDBLCLK notification */
10644 lvHitTestInfo
.pt
.x
= x
;
10645 lvHitTestInfo
.pt
.y
= y
;
10646 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10647 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10654 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10657 * [I] infoPtr : valid pointer to the listview structure
10658 * [I] wKey : key flag
10659 * [I] x, y : mouse coordinate
10664 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10669 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10671 /* send NM_RELEASEDCAPTURE notification */
10672 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10674 /* determine the index of the selected item */
10677 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10679 /* make sure the listview control window has the focus */
10680 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10682 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10684 LISTVIEW_SetItemFocus(infoPtr
, item
);
10685 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10686 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10687 LISTVIEW_SetSelection(infoPtr
, item
);
10690 LISTVIEW_DeselectAll(infoPtr
);
10692 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10694 if (ht
.iItem
!= -1)
10698 memset(&nmlv
, 0, sizeof(nmlv
));
10699 nmlv
.iItem
= ht
.iItem
;
10700 nmlv
.ptAction
= ht
.pt
;
10702 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10707 SetFocus(infoPtr
->hwndSelf
);
10711 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10713 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10715 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10716 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10717 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10729 * [I] infoPtr : valid pointer to the listview structure
10730 * [I] hwnd : window handle of window containing the cursor
10731 * [I] nHittest : hit-test code
10732 * [I] wMouseMsg : ideintifier of the mouse message
10735 * TRUE if cursor is set
10738 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10740 LVHITTESTINFO lvHitTestInfo
;
10742 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10744 if (!infoPtr
->hHotCursor
) goto forward
;
10746 GetCursorPos(&lvHitTestInfo
.pt
);
10747 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10749 SetCursor(infoPtr
->hHotCursor
);
10755 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10763 * [I] infoPtr : valid pointer to the listview structure
10764 * [I] hwndLoseFocus : handle of previously focused window
10769 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10771 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10773 /* if we have the focus already, there's nothing to do */
10774 if (infoPtr
->bFocus
) return 0;
10776 /* send NM_SETFOCUS notification */
10777 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10779 /* set window focus flag */
10780 infoPtr
->bFocus
= TRUE
;
10782 /* put the focus rect back on */
10783 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10785 /* redraw all visible selected items */
10786 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10796 * [I] infoPtr : valid pointer to the listview structure
10797 * [I] fRedraw : font handle
10798 * [I] fRedraw : redraw flag
10803 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10805 HFONT oldFont
= infoPtr
->hFont
;
10806 INT oldHeight
= infoPtr
->nItemHeight
;
10808 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10810 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10811 if (infoPtr
->hFont
== oldFont
) return 0;
10813 LISTVIEW_SaveTextMetrics(infoPtr
);
10815 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10817 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10819 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10820 LISTVIEW_UpdateSize(infoPtr
);
10821 LISTVIEW_UpdateScroll(infoPtr
);
10823 else if (infoPtr
->nItemHeight
!= oldHeight
)
10824 LISTVIEW_UpdateScroll(infoPtr
);
10826 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10833 * Message handling for WM_SETREDRAW.
10834 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10837 * [I] infoPtr : valid pointer to the listview structure
10838 * [I] bRedraw: state of redraw flag
10841 * DefWinProc return value
10843 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10845 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10847 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10848 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10850 infoPtr
->bRedraw
= bRedraw
;
10852 if(!bRedraw
) return 0;
10854 if (is_autoarrange(infoPtr
))
10855 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10856 LISTVIEW_UpdateScroll(infoPtr
);
10858 /* despite what the WM_SETREDRAW docs says, apps expect us
10859 * to invalidate the listview here... stupid! */
10860 LISTVIEW_InvalidateList(infoPtr
);
10867 * Resizes the listview control. This function processes WM_SIZE
10868 * messages. At this time, the width and height are not used.
10871 * [I] infoPtr : valid pointer to the listview structure
10872 * [I] Width : new width
10873 * [I] Height : new height
10878 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10880 RECT rcOld
= infoPtr
->rcList
;
10882 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10884 LISTVIEW_UpdateSize(infoPtr
);
10885 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10887 /* do not bother with display related stuff if we're not redrawing */
10888 if (!is_redrawing(infoPtr
)) return 0;
10890 if (is_autoarrange(infoPtr
))
10891 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10893 LISTVIEW_UpdateScroll(infoPtr
);
10895 /* refresh all only for lists whose height changed significantly */
10896 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10897 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10898 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10899 LISTVIEW_InvalidateList(infoPtr
);
10906 * Sets the size information.
10909 * [I] infoPtr : valid pointer to the listview structure
10914 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
10916 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
10918 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
10920 if (infoPtr
->uView
== LV_VIEW_LIST
)
10922 /* Apparently the "LIST" style is supposed to have the same
10923 * number of items in a column even if there is no scroll bar.
10924 * Since if a scroll bar already exists then the bottom is already
10925 * reduced, only reduce if the scroll bar does not currently exist.
10926 * The "2" is there to mimic the native control. I think it may be
10927 * related to either padding or edges. (GLA 7/2002)
10929 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
10930 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
10931 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
10934 /* if control created invisible header isn't created */
10935 if (infoPtr
->hwndHeader
)
10940 hl
.prc
= &infoPtr
->rcList
;
10942 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10943 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10945 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
10946 wp
.flags
|= SWP_SHOWWINDOW
;
10949 wp
.flags
|= SWP_HIDEWINDOW
;
10953 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
10954 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10956 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
10958 /* extra padding for grid */
10959 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
10960 infoPtr
->rcList
.top
+= 2;
10962 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
10967 * Processes WM_STYLECHANGED messages.
10970 * [I] infoPtr : valid pointer to the listview structure
10971 * [I] wStyleType : window style type (normal or extended)
10972 * [I] lpss : window style information
10977 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10978 const STYLESTRUCT
*lpss
)
10980 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
10981 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
10984 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10985 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10987 if (wStyleType
!= GWL_STYLE
) return 0;
10989 infoPtr
->dwStyle
= lpss
->styleNew
;
10990 map_style_view(infoPtr
);
10992 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
10993 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
10994 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
10996 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
10997 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
10998 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11000 if (uNewView
!= uOldView
)
11004 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11005 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11007 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11008 SetRectEmpty(&infoPtr
->rcFocus
);
11010 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11011 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11013 if (uNewView
== LVS_REPORT
)
11018 LISTVIEW_CreateHeader( infoPtr
);
11020 hl
.prc
= &infoPtr
->rcList
;
11022 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11023 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11024 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11025 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11028 LISTVIEW_UpdateItemSize(infoPtr
);
11031 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11033 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11035 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11037 /* Turn off the header control */
11038 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11039 TRACE("Hide header control, was 0x%08x\n", style
);
11040 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11042 /* Turn on the header control */
11043 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11045 TRACE("Show header control, was 0x%08x\n", style
);
11046 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11052 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11053 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11054 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11056 /* update the size of the client area */
11057 LISTVIEW_UpdateSize(infoPtr
);
11059 /* add scrollbars if needed */
11060 LISTVIEW_UpdateScroll(infoPtr
);
11062 /* invalidate client area + erase background */
11063 LISTVIEW_InvalidateList(infoPtr
);
11070 * Processes WM_STYLECHANGING messages.
11073 * [I] wStyleType : window style type (normal or extended)
11074 * [I0] lpss : window style information
11079 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11082 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11083 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11085 /* don't forward LVS_OWNERDATA only if not already set to */
11086 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11088 if (lpss
->styleOld
& LVS_OWNERDATA
)
11089 lpss
->styleNew
|= LVS_OWNERDATA
;
11091 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11099 * Processes WM_SHOWWINDOW messages.
11102 * [I] infoPtr : valid pointer to the listview structure
11103 * [I] bShown : window is being shown (FALSE when hidden)
11104 * [I] iStatus : window show status
11109 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11111 /* header delayed creation */
11112 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11114 LISTVIEW_CreateHeader(infoPtr
);
11116 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11117 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11120 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11125 * Processes CCM_GETVERSION messages.
11128 * [I] infoPtr : valid pointer to the listview structure
11133 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11135 return infoPtr
->iVersion
;
11140 * Processes CCM_SETVERSION messages.
11143 * [I] infoPtr : valid pointer to the listview structure
11144 * [I] iVersion : version to be set
11147 * -1 when requested version is greater than DLL version;
11148 * previous version otherwise
11150 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11152 INT iOldVersion
= infoPtr
->iVersion
;
11154 if (iVersion
> COMCTL32_VERSION
)
11157 infoPtr
->iVersion
= iVersion
;
11159 TRACE("new version %d\n", iVersion
);
11161 return iOldVersion
;
11166 * Window procedure of the listview control.
11169 static LRESULT WINAPI
11170 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11172 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11174 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11176 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11177 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11181 case LVM_APPROXIMATEVIEWRECT
:
11182 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11183 LOWORD(lParam
), HIWORD(lParam
));
11185 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11187 case LVM_CANCELEDITLABEL
:
11188 return LISTVIEW_CancelEditLabel(infoPtr
);
11190 case LVM_CREATEDRAGIMAGE
:
11191 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11193 case LVM_DELETEALLITEMS
:
11194 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11196 case LVM_DELETECOLUMN
:
11197 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11199 case LVM_DELETEITEM
:
11200 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11202 case LVM_EDITLABELA
:
11203 case LVM_EDITLABELW
:
11204 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11205 uMsg
== LVM_EDITLABELW
);
11206 /* case LVM_ENABLEGROUPVIEW: */
11208 case LVM_ENSUREVISIBLE
:
11209 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11211 case LVM_FINDITEMW
:
11212 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11214 case LVM_FINDITEMA
:
11215 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11217 case LVM_GETBKCOLOR
:
11218 return infoPtr
->clrBk
;
11220 /* case LVM_GETBKIMAGE: */
11222 case LVM_GETCALLBACKMASK
:
11223 return infoPtr
->uCallbackMask
;
11225 case LVM_GETCOLUMNA
:
11226 case LVM_GETCOLUMNW
:
11227 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11228 uMsg
== LVM_GETCOLUMNW
);
11230 case LVM_GETCOLUMNORDERARRAY
:
11231 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11233 case LVM_GETCOLUMNWIDTH
:
11234 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11236 case LVM_GETCOUNTPERPAGE
:
11237 return LISTVIEW_GetCountPerPage(infoPtr
);
11239 case LVM_GETEDITCONTROL
:
11240 return (LRESULT
)infoPtr
->hwndEdit
;
11242 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11243 return infoPtr
->dwLvExStyle
;
11245 /* case LVM_GETGROUPINFO: */
11247 /* case LVM_GETGROUPMETRICS: */
11249 case LVM_GETHEADER
:
11250 return (LRESULT
)infoPtr
->hwndHeader
;
11252 case LVM_GETHOTCURSOR
:
11253 return (LRESULT
)infoPtr
->hHotCursor
;
11255 case LVM_GETHOTITEM
:
11256 return infoPtr
->nHotItem
;
11258 case LVM_GETHOVERTIME
:
11259 return infoPtr
->dwHoverTime
;
11261 case LVM_GETIMAGELIST
:
11262 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11264 /* case LVM_GETINSERTMARK: */
11266 /* case LVM_GETINSERTMARKCOLOR: */
11268 /* case LVM_GETINSERTMARKRECT: */
11270 case LVM_GETISEARCHSTRINGA
:
11271 case LVM_GETISEARCHSTRINGW
:
11272 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11277 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11279 case LVM_GETITEMCOUNT
:
11280 return infoPtr
->nItemCount
;
11282 case LVM_GETITEMPOSITION
:
11283 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11285 case LVM_GETITEMRECT
:
11286 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11288 case LVM_GETITEMSPACING
:
11289 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11291 case LVM_GETITEMSTATE
:
11292 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11294 case LVM_GETITEMTEXTA
:
11295 case LVM_GETITEMTEXTW
:
11296 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11297 uMsg
== LVM_GETITEMTEXTW
);
11299 case LVM_GETNEXTITEM
:
11300 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11302 case LVM_GETNUMBEROFWORKAREAS
:
11303 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11306 case LVM_GETORIGIN
:
11307 if (!lParam
) return FALSE
;
11308 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11309 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11310 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11313 /* case LVM_GETOUTLINECOLOR: */
11315 /* case LVM_GETSELECTEDCOLUMN: */
11317 case LVM_GETSELECTEDCOUNT
:
11318 return LISTVIEW_GetSelectedCount(infoPtr
);
11320 case LVM_GETSELECTIONMARK
:
11321 return infoPtr
->nSelectionMark
;
11323 case LVM_GETSTRINGWIDTHA
:
11324 case LVM_GETSTRINGWIDTHW
:
11325 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11326 uMsg
== LVM_GETSTRINGWIDTHW
);
11328 case LVM_GETSUBITEMRECT
:
11329 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11331 case LVM_GETTEXTBKCOLOR
:
11332 return infoPtr
->clrTextBk
;
11334 case LVM_GETTEXTCOLOR
:
11335 return infoPtr
->clrText
;
11337 /* case LVM_GETTILEINFO: */
11339 /* case LVM_GETTILEVIEWINFO: */
11341 case LVM_GETTOOLTIPS
:
11342 if( !infoPtr
->hwndToolTip
)
11343 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11344 return (LRESULT
)infoPtr
->hwndToolTip
;
11346 case LVM_GETTOPINDEX
:
11347 return LISTVIEW_GetTopIndex(infoPtr
);
11349 case LVM_GETUNICODEFORMAT
:
11350 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11353 return infoPtr
->uView
;
11355 case LVM_GETVIEWRECT
:
11356 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11358 case LVM_GETWORKAREAS
:
11359 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11362 /* case LVM_HASGROUP: */
11365 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11367 case LVM_INSERTCOLUMNA
:
11368 case LVM_INSERTCOLUMNW
:
11369 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11370 uMsg
== LVM_INSERTCOLUMNW
);
11372 /* case LVM_INSERTGROUP: */
11374 /* case LVM_INSERTGROUPSORTED: */
11376 case LVM_INSERTITEMA
:
11377 case LVM_INSERTITEMW
:
11378 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11380 /* case LVM_INSERTMARKHITTEST: */
11382 /* case LVM_ISGROUPVIEWENABLED: */
11384 case LVM_ISITEMVISIBLE
:
11385 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11387 case LVM_MAPIDTOINDEX
:
11388 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11390 case LVM_MAPINDEXTOID
:
11391 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11393 /* case LVM_MOVEGROUP: */
11395 /* case LVM_MOVEITEMTOGROUP: */
11397 case LVM_REDRAWITEMS
:
11398 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11400 /* case LVM_REMOVEALLGROUPS: */
11402 /* case LVM_REMOVEGROUP: */
11405 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11407 case LVM_SETBKCOLOR
:
11408 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11410 /* case LVM_SETBKIMAGE: */
11412 case LVM_SETCALLBACKMASK
:
11413 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11416 case LVM_SETCOLUMNA
:
11417 case LVM_SETCOLUMNW
:
11418 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11419 uMsg
== LVM_SETCOLUMNW
);
11421 case LVM_SETCOLUMNORDERARRAY
:
11422 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11424 case LVM_SETCOLUMNWIDTH
:
11425 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11427 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11428 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11430 /* case LVM_SETGROUPINFO: */
11432 /* case LVM_SETGROUPMETRICS: */
11434 case LVM_SETHOTCURSOR
:
11435 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11437 case LVM_SETHOTITEM
:
11438 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11440 case LVM_SETHOVERTIME
:
11441 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11443 case LVM_SETICONSPACING
:
11445 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11446 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11448 case LVM_SETIMAGELIST
:
11449 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11451 /* case LVM_SETINFOTIP: */
11453 /* case LVM_SETINSERTMARK: */
11455 /* case LVM_SETINSERTMARKCOLOR: */
11460 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11461 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11464 case LVM_SETITEMCOUNT
:
11465 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11467 case LVM_SETITEMPOSITION
:
11470 pt
.x
= (short)LOWORD(lParam
);
11471 pt
.y
= (short)HIWORD(lParam
);
11472 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11475 case LVM_SETITEMPOSITION32
:
11476 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11478 case LVM_SETITEMSTATE
:
11479 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11481 case LVM_SETITEMTEXTA
:
11482 case LVM_SETITEMTEXTW
:
11483 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11484 uMsg
== LVM_SETITEMTEXTW
);
11486 /* case LVM_SETOUTLINECOLOR: */
11488 /* case LVM_SETSELECTEDCOLUMN: */
11490 case LVM_SETSELECTIONMARK
:
11491 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11493 case LVM_SETTEXTBKCOLOR
:
11494 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11496 case LVM_SETTEXTCOLOR
:
11497 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11499 /* case LVM_SETTILEINFO: */
11501 /* case LVM_SETTILEVIEWINFO: */
11503 /* case LVM_SETTILEWIDTH: */
11505 case LVM_SETTOOLTIPS
:
11506 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11508 case LVM_SETUNICODEFORMAT
:
11509 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11512 return LISTVIEW_SetView(infoPtr
, wParam
);
11514 /* case LVM_SETWORKAREAS: */
11516 /* case LVM_SORTGROUPS: */
11518 case LVM_SORTITEMS
:
11519 case LVM_SORTITEMSEX
:
11520 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11521 uMsg
== LVM_SORTITEMSEX
);
11522 case LVM_SUBITEMHITTEST
:
11523 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11526 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11528 case CCM_GETVERSION
:
11529 return LISTVIEW_GetVersion(infoPtr
);
11531 case CCM_SETVERSION
:
11532 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11535 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11538 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11541 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11544 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11547 return LISTVIEW_Destroy(infoPtr
);
11550 return LISTVIEW_Enable(infoPtr
);
11552 case WM_ERASEBKGND
:
11553 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11555 case WM_GETDLGCODE
:
11556 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11559 return (LRESULT
)infoPtr
->hFont
;
11562 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11565 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11568 return LISTVIEW_KillFocus(infoPtr
);
11570 case WM_LBUTTONDBLCLK
:
11571 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11573 case WM_LBUTTONDOWN
:
11574 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11577 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11580 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11582 case WM_MOUSEHOVER
:
11583 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11586 return LISTVIEW_NCDestroy(infoPtr
);
11589 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11592 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11594 case WM_NOTIFYFORMAT
:
11595 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11597 case WM_PRINTCLIENT
:
11598 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11601 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11603 case WM_RBUTTONDBLCLK
:
11604 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11606 case WM_RBUTTONDOWN
:
11607 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11610 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11613 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11616 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11619 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11621 case WM_SHOWWINDOW
:
11622 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11624 case WM_STYLECHANGED
:
11625 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11627 case WM_STYLECHANGING
:
11628 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11630 case WM_SYSCOLORCHANGE
:
11631 COMCTL32_RefreshSysColors();
11632 if (infoPtr
->bDefaultBkColor
)
11634 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
11635 infoPtr
->bDefaultBkColor
= TRUE
;
11636 LISTVIEW_InvalidateList(infoPtr
);
11640 /* case WM_TIMER: */
11641 case WM_THEMECHANGED
:
11642 return LISTVIEW_ThemeChanged(infoPtr
);
11645 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11647 case WM_MOUSEWHEEL
:
11648 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11649 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11650 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11652 case WM_WINDOWPOSCHANGED
:
11653 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11655 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11656 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11658 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11660 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11662 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11664 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11666 /* case WM_WININICHANGE: */
11669 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11670 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11672 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11679 * Registers the window class.
11687 void LISTVIEW_Register(void)
11689 WNDCLASSW wndClass
;
11691 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11692 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11693 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11694 wndClass
.cbClsExtra
= 0;
11695 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11696 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11697 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11698 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11699 RegisterClassW(&wndClass
);
11704 * Unregisters the window class.
11712 void LISTVIEW_Unregister(void)
11714 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11719 * Handle any WM_COMMAND messages
11722 * [I] infoPtr : valid pointer to the listview structure
11723 * [I] wParam : the first message parameter
11724 * [I] lParam : the second message parameter
11729 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11732 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11734 if (!infoPtr
->hwndEdit
) return 0;
11736 switch (HIWORD(wParam
))
11741 * Adjust the edit window size
11743 WCHAR buffer
[1024];
11744 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11745 HFONT hFont
, hOldFont
= 0;
11749 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11750 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11751 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11753 /* Select font to get the right dimension of the string */
11754 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11757 hOldFont
= SelectObject(hdc
, hFont
);
11760 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11762 TEXTMETRICW textMetric
;
11764 /* Add Extra spacing for the next character */
11765 GetTextMetricsW(hdc
, &textMetric
);
11766 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11768 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11769 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11772 SelectObject(hdc
, hOldFont
);
11774 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11780 LISTVIEW_CancelEditLabel(infoPtr
);
11785 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);