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-2014 Nikolay Sivov
10 * Copyright 2009 Owen Rudge for CodeWeavers
11 * Copyright 2012-2013 Daniel Jelinski
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 * This code was audited for completeness against the documented features
30 * of Comctl32.dll version 6.0 on May. 20, 2005, by James Hawkins.
32 * Unless otherwise noted, we believe this code to be complete, as per
33 * the specification mentioned above.
34 * If you discover missing features, or bugs, please note them below.
38 * Default Message Processing
39 * -- WM_CREATE: create the icon and small icon image lists at this point only if
40 * the LVS_SHAREIMAGELISTS style is not specified.
41 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
42 * or small icon and the LVS_AUTOARRANGE style is specified.
47 * -- Hot item handling, mouse hovering
48 * -- Workareas support
53 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
54 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
55 * -- LVA_SNAPTOGRID not implemented
56 * -- LISTVIEW_ApproximateViewRect partially implemented
57 * -- LISTVIEW_SetColumnWidth ignores header images & bitmap
58 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
61 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
62 * linear in the number of items in the list, and this is
63 * unacceptable for large lists.
64 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
65 * binary search to calculate item index (e.g. DPA_Search()).
66 * This requires sorted state to be reliably tracked in item modifiers.
67 * -- we should keep an ordered array of coordinates in iconic mode
68 * this would allow to frame items (iterator_frameditems),
69 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
76 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
81 * -- LVS_NOSCROLL (see Q137520)
85 * -- LVS_EX_BORDERSELECT
89 * -- LVS_EX_MULTIWORKAREAS
91 * -- LVS_EX_SIMPLESELECT
92 * -- LVS_EX_TWOCLICKACTIVATE
93 * -- LVS_EX_UNDERLINECOLD
94 * -- LVS_EX_UNDERLINEHOT
97 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
103 * -- LVM_ENABLEGROUPVIEW
104 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
105 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
106 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
107 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
108 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
109 * -- LVM_GETINSERTMARKRECT
110 * -- LVM_GETNUMBEROFWORKAREAS
111 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
112 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
113 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
114 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
115 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
116 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
117 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
118 * -- LVM_INSERTGROUPSORTED
119 * -- LVM_INSERTMARKHITTEST
120 * -- LVM_ISGROUPVIEWENABLED
122 * -- LVM_MOVEITEMTOGROUP
124 * -- LVM_SETTILEWIDTH
128 * -- ListView_GetHoverTime, ListView_SetHoverTime
129 * -- ListView_GetISearchString
130 * -- ListView_GetNumberOfWorkAreas
131 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
137 #include "comctl32.h"
141 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
143 typedef struct tagCOLUMN_INFO
145 RECT rcHeader
; /* tracks the header's rectangle */
146 INT fmt
; /* same as LVCOLUMN.fmt */
150 typedef struct tagITEMHDR
154 } ITEMHDR
, *LPITEMHDR
;
156 typedef struct tagSUBITEM_INFO
162 typedef struct tagITEM_ID ITEM_ID
;
164 typedef struct tagITEM_INFO
175 UINT id
; /* item id */
176 HDPA item
; /* link to item data */
179 typedef struct tagRANGE
185 typedef struct tagRANGES
190 typedef struct tagITERATOR
199 typedef struct tagDELAYED_ITEM_EDIT
205 typedef struct tagLISTVIEW_INFO
209 RECT rcList
; /* This rectangle is really the window
210 * client rectangle possibly reduced by the
211 * horizontal scroll bar and/or header - see
212 * LISTVIEW_UpdateSize. This rectangle offset
213 * by the LISTVIEW_GetOrigin value is in
214 * client coordinates */
216 /* notification window */
219 BOOL bDoChangeNotify
; /* send change notification messages? */
226 INT nItemCount
; /* the number of items in the list */
227 HDPA hdpaItems
; /* array ITEM_INFO pointers */
228 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
229 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
230 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
231 RANGES selectionRanges
;
232 INT nSelectionMark
; /* item to start next multiselection from */
234 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
237 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
238 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
241 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
246 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
250 DWORD dwStyle
; /* the cached window GWL_STYLE */
251 DWORD dwLvExStyle
; /* extended listview style */
252 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
258 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
261 HIMAGELIST himlNormal
;
262 HIMAGELIST himlSmall
;
263 HIMAGELIST himlState
;
268 POINT currIconPos
; /* this is the position next icon will be placed */
272 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
274 /* marquee selection */
275 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
277 RECT marqueeRect
; /* absolute coordinates of marquee selection */
278 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
279 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
282 BOOL bFocus
; /* control has focus */
284 RECT rcFocus
; /* focus bounds */
291 BOOL bDefaultBkColor
;
296 INT ntmHeight
; /* Some cached metrics of the font used */
297 INT ntmMaxCharWidth
; /* by the listview to draw items */
300 /* mouse operation */
303 POINT ptClickPos
; /* point where the user clicked */
304 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
309 /* keyboard operation */
310 DWORD lastKeyPressTimestamp
;
312 INT nSearchParamLength
;
313 WCHAR szSearchParam
[ MAX_PATH
];
316 BOOL bIsDrawing
; /* Drawing in progress */
317 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
318 BOOL bRedraw
; /* WM_SETREDRAW switch */
321 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
327 /* How many we debug buffer to allocate */
328 #define DEBUG_BUFFERS 20
329 /* The size of a single debug buffer */
330 #define DEBUG_BUFFER_SIZE 256
332 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
333 #define SB_INTERNAL -1
335 /* maximum size of a label */
336 #define DISP_TEXT_SIZE 260
338 /* padding for items in list and small icon display modes */
339 #define WIDTH_PADDING 12
341 /* padding for items in list, report and small icon display modes */
342 #define HEIGHT_PADDING 1
344 /* offset of items in report display mode */
345 #define REPORT_MARGINX 2
347 /* padding for icon in large icon display mode
348 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
349 * that HITTEST will see.
350 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
351 * ICON_TOP_PADDING - sum of the two above.
352 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
353 * LABEL_HOR_PADDING - between text and sides of box
354 * LABEL_VERT_PADDING - between bottom of text and end of box
356 * ICON_LR_PADDING - additional width above icon size.
357 * ICON_LR_HALF - half of the above value
359 #define ICON_TOP_PADDING_NOTHITABLE 2
360 #define ICON_TOP_PADDING_HITABLE 2
361 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
362 #define ICON_BOTTOM_PADDING 4
363 #define LABEL_HOR_PADDING 5
364 #define LABEL_VERT_PADDING 7
365 #define ICON_LR_PADDING 16
366 #define ICON_LR_HALF (ICON_LR_PADDING/2)
368 /* default label width for items in list and small icon display modes */
369 #define DEFAULT_LABEL_WIDTH 40
370 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
371 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
373 /* default column width for items in list display mode */
374 #define DEFAULT_COLUMN_WIDTH 128
376 /* Size of "line" scroll for V & H scrolls */
377 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
379 /* Padding between image and label */
380 #define IMAGE_PADDING 2
382 /* Padding behind the label */
383 #define TRAILING_LABEL_PADDING 12
384 #define TRAILING_HEADER_PADDING 11
386 /* Border for the icon caption */
387 #define CAPTION_BORDER 2
389 /* Standard DrawText flags */
390 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
391 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
392 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
394 /* Image index from state */
395 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
397 /* The time in milliseconds to reset the search in the list */
398 #define KEY_DELAY 450
400 /* Dump the LISTVIEW_INFO structure to the debug channel */
401 #define LISTVIEW_DUMP(iP) do { \
402 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
403 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
404 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
405 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
406 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
407 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
408 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
409 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
410 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
411 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
414 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
417 * forward declarations
419 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
420 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
421 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
422 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
423 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
424 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
425 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
426 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
427 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
428 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
429 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
430 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
431 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
432 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
433 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
434 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
435 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
436 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
437 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
438 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
440 /******** Text handling functions *************************************/
442 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
443 * text string. The string may be ANSI or Unicode, in which case
444 * the boolean isW tells us the type of the string.
446 * The name of the function tell what type of strings it expects:
447 * W: Unicode, T: ANSI/Unicode - function of isW
450 static inline BOOL
is_text(LPCWSTR text
)
452 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
455 static inline int textlenT(LPCWSTR text
, BOOL isW
)
457 return !is_text(text
) ? 0 :
458 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
461 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
464 if (isSrcW
) lstrcpynW(dest
, src
, max
);
465 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
467 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
468 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
471 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
473 LPWSTR wstr
= (LPWSTR
)text
;
475 if (!isW
&& is_text(text
))
477 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
478 wstr
= Alloc(len
* sizeof(WCHAR
));
479 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
481 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
485 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
487 if (!isW
&& is_text(wstr
)) Free (wstr
);
491 * dest is a pointer to a Unicode string
492 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
494 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
498 if (src
== LPSTR_TEXTCALLBACKW
)
500 if (is_text(*dest
)) Free(*dest
);
501 *dest
= LPSTR_TEXTCALLBACKW
;
505 LPWSTR pszText
= textdupTtoW(src
, isW
);
506 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
507 bResult
= Str_SetPtrW(dest
, pszText
);
508 textfreeT(pszText
, isW
);
514 * compares a Unicode to a Unicode/ANSI text string
516 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
518 if (!aw
) return bt
? -1 : 0;
520 if (aw
== LPSTR_TEXTCALLBACKW
)
521 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
522 if (bt
!= LPSTR_TEXTCALLBACKW
)
524 LPWSTR bw
= textdupTtoW(bt
, isW
);
525 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
533 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
535 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
536 return CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
) - CSTR_EQUAL
;
539 /******** Debugging functions *****************************************/
541 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
543 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
544 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
547 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
549 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
550 n
= min(textlenT(text
, isW
), n
);
551 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
554 static char* debug_getbuf(void)
556 static int index
= 0;
557 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
558 return buffers
[index
++ % DEBUG_BUFFERS
];
561 static inline const char* debugrange(const RANGE
*lprng
)
563 if (!lprng
) return "(null)";
564 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
567 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
569 char* buf
= debug_getbuf(), *text
= buf
;
570 int len
, size
= DEBUG_BUFFER_SIZE
;
572 if (pScrollInfo
== NULL
) return "(null)";
573 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
574 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
575 if (pScrollInfo
->fMask
& SIF_RANGE
)
576 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
578 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
579 if (pScrollInfo
->fMask
& SIF_PAGE
)
580 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
582 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
583 if (pScrollInfo
->fMask
& SIF_POS
)
584 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
586 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
587 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
588 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
590 if (len
== -1) goto end
; buf
+= len
;
593 buf
= text
+ strlen(text
);
595 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
599 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
601 if (!plvnm
) return "(null)";
602 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
603 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
604 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
605 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
608 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
610 char* buf
= debug_getbuf(), *text
= buf
;
611 int len
, size
= DEBUG_BUFFER_SIZE
;
613 if (lpLVItem
== NULL
) return "(null)";
614 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
615 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
616 if (lpLVItem
->mask
& LVIF_STATE
)
617 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
619 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
620 if (lpLVItem
->mask
& LVIF_TEXT
)
621 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
623 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
624 if (lpLVItem
->mask
& LVIF_IMAGE
)
625 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
627 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
628 if (lpLVItem
->mask
& LVIF_PARAM
)
629 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
631 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
632 if (lpLVItem
->mask
& LVIF_INDENT
)
633 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
635 if (len
== -1) goto end
; buf
+= len
;
638 buf
= text
+ strlen(text
);
640 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
644 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
646 char* buf
= debug_getbuf(), *text
= buf
;
647 int len
, size
= DEBUG_BUFFER_SIZE
;
649 if (lpColumn
== NULL
) return "(null)";
650 len
= snprintf(buf
, size
, "{");
651 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
652 if (lpColumn
->mask
& LVCF_SUBITEM
)
653 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
655 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
656 if (lpColumn
->mask
& LVCF_FMT
)
657 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
659 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
660 if (lpColumn
->mask
& LVCF_WIDTH
)
661 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
663 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
664 if (lpColumn
->mask
& LVCF_TEXT
)
665 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
667 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
668 if (lpColumn
->mask
& LVCF_IMAGE
)
669 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
671 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
672 if (lpColumn
->mask
& LVCF_ORDER
)
673 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
675 if (len
== -1) goto end
; buf
+= len
;
678 buf
= text
+ strlen(text
);
680 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
684 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
686 if (!lpht
) return "(null)";
688 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
689 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
692 /* Return the corresponding text for a given scroll value */
693 static inline LPCSTR
debugscrollcode(int nScrollCode
)
697 case SB_LINELEFT
: return "SB_LINELEFT";
698 case SB_LINERIGHT
: return "SB_LINERIGHT";
699 case SB_PAGELEFT
: return "SB_PAGELEFT";
700 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
701 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
702 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
703 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
704 case SB_INTERNAL
: return "SB_INTERNAL";
705 default: return "unknown";
710 /******** Notification functions ************************************/
712 static int get_ansi_notification(UINT unicodeNotificationCode
)
714 switch (unicodeNotificationCode
)
716 case LVN_BEGINLABELEDITA
:
717 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
718 case LVN_ENDLABELEDITA
:
719 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
720 case LVN_GETDISPINFOA
:
721 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
722 case LVN_SETDISPINFOA
:
723 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
724 case LVN_ODFINDITEMA
:
725 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
726 case LVN_GETINFOTIPA
:
727 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
728 /* header forwards */
730 case HDN_TRACKW
: return HDN_TRACKA
;
732 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
733 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
734 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
735 case HDN_ITEMCHANGINGA
:
736 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
737 case HDN_ITEMCHANGEDA
:
738 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
740 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
741 case HDN_DIVIDERDBLCLICKA
:
742 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
745 FIXME("unknown notification %x\n", unicodeNotificationCode
);
746 return unicodeNotificationCode
;
749 /* forwards header notifications to listview parent */
750 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
752 LPCWSTR text
= NULL
, filter
= NULL
;
754 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
756 /* on unicode format exit earlier */
757 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
758 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
761 /* header always supplies unicode notifications,
762 all we have to do is to convert strings to ANSI */
765 /* convert item text */
766 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
768 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
769 lpnmh
->pitem
->pszText
= NULL
;
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 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= NULL
;
778 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
781 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
783 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
789 Free(lpnmh
->pitem
->pszText
);
790 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
794 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
795 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
801 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
805 TRACE("(code=%d)\n", code
);
807 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
808 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
810 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
812 TRACE(" <= %ld\n", result
);
817 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
820 HWND hwnd
= infoPtr
->hwndSelf
;
821 notify_hdr(infoPtr
, code
, &nmh
);
822 return IsWindow(hwnd
);
825 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
836 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
837 item
.iItem
= htInfo
->iItem
;
839 item
.stateMask
= (UINT
)-1;
840 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
841 nmia
.lParam
= item
.lParam
;
842 nmia
.uOldState
= item
.state
;
843 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
844 nmia
.uChanged
= LVIF_STATE
;
847 nmia
.iItem
= htInfo
->iItem
;
848 nmia
.iSubItem
= htInfo
->iSubItem
;
849 nmia
.ptAction
= htInfo
->pt
;
851 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
852 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
853 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
855 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
858 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
860 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
861 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
864 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
865 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
869 HWND hwnd
= infoPtr
->hwndSelf
;
872 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
873 ZeroMemory(&nmia
, sizeof(nmia
));
874 nmia
.iItem
= lvht
->iItem
;
875 nmia
.iSubItem
= lvht
->iSubItem
;
876 nmia
.ptAction
= lvht
->pt
;
877 item
.mask
= LVIF_PARAM
;
878 item
.iItem
= lvht
->iItem
;
880 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
881 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
882 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
885 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
889 HWND hwnd
= infoPtr
->hwndSelf
;
891 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
893 item
.mask
= LVIF_PARAM
;
896 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
897 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
898 return IsWindow(hwnd
);
902 Send notification. depends on dispinfoW having same
903 structure as dispinfoA.
904 infoPtr : listview struct
905 code : *Unicode* notification code
906 pdi : dispinfo structure (can be unicode or ansi)
907 isW : TRUE if dispinfo is Unicode
909 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
911 INT length
= 0, ret_length
;
912 LPWSTR buffer
= NULL
, ret_text
;
913 BOOL return_ansi
= FALSE
;
914 BOOL return_unicode
= FALSE
;
917 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
919 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
920 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
923 ret_length
= pdi
->item
.cchTextMax
;
924 ret_text
= pdi
->item
.pszText
;
926 if (return_unicode
|| return_ansi
)
928 if (code
!= LVN_GETDISPINFOW
)
930 length
= return_ansi
?
931 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
932 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
936 length
= pdi
->item
.cchTextMax
;
937 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
940 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
941 if (!buffer
) return FALSE
;
944 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
947 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
950 pdi
->item
.pszText
= buffer
;
951 pdi
->item
.cchTextMax
= length
;
954 if (infoPtr
->notifyFormat
== NFR_ANSI
)
955 code
= get_ansi_notification(code
);
957 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
958 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
959 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
961 if (return_ansi
|| return_unicode
)
963 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
965 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
967 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
969 strcpyW(ret_text
, pdi
->item
.pszText
);
971 else if (return_ansi
) /* note : pointer can be changed by app ! */
973 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
974 ret_length
, NULL
, NULL
);
977 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
978 ret_text
, ret_length
);
980 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
981 pdi
->item
.cchTextMax
= ret_length
;
987 /* if dipsinfo holder changed notification code then convert */
988 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
990 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
992 buffer
= Alloc(length
* sizeof(CHAR
));
993 if (!buffer
) return FALSE
;
995 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
996 ret_length
, NULL
, NULL
);
998 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1005 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1006 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1008 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1009 lpnmlvcd
->nmcd
.hdc
= hdc
;
1010 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1011 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1012 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1013 if (!lplvItem
) return;
1014 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1015 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1016 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1017 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1018 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1019 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1022 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1024 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1027 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1028 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1029 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1030 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1031 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1032 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1036 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1038 COLORREF backcolor
, textcolor
;
1040 /* apparently, for selected items, we have to override the returned values */
1043 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1045 if (infoPtr
->bFocus
)
1047 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1048 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1050 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1052 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1053 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1058 backcolor
= lpnmlvcd
->clrTextBk
;
1059 textcolor
= lpnmlvcd
->clrText
;
1061 if (backcolor
== CLR_DEFAULT
)
1062 backcolor
= comctl32_color
.clrWindow
;
1063 if (textcolor
== CLR_DEFAULT
)
1064 textcolor
= comctl32_color
.clrWindowText
;
1066 /* Set the text attributes */
1067 if (backcolor
!= CLR_NONE
)
1069 SetBkMode(hdc
, OPAQUE
);
1070 SetBkColor(hdc
, backcolor
);
1073 SetBkMode(hdc
, TRANSPARENT
);
1074 SetTextColor(hdc
, textcolor
);
1077 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1079 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1082 /* returns TRUE when repaint needed, FALSE otherwise */
1083 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1085 MEASUREITEMSTRUCT mis
;
1086 mis
.CtlType
= ODT_LISTVIEW
;
1087 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1091 mis
.itemHeight
= infoPtr
->nItemHeight
;
1092 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1093 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1095 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1101 /******** Item iterator functions **********************************/
1103 static RANGES
ranges_create(int count
);
1104 static void ranges_destroy(RANGES ranges
);
1105 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1106 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1107 static void ranges_dump(RANGES ranges
);
1109 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1111 RANGE range
= { nItem
, nItem
+ 1 };
1113 return ranges_add(ranges
, range
);
1116 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1118 RANGE range
= { nItem
, nItem
+ 1 };
1120 return ranges_del(ranges
, range
);
1124 * ITERATOR DOCUMENTATION
1126 * The iterator functions allow for easy, and convenient iteration
1127 * over items of interest in the list. Typically, you create an
1128 * iterator, use it, and destroy it, as such:
1131 * iterator_xxxitems(&i, ...);
1132 * while (iterator_{prev,next}(&i)
1134 * //code which uses i.nItem
1136 * iterator_destroy(&i);
1138 * where xxx is either: framed, or visible.
1139 * Note that it is important that the code destroys the iterator
1140 * after it's done with it, as the creation of the iterator may
1141 * allocate memory, which thus needs to be freed.
1143 * You can iterate both forwards, and backwards through the list,
1144 * by using iterator_next or iterator_prev respectively.
1146 * Lower numbered items are draw on top of higher number items in
1147 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1148 * items may overlap). So, to test items, you should use
1150 * which lists the items top to bottom (in Z-order).
1151 * For drawing items, you should use
1153 * which lists the items bottom to top (in Z-order).
1154 * If you keep iterating over the items after the end-of-items
1155 * marker (-1) is returned, the iterator will start from the
1156 * beginning. Typically, you don't need to test for -1,
1157 * because iterator_{next,prev} will return TRUE if more items
1158 * are to be iterated over, or FALSE otherwise.
1160 * Note: the iterator is defined to be bidirectional. That is,
1161 * any number of prev followed by any number of next, or
1162 * five versa, should leave the iterator at the same item:
1163 * prev * n, next * n = next * n, prev * n
1165 * The iterator has a notion of an out-of-order, special item,
1166 * which sits at the start of the list. This is used in
1167 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1168 * which needs to be first, as it may overlap other items.
1170 * The code is a bit messy because we have:
1171 * - a special item to deal with
1172 * - simple range, or composite range
1174 * If you find bugs, or want to add features, please make sure you
1175 * always check/modify *both* iterator_prev, and iterator_next.
1179 * This function iterates through the items in increasing order,
1180 * but prefixed by the special item, then -1. That is:
1181 * special, 1, 2, 3, ..., n, -1.
1182 * Each item is listed only once.
1184 static inline BOOL
iterator_next(ITERATOR
* i
)
1188 i
->nItem
= i
->nSpecial
;
1189 if (i
->nItem
!= -1) return TRUE
;
1191 if (i
->nItem
== i
->nSpecial
)
1193 if (i
->ranges
) i
->index
= 0;
1199 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1200 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1205 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1206 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1209 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1211 i
->nItem
= i
->range
.lower
;
1212 if (i
->nItem
>= 0) goto testitem
;
1219 * This function iterates through the items in decreasing order,
1220 * followed by the special item, then -1. That is:
1221 * n, n-1, ..., 3, 2, 1, special, -1.
1222 * Each item is listed only once.
1224 static inline BOOL
iterator_prev(ITERATOR
* i
)
1231 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1234 if (i
->nItem
== i
->nSpecial
)
1242 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1243 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1249 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1252 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1254 i
->nItem
= i
->range
.upper
;
1255 if (i
->nItem
> 0) goto testitem
;
1257 return (i
->nItem
= i
->nSpecial
) != -1;
1260 static RANGE
iterator_range(const ITERATOR
*i
)
1264 if (!i
->ranges
) return i
->range
;
1266 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1268 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1269 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1271 else range
.lower
= range
.upper
= 0;
1277 * Releases resources associated with this iterator.
1279 static inline void iterator_destroy(const ITERATOR
*i
)
1281 ranges_destroy(i
->ranges
);
1285 * Create an empty iterator.
1287 static inline BOOL
iterator_empty(ITERATOR
* i
)
1289 ZeroMemory(i
, sizeof(*i
));
1290 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1295 * Create an iterator over a range.
1297 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1305 * Create an iterator over a bunch of ranges.
1306 * Please note that the iterator will take ownership of the ranges,
1307 * and will free them upon destruction.
1309 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1317 * Creates an iterator over the items which intersect frame.
1318 * Uses absolute coordinates rather than compensating for the current offset.
1320 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1322 RECT rcItem
, rcTemp
;
1324 /* in case we fail, we want to return an empty iterator */
1325 if (!iterator_empty(i
)) return FALSE
;
1327 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1329 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1333 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1335 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1336 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1337 i
->nSpecial
= infoPtr
->nFocusedItem
;
1339 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1340 /* to do better here, we need to have PosX, and PosY sorted */
1341 TRACE("building icon ranges:\n");
1342 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1344 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1345 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1346 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1347 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1348 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1349 ranges_additem(i
->ranges
, nItem
);
1353 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1357 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1358 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1360 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1361 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1362 if (range
.upper
<= range
.lower
) return TRUE
;
1363 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1364 TRACE(" report=%s\n", debugrange(&i
->range
));
1368 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1369 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1370 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1377 if (infoPtr
->nItemWidth
)
1379 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1380 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1384 nFirstCol
= max(frame
->left
, 0);
1385 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1388 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1390 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1391 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1393 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1395 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1396 TRACE("building list ranges:\n");
1397 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1399 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1400 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1401 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1402 TRACE(" list=%s\n", debugrange(&item_range
));
1403 ranges_add(i
->ranges
, item_range
);
1411 * Creates an iterator over the items which intersect lprc.
1413 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1418 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1420 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1421 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1423 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1427 * Creates an iterator over the items which intersect the visible region of hdc.
1429 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1431 POINT Origin
, Position
;
1432 RECT rcItem
, rcClip
;
1435 rgntype
= GetClipBox(hdc
, &rcClip
);
1436 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1437 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1438 if (rgntype
== SIMPLEREGION
) return TRUE
;
1440 /* first deal with the special item */
1441 if (i
->nSpecial
!= -1)
1443 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1444 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1447 /* if we can't deal with the region, we'll just go with the simple range */
1448 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1449 TRACE("building visible range:\n");
1450 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1452 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1453 if (!ranges_add(i
->ranges
, i
->range
))
1455 ranges_destroy(i
->ranges
);
1461 /* now delete the invisible items from the list */
1462 while(iterator_next(i
))
1464 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1465 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1466 rcItem
.top
= Position
.y
+ Origin
.y
;
1467 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1468 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1469 if (!RectVisible(hdc
, &rcItem
))
1470 ranges_delitem(i
->ranges
, i
->nItem
);
1472 /* the iterator should restart on the next iterator_next */
1478 /* Remove common elements from two iterators */
1479 /* Passed iterators have to point on the first elements */
1480 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1482 if(!iter1
->ranges
|| !iter2
->ranges
) {
1485 if(iter1
->ranges
|| iter2
->ranges
||
1486 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1487 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1488 ERR("result is not a one range iterator\n");
1492 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1495 lower
= iter1
->range
.lower
;
1496 upper
= iter1
->range
.upper
;
1498 if(lower
< iter2
->range
.lower
)
1499 iter1
->range
.upper
= iter2
->range
.lower
;
1500 else if(upper
> iter2
->range
.upper
)
1501 iter1
->range
.lower
= iter2
->range
.upper
;
1503 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1505 if(iter2
->range
.lower
< lower
)
1506 iter2
->range
.upper
= lower
;
1507 else if(iter2
->range
.upper
> upper
)
1508 iter2
->range
.lower
= upper
;
1510 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1515 iterator_next(iter1
);
1516 iterator_next(iter2
);
1519 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1522 if(iter1
->nItem
== iter2
->nItem
) {
1523 int delete = iter1
->nItem
;
1525 iterator_prev(iter1
);
1526 iterator_prev(iter2
);
1527 ranges_delitem(iter1
->ranges
, delete);
1528 ranges_delitem(iter2
->ranges
, delete);
1529 iterator_next(iter1
);
1530 iterator_next(iter2
);
1531 } else if(iter1
->nItem
> iter2
->nItem
)
1532 iterator_next(iter2
);
1534 iterator_next(iter1
);
1537 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1538 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1542 /******** Misc helper functions ************************************/
1544 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1545 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1547 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1548 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1551 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1553 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1554 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1557 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1559 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1560 if(state
== 1 || state
== 2)
1564 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1565 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1566 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1570 /* this should be called after window style got updated,
1571 it used to reset view state to match current window style */
1572 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1574 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1577 infoPtr
->uView
= LV_VIEW_ICON
;
1580 infoPtr
->uView
= LV_VIEW_DETAILS
;
1583 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1586 infoPtr
->uView
= LV_VIEW_LIST
;
1590 /* computes next item id value */
1591 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1593 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1597 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1598 return lpID
->id
+ 1;
1603 /******** Internal API functions ************************************/
1605 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1607 static COLUMN_INFO mainItem
;
1609 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1610 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1612 /* update cached column rectangles */
1613 if (infoPtr
->colRectsDirty
)
1616 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1619 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1620 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1621 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1623 Ptr
->colRectsDirty
= FALSE
;
1626 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1629 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1631 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1634 if (infoPtr
->hwndHeader
) return 0;
1636 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1638 /* setup creation flags */
1639 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1640 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1642 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1645 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1646 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1647 if (!infoPtr
->hwndHeader
) return -1;
1649 /* set header unicode format */
1650 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1652 /* set header font */
1653 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1655 /* set header image list */
1656 if (infoPtr
->himlSmall
)
1657 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1659 LISTVIEW_UpdateSize(infoPtr
);
1664 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1666 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1669 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1671 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1672 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1673 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1676 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1678 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1681 /* used to handle collapse main item column case */
1682 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1686 if (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
)
1688 DWORD dwOldBkColor
, dwOldTextColor
;
1690 dwOldBkColor
= SetBkColor(hdc
, RGB(255, 255, 255));
1691 dwOldTextColor
= SetBkColor(hdc
, RGB(0, 0, 0));
1692 Ret
= DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1693 SetBkColor(hdc
, dwOldBkColor
);
1694 SetBkColor(hdc
, dwOldTextColor
);
1699 /* Listview invalidation functions: use _only_ these functions to invalidate */
1701 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1703 return infoPtr
->bRedraw
;
1706 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1708 if(!is_redrawing(infoPtr
)) return;
1709 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1710 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1713 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1717 if(!is_redrawing(infoPtr
)) return;
1718 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1719 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1722 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1724 POINT Origin
, Position
;
1727 if(!is_redrawing(infoPtr
)) return;
1728 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1729 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1730 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1731 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1733 rcBox
.bottom
= infoPtr
->nItemHeight
;
1734 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1735 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1738 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1740 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1743 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1747 if(!is_redrawing(infoPtr
)) return;
1748 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1749 rcCol
.top
= infoPtr
->rcList
.top
;
1750 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1751 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1756 * Retrieves the number of items that can fit vertically in the client area.
1759 * [I] infoPtr : valid pointer to the listview structure
1762 * Number of items per row.
1764 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1766 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1768 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1773 * Retrieves the number of items that can fit horizontally in the client
1777 * [I] infoPtr : valid pointer to the listview structure
1780 * Number of items per column.
1782 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1784 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1786 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1790 /*************************************************************************
1791 * LISTVIEW_ProcessLetterKeys
1793 * Processes keyboard messages generated by pressing the letter keys
1795 * What this does is perform a case insensitive search from the
1796 * current position with the following quirks:
1797 * - If two chars or more are pressed in quick succession we search
1798 * for the corresponding string (e.g. 'abc').
1799 * - If there is a delay we wipe away the current search string and
1800 * restart with just that char.
1801 * - If the user keeps pressing the same character, whether slowly or
1802 * fast, so that the search string is entirely composed of this
1803 * character ('aaaaa' for instance), then we search for first item
1804 * that starting with that character.
1805 * - If the user types the above character in quick succession, then
1806 * we must also search for the corresponding string ('aaaaa'), and
1807 * go to that string if there is a match.
1810 * [I] hwnd : handle to the window
1811 * [I] charCode : the character code, the actual character
1812 * [I] keyData : key data
1820 * - The current implementation has a list of characters it will
1821 * accept and it ignores everything else. In particular it will
1822 * ignore accentuated characters which seems to match what
1823 * Windows does. But I'm not sure it makes sense to follow
1825 * - We don't sound a beep when the search fails.
1829 * TREEVIEW_ProcessLetterKeys
1831 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1833 WCHAR buffer
[MAX_PATH
];
1840 /* simple parameter checking */
1841 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1843 /* only allow the valid WM_CHARs through */
1844 if (!isalnumW(charCode
) &&
1845 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1846 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1847 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1848 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1849 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1850 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1851 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1852 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1853 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1856 /* update the search parameters */
1857 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1858 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1859 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1861 if (diff
>= 0 && diff
< KEY_DELAY
)
1863 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1864 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1866 if (infoPtr
->charCode
!= charCode
)
1867 infoPtr
->charCode
= charCode
= 0;
1871 infoPtr
->charCode
= charCode
;
1872 infoPtr
->szSearchParam
[0] = charCode
;
1873 infoPtr
->nSearchParamLength
= 1;
1876 /* should start from next after focused item, so next item that matches
1877 will be selected, if there isn't any and focused matches it will be selected
1878 on second search stage from beginning of the list */
1879 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1881 /* with some accumulated search data available start with current focus, otherwise
1882 it's excluded from search */
1883 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1884 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1889 /* let application handle this for virtual listview */
1890 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1894 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1895 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1896 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1897 nmlv
.iStart
= startidx
;
1899 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1901 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1905 int i
= startidx
, endidx
;
1907 /* and search from the current position */
1909 endidx
= infoPtr
->nItemCount
;
1911 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1914 /* start from first item if not found with >= startidx */
1915 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1921 for (i
= startidx
; i
< endidx
; i
++)
1924 item
.mask
= LVIF_TEXT
;
1927 item
.pszText
= buffer
;
1928 item
.cchTextMax
= MAX_PATH
;
1929 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1931 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1936 /* this is used to find first char match when search string is not available yet,
1937 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1938 already waiting for user to complete a string */
1939 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1941 /* this would work but we must keep looking for a longer match */
1946 if ( nItem
!= -1 || /* found something */
1947 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1948 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1954 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1959 /*************************************************************************
1960 * LISTVIEW_UpdateHeaderSize [Internal]
1962 * Function to resize the header control
1965 * [I] hwnd : handle to a window
1966 * [I] nNewScrollPos : scroll pos to set
1971 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1976 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1978 if (!infoPtr
->hwndHeader
) return;
1980 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1981 point
[0].x
= winRect
.left
;
1982 point
[0].y
= winRect
.top
;
1983 point
[1].x
= winRect
.right
;
1984 point
[1].y
= winRect
.bottom
;
1986 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1987 point
[0].x
= -nNewScrollPos
;
1988 point
[1].x
+= nNewScrollPos
;
1990 SetWindowPos(infoPtr
->hwndHeader
,0,
1991 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1992 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1993 SWP_NOZORDER
| SWP_NOACTIVATE
);
1998 * Update the scrollbars. This functions should be called whenever
1999 * the content, size or view changes.
2002 * [I] infoPtr : valid pointer to the listview structure
2007 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2009 SCROLLINFO horzInfo
, vertInfo
;
2012 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2014 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2015 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2016 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2018 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2019 if (infoPtr
->uView
== LV_VIEW_LIST
)
2021 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2022 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2024 /* scroll by at least one column per page */
2025 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2026 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2028 if (infoPtr
->nItemWidth
)
2029 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2031 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2033 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2035 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2039 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2042 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2044 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2049 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2050 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2052 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2053 horzInfo
.nMax
= rcHeader
.right
;
2054 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2058 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2059 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2060 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2061 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2062 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2064 /* Setting the horizontal scroll can change the listview size
2065 * (and potentially everything else) so we need to recompute
2066 * everything again for the vertical scroll
2069 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2070 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2071 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2073 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2075 vertInfo
.nMax
= infoPtr
->nItemCount
;
2077 /* scroll by at least one page */
2078 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2079 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2081 if (infoPtr
->nItemHeight
> 0)
2082 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2084 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2088 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2091 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2092 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2093 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2094 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2095 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2097 /* Change of the range may have changed the scroll pos. If so move the content */
2098 if (dx
!= 0 || dy
!= 0)
2101 listRect
= infoPtr
->rcList
;
2102 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2103 SW_ERASE
| SW_INVALIDATE
);
2106 /* Update the Header Control */
2107 if (infoPtr
->hwndHeader
)
2109 horzInfo
.fMask
= SIF_POS
;
2110 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2111 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2118 * Shows/hides the focus rectangle.
2121 * [I] infoPtr : valid pointer to the listview structure
2122 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2127 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2131 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2133 if (infoPtr
->nFocusedItem
< 0) return;
2135 /* we need some gymnastics in ICON mode to handle large items */
2136 if (infoPtr
->uView
== LV_VIEW_ICON
)
2140 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2141 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2143 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2148 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2150 /* for some reason, owner draw should work only in report mode */
2151 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2156 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2157 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2159 item
.iItem
= infoPtr
->nFocusedItem
;
2161 item
.mask
= LVIF_PARAM
;
2162 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2164 ZeroMemory(&dis
, sizeof(dis
));
2165 dis
.CtlType
= ODT_LISTVIEW
;
2166 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2167 dis
.itemID
= item
.iItem
;
2168 dis
.itemAction
= ODA_FOCUS
;
2169 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2170 dis
.hwndItem
= infoPtr
->hwndSelf
;
2172 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2173 dis
.itemData
= item
.lParam
;
2175 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2177 SelectObject(hdc
, hOldFont
);
2181 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2184 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2188 * Invalidates all visible selected items.
2190 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2194 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2195 while(iterator_next(&i
))
2197 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2198 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2200 iterator_destroy(&i
);
2205 * DESCRIPTION: [INTERNAL]
2206 * Computes an item's (left,top) corner, relative to rcView.
2207 * That is, the position has NOT been made relative to the Origin.
2208 * This is deliberate, to avoid computing the Origin over, and
2209 * over again, when this function is called in a loop. Instead,
2210 * one can factor the computation of the Origin before the loop,
2211 * and offset the value returned by this function, on every iteration.
2214 * [I] infoPtr : valid pointer to the listview structure
2215 * [I] nItem : item number
2216 * [O] lpptOrig : item top, left corner
2221 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2223 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2225 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2227 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2228 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2230 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2232 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2233 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2234 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2236 else /* LV_VIEW_DETAILS */
2238 lpptPosition
->x
= REPORT_MARGINX
;
2239 /* item is always at zero indexed column */
2240 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2241 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2242 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2247 * DESCRIPTION: [INTERNAL]
2248 * Compute the rectangles of an item. This is to localize all
2249 * the computations in one place. If you are not interested in some
2250 * of these values, simply pass in a NULL -- the function is smart
2251 * enough to compute only what's necessary. The function computes
2252 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2253 * one, the BOX rectangle. This rectangle is very cheap to compute,
2254 * and is guaranteed to contain all the other rectangles. Computing
2255 * the ICON rect is also cheap, but all the others are potentially
2256 * expensive. This gives an easy and effective optimization when
2257 * searching (like point inclusion, or rectangle intersection):
2258 * first test against the BOX, and if TRUE, test against the desired
2260 * If the function does not have all the necessary information
2261 * to computed the requested rectangles, will crash with a
2262 * failed assertion. This is done so we catch all programming
2263 * errors, given that the function is called only from our code.
2265 * We have the following 'special' meanings for a few fields:
2266 * * If LVIS_FOCUSED is set, we assume the item has the focus
2267 * This is important in ICON mode, where it might get a larger
2268 * then usual rectangle
2270 * Please note that subitem support works only in REPORT mode.
2273 * [I] infoPtr : valid pointer to the listview structure
2274 * [I] lpLVItem : item to compute the measures for
2275 * [O] lprcBox : ptr to Box rectangle
2276 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2277 * [0] lprcSelectBox : ptr to select box rectangle
2278 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2279 * [O] lprcIcon : ptr to Icon rectangle
2280 * Same as LVM_GETITEMRECT with LVIR_ICON
2281 * [O] lprcStateIcon: ptr to State Icon rectangle
2282 * [O] lprcLabel : ptr to Label rectangle
2283 * Same as LVM_GETITEMRECT with LVIR_LABEL
2288 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2289 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2290 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2292 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2293 RECT Box
, SelectBox
, Icon
, Label
;
2294 COLUMN_INFO
*lpColumnInfo
= NULL
;
2295 SIZE labelSize
= { 0, 0 };
2297 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2299 /* Be smart and try to figure out the minimum we have to do */
2300 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2301 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2303 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2304 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2306 if (lprcSelectBox
) doSelectBox
= TRUE
;
2307 if (lprcLabel
) doLabel
= TRUE
;
2308 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2315 /************************************************************/
2316 /* compute the box rectangle (it should be cheap to do) */
2317 /************************************************************/
2318 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2319 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2321 if (lpLVItem
->iSubItem
)
2323 Box
= lpColumnInfo
->rcHeader
;
2328 Box
.right
= infoPtr
->nItemWidth
;
2331 Box
.bottom
= infoPtr
->nItemHeight
;
2333 /******************************************************************/
2334 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2335 /******************************************************************/
2338 LONG state_width
= 0;
2340 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2341 state_width
= infoPtr
->iconStateSize
.cx
;
2343 if (infoPtr
->uView
== LV_VIEW_ICON
)
2345 Icon
.left
= Box
.left
+ state_width
;
2346 if (infoPtr
->himlNormal
)
2347 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2348 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2349 Icon
.right
= Icon
.left
;
2350 Icon
.bottom
= Icon
.top
;
2351 if (infoPtr
->himlNormal
)
2353 Icon
.right
+= infoPtr
->iconSize
.cx
;
2354 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2357 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2359 Icon
.left
= Box
.left
+ state_width
;
2361 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2363 /* we need the indent in report mode */
2364 assert(lpLVItem
->mask
& LVIF_INDENT
);
2365 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2369 Icon
.right
= Icon
.left
;
2370 if (infoPtr
->himlSmall
&&
2371 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2372 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2373 Icon
.right
+= infoPtr
->iconSize
.cx
;
2374 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2376 if(lprcIcon
) *lprcIcon
= Icon
;
2377 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2379 /* TODO: is this correct? */
2382 lprcStateIcon
->left
= Icon
.left
- state_width
;
2383 lprcStateIcon
->right
= Icon
.left
;
2384 lprcStateIcon
->top
= Icon
.top
;
2385 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2386 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2389 else Icon
.right
= 0;
2391 /************************************************************/
2392 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2393 /************************************************************/
2396 /* calculate how far to the right can the label stretch */
2397 Label
.right
= Box
.right
;
2398 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2400 if (lpLVItem
->iSubItem
== 0)
2402 /* we need a zero based rect here */
2403 Label
= lpColumnInfo
->rcHeader
;
2404 OffsetRect(&Label
, -Label
.left
, 0);
2408 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2410 labelSize
.cx
= infoPtr
->nItemWidth
;
2411 labelSize
.cy
= infoPtr
->nItemHeight
;
2415 /* we need the text in non owner draw mode */
2416 assert(lpLVItem
->mask
& LVIF_TEXT
);
2417 if (is_text(lpLVItem
->pszText
))
2419 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2420 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2421 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2425 /* compute rough rectangle where the label will go */
2426 SetRectEmpty(&rcText
);
2427 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2428 rcText
.bottom
= infoPtr
->nItemHeight
;
2429 if (infoPtr
->uView
== LV_VIEW_ICON
)
2430 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2432 /* now figure out the flags */
2433 if (infoPtr
->uView
== LV_VIEW_ICON
)
2434 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2436 uFormat
= LV_SL_DT_FLAGS
;
2438 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2440 if (rcText
.right
!= rcText
.left
)
2441 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2443 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2445 SelectObject(hdc
, hOldFont
);
2446 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2450 if (infoPtr
->uView
== LV_VIEW_ICON
)
2452 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2453 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2454 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2455 Label
.right
= Label
.left
+ labelSize
.cx
;
2456 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2457 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2459 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2460 labelSize
.cy
/= infoPtr
->ntmHeight
;
2461 labelSize
.cy
= max(labelSize
.cy
, 1);
2462 labelSize
.cy
*= infoPtr
->ntmHeight
;
2464 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2466 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2468 Label
.left
= Icon
.right
;
2469 Label
.top
= Box
.top
;
2470 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2471 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2472 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2474 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2476 Label
.left
= Icon
.right
;
2477 Label
.top
= Box
.top
;
2478 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2479 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2482 if (lprcLabel
) *lprcLabel
= Label
;
2483 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2486 /************************************************************/
2487 /* compute SELECT bounding box */
2488 /************************************************************/
2491 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2493 SelectBox
.left
= Icon
.left
;
2494 SelectBox
.top
= Box
.top
;
2495 SelectBox
.bottom
= Box
.bottom
;
2498 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2500 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2504 UnionRect(&SelectBox
, &Icon
, &Label
);
2506 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2507 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2510 /* Fix the Box if necessary */
2513 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2514 else *lprcBox
= Box
;
2516 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2520 * DESCRIPTION: [INTERNAL]
2523 * [I] infoPtr : valid pointer to the listview structure
2524 * [I] nItem : item number
2525 * [O] lprcBox : ptr to Box rectangle
2530 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2532 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2533 POINT Position
, Origin
;
2536 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2537 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2539 /* Be smart and try to figure out the minimum we have to do */
2541 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2542 lvItem
.mask
|= LVIF_TEXT
;
2543 lvItem
.iItem
= nItem
;
2544 lvItem
.iSubItem
= 0;
2545 lvItem
.pszText
= szDispText
;
2546 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2547 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2548 if (infoPtr
->uView
== LV_VIEW_ICON
)
2550 lvItem
.mask
|= LVIF_STATE
;
2551 lvItem
.stateMask
= LVIS_FOCUSED
;
2552 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2554 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2556 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2557 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2559 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2562 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2565 /* LISTVIEW_MapIdToIndex helper */
2566 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2568 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2569 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2571 if (id1
->id
== id2
->id
) return 0;
2573 return (id1
->id
< id2
->id
) ? -1 : 1;
2578 * Returns the item index for id specified.
2581 * [I] infoPtr : valid pointer to the listview structure
2582 * [I] iID : item id to get index for
2585 * Item index, or -1 on failure.
2587 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2592 TRACE("iID=%d\n", iID
);
2594 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2595 if (infoPtr
->nItemCount
== 0) return -1;
2598 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2602 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2603 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2611 * Returns the item id for index given.
2614 * [I] infoPtr : valid pointer to the listview structure
2615 * [I] iItem : item index to get id for
2620 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2625 TRACE("iItem=%d\n", iItem
);
2627 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2628 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2630 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2631 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2633 return lpItem
->id
->id
;
2638 * Returns the current icon position, and advances it along the top.
2639 * The returned position is not offset by Origin.
2642 * [I] infoPtr : valid pointer to the listview structure
2643 * [O] lpPos : will get the current icon position
2648 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2650 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2652 *lpPos
= infoPtr
->currIconPos
;
2654 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2655 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2657 infoPtr
->currIconPos
.x
= 0;
2658 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2664 * Returns the current icon position, and advances it down the left edge.
2665 * The returned position is not offset by Origin.
2668 * [I] infoPtr : valid pointer to the listview structure
2669 * [O] lpPos : will get the current icon position
2674 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2676 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2678 *lpPos
= infoPtr
->currIconPos
;
2680 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2681 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2683 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2684 infoPtr
->currIconPos
.y
= 0;
2690 * Moves an icon to the specified position.
2691 * It takes care of invalidating the item, etc.
2694 * [I] infoPtr : valid pointer to the listview structure
2695 * [I] nItem : the item to move
2696 * [I] lpPos : the new icon position
2697 * [I] isNew : flags the item as being new
2703 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2709 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2710 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2712 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2713 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2716 /* Allocating a POINTER for every item is too resource intensive,
2717 * so we'll keep the (x,y) in different arrays */
2718 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2719 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2721 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2728 * Arranges listview items in icon display mode.
2731 * [I] infoPtr : valid pointer to the listview structure
2732 * [I] nAlignCode : alignment code
2738 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2740 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2744 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2746 TRACE("nAlignCode=%d\n", nAlignCode
);
2748 if (nAlignCode
== LVA_DEFAULT
)
2750 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2751 else nAlignCode
= LVA_ALIGNTOP
;
2756 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2757 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2758 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2759 default: return FALSE
;
2762 infoPtr
->bAutoarrange
= TRUE
;
2763 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2764 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2766 next_pos(infoPtr
, &pos
);
2767 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2775 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2776 * For LVS_REPORT always returns empty rectangle.
2779 * [I] infoPtr : valid pointer to the listview structure
2780 * [O] lprcView : bounding rectangle
2786 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2790 SetRectEmpty(lprcView
);
2792 switch (infoPtr
->uView
)
2795 case LV_VIEW_SMALLICON
:
2796 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2798 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2799 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2800 lprcView
->right
= max(lprcView
->right
, x
);
2801 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2803 if (infoPtr
->nItemCount
> 0)
2805 lprcView
->right
+= infoPtr
->nItemWidth
;
2806 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2811 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2812 x
= infoPtr
->nItemCount
/ y
;
2813 if (infoPtr
->nItemCount
% y
) x
++;
2814 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2815 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2822 * Retrieves the bounding rectangle of all the items.
2825 * [I] infoPtr : valid pointer to the listview structure
2826 * [O] lprcView : bounding rectangle
2832 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2836 TRACE("(lprcView=%p)\n", lprcView
);
2838 if (!lprcView
) return FALSE
;
2840 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2842 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2844 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2845 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2848 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2855 * Retrieves the subitem pointer associated with the subitem index.
2858 * [I] hdpaSubItems : DPA handle for a specific item
2859 * [I] nSubItem : index of subitem
2862 * SUCCESS : subitem pointer
2865 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2867 SUBITEM_INFO
*lpSubItem
;
2870 /* we should binary search here if need be */
2871 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2873 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2874 if (lpSubItem
->iSubItem
== nSubItem
)
2884 * Calculates the desired item width.
2887 * [I] infoPtr : valid pointer to the listview structure
2890 * The desired item width.
2892 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2896 TRACE("uView=%d\n", infoPtr
->uView
);
2898 if (infoPtr
->uView
== LV_VIEW_ICON
)
2899 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2900 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2902 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2907 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2908 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2910 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2911 nItemWidth
= rcHeader
.right
;
2914 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2916 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2920 lvItem
.mask
= LVIF_TEXT
;
2921 lvItem
.iSubItem
= 0;
2923 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2926 lvItem
.pszText
= szDispText
;
2927 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2928 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2929 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2933 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2934 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2936 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2944 * Calculates the desired item height.
2947 * [I] infoPtr : valid pointer to the listview structure
2950 * The desired item height.
2952 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2956 TRACE("uView=%d\n", infoPtr
->uView
);
2958 if (infoPtr
->uView
== LV_VIEW_ICON
)
2959 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2962 nItemHeight
= infoPtr
->ntmHeight
;
2963 if (infoPtr
->himlState
)
2964 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2965 if (infoPtr
->himlSmall
)
2966 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2967 nItemHeight
+= HEIGHT_PADDING
;
2968 if (infoPtr
->nMeasureItemHeight
> 0)
2969 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2972 return max(nItemHeight
, 1);
2977 * Updates the width, and height of an item.
2980 * [I] infoPtr : valid pointer to the listview structure
2985 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2987 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2988 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2994 * Retrieves and saves important text metrics info for the current
2998 * [I] infoPtr : valid pointer to the listview structure
3001 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3003 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3004 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3005 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3009 if (GetTextMetricsW(hdc
, &tm
))
3011 infoPtr
->ntmHeight
= tm
.tmHeight
;
3012 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3015 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3016 infoPtr
->nEllipsisWidth
= sz
.cx
;
3018 SelectObject(hdc
, hOldFont
);
3019 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3021 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3026 * A compare function for ranges
3029 * [I] range1 : pointer to range 1;
3030 * [I] range2 : pointer to range 2;
3034 * > 0 : if range 1 > range 2
3035 * < 0 : if range 2 > range 1
3036 * = 0 : if range intersects range 2
3038 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3042 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3044 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3049 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3054 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3056 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3061 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3063 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3064 ranges_dump(ranges
);
3065 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3067 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3068 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3069 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3071 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3072 assert (prev
->upper
<= curr
->lower
);
3073 assert (curr
->lower
< curr
->upper
);
3077 TRACE("--- Done checking---\n");
3080 static RANGES
ranges_create(int count
)
3082 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3083 if (!ranges
) return NULL
;
3084 ranges
->hdpa
= DPA_Create(count
);
3085 if (ranges
->hdpa
) return ranges
;
3090 static void ranges_clear(RANGES ranges
)
3094 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3095 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3096 DPA_DeleteAllPtrs(ranges
->hdpa
);
3100 static void ranges_destroy(RANGES ranges
)
3102 if (!ranges
) return;
3103 ranges_clear(ranges
);
3104 DPA_Destroy(ranges
->hdpa
);
3108 static RANGES
ranges_clone(RANGES ranges
)
3113 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3115 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3117 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3118 if (!newrng
) goto fail
;
3119 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3120 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
3125 TRACE ("clone failed\n");
3126 ranges_destroy(clone
);
3130 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3134 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3135 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3140 static void ranges_dump(RANGES ranges
)
3144 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3145 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3148 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3150 RANGE srchrng
= { nItem
, nItem
+ 1 };
3152 TRACE("(nItem=%d)\n", nItem
);
3153 ranges_check(ranges
, "before contain");
3154 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3157 static INT
ranges_itemcount(RANGES ranges
)
3161 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3163 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3164 count
+= sel
->upper
- sel
->lower
;
3170 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3172 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3175 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3176 if (index
== -1) return TRUE
;
3178 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3180 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3181 if (chkrng
->lower
>= nItem
)
3182 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3183 if (chkrng
->upper
> nItem
)
3184 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3189 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3194 TRACE("(%s)\n", debugrange(&range
));
3195 ranges_check(ranges
, "before add");
3197 /* try find overlapping regions first */
3198 srchrgn
.lower
= range
.lower
- 1;
3199 srchrgn
.upper
= range
.upper
+ 1;
3200 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3206 TRACE("Adding new range\n");
3208 /* create the brand new range to insert */
3209 newrgn
= Alloc(sizeof(RANGE
));
3210 if(!newrgn
) goto fail
;
3213 /* figure out where to insert it */
3214 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3215 TRACE("index=%d\n", index
);
3216 if (index
== -1) index
= 0;
3218 /* and get it over with */
3219 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3227 RANGE
*chkrgn
, *mrgrgn
;
3228 INT fromindex
, mergeindex
;
3230 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3231 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3233 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3234 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3236 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3238 /* merge now common ranges */
3240 srchrgn
.lower
= chkrgn
->lower
- 1;
3241 srchrgn
.upper
= chkrgn
->upper
+ 1;
3245 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3246 if (mergeindex
== -1) break;
3247 if (mergeindex
== index
)
3249 fromindex
= index
+ 1;
3253 TRACE("Merge with index %i\n", mergeindex
);
3255 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3256 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3257 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3259 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3260 if (mergeindex
< index
) index
--;
3264 ranges_check(ranges
, "after add");
3268 ranges_check(ranges
, "failed add");
3272 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3277 TRACE("(%s)\n", debugrange(&range
));
3278 ranges_check(ranges
, "before del");
3280 /* we don't use DPAS_SORTED here, since we need *
3281 * to find the first overlapping range */
3282 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3285 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3287 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3289 /* case 1: Same range */
3290 if ( (chkrgn
->upper
== range
.upper
) &&
3291 (chkrgn
->lower
== range
.lower
) )
3293 DPA_DeletePtr(ranges
->hdpa
, index
);
3297 /* case 2: engulf */
3298 else if ( (chkrgn
->upper
<= range
.upper
) &&
3299 (chkrgn
->lower
>= range
.lower
) )
3301 DPA_DeletePtr(ranges
->hdpa
, index
);
3304 /* case 3: overlap upper */
3305 else if ( (chkrgn
->upper
<= range
.upper
) &&
3306 (chkrgn
->lower
< range
.lower
) )
3308 chkrgn
->upper
= range
.lower
;
3310 /* case 4: overlap lower */
3311 else if ( (chkrgn
->upper
> range
.upper
) &&
3312 (chkrgn
->lower
>= range
.lower
) )
3314 chkrgn
->lower
= range
.upper
;
3317 /* case 5: fully internal */
3322 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3323 newrgn
->lower
= chkrgn
->lower
;
3324 newrgn
->upper
= range
.lower
;
3325 chkrgn
->lower
= range
.upper
;
3326 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3334 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3337 ranges_check(ranges
, "after del");
3341 ranges_check(ranges
, "failed del");
3347 * Removes all selection ranges
3350 * [I] infoPtr : valid pointer to the listview structure
3351 * [I] toSkip : item range to skip removing the selection
3357 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3366 lvItem
.stateMask
= LVIS_SELECTED
;
3368 /* need to clone the DPA because callbacks can change it */
3369 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3370 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3371 while(iterator_next(&i
))
3372 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3373 /* note that the iterator destructor will free the cloned range */
3374 iterator_destroy(&i
);
3379 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3383 if (!(toSkip
= ranges_create(1))) return FALSE
;
3384 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3385 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3386 ranges_destroy(toSkip
);
3390 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3392 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3397 * Retrieves the number of items that are marked as selected.
3400 * [I] infoPtr : valid pointer to the listview structure
3403 * Number of items selected.
3405 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3407 INT nSelectedCount
= 0;
3409 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3412 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3414 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3419 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3421 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3422 return nSelectedCount
;
3427 * Manages the item focus.
3430 * [I] infoPtr : valid pointer to the listview structure
3431 * [I] nItem : item index
3434 * TRUE : focused item changed
3435 * FALSE : focused item has NOT changed
3437 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3439 INT oldFocus
= infoPtr
->nFocusedItem
;
3442 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3444 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3445 lvItem
.stateMask
= LVIS_FOCUSED
;
3446 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3448 return oldFocus
!= infoPtr
->nFocusedItem
;
3451 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3453 if (nShiftItem
< nItem
) return nShiftItem
;
3455 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3457 if (direction
> 0) return nShiftItem
+ direction
;
3459 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3462 /* This function updates focus index.
3465 focus : current focus index
3466 item : index of item to be added/removed
3467 direction : add/remove flag
3469 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3471 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3473 infoPtr
->bDoChangeNotify
= FALSE
;
3474 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3475 if (focus
!= infoPtr
->nFocusedItem
)
3476 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3477 infoPtr
->bDoChangeNotify
= old_change
;
3482 * Updates the various indices after an item has been inserted or deleted.
3485 * [I] infoPtr : valid pointer to the listview structure
3486 * [I] nItem : item index
3487 * [I] direction : Direction of shift, +1 or -1.
3492 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3494 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3496 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3497 assert(abs(direction
) == 1);
3498 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3500 /* But we are not supposed to modify nHotItem! */
3505 * Adds a block of selections.
3508 * [I] infoPtr : valid pointer to the listview structure
3509 * [I] nItem : item index
3512 * Whether the window is still valid.
3514 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3516 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3517 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3518 HWND hwndSelf
= infoPtr
->hwndSelf
;
3519 NMLVODSTATECHANGE nmlv
;
3524 /* Temporarily disable change notification
3525 * If the control is LVS_OWNERDATA, we need to send
3526 * only one LVN_ODSTATECHANGED notification.
3527 * See MSDN documentation for LVN_ITEMCHANGED.
3529 bOldChange
= infoPtr
->bDoChangeNotify
;
3530 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3532 if (nFirst
== -1) nFirst
= nItem
;
3534 item
.state
= LVIS_SELECTED
;
3535 item
.stateMask
= LVIS_SELECTED
;
3537 for (i
= nFirst
; i
<= nLast
; i
++)
3538 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3540 ZeroMemory(&nmlv
, sizeof(nmlv
));
3541 nmlv
.iFrom
= nFirst
;
3544 nmlv
.uNewState
= item
.state
;
3546 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3547 if (!IsWindow(hwndSelf
))
3549 infoPtr
->bDoChangeNotify
= bOldChange
;
3556 * Sets a single group selection.
3559 * [I] infoPtr : valid pointer to the listview structure
3560 * [I] nItem : item index
3565 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3572 if (!(selection
= ranges_create(100))) return;
3574 item
.state
= LVIS_SELECTED
;
3575 item
.stateMask
= LVIS_SELECTED
;
3577 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3579 if (infoPtr
->nSelectionMark
== -1)
3581 infoPtr
->nSelectionMark
= nItem
;
3582 ranges_additem(selection
, nItem
);
3588 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3589 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3590 ranges_add(selection
, sel
);
3595 RECT rcItem
, rcSel
, rcSelMark
;
3598 rcItem
.left
= LVIR_BOUNDS
;
3599 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3600 ranges_destroy (selection
);
3603 rcSelMark
.left
= LVIR_BOUNDS
;
3604 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3605 ranges_destroy (selection
);
3608 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3609 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3610 while(iterator_next(&i
))
3612 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3613 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3615 iterator_destroy(&i
);
3618 /* disable per item notifications on LVS_OWNERDATA style
3619 FIXME: single LVN_ODSTATECHANGED should be used */
3620 bOldChange
= infoPtr
->bDoChangeNotify
;
3621 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3623 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3626 iterator_rangesitems(&i
, selection
);
3627 while(iterator_next(&i
))
3628 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3629 /* this will also destroy the selection */
3630 iterator_destroy(&i
);
3632 infoPtr
->bDoChangeNotify
= bOldChange
;
3634 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3639 * Sets a single selection.
3642 * [I] infoPtr : valid pointer to the listview structure
3643 * [I] nItem : item index
3648 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3652 TRACE("nItem=%d\n", nItem
);
3654 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3656 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3657 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3658 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3660 infoPtr
->nSelectionMark
= nItem
;
3665 * Set selection(s) with keyboard.
3668 * [I] infoPtr : valid pointer to the listview structure
3669 * [I] nItem : item index
3670 * [I] space : VK_SPACE code sent
3673 * SUCCESS : TRUE (needs to be repainted)
3674 * FAILURE : FALSE (nothing has changed)
3676 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3678 /* FIXME: pass in the state */
3679 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3680 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3681 BOOL bResult
= FALSE
;
3683 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3684 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3688 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3689 LISTVIEW_SetSelection(infoPtr
, nItem
);
3693 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3697 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3698 lvItem
.stateMask
= LVIS_SELECTED
;
3701 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3702 if (lvItem
.state
& LVIS_SELECTED
)
3703 infoPtr
->nSelectionMark
= nItem
;
3705 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3708 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3711 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3715 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3717 LVHITTESTINFO lvHitTestInfo
;
3719 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3720 lvHitTestInfo
.pt
.x
= pt
.x
;
3721 lvHitTestInfo
.pt
.y
= pt
.y
;
3723 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3725 lpLVItem
->mask
= LVIF_PARAM
;
3726 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3727 lpLVItem
->iSubItem
= 0;
3729 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3732 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3734 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3735 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3736 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3741 * Called when the mouse is being actively tracked and has hovered for a specified
3745 * [I] infoPtr : valid pointer to the listview structure
3746 * [I] fwKeys : key indicator
3747 * [I] x,y : mouse position
3750 * 0 if the message was processed, non-zero if there was an error
3753 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3754 * over the item for a certain period of time.
3757 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3761 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3763 if (LISTVIEW_IsHotTracking(infoPtr
))
3771 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3772 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3774 SetFocus(infoPtr
->hwndSelf
);
3780 #define SCROLL_LEFT 0x1
3781 #define SCROLL_RIGHT 0x2
3782 #define SCROLL_UP 0x4
3783 #define SCROLL_DOWN 0x8
3787 * Utility routine to draw and highlight items within a marquee selection rectangle.
3790 * [I] infoPtr : valid pointer to the listview structure
3791 * [I] coords_orig : original co-ordinates of the cursor
3792 * [I] coords_offs : offsetted coordinates of the cursor
3793 * [I] offset : offset amount
3794 * [I] scroll : Bitmask of which directions we should scroll, if at all
3799 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3800 const POINT
*coords_offs
, const POINT
*offset
,
3803 BOOL controlDown
= FALSE
;
3805 ITERATOR old_elems
, new_elems
;
3808 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3810 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3811 rect
.right
= coords_offs
->x
;
3815 rect
.left
= coords_offs
->x
;
3816 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3819 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3821 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3822 rect
.bottom
= coords_offs
->y
;
3826 rect
.top
= coords_offs
->y
;
3827 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3830 /* Cancel out the old marquee rectangle and draw the new one */
3831 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3833 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3834 the cursor is further away */
3836 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3837 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3839 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3840 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3842 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3843 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3845 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3846 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3848 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3850 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3852 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3853 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3855 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3856 iterator_remove_common_items(&old_elems
, &new_elems
);
3858 /* Iterate over no longer selected items */
3859 while (iterator_next(&old_elems
))
3861 if (old_elems
.nItem
> -1)
3863 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3866 item
.state
= LVIS_SELECTED
;
3868 item
.stateMask
= LVIS_SELECTED
;
3870 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3873 iterator_destroy(&old_elems
);
3876 /* Iterate over newly selected items */
3877 if (GetKeyState(VK_CONTROL
) & 0x8000)
3880 while (iterator_next(&new_elems
))
3882 if (new_elems
.nItem
> -1)
3884 /* If CTRL is pressed, invert. If not, always select the item. */
3885 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3888 item
.state
= LVIS_SELECTED
;
3890 item
.stateMask
= LVIS_SELECTED
;
3892 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3895 iterator_destroy(&new_elems
);
3897 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3902 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3903 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3906 * [I] hwnd : Handle to the listview
3907 * [I] uMsg : WM_TIMER (ignored)
3908 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3909 * [I] dwTimer : The elapsed time (ignored)
3914 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3916 LISTVIEW_INFO
*infoPtr
;
3917 SCROLLINFO scrollInfo
;
3923 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3928 /* Get the current cursor position and convert to client coordinates */
3929 GetCursorPos(&coords_orig
);
3930 ScreenToClient(hWnd
, &coords_orig
);
3932 /* Ensure coordinates are within client bounds */
3933 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3934 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3937 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3939 /* Offset coordinates by the appropriate amount */
3940 coords_offs
.x
-= offset
.x
;
3941 coords_offs
.y
-= offset
.y
;
3943 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3944 scrollInfo
.fMask
= SIF_ALL
;
3946 /* Work out in which directions we can scroll */
3947 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3949 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3950 scroll
|= SCROLL_UP
;
3952 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3953 scroll
|= SCROLL_DOWN
;
3956 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3958 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3959 scroll
|= SCROLL_LEFT
;
3961 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3962 scroll
|= SCROLL_RIGHT
;
3965 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3966 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3967 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3968 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3970 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3976 * Called whenever WM_MOUSEMOVE is received.
3979 * [I] infoPtr : valid pointer to the listview structure
3980 * [I] fwKeys : key indicator
3981 * [I] x,y : mouse position
3984 * 0 if the message is processed, non-zero if there was an error
3986 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3992 if (!(fwKeys
& MK_LBUTTON
))
3993 infoPtr
->bLButtonDown
= FALSE
;
3995 if (infoPtr
->bLButtonDown
)
3997 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
3998 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4000 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4003 if (infoPtr
->bLButtonDown
)
4005 if (infoPtr
->bMarqueeSelect
)
4015 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4017 /* Ensure coordinates are within client bounds */
4018 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4019 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4021 /* Offset coordinates by the appropriate amount */
4022 coords_offs
.x
-= offset
.x
;
4023 coords_offs
.y
-= offset
.y
;
4025 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4026 move the mouse again */
4028 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4029 (y
>= infoPtr
->rcList
.bottom
))
4031 if (!infoPtr
->bScrolling
)
4033 infoPtr
->bScrolling
= TRUE
;
4034 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4039 infoPtr
->bScrolling
= FALSE
;
4040 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4043 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4051 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4053 /* reset item marker */
4054 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4055 infoPtr
->nLButtonDownItem
= -1;
4057 if (!PtInRect(&rect
, pt
))
4059 /* this path covers the following:
4060 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4061 2. change focus with keys
4062 3. move mouse over item from step 1 selects it and moves focus on it */
4063 if (infoPtr
->nLButtonDownItem
!= -1 &&
4064 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4068 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4069 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4071 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4072 infoPtr
->nLButtonDownItem
= -1;
4075 if (!infoPtr
->bDragging
)
4077 ht
.pt
= infoPtr
->ptClickPos
;
4078 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4080 /* If the click is outside the range of an item, begin a
4081 highlight. If not, begin an item drag. */
4086 /* If we're allowing multiple selections, send notification.
4087 If return value is non-zero, cancel. */
4088 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4090 /* Store the absolute coordinates of the click */
4092 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4094 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4095 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4097 /* Begin selection and capture mouse */
4098 infoPtr
->bMarqueeSelect
= TRUE
;
4099 SetCapture(infoPtr
->hwndSelf
);
4106 ZeroMemory(&nmlv
, sizeof(nmlv
));
4107 nmlv
.iItem
= ht
.iItem
;
4108 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4110 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4111 infoPtr
->bDragging
= TRUE
;
4119 /* see if we are supposed to be tracking mouse hovering */
4120 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4121 TRACKMOUSEEVENT trackinfo
;
4123 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4124 trackinfo
.dwFlags
= TME_QUERY
;
4126 /* see if we are already tracking this hwnd */
4127 _TrackMouseEvent(&trackinfo
);
4129 if(!(trackinfo
.dwFlags
& TME_HOVER
) || trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4130 trackinfo
.dwFlags
= TME_HOVER
;
4131 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4132 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4134 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4135 _TrackMouseEvent(&trackinfo
);
4144 * Tests whether the item is assignable to a list with style lStyle
4146 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4148 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4149 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4150 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4158 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4161 * [I] infoPtr : valid pointer to the listview structure
4162 * [I] lpLVItem : valid pointer to new item attributes
4163 * [I] isNew : the item being set is being inserted
4164 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4165 * [O] bChanged : will be set to TRUE if the item really changed
4171 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4177 /* stateMask is ignored for LVM_INSERTITEM */
4178 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4182 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4184 if (lpLVItem
->mask
== 0) return TRUE
;
4186 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4188 /* a virtual listview only stores selection and focus */
4189 if (lpLVItem
->mask
& ~LVIF_STATE
)
4195 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4196 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4200 /* we need to get the lParam and state of the item */
4201 item
.iItem
= lpLVItem
->iItem
;
4202 item
.iSubItem
= lpLVItem
->iSubItem
;
4203 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4204 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4208 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4210 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4211 /* determine what fields will change */
4212 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4213 uChanged
|= LVIF_STATE
;
4215 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4216 uChanged
|= LVIF_IMAGE
;
4218 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4219 uChanged
|= LVIF_PARAM
;
4221 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4222 uChanged
|= LVIF_INDENT
;
4224 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4225 uChanged
|= LVIF_TEXT
;
4227 TRACE("change mask=0x%x\n", uChanged
);
4229 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4230 nmlv
.iItem
= lpLVItem
->iItem
;
4231 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4232 nmlv
.uOldState
= item
.state
;
4233 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4234 nmlv
.lParam
= item
.lParam
;
4236 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4237 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4238 are enabled. Even nothing really changed we still need to send this,
4239 in this case uChanged mask is just set to passed item mask. */
4240 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4242 HWND hwndSelf
= infoPtr
->hwndSelf
;
4244 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4246 if (!IsWindow(hwndSelf
))
4250 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4251 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4252 /* this means we won't hit a focus change path later */
4253 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4255 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4256 infoPtr
->nFocusedItem
++;
4259 if (!uChanged
) return TRUE
;
4262 /* copy information */
4263 if (lpLVItem
->mask
& LVIF_TEXT
)
4264 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4266 if (lpLVItem
->mask
& LVIF_IMAGE
)
4267 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4269 if (lpLVItem
->mask
& LVIF_PARAM
)
4270 lpItem
->lParam
= lpLVItem
->lParam
;
4272 if (lpLVItem
->mask
& LVIF_INDENT
)
4273 lpItem
->iIndent
= lpLVItem
->iIndent
;
4275 if (uChanged
& LVIF_STATE
)
4277 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4279 lpItem
->state
&= ~stateMask
;
4280 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4282 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4284 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4285 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4287 else if (stateMask
& LVIS_SELECTED
)
4289 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4291 /* If we are asked to change focus, and we manage it, do it.
4292 It's important to have all new item data stored at this point,
4293 because changing existing focus could result in a redrawing operation,
4294 which in turn could ask for disp data, application should see all data
4295 for inserted item when processing LVN_GETDISPINFO.
4297 The way this works application will see nested item change notifications -
4298 changed item notifications interrupted by ones from item losing focus. */
4299 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4301 if (lpLVItem
->state
& LVIS_FOCUSED
)
4303 /* update selection mark */
4304 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4305 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4307 if (infoPtr
->nFocusedItem
!= -1)
4309 /* remove current focus */
4310 item
.mask
= LVIF_STATE
;
4312 item
.stateMask
= LVIS_FOCUSED
;
4314 /* recurse with redrawing an item */
4315 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4318 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4319 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4321 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4323 infoPtr
->nFocusedItem
= -1;
4328 /* if we're inserting the item, we're done */
4329 if (isNew
) return TRUE
;
4331 /* send LVN_ITEMCHANGED notification */
4332 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4333 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4340 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4343 * [I] infoPtr : valid pointer to the listview structure
4344 * [I] lpLVItem : valid pointer to new subitem attributes
4345 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4346 * [O] bChanged : will be set to TRUE if the item really changed
4352 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4355 SUBITEM_INFO
*lpSubItem
;
4357 /* we do not support subitems for virtual listviews */
4358 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4360 /* set subitem only if column is present */
4361 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4363 /* First do some sanity checks */
4364 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4365 particularly useful. We currently do not actually do anything with
4366 the flag on subitems.
4368 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4369 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4371 /* get the subitem structure, and create it if not there */
4372 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4373 assert (hdpaSubItems
);
4375 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4378 SUBITEM_INFO
*tmpSubItem
;
4381 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4382 if (!lpSubItem
) return FALSE
;
4383 /* we could binary search here, if need be...*/
4384 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4386 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4387 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4389 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4394 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4395 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4399 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4401 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4405 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4407 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4416 * Sets item attributes.
4419 * [I] infoPtr : valid pointer to the listview structure
4420 * [I] lpLVItem : new item attributes
4421 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4427 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4429 HWND hwndSelf
= infoPtr
->hwndSelf
;
4430 LPWSTR pszText
= NULL
;
4431 BOOL bResult
, bChanged
= FALSE
;
4434 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4436 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4439 /* Store old item area */
4440 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4442 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4443 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4445 pszText
= lpLVItem
->pszText
;
4446 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4449 /* actually set the fields */
4450 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4452 if (lpLVItem
->iSubItem
)
4453 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4455 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4456 if (!IsWindow(hwndSelf
))
4459 /* redraw item, if necessary */
4460 if (bChanged
&& !infoPtr
->bIsDrawing
)
4462 /* this little optimization eliminates some nasty flicker */
4463 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4464 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4465 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4466 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4469 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4470 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4476 textfreeT(lpLVItem
->pszText
, isW
);
4477 lpLVItem
->pszText
= pszText
;
4485 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4488 * [I] infoPtr : valid pointer to the listview structure
4493 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4496 SCROLLINFO scrollInfo
;
4498 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4499 scrollInfo
.fMask
= SIF_POS
;
4501 if (infoPtr
->uView
== LV_VIEW_LIST
)
4503 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4504 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4506 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4508 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4509 nItem
= scrollInfo
.nPos
;
4513 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4514 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4517 TRACE("nItem=%d\n", nItem
);
4525 * Erases the background of the given rectangle
4528 * [I] infoPtr : valid pointer to the listview structure
4529 * [I] hdc : device context handle
4530 * [I] lprcBox : clipping rectangle
4536 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4538 if (!infoPtr
->hBkBrush
) return FALSE
;
4540 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4542 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4545 /* Draw main item or subitem */
4546 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4548 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4553 /* now check if we need to update the focus rectangle */
4554 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4555 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4557 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4558 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4559 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4560 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4561 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4562 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4563 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4564 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4565 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4567 /* FIXME: temporary hack */
4568 rcSelect
.left
= rcLabel
.left
;
4570 /* in icon mode, the label rect is really what we want to draw the
4572 /* in detail mode, we want to paint background for label rect when
4573 * item is not selected or listview has full row select; otherwise paint
4574 * background for text only */
4575 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4576 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4577 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4580 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4581 ExtTextOutW(nmlvcd
->nmcd
.hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, NULL
, 0, NULL
);
4583 if (item
->state
& LVIS_FOCUSED
)
4585 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4587 /* we have to update left focus bound too if item isn't in leftmost column
4588 and reduce right box bound */
4589 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4593 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4595 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
4596 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4597 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4599 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, index
)->rcHeader
.right
+ Originx
;
4600 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4604 rcSelect
.right
= rcBox
.right
;
4607 /* store new focus rectangle */
4608 infoPtr
->rcFocus
= rcSelect
;
4612 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4614 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4617 TRACE("stateimage=%d\n", stateimage
);
4618 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4623 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4624 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4628 TRACE("iImage=%d\n", item
->iImage
);
4630 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4631 style
= ILD_SELECTED
;
4635 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4636 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4637 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4638 style
| (item
->state
& LVIS_OVERLAYMASK
));
4641 /* Don't bother painting item being edited */
4642 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4644 /* figure out the text drawing flags */
4645 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4646 if (infoPtr
->uView
== LV_VIEW_ICON
)
4647 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4648 else if (item
->iSubItem
)
4650 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4652 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4653 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4654 default: format
|= DT_LEFT
;
4657 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4659 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4660 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4662 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4664 /* for GRIDLINES reduce the bottom so the text formats correctly */
4665 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4669 if ((!(item
->state
& LVIS_SELECTED
) || !infoPtr
->bFocus
) && (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTSHADOWTEXT
))
4670 DrawShadowText(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
, RGB(255, 255, 255), RGB(0, 0, 0), 2, 2);
4673 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4681 * [I] infoPtr : valid pointer to the listview structure
4682 * [I] hdc : device context handle
4683 * [I] nItem : item index
4684 * [I] nSubItem : subitem index
4685 * [I] pos : item position in client coordinates
4686 * [I] cdmode : custom draw mode
4692 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4694 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4695 static WCHAR callbackW
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4696 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4698 NMLVCUSTOMDRAW nmlvcd
;
4701 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4703 /* get information needed for drawing the item */
4704 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4705 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4706 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4707 lvItem
.iItem
= nItem
;
4708 lvItem
.iSubItem
= 0;
4711 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4712 lvItem
.pszText
= szDispText
;
4713 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4714 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4715 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4717 /* now check if we need to update the focus rectangle */
4718 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4719 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4721 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4722 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4724 /* Full custom draw stage sequence looks like this:
4729 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4730 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item iself
4731 - CDDS_ITEMPOSTPAINT
4736 - CDDS_ITEMPOSTPAINT
4739 /* fill in the custom draw structure */
4740 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4741 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4742 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4743 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4747 while (iterator_next(subitems
))
4749 DWORD subitemstage
= CDRF_DODEFAULT
;
4751 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4752 if (subitems
->nItem
)
4754 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4755 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4756 lvItem
.iItem
= nItem
;
4757 lvItem
.iSubItem
= subitems
->nItem
;
4760 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4761 lvItem
.pszText
= szDispText
;
4762 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4763 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4764 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4765 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4766 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4768 /* update custom draw data */
4769 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4770 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4771 nmlvcd
.iSubItem
= subitems
->nItem
;
4774 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4775 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4778 nmlvcd
.clrTextBk
= infoPtr
->clrTextBk
;
4779 nmlvcd
.clrText
= infoPtr
->clrText
;
4782 if (subitems
->nItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4783 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4784 else if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4785 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4787 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4788 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4790 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4791 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4796 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4797 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4801 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4803 nmlvcd
.iSubItem
= 0;
4804 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4812 * Draws listview items when in owner draw mode.
4815 * [I] infoPtr : valid pointer to the listview structure
4816 * [I] hdc : device context handle
4821 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4823 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4824 DWORD cditemmode
= CDRF_DODEFAULT
;
4825 NMLVCUSTOMDRAW nmlvcd
;
4826 POINT Origin
, Position
;
4832 ZeroMemory(&dis
, sizeof(dis
));
4834 /* Get scroll info once before loop */
4835 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4837 /* iterate through the invalidated rows */
4838 while(iterator_next(i
))
4840 item
.iItem
= i
->nItem
;
4842 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4843 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4844 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4846 dis
.CtlType
= ODT_LISTVIEW
;
4848 dis
.itemID
= item
.iItem
;
4849 dis
.itemAction
= ODA_DRAWENTIRE
;
4851 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4852 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4853 dis
.hwndItem
= infoPtr
->hwndSelf
;
4855 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4856 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4857 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4858 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4859 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4860 dis
.itemData
= item
.lParam
;
4862 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4865 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4866 * structure for the rest. of the paint cycle
4868 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4869 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4870 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4872 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4874 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4875 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4878 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4879 notify_postpaint(infoPtr
, &nmlvcd
);
4885 * Draws listview items when in report display mode.
4888 * [I] infoPtr : valid pointer to the listview structure
4889 * [I] hdc : device context handle
4890 * [I] cdmode : custom draw mode
4895 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4898 RECT rcClip
, rcItem
;
4899 POINT Origin
, Position
;
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
);
4924 iterator_rangesitems(&j
, colRanges
);
4926 /* in full row select, we _have_ to draw the main item */
4927 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4930 /* iterate through the invalidated rows */
4931 while(iterator_next(i
))
4936 SelectObject(hdc
, infoPtr
->hFont
);
4937 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4938 Position
.y
+= Origin
.y
;
4940 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4942 /* iterate through the invalidated columns */
4943 while(iterator_next(&j
))
4945 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4946 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4948 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4951 rcItem
.bottom
= infoPtr
->nItemHeight
;
4952 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4953 if (!RectVisible(hdc
, &rcItem
)) continue;
4956 ranges_additem(subitems
, j
.nItem
);
4959 iterator_rangesitems(&k
, subitems
);
4960 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
4961 iterator_destroy(&k
);
4963 iterator_destroy(&j
);
4968 * Draws the gridlines if necessary when in report display mode.
4971 * [I] infoPtr : valid pointer to the listview structure
4972 * [I] hdc : device context handle
4977 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4983 RECT rcClip
, rcItem
= {0};
4991 /* figure out what to draw */
4992 rgntype
= GetClipBox(hdc
, &rcClip
);
4993 if (rgntype
== NULLREGION
) return;
4995 /* Get scroll info once before loop */
4996 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4998 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5000 /* narrow down the columns we need to paint */
5001 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5003 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5005 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5006 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5007 ranges_additem(colRanges
, index
);
5010 /* is right most vertical line visible? */
5011 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5013 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5014 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5015 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5018 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5020 hOldPen
= SelectObject ( hdc
, hPen
);
5022 /* draw the vertical lines for the columns */
5023 iterator_rangesitems(&j
, colRanges
);
5024 while(iterator_next(&j
))
5026 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5027 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5028 rcItem
.left
+= Origin
.x
;
5029 rcItem
.right
+= Origin
.x
;
5030 rcItem
.top
= infoPtr
->rcList
.top
;
5031 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5032 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5033 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5034 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5036 iterator_destroy(&j
);
5037 /* draw rightmost grid line if visible */
5040 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5041 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5042 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5044 rcItem
.right
+= Origin
.x
;
5046 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5047 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5050 /* draw the horizontal lines for the rows */
5051 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5052 rcItem
.left
= infoPtr
->rcList
.left
;
5053 rcItem
.right
= infoPtr
->rcList
.right
;
5054 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5056 rcItem
.bottom
= rcItem
.top
= y
;
5057 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5058 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5059 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5062 SelectObject( hdc
, hOldPen
);
5063 DeleteObject( hPen
);
5066 ranges_destroy(colRanges
);
5071 * Draws listview items when in list display mode.
5074 * [I] infoPtr : valid pointer to the listview structure
5075 * [I] hdc : device context handle
5076 * [I] cdmode : custom draw mode
5081 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5083 POINT Origin
, Position
;
5085 /* Get scroll info once before loop */
5086 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5088 while(iterator_prev(i
))
5090 SelectObject(hdc
, infoPtr
->hFont
);
5091 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5092 Position
.x
+= Origin
.x
;
5093 Position
.y
+= Origin
.y
;
5095 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5102 * Draws listview items.
5105 * [I] infoPtr : valid pointer to the listview structure
5106 * [I] hdc : device context handle
5107 * [I] prcErase : rect to be erased before refresh (may be NULL)
5112 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5114 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5115 NMLVCUSTOMDRAW nmlvcd
;
5122 HBITMAP hbmp
= NULL
;
5125 LISTVIEW_DUMP(infoPtr
);
5127 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5128 TRACE("double buffering\n");
5130 hdc
= CreateCompatibleDC(hdcOrig
);
5132 ERR("Failed to create DC for backbuffer\n");
5135 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5136 infoPtr
->rcList
.bottom
);
5138 ERR("Failed to create bitmap for backbuffer\n");
5143 SelectObject(hdc
, hbmp
);
5144 SelectObject(hdc
, infoPtr
->hFont
);
5146 if(GetClipBox(hdcOrig
, &rcClient
))
5147 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5149 /* Save dc values we're gonna trash while drawing
5150 * FIXME: Should be done in LISTVIEW_DrawItem() */
5151 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5152 oldBkMode
= GetBkMode(hdc
);
5153 oldBkColor
= GetBkColor(hdc
);
5154 oldTextColor
= GetTextColor(hdc
);
5157 infoPtr
->bIsDrawing
= TRUE
;
5160 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5161 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5162 /* If no erasing was done (usually because RedrawWindow was called
5163 * with RDW_INVALIDATE only) we need to copy the old contents into
5164 * the backbuffer before continuing. */
5165 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5166 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5167 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5168 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5171 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5172 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5173 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5174 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5176 /* nothing to draw */
5177 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5179 /* figure out what we need to draw */
5180 iterator_visibleitems(&i
, infoPtr
, hdc
);
5181 range
= iterator_range(&i
);
5183 /* send cache hint notification */
5184 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5188 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5189 nmlv
.iFrom
= range
.lower
;
5190 nmlv
.iTo
= range
.upper
- 1;
5191 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5194 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5195 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5198 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5199 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5200 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5201 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5203 /* if we have a focus rect and it's visible, draw it */
5204 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5205 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5206 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5208 iterator_destroy(&i
);
5211 /* For LVS_EX_GRIDLINES go and draw lines */
5212 /* This includes the case where there were *no* items */
5213 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5214 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5216 /* Draw marquee rectangle if appropriate */
5217 if (infoPtr
->bMarqueeSelect
)
5219 SetBkColor(hdc
, RGB(255, 255, 255));
5220 SetTextColor(hdc
, RGB(0, 0, 0));
5221 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5224 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5225 notify_postpaint(infoPtr
, &nmlvcd
);
5228 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5229 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5230 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5231 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5236 SelectObject(hdc
, hOldFont
);
5237 SetBkMode(hdc
, oldBkMode
);
5238 SetBkColor(hdc
, oldBkColor
);
5239 SetTextColor(hdc
, oldTextColor
);
5242 infoPtr
->bIsDrawing
= FALSE
;
5248 * Calculates the approximate width and height of a given number of items.
5251 * [I] infoPtr : valid pointer to the listview structure
5252 * [I] nItemCount : number of items
5253 * [I] wWidth : width
5254 * [I] wHeight : height
5257 * Returns a DWORD. The width in the low word and the height in high word.
5259 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5260 WORD wWidth
, WORD wHeight
)
5262 DWORD dwViewRect
= 0;
5264 if (nItemCount
== -1)
5265 nItemCount
= infoPtr
->nItemCount
;
5267 if (infoPtr
->uView
== LV_VIEW_LIST
)
5269 INT nItemCountPerColumn
= 1;
5270 INT nColumnCount
= 0;
5272 if (wHeight
== 0xFFFF)
5274 /* use current height */
5275 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5278 if (wHeight
< infoPtr
->nItemHeight
)
5279 wHeight
= infoPtr
->nItemHeight
;
5283 if (infoPtr
->nItemHeight
> 0)
5285 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5286 if (nItemCountPerColumn
== 0)
5287 nItemCountPerColumn
= 1;
5289 if (nItemCount
% nItemCountPerColumn
!= 0)
5290 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5292 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5296 /* Microsoft padding magic */
5297 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5298 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5300 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5302 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5306 if (infoPtr
->nItemCount
> 0)
5308 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5309 wWidth
= rcBox
.right
- rcBox
.left
;
5310 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5314 /* use current height and width */
5315 if (wHeight
== 0xffff)
5316 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5317 if (wWidth
== 0xffff)
5318 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5321 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5323 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5329 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5330 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5332 if (wWidth
== 0xffff)
5333 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5335 if (wWidth
< nItemWidth
)
5336 wWidth
= nItemWidth
;
5338 cols
= wWidth
/ nItemWidth
;
5339 if (cols
> nItemCount
)
5346 rows
= nItemCount
/ cols
;
5347 if (nItemCount
% cols
)
5353 wHeight
= (nItemHeight
* rows
)+2;
5354 wWidth
= (nItemWidth
* cols
)+2;
5356 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5358 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5359 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5366 * Cancel edit label with saving item text.
5369 * [I] infoPtr : valid pointer to the listview structure
5372 * Always returns TRUE.
5374 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5376 if (infoPtr
->hwndEdit
)
5378 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5379 HWND edit
= infoPtr
->hwndEdit
;
5381 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5382 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5390 * Create a drag image list for the specified item.
5393 * [I] infoPtr : valid pointer to the listview structure
5394 * [I] iItem : index of item
5395 * [O] lppt : Upper-left corner of the image
5398 * Returns a handle to the image list if successful, NULL otherwise.
5400 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5406 HBITMAP hbmp
, hOldbmp
;
5408 HIMAGELIST dragList
= 0;
5409 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5411 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5414 rcItem
.left
= LVIR_BOUNDS
;
5415 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5418 lppt
->x
= rcItem
.left
;
5419 lppt
->y
= rcItem
.top
;
5421 size
.cx
= rcItem
.right
- rcItem
.left
;
5422 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5424 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5425 hdc
= CreateCompatibleDC(hdcOrig
);
5426 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5427 hOldbmp
= SelectObject(hdc
, hbmp
);
5428 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5430 rcItem
.left
= rcItem
.top
= 0;
5431 rcItem
.right
= size
.cx
;
5432 rcItem
.bottom
= size
.cy
;
5433 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5436 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5438 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5439 SelectObject(hdc
, hOldbmp
);
5440 ImageList_Add(dragList
, hbmp
, 0);
5443 SelectObject(hdc
, hOldbmp
);
5445 SelectObject(hdc
, hOldFont
);
5448 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5450 TRACE("ret=%p\n", dragList
);
5458 * Removes all listview items and subitems.
5461 * [I] infoPtr : valid pointer to the listview structure
5467 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5469 HDPA hdpaSubItems
= NULL
;
5470 BOOL suppress
= FALSE
;
5478 /* we do it directly, to avoid notifications */
5479 ranges_clear(infoPtr
->selectionRanges
);
5480 infoPtr
->nSelectionMark
= -1;
5481 infoPtr
->nFocusedItem
= -1;
5482 SetRectEmpty(&infoPtr
->rcFocus
);
5483 /* But we are supposed to leave nHotItem as is! */
5485 /* send LVN_DELETEALLITEMS notification */
5486 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5490 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5492 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5495 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5497 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5499 /* send LVN_DELETEITEM notification, if not suppressed
5500 and if it is not a virtual listview */
5501 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5502 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5503 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5504 /* free id struct */
5505 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5506 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5507 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5509 /* both item and subitem start with ITEMHDR header */
5510 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5512 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5513 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5516 DPA_Destroy(hdpaSubItems
);
5517 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5519 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5520 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5521 infoPtr
->nItemCount
--;
5526 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5527 LISTVIEW_UpdateScroll(infoPtr
);
5529 LISTVIEW_InvalidateList(infoPtr
);
5536 * Scrolls, and updates the columns, when a column is changing width.
5539 * [I] infoPtr : valid pointer to the listview structure
5540 * [I] nColumn : column to scroll
5541 * [I] dx : amount of scroll, in pixels
5546 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5548 COLUMN_INFO
*lpColumnInfo
;
5554 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5555 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5556 rcCol
= lpColumnInfo
->rcHeader
;
5557 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5558 rcCol
.left
= rcCol
.right
;
5560 /* adjust the other columns */
5561 hdi
.mask
= HDI_ORDER
;
5562 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5564 INT nOrder
= hdi
.iOrder
;
5565 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5567 hdi
.mask
= HDI_ORDER
;
5568 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5569 if (hdi
.iOrder
>= nOrder
) {
5570 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5571 lpColumnInfo
->rcHeader
.left
+= dx
;
5572 lpColumnInfo
->rcHeader
.right
+= dx
;
5577 /* do not update screen if not in report mode */
5578 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5580 /* Need to reset the item width when inserting a new column */
5581 infoPtr
->nItemWidth
+= dx
;
5583 LISTVIEW_UpdateScroll(infoPtr
);
5584 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5586 /* scroll to cover the deleted column, and invalidate for redraw */
5587 rcOld
= infoPtr
->rcList
;
5588 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5589 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5594 * Removes a column from the listview control.
5597 * [I] infoPtr : valid pointer to the listview structure
5598 * [I] nColumn : column index
5604 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5608 TRACE("nColumn=%d\n", nColumn
);
5610 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5611 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5613 /* While the MSDN specifically says that column zero should not be deleted,
5614 what actually happens is that the column itself is deleted but no items or subitems
5618 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5620 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5623 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5624 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5626 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5628 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5630 INT nItem
, nSubItem
, i
;
5632 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5634 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5637 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5639 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5640 if (lpSubItem
->iSubItem
== nColumn
)
5643 lpDelItem
= lpSubItem
;
5645 else if (lpSubItem
->iSubItem
> nColumn
)
5647 lpSubItem
->iSubItem
--;
5651 /* if we found our subitem, zap it */
5655 if (is_text(lpDelItem
->hdr
.pszText
))
5656 Free(lpDelItem
->hdr
.pszText
);
5661 /* free dpa memory */
5662 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5667 /* update the other column info */
5668 LISTVIEW_UpdateItemSize(infoPtr
);
5669 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5670 LISTVIEW_InvalidateList(infoPtr
);
5672 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5679 * Invalidates the listview after an item's insertion or deletion.
5682 * [I] infoPtr : valid pointer to the listview structure
5683 * [I] nItem : item index
5684 * [I] dir : -1 if deleting, 1 if inserting
5689 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5691 INT nPerCol
, nItemCol
, nItemRow
;
5695 /* if we don't refresh, what's the point of scrolling? */
5696 if (!is_redrawing(infoPtr
)) return;
5698 assert (abs(dir
) == 1);
5700 /* arrange icons if autoarrange is on */
5701 if (is_autoarrange(infoPtr
))
5703 BOOL arrange
= TRUE
;
5704 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5705 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5706 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5709 /* scrollbars need updating */
5710 LISTVIEW_UpdateScroll(infoPtr
);
5712 /* figure out the item's position */
5713 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5714 nPerCol
= infoPtr
->nItemCount
+ 1;
5715 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5716 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5717 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5720 nItemCol
= nItem
/ nPerCol
;
5721 nItemRow
= nItem
% nPerCol
;
5722 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5724 /* move the items below up a slot */
5725 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5726 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5727 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5728 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5729 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5730 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5731 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5733 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5734 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5737 /* report has only that column, so we're done */
5738 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5740 /* now for LISTs, we have to deal with the columns to the right */
5741 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5743 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5744 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5745 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5746 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5747 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5752 * Removes an item from the listview control.
5755 * [I] infoPtr : valid pointer to the listview structure
5756 * [I] nItem : item index
5762 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5765 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5766 INT focus
= infoPtr
->nFocusedItem
;
5768 TRACE("(nItem=%d)\n", nItem
);
5770 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5772 /* remove selection, and focus */
5774 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5775 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5777 /* send LVN_DELETEITEM notification. */
5778 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5780 /* we need to do this here, because we'll be deleting stuff */
5782 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5784 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5792 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5793 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5795 /* free id struct */
5796 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5797 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5798 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5800 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5802 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5803 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5806 DPA_Destroy(hdpaSubItems
);
5811 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5812 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5815 infoPtr
->nItemCount
--;
5816 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5817 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5819 /* now is the invalidation fun */
5821 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5828 * Callback implementation for editlabel control
5831 * [I] infoPtr : valid pointer to the listview structure
5832 * [I] storeText : store edit box text as item text
5833 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5839 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5841 HWND hwndSelf
= infoPtr
->hwndSelf
;
5842 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5843 NMLVDISPINFOW dispInfo
;
5844 INT editedItem
= infoPtr
->nEditLabelItem
;
5846 WCHAR
*pszText
= NULL
;
5851 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5855 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5857 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5858 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5863 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5865 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5866 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5867 dispInfo
.item
.iItem
= editedItem
;
5868 dispInfo
.item
.iSubItem
= 0;
5869 dispInfo
.item
.stateMask
= ~0;
5870 dispInfo
.item
.pszText
= szDispText
;
5871 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5872 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5879 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5882 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5883 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5884 textfreeT(tmp
, FALSE
);
5887 /* add the text from the edit in */
5888 dispInfo
.item
.mask
|= LVIF_TEXT
;
5889 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5890 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5892 /* Do we need to update the Item Text */
5893 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5895 infoPtr
->nEditLabelItem
= -1;
5896 infoPtr
->hwndEdit
= 0;
5898 if (!res
) goto cleanup
;
5900 if (!IsWindow(hwndSelf
))
5905 if (!pszText
) return TRUE
;
5912 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5914 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5915 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5916 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5918 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5924 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5925 dispInfo
.item
.mask
= LVIF_TEXT
;
5926 dispInfo
.item
.iItem
= editedItem
;
5927 dispInfo
.item
.iSubItem
= 0;
5928 dispInfo
.item
.pszText
= pszText
;
5929 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5930 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5940 * Subclassed edit control windproc function
5943 * [I] hwnd : the edit window handle
5944 * [I] uMsg : the message that is to be processed
5945 * [I] wParam : first message parameter
5946 * [I] lParam : second message parameter
5947 * [I] isW : TRUE if input is Unicode
5952 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5954 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5957 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5958 hwnd
, uMsg
, wParam
, lParam
, isW
);
5963 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5967 WNDPROC editProc
= infoPtr
->EditWndProc
;
5968 infoPtr
->EditWndProc
= 0;
5969 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5970 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5974 if (VK_ESCAPE
== (INT
)wParam
)
5979 else if (VK_RETURN
== (INT
)wParam
)
5983 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5987 if (infoPtr
->hwndEdit
)
5988 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
5990 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
5996 * Subclassed edit control Unicode windproc function
5999 * [I] hwnd : the edit window handle
6000 * [I] uMsg : the message that is to be processed
6001 * [I] wParam : first message parameter
6002 * [I] lParam : second message parameter
6006 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6008 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6013 * Subclassed edit control ANSI windproc function
6016 * [I] hwnd : the edit window handle
6017 * [I] uMsg : the message that is to be processed
6018 * [I] wParam : first message parameter
6019 * [I] lParam : second message parameter
6023 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6025 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6030 * Creates a subclassed edit control
6033 * [I] infoPtr : valid pointer to the listview structure
6034 * [I] text : initial text for the edit
6035 * [I] style : the window style
6036 * [I] isW : TRUE if input is Unicode
6040 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6042 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6043 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6046 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6048 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6050 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6052 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6054 if (!hedit
) return 0;
6056 infoPtr
->EditWndProc
= (WNDPROC
)
6057 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6058 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6060 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6061 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6068 * Begin in place editing of specified list view item
6071 * [I] infoPtr : valid pointer to the listview structure
6072 * [I] nItem : item index
6073 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6079 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6081 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6082 HWND hwndSelf
= infoPtr
->hwndSelf
;
6083 NMLVDISPINFOW dispInfo
;
6084 HFONT hOldFont
= NULL
;
6090 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6092 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6094 /* remove existing edit box */
6095 if (infoPtr
->hwndEdit
)
6097 SetFocus(infoPtr
->hwndSelf
);
6098 infoPtr
->hwndEdit
= 0;
6101 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6103 infoPtr
->nEditLabelItem
= nItem
;
6105 LISTVIEW_SetSelection(infoPtr
, nItem
);
6106 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6107 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6109 rect
.left
= LVIR_LABEL
;
6110 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6112 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6113 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6114 dispInfo
.item
.iItem
= nItem
;
6115 dispInfo
.item
.iSubItem
= 0;
6116 dispInfo
.item
.stateMask
= ~0;
6117 dispInfo
.item
.pszText
= disptextW
;
6118 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6119 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6121 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6122 if (!infoPtr
->hwndEdit
) return 0;
6124 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6126 if (!IsWindow(hwndSelf
))
6128 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6129 infoPtr
->hwndEdit
= 0;
6133 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6135 /* position and display edit box */
6136 hdc
= GetDC(infoPtr
->hwndSelf
);
6138 /* select the font to get appropriate metric dimensions */
6140 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6142 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6143 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6144 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6146 /* get string length in pixels */
6147 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6149 /* add extra spacing for the next character */
6150 GetTextMetricsW(hdc
, &tm
);
6151 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6154 SelectObject(hdc
, hOldFont
);
6156 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6158 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6161 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6162 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6163 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6164 SetFocus(infoPtr
->hwndEdit
);
6165 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6166 return infoPtr
->hwndEdit
;
6172 * Ensures the specified item is visible, scrolling into view if necessary.
6175 * [I] infoPtr : valid pointer to the listview structure
6176 * [I] nItem : item index
6177 * [I] bPartial : partially or entirely visible
6183 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6185 INT nScrollPosHeight
= 0;
6186 INT nScrollPosWidth
= 0;
6187 INT nHorzAdjust
= 0;
6188 INT nVertAdjust
= 0;
6191 RECT rcItem
, rcTemp
;
6193 rcItem
.left
= LVIR_BOUNDS
;
6194 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6196 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6198 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6200 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6201 if (infoPtr
->uView
== LV_VIEW_LIST
)
6202 nScrollPosWidth
= infoPtr
->nItemWidth
;
6203 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6204 nScrollPosWidth
= 1;
6206 if (rcItem
.left
< infoPtr
->rcList
.left
)
6209 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6214 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6218 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6220 /* scroll up/down, but not in LVS_LIST mode */
6221 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6222 nScrollPosHeight
= infoPtr
->nItemHeight
;
6223 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6224 nScrollPosHeight
= 1;
6226 if (rcItem
.top
< infoPtr
->rcList
.top
)
6229 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6234 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6238 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6240 if (nScrollPosWidth
)
6242 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6243 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6244 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6247 if (nScrollPosHeight
)
6249 INT diff
= nVertDiff
/ nScrollPosHeight
;
6250 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6251 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6259 * Searches for an item with specific characteristics.
6262 * [I] hwnd : window handle
6263 * [I] nStart : base item index
6264 * [I] lpFindInfo : item information to look for
6267 * SUCCESS : index of item
6270 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6271 const LVFINDINFOW
*lpFindInfo
)
6273 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6274 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6275 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6276 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6277 POINT Position
, Destination
;
6280 /* Search in virtual listviews should be done by application, not by
6281 listview control, so we just send LVN_ODFINDITEMW and return the result */
6282 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6286 nmlv
.iStart
= nStart
;
6287 nmlv
.lvfi
= *lpFindInfo
;
6288 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6291 if (!lpFindInfo
|| nItem
< 0) return -1;
6294 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6295 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6297 lvItem
.mask
|= LVIF_TEXT
;
6298 lvItem
.pszText
= szDispText
;
6299 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6302 if (lpFindInfo
->flags
& LVFI_WRAP
)
6305 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6306 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6311 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6312 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6313 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6314 switch(lpFindInfo
->vkDirection
)
6316 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6317 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6318 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6319 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6320 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6321 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6322 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6324 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6325 Destination
.x
= rcArea
.right
;
6326 Destination
.y
= rcArea
.bottom
;
6328 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6332 else Destination
.x
= Destination
.y
= 0;
6334 /* if LVFI_PARAM is specified, all other flags are ignored */
6335 if (lpFindInfo
->flags
& LVFI_PARAM
)
6337 lvItem
.mask
|= LVIF_PARAM
;
6339 lvItem
.mask
&= ~LVIF_TEXT
;
6343 for (; nItem
< nLast
; nItem
++)
6345 lvItem
.iItem
= nItem
;
6346 lvItem
.iSubItem
= 0;
6347 lvItem
.pszText
= szDispText
;
6348 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6350 if (lvItem
.mask
& LVIF_PARAM
)
6352 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6358 if (lvItem
.mask
& LVIF_TEXT
)
6360 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6362 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6363 if (!p
|| p
!= lvItem
.pszText
) continue;
6367 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6371 if (!bNearest
) return nItem
;
6373 /* This is very inefficient. To do a good job here,
6374 * we need a sorted array of (x,y) item positions */
6375 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6377 /* compute the distance^2 to the destination */
6378 xdist
= Destination
.x
- Position
.x
;
6379 ydist
= Destination
.y
- Position
.y
;
6380 dist
= xdist
* xdist
+ ydist
* ydist
;
6382 /* remember the distance, and item if it's closer */
6386 nNearestItem
= nItem
;
6393 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6398 return nNearestItem
;
6403 * Searches for an item with specific characteristics.
6406 * [I] hwnd : window handle
6407 * [I] nStart : base item index
6408 * [I] lpFindInfo : item information to look for
6411 * SUCCESS : index of item
6414 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6415 const LVFINDINFOA
*lpFindInfo
)
6417 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6418 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6423 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6424 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6425 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6426 textfreeT(strW
, FALSE
);
6432 * Retrieves column attributes.
6435 * [I] infoPtr : valid pointer to the listview structure
6436 * [I] nColumn : column index
6437 * [IO] lpColumn : column information
6438 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6439 * otherwise it is in fact a LPLVCOLUMNA
6445 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6447 COLUMN_INFO
*lpColumnInfo
;
6450 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6451 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6453 /* initialize memory */
6454 ZeroMemory(&hdi
, sizeof(hdi
));
6456 if (lpColumn
->mask
& LVCF_TEXT
)
6458 hdi
.mask
|= HDI_TEXT
;
6459 hdi
.pszText
= lpColumn
->pszText
;
6460 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6463 if (lpColumn
->mask
& LVCF_IMAGE
)
6464 hdi
.mask
|= HDI_IMAGE
;
6466 if (lpColumn
->mask
& LVCF_ORDER
)
6467 hdi
.mask
|= HDI_ORDER
;
6469 if (lpColumn
->mask
& LVCF_SUBITEM
)
6470 hdi
.mask
|= HDI_LPARAM
;
6472 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6474 if (lpColumn
->mask
& LVCF_FMT
)
6475 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6477 if (lpColumn
->mask
& LVCF_WIDTH
)
6478 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6480 if (lpColumn
->mask
& LVCF_IMAGE
)
6481 lpColumn
->iImage
= hdi
.iImage
;
6483 if (lpColumn
->mask
& LVCF_ORDER
)
6484 lpColumn
->iOrder
= hdi
.iOrder
;
6486 if (lpColumn
->mask
& LVCF_SUBITEM
)
6487 lpColumn
->iSubItem
= hdi
.lParam
;
6489 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6490 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6496 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6498 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
6503 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6508 * Retrieves the column width.
6511 * [I] infoPtr : valid pointer to the listview structure
6512 * [I] int : column index
6515 * SUCCESS : column width
6518 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6520 INT nColumnWidth
= 0;
6523 TRACE("nColumn=%d\n", nColumn
);
6525 /* we have a 'column' in LIST and REPORT mode only */
6526 switch(infoPtr
->uView
)
6529 nColumnWidth
= infoPtr
->nItemWidth
;
6531 case LV_VIEW_DETAILS
:
6532 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6533 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6534 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6536 * TODO: should we do the same in LVM_GETCOLUMN?
6538 hdItem
.mask
= HDI_WIDTH
;
6539 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6541 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6544 nColumnWidth
= hdItem
.cxy
;
6548 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6549 return nColumnWidth
;
6554 * In list or report display mode, retrieves the number of items that can fit
6555 * vertically in the visible area. In icon or small icon display mode,
6556 * retrieves the total number of visible items.
6559 * [I] infoPtr : valid pointer to the listview structure
6562 * Number of fully visible items.
6564 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6566 switch (infoPtr
->uView
)
6569 case LV_VIEW_SMALLICON
:
6570 return infoPtr
->nItemCount
;
6571 case LV_VIEW_DETAILS
:
6572 return LISTVIEW_GetCountPerColumn(infoPtr
);
6574 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6582 * Retrieves an image list handle.
6585 * [I] infoPtr : valid pointer to the listview structure
6586 * [I] nImageList : image list identifier
6589 * SUCCESS : image list handle
6592 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6596 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6597 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6598 case LVSIL_STATE
: return infoPtr
->himlState
;
6599 case LVSIL_GROUPHEADER
:
6600 FIXME("LVSIL_GROUPHEADER not supported\n");
6603 WARN("got unknown imagelist index - %d\n", nImageList
);
6608 /* LISTVIEW_GetISearchString */
6612 * Retrieves item attributes.
6615 * [I] hwnd : window handle
6616 * [IO] lpLVItem : item info
6617 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6618 * if FALSE, then lpLVItem is a LPLVITEMA.
6621 * This is the internal 'GetItem' interface -- it tries to
6622 * be smart and avoid text copies, if possible, by modifying
6623 * lpLVItem->pszText to point to the text string. Please note
6624 * that this is not always possible (e.g. OWNERDATA), so on
6625 * entry you *must* supply valid values for pszText, and cchTextMax.
6626 * The only difference to the documented interface is that upon
6627 * return, you should use *only* the lpLVItem->pszText, rather than
6628 * the buffer pointer you provided on input. Most code already does
6629 * that, so it's not a problem.
6630 * For the two cases when the text must be copied (that is,
6631 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6637 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6639 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6640 NMLVDISPINFOW dispInfo
;
6646 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6648 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6651 if (lpLVItem
->mask
== 0) return TRUE
;
6652 TRACE("mask=%x\n", lpLVItem
->mask
);
6654 /* make a local copy */
6655 isubitem
= lpLVItem
->iSubItem
;
6657 /* a quick optimization if all we're asked is the focus state
6658 * these queries are worth optimising since they are common,
6659 * and can be answered in constant time, without the heavy accesses */
6660 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6661 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6663 lpLVItem
->state
= 0;
6664 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6665 lpLVItem
->state
|= LVIS_FOCUSED
;
6669 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6671 /* if the app stores all the data, handle it separately */
6672 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6674 dispInfo
.item
.state
= 0;
6676 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6677 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6678 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6680 UINT mask
= lpLVItem
->mask
;
6682 /* NOTE: copy only fields which we _know_ are initialized, some apps
6683 * depend on the uninitialized fields being 0 */
6684 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6685 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6686 dispInfo
.item
.iSubItem
= isubitem
;
6687 if (lpLVItem
->mask
& LVIF_TEXT
)
6689 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6691 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6694 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6695 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6698 if (lpLVItem
->mask
& LVIF_STATE
)
6699 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6700 /* could be zeroed on LVIF_NORECOMPUTE case */
6701 if (dispInfo
.item
.mask
)
6703 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6704 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6705 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6707 /* full size structure expected - _WIN32IE >= 0x560 */
6708 *lpLVItem
= dispInfo
.item
;
6710 else if (lpLVItem
->mask
& LVIF_INDENT
)
6712 /* indent member expected - _WIN32IE >= 0x300 */
6713 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6717 /* minimal structure expected */
6718 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6720 lpLVItem
->mask
= mask
;
6721 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6725 /* make sure lParam is zeroed out */
6726 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6728 /* callback marked pointer required here */
6729 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6730 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6732 /* we store only a little state, so if we're not asked, we're done */
6733 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6735 /* if focus is handled by us, report it */
6736 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6738 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6739 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6740 lpLVItem
->state
|= LVIS_FOCUSED
;
6743 /* and do the same for selection, if we handle it */
6744 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6746 lpLVItem
->state
&= ~LVIS_SELECTED
;
6747 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6748 lpLVItem
->state
|= LVIS_SELECTED
;
6754 /* find the item and subitem structures before we proceed */
6755 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6756 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6761 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6762 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6765 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6770 pItemHdr
= &lpItem
->hdr
;
6772 /* Do we need to query the state from the app? */
6773 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6775 dispInfo
.item
.mask
|= LVIF_STATE
;
6776 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6779 /* Do we need to enquire about the image? */
6780 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6781 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6783 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6784 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6787 /* Only items support indentation */
6788 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6791 dispInfo
.item
.mask
|= LVIF_INDENT
;
6792 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6795 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6796 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6797 !is_text(pItemHdr
->pszText
))
6799 dispInfo
.item
.mask
|= LVIF_TEXT
;
6800 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6801 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6802 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6803 *dispInfo
.item
.pszText
= '\0';
6806 /* If we don't have all the requested info, query the application */
6807 if (dispInfo
.item
.mask
)
6809 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6810 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6811 dispInfo
.item
.lParam
= lpItem
->lParam
;
6812 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6813 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6816 /* we should not store values for subitems */
6817 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6819 /* Now, handle the iImage field */
6820 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6822 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6823 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6824 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6826 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6828 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6829 lpLVItem
->iImage
= pItemHdr
->iImage
;
6831 lpLVItem
->iImage
= 0;
6834 /* The pszText field */
6835 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6837 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6838 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6840 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6842 else if (lpLVItem
->mask
& LVIF_TEXT
)
6844 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6845 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6846 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6849 /* Next is the lParam field */
6850 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6852 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6853 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6854 lpItem
->lParam
= dispInfo
.item
.lParam
;
6856 else if (lpLVItem
->mask
& LVIF_PARAM
)
6857 lpLVItem
->lParam
= lpItem
->lParam
;
6859 /* if this is a subitem, we're done */
6860 if (isubitem
) return TRUE
;
6862 /* ... the state field (this one is different due to uCallbackmask) */
6863 if (lpLVItem
->mask
& LVIF_STATE
)
6865 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6866 if (dispInfo
.item
.mask
& LVIF_STATE
)
6868 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6869 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6871 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6873 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6874 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6875 lpLVItem
->state
|= LVIS_FOCUSED
;
6877 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6879 lpLVItem
->state
&= ~LVIS_SELECTED
;
6880 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6881 lpLVItem
->state
|= LVIS_SELECTED
;
6885 /* and last, but not least, the indent field */
6886 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6888 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6889 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6890 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6892 else if (lpLVItem
->mask
& LVIF_INDENT
)
6894 lpLVItem
->iIndent
= lpItem
->iIndent
;
6902 * Retrieves item attributes.
6905 * [I] hwnd : window handle
6906 * [IO] lpLVItem : item info
6907 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6908 * if FALSE, then lpLVItem is a LPLVITEMA.
6911 * This is the external 'GetItem' interface -- it properly copies
6912 * the text in the provided buffer.
6918 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6923 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6926 pszText
= lpLVItem
->pszText
;
6927 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6928 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6930 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6931 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6933 pszText
= LPSTR_TEXTCALLBACKW
;
6935 lpLVItem
->pszText
= pszText
;
6943 * Retrieves the position (upper-left) of the listview control item.
6944 * Note that for LVS_ICON style, the upper-left is that of the icon
6945 * and not the bounding box.
6948 * [I] infoPtr : valid pointer to the listview structure
6949 * [I] nItem : item index
6950 * [O] lpptPosition : coordinate information
6956 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6960 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6962 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6964 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6965 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6967 if (infoPtr
->uView
== LV_VIEW_ICON
)
6969 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6970 lpptPosition
->y
+= ICON_TOP_PADDING
;
6972 lpptPosition
->x
+= Origin
.x
;
6973 lpptPosition
->y
+= Origin
.y
;
6975 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6982 * Retrieves the bounding rectangle for a listview control item.
6985 * [I] infoPtr : valid pointer to the listview structure
6986 * [I] nItem : item index
6987 * [IO] lprc : bounding rectangle coordinates
6988 * lprc->left specifies the portion of the item for which the bounding
6989 * rectangle will be retrieved.
6991 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6992 * including the icon and label.
6995 * * Experiment shows that native control returns:
6996 * * width = min (48, length of text line)
6997 * * .left = position.x - (width - iconsize.cx)/2
6998 * * .right = .left + width
6999 * * height = #lines of text * ntmHeight + icon height + 8
7000 * * .top = position.y - 2
7001 * * .bottom = .top + height
7002 * * separation between items .y = itemSpacing.cy - height
7003 * * .x = itemSpacing.cx - width
7004 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7007 * * Experiment shows that native control returns:
7008 * * width = iconSize.cx + 16
7009 * * .left = position.x - (width - iconsize.cx)/2
7010 * * .right = .left + width
7011 * * height = iconSize.cy + 4
7012 * * .top = position.y - 2
7013 * * .bottom = .top + height
7014 * * separation between items .y = itemSpacing.cy - height
7015 * * .x = itemSpacing.cx - width
7016 * LVIR_LABEL Returns the bounding rectangle of the item text.
7019 * * Experiment shows that native control returns:
7020 * * width = text length
7021 * * .left = position.x - width/2
7022 * * .right = .left + width
7023 * * height = ntmH * linecount + 2
7024 * * .top = position.y + iconSize.cy + 6
7025 * * .bottom = .top + height
7026 * * separation between items .y = itemSpacing.cy - height
7027 * * .x = itemSpacing.cx - width
7028 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7029 * rectangles, but excludes columns in report view.
7036 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7037 * upon whether the window has the focus currently and on whether the item
7038 * is the one with the focus. Ensure that the control's record of which
7039 * item has the focus agrees with the items' records.
7041 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7043 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7044 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7045 POINT Position
, Origin
;
7049 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7051 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7053 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7054 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7056 /* Be smart and try to figure out the minimum we have to do */
7057 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7058 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7059 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7060 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7061 oversizedBox
= TRUE
;
7063 /* get what we need from the item before hand, so we make
7064 * only one request. This can speed up things, if data
7065 * is stored on the app side */
7067 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7068 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7069 lvItem
.iItem
= nItem
;
7070 lvItem
.iSubItem
= 0;
7071 lvItem
.pszText
= szDispText
;
7072 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7073 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7074 /* we got the state already up, simulate it here, to avoid a reget */
7075 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7077 lvItem
.mask
|= LVIF_STATE
;
7078 lvItem
.stateMask
= LVIS_FOCUSED
;
7079 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7082 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7083 lprc
->left
= LVIR_BOUNDS
;
7089 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7093 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7097 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7100 case LVIR_SELECTBOUNDS
:
7101 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7105 WARN("Unknown value: %d\n", lprc
->left
);
7109 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7111 if (mode
!= LVIR_BOUNDS
)
7112 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7113 Position
.y
+ Origin
.y
);
7115 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7118 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7120 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7127 * Retrieves the spacing between listview control items.
7130 * [I] infoPtr : valid pointer to the listview structure
7131 * [IO] lprc : rectangle to receive the output
7132 * on input, lprc->top = nSubItem
7133 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7135 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7136 * not only those of the first column.
7142 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7144 RECT rect
= { 0, 0, 0, 0 };
7148 if (!lprc
) return FALSE
;
7150 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7151 /* Subitem of '0' means item itself, and this works for all control view modes */
7153 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7155 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7157 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7158 /* this works for any item index, no matter if it exists or not */
7159 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7161 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7164 rect
.bottom
= infoPtr
->nItemHeight
;
7168 /* Native implementation is broken for this case and garbage is left for left and right fields,
7169 we zero them to get predictable output */
7170 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7171 lprc
->bottom
= infoPtr
->nItemHeight
;
7172 OffsetRect(lprc
, origin
.x
, y
);
7173 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7181 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7182 if (infoPtr
->himlSmall
)
7183 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7185 rect
.right
= rect
.left
;
7187 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7195 ERR("Unknown bounds=%d\n", lprc
->left
);
7199 OffsetRect(&rect
, origin
.x
, y
);
7201 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7208 * Retrieves the spacing between listview control items.
7211 * [I] infoPtr : valid pointer to the listview structure
7212 * [I] bSmall : flag for small or large icon
7215 * Horizontal + vertical spacing
7217 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7223 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7227 if (infoPtr
->uView
== LV_VIEW_ICON
)
7228 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7230 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7237 * Retrieves the state of a listview control item.
7240 * [I] infoPtr : valid pointer to the listview structure
7241 * [I] nItem : item index
7242 * [I] uMask : state mask
7245 * State specified by the mask.
7247 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7251 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7253 lvItem
.iItem
= nItem
;
7254 lvItem
.iSubItem
= 0;
7255 lvItem
.mask
= LVIF_STATE
;
7256 lvItem
.stateMask
= uMask
;
7257 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7259 return lvItem
.state
& uMask
;
7264 * Retrieves the text of a listview control item or subitem.
7267 * [I] hwnd : window handle
7268 * [I] nItem : item index
7269 * [IO] lpLVItem : item information
7270 * [I] isW : TRUE if lpLVItem is Unicode
7273 * SUCCESS : string length
7276 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7278 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7280 lpLVItem
->mask
= LVIF_TEXT
;
7281 lpLVItem
->iItem
= nItem
;
7282 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7284 return textlenT(lpLVItem
->pszText
, isW
);
7289 * Searches for an item based on properties + relationships.
7292 * [I] infoPtr : valid pointer to the listview structure
7293 * [I] nItem : item index
7294 * [I] uFlags : relationship flag
7297 * SUCCESS : item index
7300 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7303 LVFINDINFOW lvFindInfo
;
7304 INT nCountPerColumn
;
7308 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7309 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7311 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7313 if (uFlags
& LVNI_CUT
)
7316 if (uFlags
& LVNI_DROPHILITED
)
7317 uMask
|= LVIS_DROPHILITED
;
7319 if (uFlags
& LVNI_FOCUSED
)
7320 uMask
|= LVIS_FOCUSED
;
7322 if (uFlags
& LVNI_SELECTED
)
7323 uMask
|= LVIS_SELECTED
;
7325 /* if we're asked for the focused item, that's only one,
7326 * so it's worth optimizing */
7327 if (uFlags
& LVNI_FOCUSED
)
7329 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7330 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7333 if (uFlags
& LVNI_ABOVE
)
7335 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7340 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7346 /* Special case for autoarrange - move 'til the top of a list */
7347 if (is_autoarrange(infoPtr
))
7349 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7350 while (nItem
- nCountPerRow
>= 0)
7352 nItem
-= nCountPerRow
;
7353 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7358 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7359 lvFindInfo
.vkDirection
= VK_UP
;
7360 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7361 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7363 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7368 else if (uFlags
& LVNI_BELOW
)
7370 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7372 while (nItem
< infoPtr
->nItemCount
)
7375 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7381 /* Special case for autoarrange - move 'til the bottom of a list */
7382 if (is_autoarrange(infoPtr
))
7384 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7385 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7387 nItem
+= nCountPerRow
;
7388 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7393 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7394 lvFindInfo
.vkDirection
= VK_DOWN
;
7395 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7396 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7398 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7403 else if (uFlags
& LVNI_TOLEFT
)
7405 if (infoPtr
->uView
== LV_VIEW_LIST
)
7407 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7408 while (nItem
- nCountPerColumn
>= 0)
7410 nItem
-= nCountPerColumn
;
7411 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7415 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7417 /* Special case for autoarrange - move 'til the beginning of a row */
7418 if (is_autoarrange(infoPtr
))
7420 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7421 while (nItem
% nCountPerRow
> 0)
7424 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7429 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7430 lvFindInfo
.vkDirection
= VK_LEFT
;
7431 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7432 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7434 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7439 else if (uFlags
& LVNI_TORIGHT
)
7441 if (infoPtr
->uView
== LV_VIEW_LIST
)
7443 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7444 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7446 nItem
+= nCountPerColumn
;
7447 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7451 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7453 /* Special case for autoarrange - move 'til the end of a row */
7454 if (is_autoarrange(infoPtr
))
7456 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7457 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7460 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7465 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7466 lvFindInfo
.vkDirection
= VK_RIGHT
;
7467 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7468 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7470 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7479 /* search by index */
7480 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7482 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7490 /* LISTVIEW_GetNumberOfWorkAreas */
7494 * Retrieves the origin coordinates when in icon or small icon display mode.
7497 * [I] infoPtr : valid pointer to the listview structure
7498 * [O] lpptOrigin : coordinate information
7503 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7505 INT nHorzPos
= 0, nVertPos
= 0;
7506 SCROLLINFO scrollInfo
;
7508 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7509 scrollInfo
.fMask
= SIF_POS
;
7511 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7512 nHorzPos
= scrollInfo
.nPos
;
7513 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7514 nVertPos
= scrollInfo
.nPos
;
7516 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7518 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7519 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7520 if (infoPtr
->uView
== LV_VIEW_LIST
)
7521 nHorzPos
*= infoPtr
->nItemWidth
;
7522 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7523 nVertPos
*= infoPtr
->nItemHeight
;
7525 lpptOrigin
->x
-= nHorzPos
;
7526 lpptOrigin
->y
-= nVertPos
;
7528 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7533 * Retrieves the width of a string.
7536 * [I] hwnd : window handle
7537 * [I] lpszText : text string to process
7538 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7541 * SUCCESS : string width (in pixels)
7544 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7549 if (is_text(lpszText
))
7551 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7552 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7553 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7556 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7558 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7559 SelectObject(hdc
, hOldFont
);
7560 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7562 return stringSize
.cx
;
7567 * Determines which listview item is located at the specified position.
7570 * [I] infoPtr : valid pointer to the listview structure
7571 * [IO] lpht : hit test information
7572 * [I] subitem : fill out iSubItem.
7573 * [I] select : return the index only if the hit selects the item
7576 * (mm 20001022): We must not allow iSubItem to be touched, for
7577 * an app might pass only a structure with space up to iItem!
7578 * (MS Office 97 does that for instance in the file open dialog)
7581 * SUCCESS : item index
7584 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7586 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7587 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7588 POINT Origin
, Position
, opt
;
7594 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7598 if (subitem
) lpht
->iSubItem
= 0;
7600 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7602 /* set whole list relation flags */
7603 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7605 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7606 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7607 lpht
->flags
|= LVHT_TOLEFT
;
7609 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7610 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7614 if (infoPtr
->rcList
.bottom
< opt
.y
)
7615 lpht
->flags
|= LVHT_BELOW
;
7619 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7620 lpht
->flags
|= LVHT_TOLEFT
;
7621 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7622 lpht
->flags
|= LVHT_TORIGHT
;
7624 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7625 lpht
->flags
|= LVHT_ABOVE
;
7626 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7627 lpht
->flags
|= LVHT_BELOW
;
7630 /* even if item is invalid try to find subitem */
7631 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7636 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7638 lpht
->iSubItem
= -1;
7639 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7641 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7643 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7649 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7651 /* if we're outside horizontal columns bounds there's nothing to test further */
7652 if (lpht
->iSubItem
== -1)
7655 lpht
->flags
= LVHT_NOWHERE
;
7660 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7661 if (lpht
->flags
) return -1;
7663 lpht
->flags
|= LVHT_NOWHERE
;
7665 /* first deal with the large items */
7666 rcSearch
.left
= lpht
->pt
.x
;
7667 rcSearch
.top
= lpht
->pt
.y
;
7668 rcSearch
.right
= rcSearch
.left
+ 1;
7669 rcSearch
.bottom
= rcSearch
.top
+ 1;
7671 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7672 iterator_next(&i
); /* go to first item in the sequence */
7674 iterator_destroy(&i
);
7676 TRACE("lpht->iItem=%d\n", iItem
);
7677 if (iItem
== -1) return -1;
7679 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7680 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7681 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7682 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7683 lvItem
.iItem
= iItem
;
7684 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7685 lvItem
.pszText
= szDispText
;
7686 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7687 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7688 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7690 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7691 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7692 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7694 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7695 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7697 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7699 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7702 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7703 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7707 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7708 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7710 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7711 if (!PtInRect(&rcBounds
, opt
)) return -1;
7713 /* That's a special case - row rectangle is used as item rectangle and
7714 returned flags contain all item parts. */
7715 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7717 if (PtInRect(&rcIcon
, opt
))
7718 lpht
->flags
|= LVHT_ONITEMICON
;
7719 else if (PtInRect(&rcLabel
, opt
))
7720 lpht
->flags
|= LVHT_ONITEMLABEL
;
7721 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7722 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7723 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7725 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7727 if (lpht
->flags
& LVHT_ONITEM
)
7728 lpht
->flags
&= ~LVHT_NOWHERE
;
7729 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7731 if (select
&& !is_fullrow
)
7733 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7735 /* get main item bounds */
7736 lvItem
.iSubItem
= 0;
7737 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7738 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7739 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7741 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7743 return lpht
->iItem
= iItem
;
7748 * Inserts a new item in the listview control.
7751 * [I] infoPtr : valid pointer to the listview structure
7752 * [I] lpLVItem : item information
7753 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7756 * SUCCESS : new item index
7759 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7766 BOOL is_sorted
, has_changed
;
7768 HWND hwndSelf
= infoPtr
->hwndSelf
;
7770 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7772 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7774 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7775 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7777 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7779 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7781 /* insert item in listview control data structure */
7782 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7783 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7785 /* link with id struct */
7786 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7788 lpID
->item
= hdpaSubItems
;
7789 lpID
->id
= get_next_itemid(infoPtr
);
7790 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7792 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7793 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7795 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7797 /* calculate new item index */
7804 while (i
< infoPtr
->nItemCount
)
7806 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7807 item_s
= DPA_GetPtr(hItem
, 0);
7809 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7810 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7812 if (cmpv
>= 0) break;
7818 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7820 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7821 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7822 if (nItem
== -1) goto fail
;
7823 infoPtr
->nItemCount
++;
7825 /* shift indices first so they don't get tangled */
7826 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7828 /* set the item attributes */
7829 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7831 /* full size structure expected - _WIN32IE >= 0x560 */
7834 else if (lpLVItem
->mask
& LVIF_INDENT
)
7836 /* indent member expected - _WIN32IE >= 0x300 */
7837 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7841 /* minimal structure expected */
7842 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7845 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7847 item
.mask
|= LVIF_STATE
;
7848 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7849 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7850 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7853 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7855 /* make room for the position, if we are in the right mode */
7856 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7858 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7860 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7862 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7867 /* send LVN_INSERTITEM notification */
7868 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7870 nmlv
.lParam
= lpItem
->lParam
;
7871 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7872 if (!IsWindow(hwndSelf
))
7875 /* align items (set position of each item) */
7876 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7880 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7881 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7883 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7885 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7888 /* now is the invalidation fun */
7889 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7893 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7894 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7895 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7896 infoPtr
->nItemCount
--;
7898 DPA_DeletePtr(hdpaSubItems
, 0);
7899 DPA_Destroy (hdpaSubItems
);
7906 * Checks item visibility.
7909 * [I] infoPtr : valid pointer to the listview structure
7910 * [I] nFirst : item index to check for
7913 * Item visible : TRUE
7914 * Item invisible or failure : FALSE
7916 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7918 POINT Origin
, Position
;
7923 TRACE("nItem=%d\n", nItem
);
7925 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7927 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7928 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7929 rcItem
.left
= Position
.x
+ Origin
.x
;
7930 rcItem
.top
= Position
.y
+ Origin
.y
;
7931 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7932 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7934 hdc
= GetDC(infoPtr
->hwndSelf
);
7935 if (!hdc
) return FALSE
;
7936 ret
= RectVisible(hdc
, &rcItem
);
7937 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7944 * Redraws a range of items.
7947 * [I] infoPtr : valid pointer to the listview structure
7948 * [I] nFirst : first item
7949 * [I] nLast : last item
7955 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7959 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7960 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7963 for (i
= nFirst
; i
<= nLast
; i
++)
7964 LISTVIEW_InvalidateItem(infoPtr
, i
);
7971 * Scroll the content of a listview.
7974 * [I] infoPtr : valid pointer to the listview structure
7975 * [I] dx : horizontal scroll amount in pixels
7976 * [I] dy : vertical scroll amount in pixels
7983 * If the control is in report view (LV_VIEW_DETAILS) the control can
7984 * be scrolled only in line increments. "dy" will be rounded to the
7985 * nearest number of pixels that are a whole line. Ex: if line height
7986 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7987 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7989 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7991 switch(infoPtr
->uView
) {
7992 case LV_VIEW_DETAILS
:
7993 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7994 dy
/= infoPtr
->nItemHeight
;
7997 if (dy
!= 0) return FALSE
;
8003 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8004 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8011 * Sets the background color.
8014 * [I] infoPtr : valid pointer to the listview structure
8015 * [I] color : background color
8021 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8023 TRACE("(color=%x)\n", color
);
8025 infoPtr
->bDefaultBkColor
= FALSE
;
8026 if(infoPtr
->clrBk
!= color
) {
8027 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8028 infoPtr
->clrBk
= color
;
8029 if (color
== CLR_NONE
)
8030 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8033 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8034 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8041 /* LISTVIEW_SetBkImage */
8043 /*** Helper for {Insert,Set}ColumnT *only* */
8044 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8045 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8047 if (lpColumn
->mask
& LVCF_FMT
)
8049 /* format member is valid */
8050 lphdi
->mask
|= HDI_FORMAT
;
8052 /* set text alignment (leftmost column must be left-aligned) */
8053 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8054 lphdi
->fmt
|= HDF_LEFT
;
8055 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8056 lphdi
->fmt
|= HDF_RIGHT
;
8057 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8058 lphdi
->fmt
|= HDF_CENTER
;
8060 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8061 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8063 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8065 lphdi
->fmt
|= HDF_IMAGE
;
8066 lphdi
->iImage
= I_IMAGECALLBACK
;
8069 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8070 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8073 if (lpColumn
->mask
& LVCF_WIDTH
)
8075 lphdi
->mask
|= HDI_WIDTH
;
8076 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8078 /* make it fill the remainder of the controls width */
8082 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8084 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8085 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8088 /* retrieve the layout of the header */
8089 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8090 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8092 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8095 lphdi
->cxy
= lpColumn
->cx
;
8098 if (lpColumn
->mask
& LVCF_TEXT
)
8100 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8101 lphdi
->fmt
|= HDF_STRING
;
8102 lphdi
->pszText
= lpColumn
->pszText
;
8103 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8106 if (lpColumn
->mask
& LVCF_IMAGE
)
8108 lphdi
->mask
|= HDI_IMAGE
;
8109 lphdi
->iImage
= lpColumn
->iImage
;
8112 if (lpColumn
->mask
& LVCF_ORDER
)
8114 lphdi
->mask
|= HDI_ORDER
;
8115 lphdi
->iOrder
= lpColumn
->iOrder
;
8122 * Inserts a new column.
8125 * [I] infoPtr : valid pointer to the listview structure
8126 * [I] nColumn : column index
8127 * [I] lpColumn : column information
8128 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8131 * SUCCESS : new column index
8134 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8135 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8137 COLUMN_INFO
*lpColumnInfo
;
8141 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8143 if (!lpColumn
|| nColumn
< 0) return -1;
8144 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8146 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8147 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8150 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8151 * (can be seen in SPY) otherwise column never gets added.
8153 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8154 hdi
.mask
|= HDI_WIDTH
;
8159 * when the iSubItem is available Windows copies it to the header lParam. It seems
8160 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8162 if (lpColumn
->mask
& LVCF_SUBITEM
)
8164 hdi
.mask
|= HDI_LPARAM
;
8165 hdi
.lParam
= lpColumn
->iSubItem
;
8168 /* create header if not present */
8169 LISTVIEW_CreateHeader(infoPtr
);
8170 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8171 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8173 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8176 /* insert item in header control */
8177 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8178 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8179 nColumn
, (LPARAM
)&hdi
);
8180 if (nNewColumn
== -1) return -1;
8181 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8183 /* create our own column info */
8184 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8185 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8187 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8188 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8189 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8192 /* now we have to actually adjust the data */
8193 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8195 SUBITEM_INFO
*lpSubItem
;
8201 item
.iSubItem
= nNewColumn
;
8202 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8203 item
.iImage
= I_IMAGECALLBACK
;
8204 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8206 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8208 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8209 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8211 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8212 if (lpSubItem
->iSubItem
>= nNewColumn
)
8213 lpSubItem
->iSubItem
++;
8216 /* add new subitem for each item */
8218 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8222 /* make space for the new column */
8223 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8224 LISTVIEW_UpdateItemSize(infoPtr
);
8229 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8232 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8240 * Sets the attributes of a header item.
8243 * [I] infoPtr : valid pointer to the listview structure
8244 * [I] nColumn : column index
8245 * [I] lpColumn : column attributes
8246 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8252 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8253 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8255 HDITEMW hdi
, hdiget
;
8258 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8260 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8262 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8263 if (lpColumn
->mask
& LVCF_FMT
)
8265 hdi
.mask
|= HDI_FORMAT
;
8266 hdiget
.mask
= HDI_FORMAT
;
8267 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8268 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8270 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8272 /* set header item attributes */
8273 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8274 if (!bResult
) return FALSE
;
8276 if (lpColumn
->mask
& LVCF_FMT
)
8278 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8279 INT oldFmt
= lpColumnInfo
->fmt
;
8281 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8282 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8284 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8288 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8289 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8296 * Sets the column order array
8299 * [I] infoPtr : valid pointer to the listview structure
8300 * [I] iCount : number of elements in column order array
8301 * [I] lpiArray : pointer to column order array
8307 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8309 TRACE("iCount %d lpiArray %p\n", iCount
, lpiArray
);
8311 if (!lpiArray
|| !IsWindow(infoPtr
->hwndHeader
)) return FALSE
;
8313 infoPtr
->colRectsDirty
= TRUE
;
8315 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8320 * Sets the width of a column
8323 * [I] infoPtr : valid pointer to the listview structure
8324 * [I] nColumn : column index
8325 * [I] cx : column width
8331 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8333 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8337 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8339 /* set column width only if in report or list mode */
8340 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8342 /* take care of invalid cx values */
8343 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
8344 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
8346 /* resize all columns if in LV_VIEW_LIST mode */
8347 if(infoPtr
->uView
== LV_VIEW_LIST
)
8349 infoPtr
->nItemWidth
= cx
;
8350 LISTVIEW_InvalidateList(infoPtr
);
8354 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8356 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8361 lvItem
.mask
= LVIF_TEXT
;
8363 lvItem
.iSubItem
= nColumn
;
8364 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8365 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8367 lvItem
.pszText
= szDispText
;
8368 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8369 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8370 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8372 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8373 max_cx
+= infoPtr
->iconSize
.cx
;
8374 max_cx
+= TRAILING_LABEL_PADDING
;
8377 /* autosize based on listview items width */
8378 if(cx
== LVSCW_AUTOSIZE
)
8380 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8382 /* if iCol is the last column make it fill the remainder of the controls width */
8383 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8388 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8389 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8391 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8395 /* Despite what the MS docs say, if this is not the last
8396 column, then MS resizes the column to the width of the
8397 largest text string in the column, including headers
8398 and items. This is different from LVSCW_AUTOSIZE in that
8399 LVSCW_AUTOSIZE ignores the header string length. */
8402 /* retrieve header text */
8403 hdi
.mask
= HDI_TEXT
;
8404 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8405 hdi
.pszText
= szDispText
;
8406 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8408 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8409 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8412 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8413 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8414 /* FIXME: Take into account the header image, if one is present */
8415 SelectObject(hdc
, old_font
);
8416 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8418 cx
= max (cx
, max_cx
);
8422 if (cx
< 0) return FALSE
;
8424 /* call header to update the column change */
8425 hdi
.mask
= HDI_WIDTH
;
8426 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8427 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8428 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8432 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8435 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8438 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8440 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8441 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8444 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8445 ILC_COLOR
| ILC_MASK
, 2, 2);
8446 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8447 hdc
= CreateCompatibleDC(hdc_wnd
);
8448 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8449 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8450 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8452 rc
.left
= rc
.top
= 0;
8453 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
8454 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
8456 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8457 FillRect(hdc
, &rc
, hbr_white
);
8458 InflateRect(&rc
, -2, -2);
8459 FillRect(hdc
, &rc
, hbr_black
);
8461 SelectObject(hdc
, hbm_im
);
8462 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8463 SelectObject(hdc
, hbm_orig
);
8464 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8466 SelectObject(hdc
, hbm_im
);
8467 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8468 SelectObject(hdc
, hbm_orig
);
8469 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8471 DeleteObject(hbm_mask
);
8472 DeleteObject(hbm_im
);
8480 * Sets the extended listview style.
8483 * [I] infoPtr : valid pointer to the listview structure
8485 * [I] dwStyle : style
8488 * SUCCESS : previous style
8491 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8493 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8495 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8499 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8501 infoPtr
->dwLvExStyle
= ex_style
;
8503 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8505 HIMAGELIST himl
= 0;
8506 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8509 item
.mask
= LVIF_STATE
;
8510 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8511 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8512 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8514 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8515 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8516 ImageList_Destroy(infoPtr
->himlState
);
8518 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8519 /* checkbox list replaces previous custom list or... */
8520 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8521 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8522 /* ...previous was checkbox list */
8523 (old_ex_style
& LVS_EX_CHECKBOXES
))
8524 ImageList_Destroy(himl
);
8527 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8531 /* if not already created */
8532 LISTVIEW_CreateHeader(infoPtr
);
8534 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8535 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8536 style
|= HDS_DRAGDROP
;
8538 style
&= ~HDS_DRAGDROP
;
8539 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8542 /* GRIDLINES adds decoration at top so changes sizes */
8543 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8545 LISTVIEW_CreateHeader(infoPtr
);
8546 LISTVIEW_UpdateSize(infoPtr
);
8549 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8551 LISTVIEW_CreateHeader(infoPtr
);
8554 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8556 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8557 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8560 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8562 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8563 LISTVIEW_CreateHeader(infoPtr
);
8565 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8566 LISTVIEW_UpdateSize(infoPtr
);
8567 LISTVIEW_UpdateScroll(infoPtr
);
8570 LISTVIEW_InvalidateList(infoPtr
);
8571 return old_ex_style
;
8576 * Sets the new hot cursor used during hot tracking and hover selection.
8579 * [I] infoPtr : valid pointer to the listview structure
8580 * [I] hCursor : the new hot cursor handle
8583 * Returns the previous hot cursor
8585 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8587 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8589 infoPtr
->hHotCursor
= hCursor
;
8597 * Sets the hot item index.
8600 * [I] infoPtr : valid pointer to the listview structure
8601 * [I] iIndex : index
8604 * SUCCESS : previous hot item index
8605 * FAILURE : -1 (no hot item)
8607 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8609 INT iOldIndex
= infoPtr
->nHotItem
;
8611 infoPtr
->nHotItem
= iIndex
;
8619 * Sets the amount of time the cursor must hover over an item before it is selected.
8622 * [I] infoPtr : valid pointer to the listview structure
8623 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8626 * Returns the previous hover time
8628 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8630 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8632 infoPtr
->dwHoverTime
= dwHoverTime
;
8634 return oldHoverTime
;
8639 * Sets spacing for icons of LVS_ICON style.
8642 * [I] infoPtr : valid pointer to the listview structure
8643 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8644 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8647 * MAKELONG(oldcx, oldcy)
8649 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8651 INT iconWidth
= 0, iconHeight
= 0;
8652 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8654 TRACE("requested=(%d,%d)\n", cx
, cy
);
8656 /* set to defaults, if instructed to */
8657 if (cx
== -1 && cy
== -1)
8659 infoPtr
->autoSpacing
= TRUE
;
8660 if (infoPtr
->himlNormal
)
8661 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8662 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8663 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8666 infoPtr
->autoSpacing
= FALSE
;
8668 /* if 0 then keep width */
8670 infoPtr
->iconSpacing
.cx
= cx
;
8672 /* if 0 then keep height */
8674 infoPtr
->iconSpacing
.cy
= cy
;
8676 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8677 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8678 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8679 infoPtr
->ntmHeight
);
8681 /* these depend on the iconSpacing */
8682 LISTVIEW_UpdateItemSize(infoPtr
);
8687 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL is_small
)
8691 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8698 size
->cx
= GetSystemMetrics(is_small
? SM_CXSMICON
: SM_CXICON
);
8699 size
->cy
= GetSystemMetrics(is_small
? SM_CYSMICON
: SM_CYICON
);
8708 * [I] infoPtr : valid pointer to the listview structure
8709 * [I] nType : image list type
8710 * [I] himl : image list handle
8713 * SUCCESS : old image list
8716 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8718 INT oldHeight
= infoPtr
->nItemHeight
;
8719 HIMAGELIST himlOld
= 0;
8721 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8726 himlOld
= infoPtr
->himlNormal
;
8727 infoPtr
->himlNormal
= himl
;
8728 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8729 if (infoPtr
->autoSpacing
)
8730 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8734 himlOld
= infoPtr
->himlSmall
;
8735 infoPtr
->himlSmall
= himl
;
8736 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8737 if (infoPtr
->hwndHeader
)
8738 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8742 himlOld
= infoPtr
->himlState
;
8743 infoPtr
->himlState
= himl
;
8744 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8745 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8749 ERR("Unknown icon type=%d\n", nType
);
8753 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8754 if (infoPtr
->nItemHeight
!= oldHeight
)
8755 LISTVIEW_UpdateScroll(infoPtr
);
8762 * Preallocates memory (does *not* set the actual count of items !)
8765 * [I] infoPtr : valid pointer to the listview structure
8766 * [I] nItems : item count (projected number of items to allocate)
8767 * [I] dwFlags : update flags
8773 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8775 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8777 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8779 INT nOldCount
= infoPtr
->nItemCount
;
8781 if (nItems
< nOldCount
)
8783 RANGE range
= { nItems
, nOldCount
};
8784 ranges_del(infoPtr
->selectionRanges
, range
);
8785 if (infoPtr
->nFocusedItem
>= nItems
)
8787 LISTVIEW_SetItemFocus(infoPtr
, -1);
8788 SetRectEmpty(&infoPtr
->rcFocus
);
8792 infoPtr
->nItemCount
= nItems
;
8793 LISTVIEW_UpdateScroll(infoPtr
);
8795 /* the flags are valid only in ownerdata report and list modes */
8796 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8798 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8799 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8801 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8802 LISTVIEW_InvalidateList(infoPtr
);
8809 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8810 nFrom
= min(nOldCount
, nItems
);
8811 nTo
= max(nOldCount
, nItems
);
8813 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8816 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8817 rcErase
.right
= infoPtr
->nItemWidth
;
8818 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8819 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8820 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8821 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8823 else /* LV_VIEW_LIST */
8825 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8827 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8828 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8829 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8830 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8831 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8832 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8833 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8835 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8837 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8838 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8839 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8840 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8841 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8847 /* According to MSDN for non-LVS_OWNERDATA this is just
8848 * a performance issue. The control allocates its internal
8849 * data structures for the number of items specified. It
8850 * cuts down on the number of memory allocations. Therefore
8851 * we will just issue a WARN here
8853 WARN("for non-ownerdata performance option not implemented.\n");
8861 * Sets the position of an item.
8864 * [I] infoPtr : valid pointer to the listview structure
8865 * [I] nItem : item index
8866 * [I] pt : coordinate
8872 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8876 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8878 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8879 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8882 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8884 /* This point value seems to be an undocumented feature.
8885 * The best guess is that it means either at the origin,
8886 * or at true beginning of the list. I will assume the origin. */
8887 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8890 if (infoPtr
->uView
== LV_VIEW_ICON
)
8892 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8893 Pt
.y
-= ICON_TOP_PADDING
;
8898 infoPtr
->bAutoarrange
= FALSE
;
8900 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8905 * Sets the state of one or many items.
8908 * [I] infoPtr : valid pointer to the listview structure
8909 * [I] nItem : item index
8910 * [I] item : item or subitem info
8916 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8921 if (!item
) return FALSE
;
8923 lvItem
.iItem
= nItem
;
8924 lvItem
.iSubItem
= 0;
8925 lvItem
.mask
= LVIF_STATE
;
8926 lvItem
.state
= item
->state
;
8927 lvItem
.stateMask
= item
->stateMask
;
8928 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8935 /* special case optimization for recurring attempt to deselect all */
8936 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8939 /* select all isn't allowed in LVS_SINGLESEL */
8940 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8943 /* focus all isn't allowed */
8944 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8946 notify
= infoPtr
->bDoChangeNotify
;
8947 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8949 infoPtr
->bDoChangeNotify
= FALSE
;
8950 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8951 oldstate
|= LVIS_SELECTED
;
8952 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
8955 /* apply to all items */
8956 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8957 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
8959 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8963 infoPtr
->bDoChangeNotify
= notify
;
8967 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
8968 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
8969 nmlv
.uChanged
= LVIF_STATE
;
8970 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
8973 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
8977 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8984 * Sets the text of an item or subitem.
8987 * [I] hwnd : window handle
8988 * [I] nItem : item index
8989 * [I] lpLVItem : item or subitem info
8990 * [I] isW : TRUE if input is Unicode
8996 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9000 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9001 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9003 lvItem
.iItem
= nItem
;
9004 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9005 lvItem
.mask
= LVIF_TEXT
;
9006 lvItem
.pszText
= lpLVItem
->pszText
;
9007 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9009 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9011 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9016 * Set item index that marks the start of a multiple selection.
9019 * [I] infoPtr : valid pointer to the listview structure
9020 * [I] nIndex : index
9023 * Index number or -1 if there is no selection mark.
9025 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9027 INT nOldIndex
= infoPtr
->nSelectionMark
;
9029 TRACE("(nIndex=%d)\n", nIndex
);
9031 infoPtr
->nSelectionMark
= nIndex
;
9038 * Sets the text background color.
9041 * [I] infoPtr : valid pointer to the listview structure
9042 * [I] color : text background color
9048 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9050 TRACE("(color=%x)\n", color
);
9052 infoPtr
->clrTextBk
= color
;
9058 * Sets the text foreground color.
9061 * [I] infoPtr : valid pointer to the listview structure
9062 * [I] color : text color
9068 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9070 TRACE("(color=%x)\n", color
);
9072 infoPtr
->clrText
= color
;
9078 * Sets new ToolTip window to ListView control.
9081 * [I] infoPtr : valid pointer to the listview structure
9082 * [I] hwndNewToolTip : handle to new ToolTip
9087 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9089 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9090 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9091 return hwndOldToolTip
;
9096 * sets the Unicode character format flag for the control
9098 * [I] infoPtr :valid pointer to the listview structure
9099 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9102 * Old Unicode Format
9104 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9106 SHORT rc
= infoPtr
->notifyFormat
;
9107 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9108 return rc
== NFR_UNICODE
;
9113 * sets the control view mode
9115 * [I] infoPtr :valid pointer to the listview structure
9116 * [I] nView :new view mode value
9122 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9126 if (infoPtr
->uView
== nView
) return 1;
9128 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9129 if (nView
== LV_VIEW_TILE
)
9131 FIXME("View LV_VIEW_TILE unimplemented\n");
9135 infoPtr
->uView
= nView
;
9137 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9138 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9140 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9141 SetRectEmpty(&infoPtr
->rcFocus
);
9143 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9144 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9149 case LV_VIEW_SMALLICON
:
9150 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9152 case LV_VIEW_DETAILS
:
9157 LISTVIEW_CreateHeader( infoPtr
);
9159 hl
.prc
= &infoPtr
->rcList
;
9161 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9162 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9163 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9170 LISTVIEW_UpdateItemSize(infoPtr
);
9171 LISTVIEW_UpdateSize(infoPtr
);
9172 LISTVIEW_UpdateScroll(infoPtr
);
9173 LISTVIEW_InvalidateList(infoPtr
);
9175 TRACE("nView=%d\n", nView
);
9180 /* LISTVIEW_SetWorkAreas */
9184 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9187 * [I] first : pointer to first ITEM_INFO to compare
9188 * [I] second : pointer to second ITEM_INFO to compare
9189 * [I] lParam : HWND of control
9192 * if first comes before second : negative
9193 * if first comes after second : positive
9194 * if first and second are equivalent : zero
9196 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9198 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9199 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9200 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9202 /* Forward the call to the client defined callback */
9203 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9208 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9211 * [I] first : pointer to first ITEM_INFO to compare
9212 * [I] second : pointer to second ITEM_INFO to compare
9213 * [I] lParam : HWND of control
9216 * if first comes before second : negative
9217 * if first comes after second : positive
9218 * if first and second are equivalent : zero
9220 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9222 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9223 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9224 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9226 /* Forward the call to the client defined callback */
9227 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9232 * Sorts the listview items.
9235 * [I] infoPtr : valid pointer to the listview structure
9236 * [I] pfnCompare : application-defined value
9237 * [I] lParamSort : pointer to comparison callback
9238 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9244 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9245 LPARAM lParamSort
, BOOL IsEx
)
9249 LPVOID selectionMarkItem
= NULL
;
9250 LPVOID focusedItem
= NULL
;
9253 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9255 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9257 if (!pfnCompare
) return FALSE
;
9258 if (!infoPtr
->hdpaItems
) return FALSE
;
9260 /* if there are 0 or 1 items, there is no need to sort */
9261 if (infoPtr
->nItemCount
< 2) return TRUE
;
9263 /* clear selection */
9264 ranges_clear(infoPtr
->selectionRanges
);
9266 /* save selection mark and focused item */
9267 if (infoPtr
->nSelectionMark
>= 0)
9268 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9269 if (infoPtr
->nFocusedItem
>= 0)
9270 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9272 infoPtr
->pfnCompare
= pfnCompare
;
9273 infoPtr
->lParamSort
= lParamSort
;
9275 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9277 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9279 /* restore selection ranges */
9280 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9282 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9283 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9285 if (lpItem
->state
& LVIS_SELECTED
)
9286 ranges_additem(infoPtr
->selectionRanges
, i
);
9288 /* restore selection mark and focused item */
9289 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9290 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9292 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9294 /* refresh the display */
9295 LISTVIEW_InvalidateList(infoPtr
);
9301 * Update theme handle after a theme change.
9304 * [I] infoPtr : valid pointer to the listview structure
9308 * FAILURE : something else
9310 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9312 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9313 CloseThemeData(theme
);
9314 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9320 * Updates an items or rearranges the listview control.
9323 * [I] infoPtr : valid pointer to the listview structure
9324 * [I] nItem : item index
9330 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9332 TRACE("(nItem=%d)\n", nItem
);
9334 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9336 /* rearrange with default alignment style */
9337 if (is_autoarrange(infoPtr
))
9338 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9340 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9347 * Draw the track line at the place defined in the infoPtr structure.
9348 * The line is drawn with a XOR pen so drawing the line for the second time
9349 * in the same place erases the line.
9352 * [I] infoPtr : valid pointer to the listview structure
9358 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9362 if (infoPtr
->xTrackLine
== -1)
9365 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9367 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9368 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9369 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9375 * Called when an edit control should be displayed. This function is called after
9376 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9379 * [I] hwnd : Handle to the listview
9380 * [I] uMsg : WM_TIMER (ignored)
9381 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9382 * [I] dwTimer : The elapsed time (ignored)
9387 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9389 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9390 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9392 KillTimer(hwnd
, idEvent
);
9393 editItem
->fEnabled
= FALSE
;
9394 /* check if the item is still selected */
9395 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9396 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9401 * Creates the listview control - the WM_NCCREATE phase.
9404 * [I] hwnd : window handle
9405 * [I] lpcs : the create parameters
9411 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9413 LISTVIEW_INFO
*infoPtr
;
9416 TRACE("(lpcs=%p)\n", lpcs
);
9418 /* initialize info pointer */
9419 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9420 if (!infoPtr
) return FALSE
;
9422 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9424 infoPtr
->hwndSelf
= hwnd
;
9425 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9426 map_style_view(infoPtr
);
9427 /* determine the type of structures to use */
9428 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9429 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9431 /* initialize color information */
9432 infoPtr
->clrBk
= CLR_NONE
;
9433 infoPtr
->clrText
= CLR_DEFAULT
;
9434 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9435 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9436 infoPtr
->bDefaultBkColor
= TRUE
;
9438 /* set default values */
9439 infoPtr
->nFocusedItem
= -1;
9440 infoPtr
->nSelectionMark
= -1;
9441 infoPtr
->nHotItem
= -1;
9442 infoPtr
->bRedraw
= TRUE
;
9443 infoPtr
->bNoItemMetrics
= TRUE
;
9444 infoPtr
->bDoChangeNotify
= TRUE
;
9445 infoPtr
->autoSpacing
= TRUE
;
9446 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9447 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9448 infoPtr
->nEditLabelItem
= -1;
9449 infoPtr
->nLButtonDownItem
= -1;
9450 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9451 infoPtr
->cWheelRemainder
= 0;
9452 infoPtr
->nMeasureItemHeight
= 0;
9453 infoPtr
->xTrackLine
= -1; /* no track line */
9454 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9455 infoPtr
->iVersion
= COMCTL32_VERSION
;
9456 infoPtr
->colRectsDirty
= FALSE
;
9458 /* get default font (icon title) */
9459 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9460 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9461 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9462 LISTVIEW_SaveTextMetrics(infoPtr
);
9464 /* allocate memory for the data structure */
9465 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9466 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9467 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9468 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9469 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9470 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9474 DestroyWindow(infoPtr
->hwndHeader
);
9475 ranges_destroy(infoPtr
->selectionRanges
);
9476 DPA_Destroy(infoPtr
->hdpaItems
);
9477 DPA_Destroy(infoPtr
->hdpaItemIds
);
9478 DPA_Destroy(infoPtr
->hdpaPosX
);
9479 DPA_Destroy(infoPtr
->hdpaPosY
);
9480 DPA_Destroy(infoPtr
->hdpaColumns
);
9487 * Creates the listview control - the WM_CREATE phase. Most of the data is
9488 * already set up in LISTVIEW_NCCreate
9491 * [I] hwnd : window handle
9492 * [I] lpcs : the create parameters
9498 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9500 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9502 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9504 infoPtr
->dwStyle
= lpcs
->style
;
9505 map_style_view(infoPtr
);
9507 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9508 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9509 /* on error defaulting to ANSI notifications */
9510 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9511 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9513 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9515 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9518 infoPtr
->hwndHeader
= 0;
9520 /* init item size to avoid division by 0 */
9521 LISTVIEW_UpdateItemSize (infoPtr
);
9522 LISTVIEW_UpdateSize (infoPtr
);
9524 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9526 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9528 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9530 LISTVIEW_UpdateScroll(infoPtr
);
9531 /* send WM_MEASUREITEM notification */
9532 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9535 OpenThemeData(hwnd
, themeClass
);
9537 /* initialize the icon sizes */
9538 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9539 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9545 * Destroys the listview control.
9548 * [I] infoPtr : valid pointer to the listview structure
9554 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9556 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9557 CloseThemeData(theme
);
9559 /* delete all items */
9560 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9567 * Enables the listview control.
9570 * [I] infoPtr : valid pointer to the listview structure
9571 * [I] bEnable : specifies whether to enable or disable the window
9577 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9579 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9580 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9586 * Erases the background of the listview control.
9589 * [I] infoPtr : valid pointer to the listview structure
9590 * [I] hdc : device context handle
9596 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9600 TRACE("(hdc=%p)\n", hdc
);
9602 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9604 if (infoPtr
->clrBk
== CLR_NONE
)
9606 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9607 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9608 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9610 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9613 /* for double buffered controls we need to do this during refresh */
9614 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9616 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9622 * Helper function for LISTVIEW_[HV]Scroll *only*.
9623 * Performs vertical/horizontal scrolling by a give amount.
9626 * [I] infoPtr : valid pointer to the listview structure
9627 * [I] dx : amount of horizontal scroll
9628 * [I] dy : amount of vertical scroll
9630 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9632 /* now we can scroll the list */
9633 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9634 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9635 /* if we have focus, adjust rect */
9636 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9637 UpdateWindow(infoPtr
->hwndSelf
);
9642 * Performs vertical scrolling.
9645 * [I] infoPtr : valid pointer to the listview structure
9646 * [I] nScrollCode : scroll code
9647 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9648 * [I] hScrollWnd : scrollbar control window handle
9654 * SB_LINEUP/SB_LINEDOWN:
9655 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9656 * for LVS_REPORT is 1 line
9657 * for LVS_LIST cannot occur
9660 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9663 INT nOldScrollPos
, nNewScrollPos
;
9664 SCROLLINFO scrollInfo
;
9667 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9668 debugscrollcode(nScrollCode
), nScrollDiff
);
9670 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9672 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9673 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9675 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9677 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9679 nOldScrollPos
= scrollInfo
.nPos
;
9680 switch (nScrollCode
)
9686 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9690 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9694 nScrollDiff
= -scrollInfo
.nPage
;
9698 nScrollDiff
= scrollInfo
.nPage
;
9701 case SB_THUMBPOSITION
:
9703 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9710 /* quit right away if pos isn't changing */
9711 if (nScrollDiff
== 0) return 0;
9713 /* calculate new position, and handle overflows */
9714 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9715 if (nScrollDiff
> 0) {
9716 if (nNewScrollPos
< nOldScrollPos
||
9717 nNewScrollPos
> scrollInfo
.nMax
)
9718 nNewScrollPos
= scrollInfo
.nMax
;
9720 if (nNewScrollPos
> nOldScrollPos
||
9721 nNewScrollPos
< scrollInfo
.nMin
)
9722 nNewScrollPos
= scrollInfo
.nMin
;
9725 /* set the new position, and reread in case it changed */
9726 scrollInfo
.fMask
= SIF_POS
;
9727 scrollInfo
.nPos
= nNewScrollPos
;
9728 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9730 /* carry on only if it really changed */
9731 if (nNewScrollPos
== nOldScrollPos
) return 0;
9733 /* now adjust to client coordinates */
9734 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9735 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9737 /* and scroll the window */
9738 scroll_list(infoPtr
, 0, nScrollDiff
);
9745 * Performs horizontal scrolling.
9748 * [I] infoPtr : valid pointer to the listview structure
9749 * [I] nScrollCode : scroll code
9750 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9751 * [I] hScrollWnd : scrollbar control window handle
9757 * SB_LINELEFT/SB_LINERIGHT:
9758 * for LVS_ICON, LVS_SMALLICON 1 pixel
9759 * for LVS_REPORT is 1 pixel
9760 * for LVS_LIST is 1 column --> which is a 1 because the
9761 * scroll is based on columns not pixels
9764 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9767 INT nOldScrollPos
, nNewScrollPos
;
9768 SCROLLINFO scrollInfo
;
9771 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9772 debugscrollcode(nScrollCode
), nScrollDiff
);
9774 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9776 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9777 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9779 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9781 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9783 nOldScrollPos
= scrollInfo
.nPos
;
9785 switch (nScrollCode
)
9791 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9795 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9799 nScrollDiff
= -scrollInfo
.nPage
;
9803 nScrollDiff
= scrollInfo
.nPage
;
9806 case SB_THUMBPOSITION
:
9808 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9815 /* quit right away if pos isn't changing */
9816 if (nScrollDiff
== 0) return 0;
9818 /* calculate new position, and handle overflows */
9819 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9820 if (nScrollDiff
> 0) {
9821 if (nNewScrollPos
< nOldScrollPos
||
9822 nNewScrollPos
> scrollInfo
.nMax
)
9823 nNewScrollPos
= scrollInfo
.nMax
;
9825 if (nNewScrollPos
> nOldScrollPos
||
9826 nNewScrollPos
< scrollInfo
.nMin
)
9827 nNewScrollPos
= scrollInfo
.nMin
;
9830 /* set the new position, and reread in case it changed */
9831 scrollInfo
.fMask
= SIF_POS
;
9832 scrollInfo
.nPos
= nNewScrollPos
;
9833 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9835 /* carry on only if it really changed */
9836 if (nNewScrollPos
== nOldScrollPos
) return 0;
9838 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9840 /* now adjust to client coordinates */
9841 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9842 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9844 /* and scroll the window */
9845 scroll_list(infoPtr
, nScrollDiff
, 0);
9850 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9852 UINT pulScrollLines
= 3;
9854 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9856 switch(infoPtr
->uView
)
9859 case LV_VIEW_SMALLICON
:
9861 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9862 * should be fixed in the future.
9864 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9865 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9868 case LV_VIEW_DETAILS
:
9869 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9871 /* if scrolling changes direction, ignore left overs */
9872 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9873 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9874 infoPtr
->cWheelRemainder
+= wheelDelta
;
9876 infoPtr
->cWheelRemainder
= wheelDelta
;
9877 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9880 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9881 cLineScroll
= pulScrollLines
* (float)infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9882 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
9883 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9888 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9899 * [I] infoPtr : valid pointer to the listview structure
9900 * [I] nVirtualKey : virtual key
9901 * [I] lKeyData : key data
9906 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9908 HWND hwndSelf
= infoPtr
->hwndSelf
;
9910 NMLVKEYDOWN nmKeyDown
;
9912 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9914 /* send LVN_KEYDOWN notification */
9915 nmKeyDown
.wVKey
= nVirtualKey
;
9916 nmKeyDown
.flags
= 0;
9917 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9918 if (!IsWindow(hwndSelf
))
9921 switch (nVirtualKey
)
9924 nItem
= infoPtr
->nFocusedItem
;
9925 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9926 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9930 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9932 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9933 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9938 if (infoPtr
->nItemCount
> 0)
9943 if (infoPtr
->nItemCount
> 0)
9944 nItem
= infoPtr
->nItemCount
- 1;
9948 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9952 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9956 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9960 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9964 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9966 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9967 if (infoPtr
->nFocusedItem
== topidx
)
9968 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9973 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9974 * LISTVIEW_GetCountPerRow(infoPtr
);
9975 if(nItem
< 0) nItem
= 0;
9979 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9981 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9982 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9983 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9984 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9986 nItem
= topidx
+ cnt
- 1;
9989 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9990 * LISTVIEW_GetCountPerRow(infoPtr
);
9991 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9995 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9996 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10006 * [I] infoPtr : valid pointer to the listview structure
10011 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10015 /* drop any left over scroll amount */
10016 infoPtr
->cWheelRemainder
= 0;
10018 /* if we did not have the focus, there's nothing more to do */
10019 if (!infoPtr
->bFocus
) return 0;
10021 /* send NM_KILLFOCUS notification */
10022 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10024 /* if we have a focus rectangle, get rid of it */
10025 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10027 /* if have a marquee selection, stop it */
10028 if (infoPtr
->bMarqueeSelect
)
10030 /* Remove the marquee rectangle and release our mouse capture */
10031 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10034 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10036 infoPtr
->bMarqueeSelect
= FALSE
;
10037 infoPtr
->bScrolling
= FALSE
;
10038 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10041 /* set window focus flag */
10042 infoPtr
->bFocus
= FALSE
;
10044 /* invalidate the selected items before resetting focus flag */
10045 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10052 * Processes double click messages (left mouse button).
10055 * [I] infoPtr : valid pointer to the listview structure
10056 * [I] wKey : key flag
10057 * [I] x,y : mouse coordinate
10062 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10064 LVHITTESTINFO htInfo
;
10066 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10068 /* Cancel the item edition if any */
10069 if (infoPtr
->itemEdit
.fEnabled
)
10071 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10072 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10075 /* send NM_RELEASEDCAPTURE notification */
10076 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10081 /* send NM_DBLCLK notification */
10082 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10083 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10085 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10086 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10091 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10096 r
.top
= r
.bottom
= pt
.y
;
10097 r
.left
= r
.right
= pt
.x
;
10099 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10101 SetCapture(infoPtr
->hwndSelf
);
10105 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10107 if (msg
.message
== WM_MOUSEMOVE
)
10109 pt
.x
= (short)LOWORD(msg
.lParam
);
10110 pt
.y
= (short)HIWORD(msg
.lParam
);
10111 if (PtInRect(&r
, pt
))
10119 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10120 msg
.message
<= WM_RBUTTONDBLCLK
)
10125 DispatchMessageW(&msg
);
10128 if (GetCapture() != infoPtr
->hwndSelf
)
10139 * Processes mouse down messages (left mouse button).
10142 * infoPtr [I ] valid pointer to the listview structure
10143 * wKey [I ] key flag
10144 * x,y [I ] mouse coordinate
10149 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10151 LVHITTESTINFO lvHitTestInfo
;
10152 static BOOL bGroupSelect
= TRUE
;
10153 POINT pt
= { x
, y
};
10156 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10158 /* send NM_RELEASEDCAPTURE notification */
10159 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10161 /* set left button down flag and record the click position */
10162 infoPtr
->bLButtonDown
= TRUE
;
10163 infoPtr
->ptClickPos
= pt
;
10164 infoPtr
->bDragging
= FALSE
;
10165 infoPtr
->bMarqueeSelect
= FALSE
;
10166 infoPtr
->bScrolling
= FALSE
;
10168 lvHitTestInfo
.pt
.x
= x
;
10169 lvHitTestInfo
.pt
.y
= y
;
10171 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10172 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10173 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10175 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10177 toggle_checkbox_state(infoPtr
, nItem
);
10181 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10183 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10184 infoPtr
->nEditLabelItem
= nItem
;
10186 LISTVIEW_SetSelection(infoPtr
, nItem
);
10190 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10194 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10195 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10196 infoPtr
->nSelectionMark
= nItem
;
10202 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10203 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10205 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10206 infoPtr
->nSelectionMark
= nItem
;
10209 else if (wKey
& MK_CONTROL
)
10213 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10215 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10216 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10217 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10218 infoPtr
->nSelectionMark
= nItem
;
10220 else if (wKey
& MK_SHIFT
)
10222 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10226 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10228 infoPtr
->nEditLabelItem
= nItem
;
10229 infoPtr
->nLButtonDownItem
= nItem
;
10231 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10234 /* set selection (clears other pre-existing selections) */
10235 LISTVIEW_SetSelection(infoPtr
, nItem
);
10239 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10240 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10244 if (!infoPtr
->bFocus
)
10245 SetFocus(infoPtr
->hwndSelf
);
10247 /* remove all selections */
10248 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10249 LISTVIEW_DeselectAll(infoPtr
);
10258 * Processes mouse up messages (left mouse button).
10261 * infoPtr [I ] valid pointer to the listview structure
10262 * wKey [I ] key flag
10263 * x,y [I ] mouse coordinate
10268 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10270 LVHITTESTINFO lvHitTestInfo
;
10272 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10274 if (!infoPtr
->bLButtonDown
) return 0;
10276 lvHitTestInfo
.pt
.x
= x
;
10277 lvHitTestInfo
.pt
.y
= y
;
10279 /* send NM_CLICK notification */
10280 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10281 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10283 /* set left button flag */
10284 infoPtr
->bLButtonDown
= FALSE
;
10286 /* set a single selection, reset others */
10287 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10288 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10289 infoPtr
->nLButtonDownItem
= -1;
10291 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10293 /* Remove the marquee rectangle and release our mouse capture */
10294 if (infoPtr
->bMarqueeSelect
)
10296 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10300 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10301 SetRect(&infoPtr
->marqueeDrawRect
, 0, 0, 0, 0);
10303 infoPtr
->bDragging
= FALSE
;
10304 infoPtr
->bMarqueeSelect
= FALSE
;
10305 infoPtr
->bScrolling
= FALSE
;
10307 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10311 /* if we clicked on a selected item, edit the label */
10312 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10314 /* we want to make sure the user doesn't want to do a double click. So we will
10315 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10317 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10318 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10319 SetTimer(infoPtr
->hwndSelf
,
10320 (UINT_PTR
)&infoPtr
->itemEdit
,
10321 GetDoubleClickTime(),
10322 LISTVIEW_DelayedEditItem
);
10325 if (!infoPtr
->bFocus
)
10326 SetFocus(infoPtr
->hwndSelf
);
10333 * Destroys the listview control (called after WM_DESTROY).
10336 * [I] infoPtr : valid pointer to the listview structure
10341 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10347 /* destroy data structure */
10348 DPA_Destroy(infoPtr
->hdpaItems
);
10349 DPA_Destroy(infoPtr
->hdpaItemIds
);
10350 DPA_Destroy(infoPtr
->hdpaPosX
);
10351 DPA_Destroy(infoPtr
->hdpaPosY
);
10353 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10354 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10355 DPA_Destroy(infoPtr
->hdpaColumns
);
10356 ranges_destroy(infoPtr
->selectionRanges
);
10358 /* destroy image lists */
10359 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10361 ImageList_Destroy(infoPtr
->himlNormal
);
10362 ImageList_Destroy(infoPtr
->himlSmall
);
10363 ImageList_Destroy(infoPtr
->himlState
);
10366 /* destroy font, bkgnd brush */
10367 infoPtr
->hFont
= 0;
10368 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10369 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10371 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10373 /* free listview info pointer*/
10381 * Handles notifications.
10384 * [I] infoPtr : valid pointer to the listview structure
10385 * [I] lpnmhdr : notification information
10390 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10394 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10396 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10398 /* remember: HDN_LAST < HDN_FIRST */
10399 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10400 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10402 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10404 switch (lpnmhdr
->code
)
10409 COLUMN_INFO
*lpColumnInfo
;
10413 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10416 /* remove the old line (if any) */
10417 LISTVIEW_DrawTrackLine(infoPtr
);
10419 /* compute & draw the new line */
10420 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10421 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10422 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10423 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10424 LISTVIEW_DrawTrackLine(infoPtr
);
10425 return notify_forward_header(infoPtr
, lpnmh
);
10428 case HDN_ENDTRACKA
:
10429 case HDN_ENDTRACKW
:
10430 /* remove the track line (if any) */
10431 LISTVIEW_DrawTrackLine(infoPtr
);
10432 infoPtr
->xTrackLine
= -1;
10433 return notify_forward_header(infoPtr
, lpnmh
);
10435 case HDN_BEGINDRAG
:
10436 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10437 return notify_forward_header(infoPtr
, lpnmh
);
10440 infoPtr
->colRectsDirty
= TRUE
;
10441 LISTVIEW_InvalidateList(infoPtr
);
10442 return notify_forward_header(infoPtr
, lpnmh
);
10444 case HDN_ITEMCHANGEDW
:
10445 case HDN_ITEMCHANGEDA
:
10447 COLUMN_INFO
*lpColumnInfo
;
10451 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10453 hdi
.mask
= HDI_WIDTH
;
10454 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10458 cxy
= lpnmh
->pitem
->cxy
;
10460 /* determine how much we change since the last know position */
10461 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10462 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10465 lpColumnInfo
->rcHeader
.right
+= dx
;
10467 hdi
.mask
= HDI_ORDER
;
10468 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10470 /* not the rightmost one */
10471 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10473 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10474 hdi
.iOrder
+ 1, 0);
10475 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10479 /* only needs to update the scrolls */
10480 infoPtr
->nItemWidth
+= dx
;
10481 LISTVIEW_UpdateScroll(infoPtr
);
10483 LISTVIEW_UpdateItemSize(infoPtr
);
10484 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10487 RECT rcCol
= lpColumnInfo
->rcHeader
;
10489 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10490 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10492 rcCol
.top
= infoPtr
->rcList
.top
;
10493 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10495 /* resizing left-aligned columns leaves most of the left side untouched */
10496 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10498 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10501 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10504 /* when shrinking the last column clear the now unused field */
10505 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10511 /* deal with right from rightmost column area */
10512 right
.left
= rcCol
.right
;
10513 right
.top
= rcCol
.top
;
10514 right
.bottom
= rcCol
.bottom
;
10515 right
.right
= infoPtr
->rcList
.right
;
10517 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10520 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10526 case HDN_ITEMCLICKW
:
10527 case HDN_ITEMCLICKA
:
10529 /* Handle sorting by Header Column */
10532 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10534 nmlv
.iSubItem
= lpnmh
->iItem
;
10535 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10536 return notify_forward_header(infoPtr
, lpnmh
);
10539 case HDN_DIVIDERDBLCLICKW
:
10540 case HDN_DIVIDERDBLCLICKA
:
10541 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10542 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10543 split needed for that */
10544 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10545 return notify_forward_header(infoPtr
, lpnmh
);
10552 * Paint non-client area of control.
10555 * [I] infoPtr : valid pointer to the listview structureof the sender
10556 * [I] region : update region
10559 * TRUE - frame was painted
10560 * FALSE - call default window proc
10562 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10564 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10568 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10569 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10572 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10574 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10576 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10577 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10578 if (region
!= (HRGN
)1)
10579 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10580 OffsetRect(&r
, -r
.left
, -r
.top
);
10582 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10583 OffsetRect(&r
, -r
.left
, -r
.top
);
10585 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10586 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10587 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10588 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10590 /* Call default proc to get the scrollbars etc. painted */
10591 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10598 * Determines the type of structure to use.
10601 * [I] infoPtr : valid pointer to the listview structureof the sender
10602 * [I] hwndFrom : listview window handle
10603 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10608 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10610 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10612 if (nCommand
== NF_REQUERY
)
10613 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10615 return infoPtr
->notifyFormat
;
10620 * Paints/Repaints the listview control. Internal use.
10623 * [I] infoPtr : valid pointer to the listview structure
10624 * [I] hdc : device context handle
10629 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10631 TRACE("(hdc=%p)\n", hdc
);
10633 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10635 infoPtr
->bNoItemMetrics
= FALSE
;
10636 LISTVIEW_UpdateItemSize(infoPtr
);
10637 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10638 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10639 LISTVIEW_UpdateScroll(infoPtr
);
10642 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10645 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10650 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10651 if (!hdc
) return 1;
10652 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10653 EndPaint(infoPtr
->hwndSelf
, &ps
);
10661 * Paints/Repaints the listview control, WM_PAINT handler.
10664 * [I] infoPtr : valid pointer to the listview structure
10665 * [I] hdc : device context handle
10670 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10672 TRACE("(hdc=%p)\n", hdc
);
10674 if (!is_redrawing(infoPtr
))
10675 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10677 return LISTVIEW_Paint(infoPtr
, hdc
);
10682 * Paints/Repaints the listview control.
10685 * [I] infoPtr : valid pointer to the listview structure
10686 * [I] hdc : device context handle
10687 * [I] options : drawing options
10692 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10694 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10696 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10699 if (options
& PRF_ERASEBKGND
)
10700 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10702 if (options
& PRF_CLIENT
)
10703 LISTVIEW_Paint(infoPtr
, hdc
);
10711 * Processes double click messages (right mouse button).
10714 * [I] infoPtr : valid pointer to the listview structure
10715 * [I] wKey : key flag
10716 * [I] x,y : mouse coordinate
10721 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10723 LVHITTESTINFO lvHitTestInfo
;
10725 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10727 /* send NM_RELEASEDCAPTURE notification */
10728 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10730 /* send NM_RDBLCLK notification */
10731 lvHitTestInfo
.pt
.x
= x
;
10732 lvHitTestInfo
.pt
.y
= y
;
10733 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10734 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10741 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10744 * [I] infoPtr : valid pointer to the listview structure
10745 * [I] wKey : key flag
10746 * [I] x, y : mouse coordinate
10751 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10756 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10758 /* send NM_RELEASEDCAPTURE notification */
10759 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10761 /* determine the index of the selected item */
10764 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10766 /* make sure the listview control window has the focus */
10767 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10769 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10771 LISTVIEW_SetItemFocus(infoPtr
, item
);
10772 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10773 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10774 LISTVIEW_SetSelection(infoPtr
, item
);
10777 LISTVIEW_DeselectAll(infoPtr
);
10779 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10781 if (ht
.iItem
!= -1)
10785 memset(&nmlv
, 0, sizeof(nmlv
));
10786 nmlv
.iItem
= ht
.iItem
;
10787 nmlv
.ptAction
= ht
.pt
;
10789 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10794 SetFocus(infoPtr
->hwndSelf
);
10798 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10800 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10802 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10803 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10804 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10816 * [I] infoPtr : valid pointer to the listview structure
10817 * [I] hwnd : window handle of window containing the cursor
10818 * [I] nHittest : hit-test code
10819 * [I] wMouseMsg : ideintifier of the mouse message
10822 * TRUE if cursor is set
10825 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10827 LVHITTESTINFO lvHitTestInfo
;
10829 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10831 if (!infoPtr
->hHotCursor
) goto forward
;
10833 GetCursorPos(&lvHitTestInfo
.pt
);
10834 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10836 SetCursor(infoPtr
->hHotCursor
);
10842 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10850 * [I] infoPtr : valid pointer to the listview structure
10851 * [I] hwndLoseFocus : handle of previously focused window
10856 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10858 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10860 /* if we have the focus already, there's nothing to do */
10861 if (infoPtr
->bFocus
) return 0;
10863 /* send NM_SETFOCUS notification */
10864 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10866 /* set window focus flag */
10867 infoPtr
->bFocus
= TRUE
;
10869 /* put the focus rect back on */
10870 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10872 /* redraw all visible selected items */
10873 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10883 * [I] infoPtr : valid pointer to the listview structure
10884 * [I] fRedraw : font handle
10885 * [I] fRedraw : redraw flag
10890 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10892 HFONT oldFont
= infoPtr
->hFont
;
10893 INT oldHeight
= infoPtr
->nItemHeight
;
10895 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10897 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10898 if (infoPtr
->hFont
== oldFont
) return 0;
10900 LISTVIEW_SaveTextMetrics(infoPtr
);
10902 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10904 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10906 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10907 LISTVIEW_UpdateSize(infoPtr
);
10908 LISTVIEW_UpdateScroll(infoPtr
);
10910 else if (infoPtr
->nItemHeight
!= oldHeight
)
10911 LISTVIEW_UpdateScroll(infoPtr
);
10913 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10920 * Message handling for WM_SETREDRAW.
10921 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10924 * [I] infoPtr : valid pointer to the listview structure
10925 * [I] bRedraw: state of redraw flag
10928 * DefWinProc return value
10930 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10932 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10934 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10935 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10937 infoPtr
->bRedraw
= bRedraw
;
10939 if(!bRedraw
) return 0;
10941 if (is_autoarrange(infoPtr
))
10942 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10943 LISTVIEW_UpdateScroll(infoPtr
);
10945 /* despite what the WM_SETREDRAW docs says, apps expect us
10946 * to invalidate the listview here... stupid! */
10947 LISTVIEW_InvalidateList(infoPtr
);
10954 * Resizes the listview control. This function processes WM_SIZE
10955 * messages. At this time, the width and height are not used.
10958 * [I] infoPtr : valid pointer to the listview structure
10959 * [I] Width : new width
10960 * [I] Height : new height
10965 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10967 RECT rcOld
= infoPtr
->rcList
;
10969 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10971 LISTVIEW_UpdateSize(infoPtr
);
10972 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10974 /* do not bother with display related stuff if we're not redrawing */
10975 if (!is_redrawing(infoPtr
)) return 0;
10977 if (is_autoarrange(infoPtr
))
10978 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10980 LISTVIEW_UpdateScroll(infoPtr
);
10982 /* refresh all only for lists whose height changed significantly */
10983 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10984 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10985 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10986 LISTVIEW_InvalidateList(infoPtr
);
10993 * Sets the size information.
10996 * [I] infoPtr : valid pointer to the listview structure
11001 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11003 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11005 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11007 if (infoPtr
->uView
== LV_VIEW_LIST
)
11009 /* Apparently the "LIST" style is supposed to have the same
11010 * number of items in a column even if there is no scroll bar.
11011 * Since if a scroll bar already exists then the bottom is already
11012 * reduced, only reduce if the scroll bar does not currently exist.
11013 * The "2" is there to mimic the native control. I think it may be
11014 * related to either padding or edges. (GLA 7/2002)
11016 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11017 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11018 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11021 /* if control created invisible header isn't created */
11022 if (infoPtr
->hwndHeader
)
11027 hl
.prc
= &infoPtr
->rcList
;
11029 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11030 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11032 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11033 wp
.flags
|= SWP_SHOWWINDOW
;
11036 wp
.flags
|= SWP_HIDEWINDOW
;
11040 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11041 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11043 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11045 /* extra padding for grid */
11046 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11047 infoPtr
->rcList
.top
+= 2;
11049 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11054 * Processes WM_STYLECHANGED messages.
11057 * [I] infoPtr : valid pointer to the listview structure
11058 * [I] wStyleType : window style type (normal or extended)
11059 * [I] lpss : window style information
11064 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11065 const STYLESTRUCT
*lpss
)
11067 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11068 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11071 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11072 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11074 if (wStyleType
!= GWL_STYLE
) return 0;
11076 infoPtr
->dwStyle
= lpss
->styleNew
;
11077 map_style_view(infoPtr
);
11079 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11080 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11081 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11083 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11084 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11085 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11087 if (uNewView
!= uOldView
)
11091 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11092 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11094 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11095 SetRectEmpty(&infoPtr
->rcFocus
);
11097 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11098 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11100 if (uNewView
== LVS_REPORT
)
11105 LISTVIEW_CreateHeader( infoPtr
);
11107 hl
.prc
= &infoPtr
->rcList
;
11109 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11110 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11111 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11112 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11115 LISTVIEW_UpdateItemSize(infoPtr
);
11118 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11120 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11122 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11124 /* Turn off the header control */
11125 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11126 TRACE("Hide header control, was 0x%08x\n", style
);
11127 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11129 /* Turn on the header control */
11130 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11132 TRACE("Show header control, was 0x%08x\n", style
);
11133 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11139 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11140 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11141 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11143 /* update the size of the client area */
11144 LISTVIEW_UpdateSize(infoPtr
);
11146 /* add scrollbars if needed */
11147 LISTVIEW_UpdateScroll(infoPtr
);
11149 /* invalidate client area + erase background */
11150 LISTVIEW_InvalidateList(infoPtr
);
11157 * Processes WM_STYLECHANGING messages.
11160 * [I] wStyleType : window style type (normal or extended)
11161 * [I0] lpss : window style information
11166 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11169 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11170 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11172 /* don't forward LVS_OWNERDATA only if not already set to */
11173 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11175 if (lpss
->styleOld
& LVS_OWNERDATA
)
11176 lpss
->styleNew
|= LVS_OWNERDATA
;
11178 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11186 * Processes WM_SHOWWINDOW messages.
11189 * [I] infoPtr : valid pointer to the listview structure
11190 * [I] bShown : window is being shown (FALSE when hidden)
11191 * [I] iStatus : window show status
11196 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11198 /* header delayed creation */
11199 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11201 LISTVIEW_CreateHeader(infoPtr
);
11203 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11204 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11207 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11212 * Processes CCM_GETVERSION messages.
11215 * [I] infoPtr : valid pointer to the listview structure
11220 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11222 return infoPtr
->iVersion
;
11227 * Processes CCM_SETVERSION messages.
11230 * [I] infoPtr : valid pointer to the listview structure
11231 * [I] iVersion : version to be set
11234 * -1 when requested version is greater than DLL version;
11235 * previous version otherwise
11237 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11239 INT iOldVersion
= infoPtr
->iVersion
;
11241 if (iVersion
> COMCTL32_VERSION
)
11244 infoPtr
->iVersion
= iVersion
;
11246 TRACE("new version %d\n", iVersion
);
11248 return iOldVersion
;
11253 * Window procedure of the listview control.
11256 static LRESULT WINAPI
11257 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11259 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11261 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11263 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11264 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11268 case LVM_APPROXIMATEVIEWRECT
:
11269 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11270 LOWORD(lParam
), HIWORD(lParam
));
11272 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11274 case LVM_CANCELEDITLABEL
:
11275 return LISTVIEW_CancelEditLabel(infoPtr
);
11277 case LVM_CREATEDRAGIMAGE
:
11278 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11280 case LVM_DELETEALLITEMS
:
11281 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11283 case LVM_DELETECOLUMN
:
11284 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11286 case LVM_DELETEITEM
:
11287 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11289 case LVM_EDITLABELA
:
11290 case LVM_EDITLABELW
:
11291 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11292 uMsg
== LVM_EDITLABELW
);
11293 /* case LVM_ENABLEGROUPVIEW: */
11295 case LVM_ENSUREVISIBLE
:
11296 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11298 case LVM_FINDITEMW
:
11299 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11301 case LVM_FINDITEMA
:
11302 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11304 case LVM_GETBKCOLOR
:
11305 return infoPtr
->clrBk
;
11307 /* case LVM_GETBKIMAGE: */
11309 case LVM_GETCALLBACKMASK
:
11310 return infoPtr
->uCallbackMask
;
11312 case LVM_GETCOLUMNA
:
11313 case LVM_GETCOLUMNW
:
11314 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11315 uMsg
== LVM_GETCOLUMNW
);
11317 case LVM_GETCOLUMNORDERARRAY
:
11318 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11320 case LVM_GETCOLUMNWIDTH
:
11321 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11323 case LVM_GETCOUNTPERPAGE
:
11324 return LISTVIEW_GetCountPerPage(infoPtr
);
11326 case LVM_GETEDITCONTROL
:
11327 return (LRESULT
)infoPtr
->hwndEdit
;
11329 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11330 return infoPtr
->dwLvExStyle
;
11332 /* case LVM_GETGROUPINFO: */
11334 /* case LVM_GETGROUPMETRICS: */
11336 case LVM_GETHEADER
:
11337 return (LRESULT
)infoPtr
->hwndHeader
;
11339 case LVM_GETHOTCURSOR
:
11340 return (LRESULT
)infoPtr
->hHotCursor
;
11342 case LVM_GETHOTITEM
:
11343 return infoPtr
->nHotItem
;
11345 case LVM_GETHOVERTIME
:
11346 return infoPtr
->dwHoverTime
;
11348 case LVM_GETIMAGELIST
:
11349 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11351 /* case LVM_GETINSERTMARK: */
11353 /* case LVM_GETINSERTMARKCOLOR: */
11355 /* case LVM_GETINSERTMARKRECT: */
11357 case LVM_GETISEARCHSTRINGA
:
11358 case LVM_GETISEARCHSTRINGW
:
11359 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11364 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11366 case LVM_GETITEMCOUNT
:
11367 return infoPtr
->nItemCount
;
11369 case LVM_GETITEMPOSITION
:
11370 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11372 case LVM_GETITEMRECT
:
11373 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11375 case LVM_GETITEMSPACING
:
11376 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11378 case LVM_GETITEMSTATE
:
11379 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11381 case LVM_GETITEMTEXTA
:
11382 case LVM_GETITEMTEXTW
:
11383 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11384 uMsg
== LVM_GETITEMTEXTW
);
11386 case LVM_GETNEXTITEM
:
11387 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11389 case LVM_GETNUMBEROFWORKAREAS
:
11390 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11393 case LVM_GETORIGIN
:
11394 if (!lParam
) return FALSE
;
11395 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11396 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11397 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11400 /* case LVM_GETOUTLINECOLOR: */
11402 /* case LVM_GETSELECTEDCOLUMN: */
11404 case LVM_GETSELECTEDCOUNT
:
11405 return LISTVIEW_GetSelectedCount(infoPtr
);
11407 case LVM_GETSELECTIONMARK
:
11408 return infoPtr
->nSelectionMark
;
11410 case LVM_GETSTRINGWIDTHA
:
11411 case LVM_GETSTRINGWIDTHW
:
11412 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11413 uMsg
== LVM_GETSTRINGWIDTHW
);
11415 case LVM_GETSUBITEMRECT
:
11416 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11418 case LVM_GETTEXTBKCOLOR
:
11419 return infoPtr
->clrTextBk
;
11421 case LVM_GETTEXTCOLOR
:
11422 return infoPtr
->clrText
;
11424 /* case LVM_GETTILEINFO: */
11426 /* case LVM_GETTILEVIEWINFO: */
11428 case LVM_GETTOOLTIPS
:
11429 if( !infoPtr
->hwndToolTip
)
11430 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11431 return (LRESULT
)infoPtr
->hwndToolTip
;
11433 case LVM_GETTOPINDEX
:
11434 return LISTVIEW_GetTopIndex(infoPtr
);
11436 case LVM_GETUNICODEFORMAT
:
11437 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11440 return infoPtr
->uView
;
11442 case LVM_GETVIEWRECT
:
11443 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11445 case LVM_GETWORKAREAS
:
11446 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11449 /* case LVM_HASGROUP: */
11452 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11454 case LVM_INSERTCOLUMNA
:
11455 case LVM_INSERTCOLUMNW
:
11456 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11457 uMsg
== LVM_INSERTCOLUMNW
);
11459 /* case LVM_INSERTGROUP: */
11461 /* case LVM_INSERTGROUPSORTED: */
11463 case LVM_INSERTITEMA
:
11464 case LVM_INSERTITEMW
:
11465 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11467 /* case LVM_INSERTMARKHITTEST: */
11469 /* case LVM_ISGROUPVIEWENABLED: */
11471 case LVM_ISITEMVISIBLE
:
11472 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11474 case LVM_MAPIDTOINDEX
:
11475 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11477 case LVM_MAPINDEXTOID
:
11478 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11480 /* case LVM_MOVEGROUP: */
11482 /* case LVM_MOVEITEMTOGROUP: */
11484 case LVM_REDRAWITEMS
:
11485 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11487 /* case LVM_REMOVEALLGROUPS: */
11489 /* case LVM_REMOVEGROUP: */
11492 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11494 case LVM_SETBKCOLOR
:
11495 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11497 /* case LVM_SETBKIMAGE: */
11499 case LVM_SETCALLBACKMASK
:
11500 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11503 case LVM_SETCOLUMNA
:
11504 case LVM_SETCOLUMNW
:
11505 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11506 uMsg
== LVM_SETCOLUMNW
);
11508 case LVM_SETCOLUMNORDERARRAY
:
11509 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11511 case LVM_SETCOLUMNWIDTH
:
11512 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11514 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11515 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11517 /* case LVM_SETGROUPINFO: */
11519 /* case LVM_SETGROUPMETRICS: */
11521 case LVM_SETHOTCURSOR
:
11522 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11524 case LVM_SETHOTITEM
:
11525 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11527 case LVM_SETHOVERTIME
:
11528 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11530 case LVM_SETICONSPACING
:
11532 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11533 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11535 case LVM_SETIMAGELIST
:
11536 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11538 /* case LVM_SETINFOTIP: */
11540 /* case LVM_SETINSERTMARK: */
11542 /* case LVM_SETINSERTMARKCOLOR: */
11547 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11548 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11551 case LVM_SETITEMCOUNT
:
11552 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11554 case LVM_SETITEMPOSITION
:
11557 pt
.x
= (short)LOWORD(lParam
);
11558 pt
.y
= (short)HIWORD(lParam
);
11559 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11562 case LVM_SETITEMPOSITION32
:
11563 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11565 case LVM_SETITEMSTATE
:
11566 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11568 case LVM_SETITEMTEXTA
:
11569 case LVM_SETITEMTEXTW
:
11570 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11571 uMsg
== LVM_SETITEMTEXTW
);
11573 /* case LVM_SETOUTLINECOLOR: */
11575 /* case LVM_SETSELECTEDCOLUMN: */
11577 case LVM_SETSELECTIONMARK
:
11578 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11580 case LVM_SETTEXTBKCOLOR
:
11581 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11583 case LVM_SETTEXTCOLOR
:
11584 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11586 /* case LVM_SETTILEINFO: */
11588 /* case LVM_SETTILEVIEWINFO: */
11590 /* case LVM_SETTILEWIDTH: */
11592 case LVM_SETTOOLTIPS
:
11593 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11595 case LVM_SETUNICODEFORMAT
:
11596 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11599 return LISTVIEW_SetView(infoPtr
, wParam
);
11601 /* case LVM_SETWORKAREAS: */
11603 /* case LVM_SORTGROUPS: */
11605 case LVM_SORTITEMS
:
11606 case LVM_SORTITEMSEX
:
11607 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11608 uMsg
== LVM_SORTITEMSEX
);
11609 case LVM_SUBITEMHITTEST
:
11610 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11613 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11615 case CCM_GETVERSION
:
11616 return LISTVIEW_GetVersion(infoPtr
);
11618 case CCM_SETVERSION
:
11619 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11622 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11625 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11628 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11631 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11634 return LISTVIEW_Destroy(infoPtr
);
11637 return LISTVIEW_Enable(infoPtr
);
11639 case WM_ERASEBKGND
:
11640 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11642 case WM_GETDLGCODE
:
11643 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11646 return (LRESULT
)infoPtr
->hFont
;
11649 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11652 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11655 return LISTVIEW_KillFocus(infoPtr
);
11657 case WM_LBUTTONDBLCLK
:
11658 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11660 case WM_LBUTTONDOWN
:
11661 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11664 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11667 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11669 case WM_MOUSEHOVER
:
11670 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11673 return LISTVIEW_NCDestroy(infoPtr
);
11676 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11679 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11681 case WM_NOTIFYFORMAT
:
11682 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11684 case WM_PRINTCLIENT
:
11685 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11688 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11690 case WM_RBUTTONDBLCLK
:
11691 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11693 case WM_RBUTTONDOWN
:
11694 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11697 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11700 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11703 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11706 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11708 case WM_SHOWWINDOW
:
11709 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11711 case WM_STYLECHANGED
:
11712 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11714 case WM_STYLECHANGING
:
11715 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11717 case WM_SYSCOLORCHANGE
:
11718 COMCTL32_RefreshSysColors();
11719 if (infoPtr
->bDefaultBkColor
)
11721 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
11722 infoPtr
->bDefaultBkColor
= TRUE
;
11723 LISTVIEW_InvalidateList(infoPtr
);
11727 /* case WM_TIMER: */
11728 case WM_THEMECHANGED
:
11729 return LISTVIEW_ThemeChanged(infoPtr
);
11732 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11734 case WM_MOUSEWHEEL
:
11735 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11736 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11737 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11739 case WM_WINDOWPOSCHANGED
:
11740 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11742 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11743 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11745 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11747 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11749 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11751 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11753 /* case WM_WININICHANGE: */
11756 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11757 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11759 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11766 * Registers the window class.
11774 void LISTVIEW_Register(void)
11776 WNDCLASSW wndClass
;
11778 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11779 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11780 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11781 wndClass
.cbClsExtra
= 0;
11782 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11783 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11784 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11785 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11786 RegisterClassW(&wndClass
);
11791 * Unregisters the window class.
11799 void LISTVIEW_Unregister(void)
11801 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11806 * Handle any WM_COMMAND messages
11809 * [I] infoPtr : valid pointer to the listview structure
11810 * [I] wParam : the first message parameter
11811 * [I] lParam : the second message parameter
11816 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11819 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11821 if (!infoPtr
->hwndEdit
) return 0;
11823 switch (HIWORD(wParam
))
11828 * Adjust the edit window size
11830 WCHAR buffer
[1024];
11831 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11832 HFONT hFont
, hOldFont
= 0;
11836 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11837 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11838 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11840 /* Select font to get the right dimension of the string */
11841 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11844 hOldFont
= SelectObject(hdc
, hFont
);
11847 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11849 TEXTMETRICW textMetric
;
11851 /* Add Extra spacing for the next character */
11852 GetTextMetricsW(hdc
, &textMetric
);
11853 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11855 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11856 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11859 SelectObject(hdc
, hOldFont
);
11861 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11867 LISTVIEW_CancelEditLabel(infoPtr
);
11872 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);