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
138 #include "wine/port.h"
153 #include "commctrl.h"
154 #include "comctl32.h"
157 #include "wine/debug.h"
158 #include "wine/unicode.h"
160 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
162 typedef struct tagCOLUMN_INFO
164 RECT rcHeader
; /* tracks the header's rectangle */
165 INT fmt
; /* same as LVCOLUMN.fmt */
169 typedef struct tagITEMHDR
173 } ITEMHDR
, *LPITEMHDR
;
175 typedef struct tagSUBITEM_INFO
181 typedef struct tagITEM_ID ITEM_ID
;
183 typedef struct tagITEM_INFO
194 UINT id
; /* item id */
195 HDPA item
; /* link to item data */
198 typedef struct tagRANGE
204 typedef struct tagRANGES
209 typedef struct tagITERATOR
218 typedef struct tagDELAYED_ITEM_EDIT
224 typedef struct tagLISTVIEW_INFO
228 RECT rcList
; /* This rectangle is really the window
229 * client rectangle possibly reduced by the
230 * horizontal scroll bar and/or header - see
231 * LISTVIEW_UpdateSize. This rectangle offset
232 * by the LISTVIEW_GetOrigin value is in
233 * client coordinates */
235 /* notification window */
238 BOOL bDoChangeNotify
; /* send change notification messages? */
245 INT nItemCount
; /* the number of items in the list */
246 HDPA hdpaItems
; /* array ITEM_INFO pointers */
247 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
248 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
249 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
250 RANGES selectionRanges
;
251 INT nSelectionMark
; /* item to start next multiselection from */
253 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
256 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
257 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
260 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
265 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
269 DWORD dwStyle
; /* the cached window GWL_STYLE */
270 DWORD dwLvExStyle
; /* extended listview style */
271 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
277 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
280 HIMAGELIST himlNormal
;
281 HIMAGELIST himlSmall
;
282 HIMAGELIST himlState
;
287 POINT currIconPos
; /* this is the position next icon will be placed */
291 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
293 /* marquee selection */
294 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
296 RECT marqueeRect
; /* absolute coordinates of marquee selection */
297 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
298 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
301 BOOL bFocus
; /* control has focus */
303 RECT rcFocus
; /* focus bounds */
314 INT ntmHeight
; /* Some cached metrics of the font used */
315 INT ntmMaxCharWidth
; /* by the listview to draw items */
318 /* mouse operation */
321 POINT ptClickPos
; /* point where the user clicked */
322 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
327 /* keyboard operation */
328 DWORD lastKeyPressTimestamp
;
330 INT nSearchParamLength
;
331 WCHAR szSearchParam
[ MAX_PATH
];
334 BOOL bIsDrawing
; /* Drawing in progress */
335 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
336 BOOL bRedraw
; /* WM_SETREDRAW switch */
339 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
345 /* How many we debug buffer to allocate */
346 #define DEBUG_BUFFERS 20
347 /* The size of a single debug buffer */
348 #define DEBUG_BUFFER_SIZE 256
350 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
351 #define SB_INTERNAL -1
353 /* maximum size of a label */
354 #define DISP_TEXT_SIZE 260
356 /* padding for items in list and small icon display modes */
357 #define WIDTH_PADDING 12
359 /* padding for items in list, report and small icon display modes */
360 #define HEIGHT_PADDING 1
362 /* offset of items in report display mode */
363 #define REPORT_MARGINX 2
365 /* padding for icon in large icon display mode
366 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
367 * that HITTEST will see.
368 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
369 * ICON_TOP_PADDING - sum of the two above.
370 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
371 * LABEL_HOR_PADDING - between text and sides of box
372 * LABEL_VERT_PADDING - between bottom of text and end of box
374 * ICON_LR_PADDING - additional width above icon size.
375 * ICON_LR_HALF - half of the above value
377 #define ICON_TOP_PADDING_NOTHITABLE 2
378 #define ICON_TOP_PADDING_HITABLE 2
379 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
380 #define ICON_BOTTOM_PADDING 4
381 #define LABEL_HOR_PADDING 5
382 #define LABEL_VERT_PADDING 7
383 #define ICON_LR_PADDING 16
384 #define ICON_LR_HALF (ICON_LR_PADDING/2)
386 /* default label width for items in list and small icon display modes */
387 #define DEFAULT_LABEL_WIDTH 40
388 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
389 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
391 /* default column width for items in list display mode */
392 #define DEFAULT_COLUMN_WIDTH 128
394 /* Size of "line" scroll for V & H scrolls */
395 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
397 /* Padding between image and label */
398 #define IMAGE_PADDING 2
400 /* Padding behind the label */
401 #define TRAILING_LABEL_PADDING 12
402 #define TRAILING_HEADER_PADDING 11
404 /* Border for the icon caption */
405 #define CAPTION_BORDER 2
407 /* Standard DrawText flags */
408 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
409 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
410 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
412 /* Image index from state */
413 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
415 /* The time in milliseconds to reset the search in the list */
416 #define KEY_DELAY 450
418 /* Dump the LISTVIEW_INFO structure to the debug channel */
419 #define LISTVIEW_DUMP(iP) do { \
420 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
421 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
422 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
423 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
424 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
425 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
426 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
427 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
428 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
429 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
432 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
435 * forward declarations
437 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
438 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
439 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
440 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
441 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
442 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
443 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
444 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
445 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
446 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
447 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
448 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
449 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
450 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
451 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
452 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
453 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
454 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
455 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
456 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
458 /******** Text handling functions *************************************/
460 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
461 * text string. The string may be ANSI or Unicode, in which case
462 * the boolean isW tells us the type of the string.
464 * The name of the function tell what type of strings it expects:
465 * W: Unicode, T: ANSI/Unicode - function of isW
468 static inline BOOL
is_text(LPCWSTR text
)
470 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
473 static inline int textlenT(LPCWSTR text
, BOOL isW
)
475 return !is_text(text
) ? 0 :
476 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
479 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
482 if (isSrcW
) lstrcpynW(dest
, src
, max
);
483 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
485 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
486 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
489 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
491 LPWSTR wstr
= (LPWSTR
)text
;
493 if (!isW
&& is_text(text
))
495 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
496 wstr
= Alloc(len
* sizeof(WCHAR
));
497 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
499 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
503 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
505 if (!isW
&& is_text(wstr
)) Free (wstr
);
509 * dest is a pointer to a Unicode string
510 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
512 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
516 if (src
== LPSTR_TEXTCALLBACKW
)
518 if (is_text(*dest
)) Free(*dest
);
519 *dest
= LPSTR_TEXTCALLBACKW
;
523 LPWSTR pszText
= textdupTtoW(src
, isW
);
524 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
525 bResult
= Str_SetPtrW(dest
, pszText
);
526 textfreeT(pszText
, isW
);
532 * compares a Unicode to a Unicode/ANSI text string
534 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
536 if (!aw
) return bt
? -1 : 0;
538 if (aw
== LPSTR_TEXTCALLBACKW
)
539 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
540 if (bt
!= LPSTR_TEXTCALLBACKW
)
542 LPWSTR bw
= textdupTtoW(bt
, isW
);
543 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
551 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
553 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
554 return CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
) - CSTR_EQUAL
;
557 /******** Debugging functions *****************************************/
559 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
561 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
562 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
565 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
567 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
568 n
= min(textlenT(text
, isW
), n
);
569 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
572 static char* debug_getbuf(void)
574 static int index
= 0;
575 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
576 return buffers
[index
++ % DEBUG_BUFFERS
];
579 static inline const char* debugrange(const RANGE
*lprng
)
581 if (!lprng
) return "(null)";
582 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
585 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
587 char* buf
= debug_getbuf(), *text
= buf
;
588 int len
, size
= DEBUG_BUFFER_SIZE
;
590 if (pScrollInfo
== NULL
) return "(null)";
591 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
592 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
593 if (pScrollInfo
->fMask
& SIF_RANGE
)
594 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
596 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
597 if (pScrollInfo
->fMask
& SIF_PAGE
)
598 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
600 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
601 if (pScrollInfo
->fMask
& SIF_POS
)
602 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
604 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
605 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
606 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
608 if (len
== -1) goto end
; buf
+= len
;
611 buf
= text
+ strlen(text
);
613 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
617 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
619 if (!plvnm
) return "(null)";
620 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
621 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
622 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
623 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
626 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
628 char* buf
= debug_getbuf(), *text
= buf
;
629 int len
, size
= DEBUG_BUFFER_SIZE
;
631 if (lpLVItem
== NULL
) return "(null)";
632 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
633 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
634 if (lpLVItem
->mask
& LVIF_STATE
)
635 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
637 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
638 if (lpLVItem
->mask
& LVIF_TEXT
)
639 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
641 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
642 if (lpLVItem
->mask
& LVIF_IMAGE
)
643 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
645 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
646 if (lpLVItem
->mask
& LVIF_PARAM
)
647 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
649 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
650 if (lpLVItem
->mask
& LVIF_INDENT
)
651 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
653 if (len
== -1) goto end
; buf
+= len
;
656 buf
= text
+ strlen(text
);
658 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
662 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
664 char* buf
= debug_getbuf(), *text
= buf
;
665 int len
, size
= DEBUG_BUFFER_SIZE
;
667 if (lpColumn
== NULL
) return "(null)";
668 len
= snprintf(buf
, size
, "{");
669 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
670 if (lpColumn
->mask
& LVCF_SUBITEM
)
671 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
673 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
674 if (lpColumn
->mask
& LVCF_FMT
)
675 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
677 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
678 if (lpColumn
->mask
& LVCF_WIDTH
)
679 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
681 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
682 if (lpColumn
->mask
& LVCF_TEXT
)
683 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
685 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
686 if (lpColumn
->mask
& LVCF_IMAGE
)
687 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
689 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
690 if (lpColumn
->mask
& LVCF_ORDER
)
691 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
693 if (len
== -1) goto end
; buf
+= len
;
696 buf
= text
+ strlen(text
);
698 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
702 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
704 if (!lpht
) return "(null)";
706 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
707 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
710 /* Return the corresponding text for a given scroll value */
711 static inline LPCSTR
debugscrollcode(int nScrollCode
)
715 case SB_LINELEFT
: return "SB_LINELEFT";
716 case SB_LINERIGHT
: return "SB_LINERIGHT";
717 case SB_PAGELEFT
: return "SB_PAGELEFT";
718 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
719 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
720 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
721 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
722 case SB_INTERNAL
: return "SB_INTERNAL";
723 default: return "unknown";
728 /******** Notification functions ************************************/
730 static int get_ansi_notification(UINT unicodeNotificationCode
)
732 switch (unicodeNotificationCode
)
734 case LVN_BEGINLABELEDITA
:
735 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
736 case LVN_ENDLABELEDITA
:
737 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
738 case LVN_GETDISPINFOA
:
739 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
740 case LVN_SETDISPINFOA
:
741 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
742 case LVN_ODFINDITEMA
:
743 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
744 case LVN_GETINFOTIPA
:
745 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
746 /* header forwards */
748 case HDN_TRACKW
: return HDN_TRACKA
;
750 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
751 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
752 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
753 case HDN_ITEMCHANGINGA
:
754 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
755 case HDN_ITEMCHANGEDA
:
756 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
758 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
759 case HDN_DIVIDERDBLCLICKA
:
760 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
763 FIXME("unknown notification %x\n", unicodeNotificationCode
);
764 return unicodeNotificationCode
;
767 /* forwards header notifications to listview parent */
768 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
770 LPCWSTR text
= NULL
, filter
= NULL
;
772 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
774 /* on unicode format exit earlier */
775 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
776 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
779 /* header always supplies unicode notifications,
780 all we have to do is to convert strings to ANSI */
783 /* convert item text */
784 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
786 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
787 lpnmh
->pitem
->pszText
= NULL
;
788 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
790 /* convert filter text */
791 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
792 lpnmh
->pitem
->pvFilter
)
794 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
795 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= NULL
;
796 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
799 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
801 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
807 Free(lpnmh
->pitem
->pszText
);
808 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
812 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
813 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
819 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
823 TRACE("(code=%d)\n", code
);
825 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
826 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
828 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
830 TRACE(" <= %ld\n", result
);
835 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
838 HWND hwnd
= infoPtr
->hwndSelf
;
839 notify_hdr(infoPtr
, code
, &nmh
);
840 return IsWindow(hwnd
);
843 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
854 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
855 item
.iItem
= htInfo
->iItem
;
857 item
.stateMask
= (UINT
)-1;
858 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
859 nmia
.lParam
= item
.lParam
;
860 nmia
.uOldState
= item
.state
;
861 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
862 nmia
.uChanged
= LVIF_STATE
;
865 nmia
.iItem
= htInfo
->iItem
;
866 nmia
.iSubItem
= htInfo
->iSubItem
;
867 nmia
.ptAction
= htInfo
->pt
;
869 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
870 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
871 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
873 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
876 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
878 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
879 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
882 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
883 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
887 HWND hwnd
= infoPtr
->hwndSelf
;
890 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
891 ZeroMemory(&nmia
, sizeof(nmia
));
892 nmia
.iItem
= lvht
->iItem
;
893 nmia
.iSubItem
= lvht
->iSubItem
;
894 nmia
.ptAction
= lvht
->pt
;
895 item
.mask
= LVIF_PARAM
;
896 item
.iItem
= lvht
->iItem
;
898 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
899 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
900 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
903 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
907 HWND hwnd
= infoPtr
->hwndSelf
;
909 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
911 item
.mask
= LVIF_PARAM
;
914 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
915 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
916 return IsWindow(hwnd
);
920 Send notification. depends on dispinfoW having same
921 structure as dispinfoA.
922 infoPtr : listview struct
923 code : *Unicode* notification code
924 pdi : dispinfo structure (can be unicode or ansi)
925 isW : TRUE if dispinfo is Unicode
927 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
929 INT length
= 0, ret_length
;
930 LPWSTR buffer
= NULL
, ret_text
;
931 BOOL return_ansi
= FALSE
;
932 BOOL return_unicode
= FALSE
;
935 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
937 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
938 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
941 ret_length
= pdi
->item
.cchTextMax
;
942 ret_text
= pdi
->item
.pszText
;
944 if (return_unicode
|| return_ansi
)
946 if (code
!= LVN_GETDISPINFOW
)
948 length
= return_ansi
?
949 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
950 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
954 length
= pdi
->item
.cchTextMax
;
955 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
958 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
959 if (!buffer
) return FALSE
;
962 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
965 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
968 pdi
->item
.pszText
= buffer
;
969 pdi
->item
.cchTextMax
= length
;
972 if (infoPtr
->notifyFormat
== NFR_ANSI
)
973 code
= get_ansi_notification(code
);
975 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
976 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
977 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
979 if (return_ansi
|| return_unicode
)
981 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
983 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
985 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
987 strcpyW(ret_text
, pdi
->item
.pszText
);
989 else if (return_ansi
) /* note : pointer can be changed by app ! */
991 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
992 ret_length
, NULL
, NULL
);
995 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
996 ret_text
, ret_length
);
998 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
999 pdi
->item
.cchTextMax
= ret_length
;
1005 /* if dipsinfo holder changed notification code then convert */
1006 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1008 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1010 buffer
= Alloc(length
* sizeof(CHAR
));
1011 if (!buffer
) return FALSE
;
1013 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1014 ret_length
, NULL
, NULL
);
1016 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1023 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1024 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1026 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1027 lpnmlvcd
->nmcd
.hdc
= hdc
;
1028 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1029 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1030 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1031 if (!lplvItem
) return;
1032 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1033 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1034 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1035 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1036 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1037 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1040 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1042 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1045 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1046 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1047 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1048 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1049 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1050 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1054 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1056 COLORREF backcolor
, textcolor
;
1058 /* apparently, for selected items, we have to override the returned values */
1061 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1063 if (infoPtr
->bFocus
)
1065 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1066 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1068 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1070 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1071 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1076 backcolor
= lpnmlvcd
->clrTextBk
;
1077 textcolor
= lpnmlvcd
->clrText
;
1079 if (backcolor
== CLR_DEFAULT
)
1080 backcolor
= comctl32_color
.clrWindow
;
1081 if (textcolor
== CLR_DEFAULT
)
1082 textcolor
= comctl32_color
.clrWindowText
;
1084 /* Set the text attributes */
1085 if (backcolor
!= CLR_NONE
)
1087 SetBkMode(hdc
, OPAQUE
);
1088 SetBkColor(hdc
, backcolor
);
1091 SetBkMode(hdc
, TRANSPARENT
);
1092 SetTextColor(hdc
, textcolor
);
1095 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1097 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1100 /* returns TRUE when repaint needed, FALSE otherwise */
1101 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1103 MEASUREITEMSTRUCT mis
;
1104 mis
.CtlType
= ODT_LISTVIEW
;
1105 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1109 mis
.itemHeight
= infoPtr
->nItemHeight
;
1110 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1111 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1113 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1119 /******** Item iterator functions **********************************/
1121 static RANGES
ranges_create(int count
);
1122 static void ranges_destroy(RANGES ranges
);
1123 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1124 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1125 static void ranges_dump(RANGES ranges
);
1127 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1129 RANGE range
= { nItem
, nItem
+ 1 };
1131 return ranges_add(ranges
, range
);
1134 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1136 RANGE range
= { nItem
, nItem
+ 1 };
1138 return ranges_del(ranges
, range
);
1142 * ITERATOR DOCUMENTATION
1144 * The iterator functions allow for easy, and convenient iteration
1145 * over items of interest in the list. Typically, you create an
1146 * iterator, use it, and destroy it, as such:
1149 * iterator_xxxitems(&i, ...);
1150 * while (iterator_{prev,next}(&i)
1152 * //code which uses i.nItem
1154 * iterator_destroy(&i);
1156 * where xxx is either: framed, or visible.
1157 * Note that it is important that the code destroys the iterator
1158 * after it's done with it, as the creation of the iterator may
1159 * allocate memory, which thus needs to be freed.
1161 * You can iterate both forwards, and backwards through the list,
1162 * by using iterator_next or iterator_prev respectively.
1164 * Lower numbered items are draw on top of higher number items in
1165 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1166 * items may overlap). So, to test items, you should use
1168 * which lists the items top to bottom (in Z-order).
1169 * For drawing items, you should use
1171 * which lists the items bottom to top (in Z-order).
1172 * If you keep iterating over the items after the end-of-items
1173 * marker (-1) is returned, the iterator will start from the
1174 * beginning. Typically, you don't need to test for -1,
1175 * because iterator_{next,prev} will return TRUE if more items
1176 * are to be iterated over, or FALSE otherwise.
1178 * Note: the iterator is defined to be bidirectional. That is,
1179 * any number of prev followed by any number of next, or
1180 * five versa, should leave the iterator at the same item:
1181 * prev * n, next * n = next * n, prev * n
1183 * The iterator has a notion of an out-of-order, special item,
1184 * which sits at the start of the list. This is used in
1185 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1186 * which needs to be first, as it may overlap other items.
1188 * The code is a bit messy because we have:
1189 * - a special item to deal with
1190 * - simple range, or composite range
1192 * If you find bugs, or want to add features, please make sure you
1193 * always check/modify *both* iterator_prev, and iterator_next.
1197 * This function iterates through the items in increasing order,
1198 * but prefixed by the special item, then -1. That is:
1199 * special, 1, 2, 3, ..., n, -1.
1200 * Each item is listed only once.
1202 static inline BOOL
iterator_next(ITERATOR
* i
)
1206 i
->nItem
= i
->nSpecial
;
1207 if (i
->nItem
!= -1) return TRUE
;
1209 if (i
->nItem
== i
->nSpecial
)
1211 if (i
->ranges
) i
->index
= 0;
1217 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1218 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1223 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1224 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1227 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1229 i
->nItem
= i
->range
.lower
;
1230 if (i
->nItem
>= 0) goto testitem
;
1237 * This function iterates through the items in decreasing order,
1238 * followed by the special item, then -1. That is:
1239 * n, n-1, ..., 3, 2, 1, special, -1.
1240 * Each item is listed only once.
1242 static inline BOOL
iterator_prev(ITERATOR
* i
)
1249 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1252 if (i
->nItem
== i
->nSpecial
)
1260 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1261 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1267 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1270 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1272 i
->nItem
= i
->range
.upper
;
1273 if (i
->nItem
> 0) goto testitem
;
1275 return (i
->nItem
= i
->nSpecial
) != -1;
1278 static RANGE
iterator_range(const ITERATOR
*i
)
1282 if (!i
->ranges
) return i
->range
;
1284 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1286 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1287 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1289 else range
.lower
= range
.upper
= 0;
1295 * Releases resources associated with this iterator.
1297 static inline void iterator_destroy(const ITERATOR
*i
)
1299 ranges_destroy(i
->ranges
);
1303 * Create an empty iterator.
1305 static inline BOOL
iterator_empty(ITERATOR
* i
)
1307 ZeroMemory(i
, sizeof(*i
));
1308 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1313 * Create an iterator over a range.
1315 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1323 * Create an iterator over a bunch of ranges.
1324 * Please note that the iterator will take ownership of the ranges,
1325 * and will free them upon destruction.
1327 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1335 * Creates an iterator over the items which intersect frame.
1336 * Uses absolute coordinates rather than compensating for the current offset.
1338 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1340 RECT rcItem
, rcTemp
;
1342 /* in case we fail, we want to return an empty iterator */
1343 if (!iterator_empty(i
)) return FALSE
;
1345 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1347 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1351 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1353 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1354 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1355 i
->nSpecial
= infoPtr
->nFocusedItem
;
1357 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1358 /* to do better here, we need to have PosX, and PosY sorted */
1359 TRACE("building icon ranges:\n");
1360 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1362 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1363 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1364 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1365 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1366 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1367 ranges_additem(i
->ranges
, nItem
);
1371 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1375 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1376 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1378 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1379 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1380 if (range
.upper
<= range
.lower
) return TRUE
;
1381 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1382 TRACE(" report=%s\n", debugrange(&i
->range
));
1386 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1387 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1388 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1395 if (infoPtr
->nItemWidth
)
1397 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1398 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1402 nFirstCol
= max(frame
->left
, 0);
1403 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1406 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1408 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1409 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1411 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1413 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1414 TRACE("building list ranges:\n");
1415 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1417 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1418 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1419 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1420 TRACE(" list=%s\n", debugrange(&item_range
));
1421 ranges_add(i
->ranges
, item_range
);
1429 * Creates an iterator over the items which intersect lprc.
1431 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1436 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1438 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1439 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1441 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1445 * Creates an iterator over the items which intersect the visible region of hdc.
1447 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1449 POINT Origin
, Position
;
1450 RECT rcItem
, rcClip
;
1453 rgntype
= GetClipBox(hdc
, &rcClip
);
1454 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1455 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1456 if (rgntype
== SIMPLEREGION
) return TRUE
;
1458 /* first deal with the special item */
1459 if (i
->nSpecial
!= -1)
1461 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1462 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1465 /* if we can't deal with the region, we'll just go with the simple range */
1466 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1467 TRACE("building visible range:\n");
1468 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1470 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1471 if (!ranges_add(i
->ranges
, i
->range
))
1473 ranges_destroy(i
->ranges
);
1479 /* now delete the invisible items from the list */
1480 while(iterator_next(i
))
1482 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1483 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1484 rcItem
.top
= Position
.y
+ Origin
.y
;
1485 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1486 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1487 if (!RectVisible(hdc
, &rcItem
))
1488 ranges_delitem(i
->ranges
, i
->nItem
);
1490 /* the iterator should restart on the next iterator_next */
1496 /* Remove common elements from two iterators */
1497 /* Passed iterators have to point on the first elements */
1498 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1500 if(!iter1
->ranges
|| !iter2
->ranges
) {
1503 if(iter1
->ranges
|| iter2
->ranges
||
1504 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1505 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1506 ERR("result is not a one range iterator\n");
1510 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1513 lower
= iter1
->range
.lower
;
1514 upper
= iter1
->range
.upper
;
1516 if(lower
< iter2
->range
.lower
)
1517 iter1
->range
.upper
= iter2
->range
.lower
;
1518 else if(upper
> iter2
->range
.upper
)
1519 iter1
->range
.lower
= iter2
->range
.upper
;
1521 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1523 if(iter2
->range
.lower
< lower
)
1524 iter2
->range
.upper
= lower
;
1525 else if(iter2
->range
.upper
> upper
)
1526 iter2
->range
.lower
= upper
;
1528 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1533 iterator_next(iter1
);
1534 iterator_next(iter2
);
1537 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1540 if(iter1
->nItem
== iter2
->nItem
) {
1541 int delete = iter1
->nItem
;
1543 iterator_prev(iter1
);
1544 iterator_prev(iter2
);
1545 ranges_delitem(iter1
->ranges
, delete);
1546 ranges_delitem(iter2
->ranges
, delete);
1547 iterator_next(iter1
);
1548 iterator_next(iter2
);
1549 } else if(iter1
->nItem
> iter2
->nItem
)
1550 iterator_next(iter2
);
1552 iterator_next(iter1
);
1555 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1556 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1560 /******** Misc helper functions ************************************/
1562 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1563 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1565 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1566 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1569 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1571 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1572 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1575 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1577 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1578 if(state
== 1 || state
== 2)
1582 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1583 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1584 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1588 /* this should be called after window style got updated,
1589 it used to reset view state to match current window style */
1590 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1592 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1595 infoPtr
->uView
= LV_VIEW_ICON
;
1598 infoPtr
->uView
= LV_VIEW_DETAILS
;
1601 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1604 infoPtr
->uView
= LV_VIEW_LIST
;
1608 /* computes next item id value */
1609 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1611 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1615 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1616 return lpID
->id
+ 1;
1621 /******** Internal API functions ************************************/
1623 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1625 static COLUMN_INFO mainItem
;
1627 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1628 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1630 /* update cached column rectangles */
1631 if (infoPtr
->colRectsDirty
)
1634 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1637 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1638 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1639 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1641 Ptr
->colRectsDirty
= FALSE
;
1644 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1647 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1649 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1652 if (infoPtr
->hwndHeader
) return 0;
1654 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1656 /* setup creation flags */
1657 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1658 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1660 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1663 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1664 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1665 if (!infoPtr
->hwndHeader
) return -1;
1667 /* set header unicode format */
1668 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1670 /* set header font */
1671 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1673 /* set header image list */
1674 if (infoPtr
->himlSmall
)
1675 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1677 LISTVIEW_UpdateSize(infoPtr
);
1682 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1684 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1687 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1689 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1690 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1691 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1694 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1696 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1699 /* used to handle collapse main item column case */
1700 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1702 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1703 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1706 /* Listview invalidation functions: use _only_ these functions to invalidate */
1708 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1710 return infoPtr
->bRedraw
;
1713 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1715 if(!is_redrawing(infoPtr
)) return;
1716 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1717 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1720 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1724 if(!is_redrawing(infoPtr
)) return;
1725 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1726 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1729 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1731 POINT Origin
, Position
;
1734 if(!is_redrawing(infoPtr
)) return;
1735 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1736 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1737 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1738 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1740 rcBox
.bottom
= infoPtr
->nItemHeight
;
1741 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1742 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1745 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1747 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1750 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1754 if(!is_redrawing(infoPtr
)) return;
1755 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1756 rcCol
.top
= infoPtr
->rcList
.top
;
1757 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1758 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1763 * Retrieves the number of items that can fit vertically in the client area.
1766 * [I] infoPtr : valid pointer to the listview structure
1769 * Number of items per row.
1771 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1773 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1775 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1780 * Retrieves the number of items that can fit horizontally in the client
1784 * [I] infoPtr : valid pointer to the listview structure
1787 * Number of items per column.
1789 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1791 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1793 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1797 /*************************************************************************
1798 * LISTVIEW_ProcessLetterKeys
1800 * Processes keyboard messages generated by pressing the letter keys
1802 * What this does is perform a case insensitive search from the
1803 * current position with the following quirks:
1804 * - If two chars or more are pressed in quick succession we search
1805 * for the corresponding string (e.g. 'abc').
1806 * - If there is a delay we wipe away the current search string and
1807 * restart with just that char.
1808 * - If the user keeps pressing the same character, whether slowly or
1809 * fast, so that the search string is entirely composed of this
1810 * character ('aaaaa' for instance), then we search for first item
1811 * that starting with that character.
1812 * - If the user types the above character in quick succession, then
1813 * we must also search for the corresponding string ('aaaaa'), and
1814 * go to that string if there is a match.
1817 * [I] hwnd : handle to the window
1818 * [I] charCode : the character code, the actual character
1819 * [I] keyData : key data
1827 * - The current implementation has a list of characters it will
1828 * accept and it ignores everything else. In particular it will
1829 * ignore accentuated characters which seems to match what
1830 * Windows does. But I'm not sure it makes sense to follow
1832 * - We don't sound a beep when the search fails.
1836 * TREEVIEW_ProcessLetterKeys
1838 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1840 WCHAR buffer
[MAX_PATH
];
1847 /* simple parameter checking */
1848 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1850 /* only allow the valid WM_CHARs through */
1851 if (!isalnumW(charCode
) &&
1852 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1853 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1854 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1855 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1856 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1857 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1858 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1859 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1860 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1863 /* update the search parameters */
1864 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1865 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1866 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1868 if (diff
>= 0 && diff
< KEY_DELAY
)
1870 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1871 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1873 if (infoPtr
->charCode
!= charCode
)
1874 infoPtr
->charCode
= charCode
= 0;
1878 infoPtr
->charCode
= charCode
;
1879 infoPtr
->szSearchParam
[0] = charCode
;
1880 infoPtr
->nSearchParamLength
= 1;
1883 /* should start from next after focused item, so next item that matches
1884 will be selected, if there isn't any and focused matches it will be selected
1885 on second search stage from beginning of the list */
1886 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1888 /* with some accumulated search data available start with current focus, otherwise
1889 it's excluded from search */
1890 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1891 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1896 /* let application handle this for virtual listview */
1897 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1901 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1902 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1903 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1904 nmlv
.iStart
= startidx
;
1906 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1908 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1912 int i
= startidx
, endidx
;
1914 /* and search from the current position */
1916 endidx
= infoPtr
->nItemCount
;
1918 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1921 /* start from first item if not found with >= startidx */
1922 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1928 for (i
= startidx
; i
< endidx
; i
++)
1931 item
.mask
= LVIF_TEXT
;
1934 item
.pszText
= buffer
;
1935 item
.cchTextMax
= MAX_PATH
;
1936 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1938 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1943 /* this is used to find first char match when search string is not available yet,
1944 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1945 already waiting for user to complete a string */
1946 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1948 /* this would work but we must keep looking for a longer match */
1953 if ( nItem
!= -1 || /* found something */
1954 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1955 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1961 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1966 /*************************************************************************
1967 * LISTVIEW_UpdateHeaderSize [Internal]
1969 * Function to resize the header control
1972 * [I] hwnd : handle to a window
1973 * [I] nNewScrollPos : scroll pos to set
1978 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1983 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1985 if (!infoPtr
->hwndHeader
) return;
1987 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1988 point
[0].x
= winRect
.left
;
1989 point
[0].y
= winRect
.top
;
1990 point
[1].x
= winRect
.right
;
1991 point
[1].y
= winRect
.bottom
;
1993 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1994 point
[0].x
= -nNewScrollPos
;
1995 point
[1].x
+= nNewScrollPos
;
1997 SetWindowPos(infoPtr
->hwndHeader
,0,
1998 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1999 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
2000 SWP_NOZORDER
| SWP_NOACTIVATE
);
2005 * Update the scrollbars. This functions should be called whenever
2006 * the content, size or view changes.
2009 * [I] infoPtr : valid pointer to the listview structure
2014 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2016 SCROLLINFO horzInfo
, vertInfo
;
2019 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2021 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2022 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2023 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2025 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2026 if (infoPtr
->uView
== LV_VIEW_LIST
)
2028 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2029 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2031 /* scroll by at least one column per page */
2032 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2033 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2035 if (infoPtr
->nItemWidth
)
2036 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2038 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2040 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2042 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2046 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2049 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2051 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2056 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2057 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2059 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2060 horzInfo
.nMax
= rcHeader
.right
;
2061 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2065 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2066 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2067 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2068 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2069 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2071 /* Setting the horizontal scroll can change the listview size
2072 * (and potentially everything else) so we need to recompute
2073 * everything again for the vertical scroll
2076 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2077 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2078 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2080 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2082 vertInfo
.nMax
= infoPtr
->nItemCount
;
2084 /* scroll by at least one page */
2085 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2086 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2088 if (infoPtr
->nItemHeight
> 0)
2089 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2091 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2095 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2098 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2099 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2100 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2101 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2102 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2104 /* Change of the range may have changed the scroll pos. If so move the content */
2105 if (dx
!= 0 || dy
!= 0)
2108 listRect
= infoPtr
->rcList
;
2109 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2110 SW_ERASE
| SW_INVALIDATE
);
2113 /* Update the Header Control */
2114 if (infoPtr
->hwndHeader
)
2116 horzInfo
.fMask
= SIF_POS
;
2117 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2118 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2125 * Shows/hides the focus rectangle.
2128 * [I] infoPtr : valid pointer to the listview structure
2129 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2134 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2138 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2140 if (infoPtr
->nFocusedItem
< 0) return;
2142 /* we need some gymnastics in ICON mode to handle large items */
2143 if (infoPtr
->uView
== LV_VIEW_ICON
)
2147 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2148 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2150 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2155 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2157 /* for some reason, owner draw should work only in report mode */
2158 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2163 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2164 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2166 item
.iItem
= infoPtr
->nFocusedItem
;
2168 item
.mask
= LVIF_PARAM
;
2169 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2171 ZeroMemory(&dis
, sizeof(dis
));
2172 dis
.CtlType
= ODT_LISTVIEW
;
2173 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2174 dis
.itemID
= item
.iItem
;
2175 dis
.itemAction
= ODA_FOCUS
;
2176 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2177 dis
.hwndItem
= infoPtr
->hwndSelf
;
2179 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2180 dis
.itemData
= item
.lParam
;
2182 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2184 SelectObject(hdc
, hOldFont
);
2188 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2191 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2195 * Invalidates all visible selected items.
2197 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2201 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2202 while(iterator_next(&i
))
2204 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2205 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2207 iterator_destroy(&i
);
2212 * DESCRIPTION: [INTERNAL]
2213 * Computes an item's (left,top) corner, relative to rcView.
2214 * That is, the position has NOT been made relative to the Origin.
2215 * This is deliberate, to avoid computing the Origin over, and
2216 * over again, when this function is called in a loop. Instead,
2217 * one can factor the computation of the Origin before the loop,
2218 * and offset the value returned by this function, on every iteration.
2221 * [I] infoPtr : valid pointer to the listview structure
2222 * [I] nItem : item number
2223 * [O] lpptOrig : item top, left corner
2228 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2230 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2232 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2234 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2235 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2237 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2239 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2240 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2241 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2243 else /* LV_VIEW_DETAILS */
2245 lpptPosition
->x
= REPORT_MARGINX
;
2246 /* item is always at zero indexed column */
2247 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2248 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2249 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2254 * DESCRIPTION: [INTERNAL]
2255 * Compute the rectangles of an item. This is to localize all
2256 * the computations in one place. If you are not interested in some
2257 * of these values, simply pass in a NULL -- the function is smart
2258 * enough to compute only what's necessary. The function computes
2259 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2260 * one, the BOX rectangle. This rectangle is very cheap to compute,
2261 * and is guaranteed to contain all the other rectangles. Computing
2262 * the ICON rect is also cheap, but all the others are potentially
2263 * expensive. This gives an easy and effective optimization when
2264 * searching (like point inclusion, or rectangle intersection):
2265 * first test against the BOX, and if TRUE, test against the desired
2267 * If the function does not have all the necessary information
2268 * to computed the requested rectangles, will crash with a
2269 * failed assertion. This is done so we catch all programming
2270 * errors, given that the function is called only from our code.
2272 * We have the following 'special' meanings for a few fields:
2273 * * If LVIS_FOCUSED is set, we assume the item has the focus
2274 * This is important in ICON mode, where it might get a larger
2275 * then usual rectangle
2277 * Please note that subitem support works only in REPORT mode.
2280 * [I] infoPtr : valid pointer to the listview structure
2281 * [I] lpLVItem : item to compute the measures for
2282 * [O] lprcBox : ptr to Box rectangle
2283 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2284 * [0] lprcSelectBox : ptr to select box rectangle
2285 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2286 * [O] lprcIcon : ptr to Icon rectangle
2287 * Same as LVM_GETITEMRECT with LVIR_ICON
2288 * [O] lprcStateIcon: ptr to State Icon rectangle
2289 * [O] lprcLabel : ptr to Label rectangle
2290 * Same as LVM_GETITEMRECT with LVIR_LABEL
2295 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2296 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2297 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2299 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2300 RECT Box
, SelectBox
, Icon
, Label
;
2301 COLUMN_INFO
*lpColumnInfo
= NULL
;
2302 SIZE labelSize
= { 0, 0 };
2304 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2306 /* Be smart and try to figure out the minimum we have to do */
2307 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2308 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2310 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2311 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2313 if (lprcSelectBox
) doSelectBox
= TRUE
;
2314 if (lprcLabel
) doLabel
= TRUE
;
2315 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2322 /************************************************************/
2323 /* compute the box rectangle (it should be cheap to do) */
2324 /************************************************************/
2325 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2326 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2328 if (lpLVItem
->iSubItem
)
2330 Box
= lpColumnInfo
->rcHeader
;
2335 Box
.right
= infoPtr
->nItemWidth
;
2338 Box
.bottom
= infoPtr
->nItemHeight
;
2340 /******************************************************************/
2341 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2342 /******************************************************************/
2345 LONG state_width
= 0;
2347 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2348 state_width
= infoPtr
->iconStateSize
.cx
;
2350 if (infoPtr
->uView
== LV_VIEW_ICON
)
2352 Icon
.left
= Box
.left
+ state_width
;
2353 if (infoPtr
->himlNormal
)
2354 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2355 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2356 Icon
.right
= Icon
.left
;
2357 Icon
.bottom
= Icon
.top
;
2358 if (infoPtr
->himlNormal
)
2360 Icon
.right
+= infoPtr
->iconSize
.cx
;
2361 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2364 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2366 Icon
.left
= Box
.left
+ state_width
;
2368 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2370 /* we need the indent in report mode */
2371 assert(lpLVItem
->mask
& LVIF_INDENT
);
2372 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2376 Icon
.right
= Icon
.left
;
2377 if (infoPtr
->himlSmall
&&
2378 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2379 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2380 Icon
.right
+= infoPtr
->iconSize
.cx
;
2381 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2383 if(lprcIcon
) *lprcIcon
= Icon
;
2384 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2386 /* TODO: is this correct? */
2389 lprcStateIcon
->left
= Icon
.left
- state_width
;
2390 lprcStateIcon
->right
= Icon
.left
;
2391 lprcStateIcon
->top
= Icon
.top
;
2392 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2393 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2396 else Icon
.right
= 0;
2398 /************************************************************/
2399 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2400 /************************************************************/
2403 /* calculate how far to the right can the label stretch */
2404 Label
.right
= Box
.right
;
2405 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2407 if (lpLVItem
->iSubItem
== 0)
2409 /* we need a zero based rect here */
2410 Label
= lpColumnInfo
->rcHeader
;
2411 OffsetRect(&Label
, -Label
.left
, 0);
2415 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2417 labelSize
.cx
= infoPtr
->nItemWidth
;
2418 labelSize
.cy
= infoPtr
->nItemHeight
;
2422 /* we need the text in non owner draw mode */
2423 assert(lpLVItem
->mask
& LVIF_TEXT
);
2424 if (is_text(lpLVItem
->pszText
))
2426 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2427 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2428 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2432 /* compute rough rectangle where the label will go */
2433 SetRectEmpty(&rcText
);
2434 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2435 rcText
.bottom
= infoPtr
->nItemHeight
;
2436 if (infoPtr
->uView
== LV_VIEW_ICON
)
2437 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2439 /* now figure out the flags */
2440 if (infoPtr
->uView
== LV_VIEW_ICON
)
2441 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2443 uFormat
= LV_SL_DT_FLAGS
;
2445 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2447 if (rcText
.right
!= rcText
.left
)
2448 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2450 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2452 SelectObject(hdc
, hOldFont
);
2453 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2457 if (infoPtr
->uView
== LV_VIEW_ICON
)
2459 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2460 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2461 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2462 Label
.right
= Label
.left
+ labelSize
.cx
;
2463 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2464 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2466 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2467 labelSize
.cy
/= infoPtr
->ntmHeight
;
2468 labelSize
.cy
= max(labelSize
.cy
, 1);
2469 labelSize
.cy
*= infoPtr
->ntmHeight
;
2471 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2473 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2475 Label
.left
= Icon
.right
;
2476 Label
.top
= Box
.top
;
2477 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2478 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2479 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2481 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2483 Label
.left
= Icon
.right
;
2484 Label
.top
= Box
.top
;
2485 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2486 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2489 if (lprcLabel
) *lprcLabel
= Label
;
2490 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2493 /************************************************************/
2494 /* compute SELECT bounding box */
2495 /************************************************************/
2498 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2500 SelectBox
.left
= Icon
.left
;
2501 SelectBox
.top
= Box
.top
;
2502 SelectBox
.bottom
= Box
.bottom
;
2505 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2507 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2511 UnionRect(&SelectBox
, &Icon
, &Label
);
2513 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2514 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2517 /* Fix the Box if necessary */
2520 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2521 else *lprcBox
= Box
;
2523 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2527 * DESCRIPTION: [INTERNAL]
2530 * [I] infoPtr : valid pointer to the listview structure
2531 * [I] nItem : item number
2532 * [O] lprcBox : ptr to Box rectangle
2537 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2539 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2540 POINT Position
, Origin
;
2543 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2544 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2546 /* Be smart and try to figure out the minimum we have to do */
2548 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2549 lvItem
.mask
|= LVIF_TEXT
;
2550 lvItem
.iItem
= nItem
;
2551 lvItem
.iSubItem
= 0;
2552 lvItem
.pszText
= szDispText
;
2553 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2554 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2555 if (infoPtr
->uView
== LV_VIEW_ICON
)
2557 lvItem
.mask
|= LVIF_STATE
;
2558 lvItem
.stateMask
= LVIS_FOCUSED
;
2559 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2561 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2563 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2564 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2566 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2569 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2572 /* LISTVIEW_MapIdToIndex helper */
2573 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2575 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2576 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2578 if (id1
->id
== id2
->id
) return 0;
2580 return (id1
->id
< id2
->id
) ? -1 : 1;
2585 * Returns the item index for id specified.
2588 * [I] infoPtr : valid pointer to the listview structure
2589 * [I] iID : item id to get index for
2592 * Item index, or -1 on failure.
2594 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2599 TRACE("iID=%d\n", iID
);
2601 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2602 if (infoPtr
->nItemCount
== 0) return -1;
2605 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2609 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2610 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2618 * Returns the item id for index given.
2621 * [I] infoPtr : valid pointer to the listview structure
2622 * [I] iItem : item index to get id for
2627 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2632 TRACE("iItem=%d\n", iItem
);
2634 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2635 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2637 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2638 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2640 return lpItem
->id
->id
;
2645 * Returns the current icon position, and advances it along the top.
2646 * The returned position is not offset by Origin.
2649 * [I] infoPtr : valid pointer to the listview structure
2650 * [O] lpPos : will get the current icon position
2655 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2657 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2659 *lpPos
= infoPtr
->currIconPos
;
2661 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2662 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2664 infoPtr
->currIconPos
.x
= 0;
2665 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2671 * Returns the current icon position, and advances it down the left edge.
2672 * The returned position is not offset by Origin.
2675 * [I] infoPtr : valid pointer to the listview structure
2676 * [O] lpPos : will get the current icon position
2681 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2683 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2685 *lpPos
= infoPtr
->currIconPos
;
2687 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2688 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2690 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2691 infoPtr
->currIconPos
.y
= 0;
2697 * Moves an icon to the specified position.
2698 * It takes care of invalidating the item, etc.
2701 * [I] infoPtr : valid pointer to the listview structure
2702 * [I] nItem : the item to move
2703 * [I] lpPos : the new icon position
2704 * [I] isNew : flags the item as being new
2710 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2716 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2717 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2719 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2720 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2723 /* Allocating a POINTER for every item is too resource intensive,
2724 * so we'll keep the (x,y) in different arrays */
2725 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2726 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2728 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2735 * Arranges listview items in icon display mode.
2738 * [I] infoPtr : valid pointer to the listview structure
2739 * [I] nAlignCode : alignment code
2745 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2747 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2751 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2753 TRACE("nAlignCode=%d\n", nAlignCode
);
2755 if (nAlignCode
== LVA_DEFAULT
)
2757 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2758 else nAlignCode
= LVA_ALIGNTOP
;
2763 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2764 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2765 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2766 default: return FALSE
;
2769 infoPtr
->bAutoarrange
= TRUE
;
2770 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2771 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2773 next_pos(infoPtr
, &pos
);
2774 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2782 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2783 * For LVS_REPORT always returns empty rectangle.
2786 * [I] infoPtr : valid pointer to the listview structure
2787 * [O] lprcView : bounding rectangle
2793 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2797 SetRectEmpty(lprcView
);
2799 switch (infoPtr
->uView
)
2802 case LV_VIEW_SMALLICON
:
2803 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2805 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2806 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2807 lprcView
->right
= max(lprcView
->right
, x
);
2808 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2810 if (infoPtr
->nItemCount
> 0)
2812 lprcView
->right
+= infoPtr
->nItemWidth
;
2813 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2818 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2819 x
= infoPtr
->nItemCount
/ y
;
2820 if (infoPtr
->nItemCount
% y
) x
++;
2821 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2822 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2829 * Retrieves the bounding rectangle of all the items.
2832 * [I] infoPtr : valid pointer to the listview structure
2833 * [O] lprcView : bounding rectangle
2839 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2843 TRACE("(lprcView=%p)\n", lprcView
);
2845 if (!lprcView
) return FALSE
;
2847 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2849 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2851 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2852 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2855 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2862 * Retrieves the subitem pointer associated with the subitem index.
2865 * [I] hdpaSubItems : DPA handle for a specific item
2866 * [I] nSubItem : index of subitem
2869 * SUCCESS : subitem pointer
2872 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2874 SUBITEM_INFO
*lpSubItem
;
2877 /* we should binary search here if need be */
2878 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2880 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2881 if (lpSubItem
->iSubItem
== nSubItem
)
2891 * Calculates the desired item width.
2894 * [I] infoPtr : valid pointer to the listview structure
2897 * The desired item width.
2899 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2903 TRACE("uView=%d\n", infoPtr
->uView
);
2905 if (infoPtr
->uView
== LV_VIEW_ICON
)
2906 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2907 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2909 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2914 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2915 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2917 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2918 nItemWidth
= rcHeader
.right
;
2921 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2923 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2927 lvItem
.mask
= LVIF_TEXT
;
2928 lvItem
.iSubItem
= 0;
2930 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2933 lvItem
.pszText
= szDispText
;
2934 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2935 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2936 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2940 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2941 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2943 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2951 * Calculates the desired item height.
2954 * [I] infoPtr : valid pointer to the listview structure
2957 * The desired item height.
2959 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2963 TRACE("uView=%d\n", infoPtr
->uView
);
2965 if (infoPtr
->uView
== LV_VIEW_ICON
)
2966 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2969 nItemHeight
= infoPtr
->ntmHeight
;
2970 if (infoPtr
->himlState
)
2971 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2972 if (infoPtr
->himlSmall
)
2973 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2974 nItemHeight
+= HEIGHT_PADDING
;
2975 if (infoPtr
->nMeasureItemHeight
> 0)
2976 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2979 return max(nItemHeight
, 1);
2984 * Updates the width, and height of an item.
2987 * [I] infoPtr : valid pointer to the listview structure
2992 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2994 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2995 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3001 * Retrieves and saves important text metrics info for the current
3005 * [I] infoPtr : valid pointer to the listview structure
3008 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3010 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3011 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3012 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3016 if (GetTextMetricsW(hdc
, &tm
))
3018 infoPtr
->ntmHeight
= tm
.tmHeight
;
3019 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3022 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3023 infoPtr
->nEllipsisWidth
= sz
.cx
;
3025 SelectObject(hdc
, hOldFont
);
3026 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3028 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3033 * A compare function for ranges
3036 * [I] range1 : pointer to range 1;
3037 * [I] range2 : pointer to range 2;
3041 * > 0 : if range 1 > range 2
3042 * < 0 : if range 2 > range 1
3043 * = 0 : if range intersects range 2
3045 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3049 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3051 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3056 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3061 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3063 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3068 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3070 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3071 ranges_dump(ranges
);
3072 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3074 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3075 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3076 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3078 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3079 assert (prev
->upper
<= curr
->lower
);
3080 assert (curr
->lower
< curr
->upper
);
3084 TRACE("--- Done checking---\n");
3087 static RANGES
ranges_create(int count
)
3089 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3090 if (!ranges
) return NULL
;
3091 ranges
->hdpa
= DPA_Create(count
);
3092 if (ranges
->hdpa
) return ranges
;
3097 static void ranges_clear(RANGES ranges
)
3101 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3102 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3103 DPA_DeleteAllPtrs(ranges
->hdpa
);
3107 static void ranges_destroy(RANGES ranges
)
3109 if (!ranges
) return;
3110 ranges_clear(ranges
);
3111 DPA_Destroy(ranges
->hdpa
);
3115 static RANGES
ranges_clone(RANGES ranges
)
3120 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3122 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3124 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3125 if (!newrng
) goto fail
;
3126 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3127 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
3132 TRACE ("clone failed\n");
3133 ranges_destroy(clone
);
3137 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3141 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3142 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3147 static void ranges_dump(RANGES ranges
)
3151 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3152 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3155 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3157 RANGE srchrng
= { nItem
, nItem
+ 1 };
3159 TRACE("(nItem=%d)\n", nItem
);
3160 ranges_check(ranges
, "before contain");
3161 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3164 static INT
ranges_itemcount(RANGES ranges
)
3168 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3170 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3171 count
+= sel
->upper
- sel
->lower
;
3177 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3179 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3182 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3183 if (index
== -1) return TRUE
;
3185 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3187 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3188 if (chkrng
->lower
>= nItem
)
3189 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3190 if (chkrng
->upper
> nItem
)
3191 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3196 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3201 TRACE("(%s)\n", debugrange(&range
));
3202 ranges_check(ranges
, "before add");
3204 /* try find overlapping regions first */
3205 srchrgn
.lower
= range
.lower
- 1;
3206 srchrgn
.upper
= range
.upper
+ 1;
3207 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3213 TRACE("Adding new range\n");
3215 /* create the brand new range to insert */
3216 newrgn
= Alloc(sizeof(RANGE
));
3217 if(!newrgn
) goto fail
;
3220 /* figure out where to insert it */
3221 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3222 TRACE("index=%d\n", index
);
3223 if (index
== -1) index
= 0;
3225 /* and get it over with */
3226 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3234 RANGE
*chkrgn
, *mrgrgn
;
3235 INT fromindex
, mergeindex
;
3237 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3238 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3240 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3241 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3243 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3245 /* merge now common ranges */
3247 srchrgn
.lower
= chkrgn
->lower
- 1;
3248 srchrgn
.upper
= chkrgn
->upper
+ 1;
3252 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3253 if (mergeindex
== -1) break;
3254 if (mergeindex
== index
)
3256 fromindex
= index
+ 1;
3260 TRACE("Merge with index %i\n", mergeindex
);
3262 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3263 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3264 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3266 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3267 if (mergeindex
< index
) index
--;
3271 ranges_check(ranges
, "after add");
3275 ranges_check(ranges
, "failed add");
3279 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3284 TRACE("(%s)\n", debugrange(&range
));
3285 ranges_check(ranges
, "before del");
3287 /* we don't use DPAS_SORTED here, since we need *
3288 * to find the first overlapping range */
3289 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3292 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3294 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3296 /* case 1: Same range */
3297 if ( (chkrgn
->upper
== range
.upper
) &&
3298 (chkrgn
->lower
== range
.lower
) )
3300 DPA_DeletePtr(ranges
->hdpa
, index
);
3304 /* case 2: engulf */
3305 else if ( (chkrgn
->upper
<= range
.upper
) &&
3306 (chkrgn
->lower
>= range
.lower
) )
3308 DPA_DeletePtr(ranges
->hdpa
, index
);
3311 /* case 3: overlap upper */
3312 else if ( (chkrgn
->upper
<= range
.upper
) &&
3313 (chkrgn
->lower
< range
.lower
) )
3315 chkrgn
->upper
= range
.lower
;
3317 /* case 4: overlap lower */
3318 else if ( (chkrgn
->upper
> range
.upper
) &&
3319 (chkrgn
->lower
>= range
.lower
) )
3321 chkrgn
->lower
= range
.upper
;
3324 /* case 5: fully internal */
3329 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3330 newrgn
->lower
= chkrgn
->lower
;
3331 newrgn
->upper
= range
.lower
;
3332 chkrgn
->lower
= range
.upper
;
3333 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3341 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3344 ranges_check(ranges
, "after del");
3348 ranges_check(ranges
, "failed del");
3354 * Removes all selection ranges
3357 * [I] infoPtr : valid pointer to the listview structure
3358 * [I] toSkip : item range to skip removing the selection
3364 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3373 lvItem
.stateMask
= LVIS_SELECTED
;
3375 /* need to clone the DPA because callbacks can change it */
3376 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3377 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3378 while(iterator_next(&i
))
3379 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3380 /* note that the iterator destructor will free the cloned range */
3381 iterator_destroy(&i
);
3386 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3390 if (!(toSkip
= ranges_create(1))) return FALSE
;
3391 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3392 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3393 ranges_destroy(toSkip
);
3397 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3399 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3404 * Retrieves the number of items that are marked as selected.
3407 * [I] infoPtr : valid pointer to the listview structure
3410 * Number of items selected.
3412 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3414 INT nSelectedCount
= 0;
3416 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3419 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3421 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3426 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3428 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3429 return nSelectedCount
;
3434 * Manages the item focus.
3437 * [I] infoPtr : valid pointer to the listview structure
3438 * [I] nItem : item index
3441 * TRUE : focused item changed
3442 * FALSE : focused item has NOT changed
3444 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3446 INT oldFocus
= infoPtr
->nFocusedItem
;
3449 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3451 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3452 lvItem
.stateMask
= LVIS_FOCUSED
;
3453 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3455 return oldFocus
!= infoPtr
->nFocusedItem
;
3458 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3460 if (nShiftItem
< nItem
) return nShiftItem
;
3462 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3464 if (direction
> 0) return nShiftItem
+ direction
;
3466 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3469 /* This function updates focus index.
3472 focus : current focus index
3473 item : index of item to be added/removed
3474 direction : add/remove flag
3476 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3478 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3480 infoPtr
->bDoChangeNotify
= FALSE
;
3481 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3482 if (focus
!= infoPtr
->nFocusedItem
)
3483 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3484 infoPtr
->bDoChangeNotify
= old_change
;
3489 * Updates the various indices after an item has been inserted or deleted.
3492 * [I] infoPtr : valid pointer to the listview structure
3493 * [I] nItem : item index
3494 * [I] direction : Direction of shift, +1 or -1.
3499 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3501 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3503 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3504 assert(abs(direction
) == 1);
3505 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3507 /* But we are not supposed to modify nHotItem! */
3512 * Adds a block of selections.
3515 * [I] infoPtr : valid pointer to the listview structure
3516 * [I] nItem : item index
3519 * Whether the window is still valid.
3521 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3523 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3524 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3525 HWND hwndSelf
= infoPtr
->hwndSelf
;
3526 NMLVODSTATECHANGE nmlv
;
3531 /* Temporarily disable change notification
3532 * If the control is LVS_OWNERDATA, we need to send
3533 * only one LVN_ODSTATECHANGED notification.
3534 * See MSDN documentation for LVN_ITEMCHANGED.
3536 bOldChange
= infoPtr
->bDoChangeNotify
;
3537 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3539 if (nFirst
== -1) nFirst
= nItem
;
3541 item
.state
= LVIS_SELECTED
;
3542 item
.stateMask
= LVIS_SELECTED
;
3544 for (i
= nFirst
; i
<= nLast
; i
++)
3545 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3547 ZeroMemory(&nmlv
, sizeof(nmlv
));
3548 nmlv
.iFrom
= nFirst
;
3551 nmlv
.uNewState
= item
.state
;
3553 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3554 if (!IsWindow(hwndSelf
))
3556 infoPtr
->bDoChangeNotify
= bOldChange
;
3563 * Sets a single group selection.
3566 * [I] infoPtr : valid pointer to the listview structure
3567 * [I] nItem : item index
3572 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3579 if (!(selection
= ranges_create(100))) return;
3581 item
.state
= LVIS_SELECTED
;
3582 item
.stateMask
= LVIS_SELECTED
;
3584 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3586 if (infoPtr
->nSelectionMark
== -1)
3588 infoPtr
->nSelectionMark
= nItem
;
3589 ranges_additem(selection
, nItem
);
3595 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3596 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3597 ranges_add(selection
, sel
);
3602 RECT rcItem
, rcSel
, rcSelMark
;
3605 rcItem
.left
= LVIR_BOUNDS
;
3606 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3607 ranges_destroy (selection
);
3610 rcSelMark
.left
= LVIR_BOUNDS
;
3611 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3612 ranges_destroy (selection
);
3615 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3616 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3617 while(iterator_next(&i
))
3619 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3620 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3622 iterator_destroy(&i
);
3625 /* disable per item notifications on LVS_OWNERDATA style
3626 FIXME: single LVN_ODSTATECHANGED should be used */
3627 bOldChange
= infoPtr
->bDoChangeNotify
;
3628 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3630 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3633 iterator_rangesitems(&i
, selection
);
3634 while(iterator_next(&i
))
3635 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3636 /* this will also destroy the selection */
3637 iterator_destroy(&i
);
3639 infoPtr
->bDoChangeNotify
= bOldChange
;
3641 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3646 * Sets a single selection.
3649 * [I] infoPtr : valid pointer to the listview structure
3650 * [I] nItem : item index
3655 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3659 TRACE("nItem=%d\n", nItem
);
3661 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3663 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3664 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3665 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3667 infoPtr
->nSelectionMark
= nItem
;
3672 * Set selection(s) with keyboard.
3675 * [I] infoPtr : valid pointer to the listview structure
3676 * [I] nItem : item index
3677 * [I] space : VK_SPACE code sent
3680 * SUCCESS : TRUE (needs to be repainted)
3681 * FAILURE : FALSE (nothing has changed)
3683 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3685 /* FIXME: pass in the state */
3686 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3687 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3688 BOOL bResult
= FALSE
;
3690 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3691 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3695 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3696 LISTVIEW_SetSelection(infoPtr
, nItem
);
3700 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3704 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3705 lvItem
.stateMask
= LVIS_SELECTED
;
3708 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3709 if (lvItem
.state
& LVIS_SELECTED
)
3710 infoPtr
->nSelectionMark
= nItem
;
3712 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3715 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3718 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3722 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3724 LVHITTESTINFO lvHitTestInfo
;
3726 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3727 lvHitTestInfo
.pt
.x
= pt
.x
;
3728 lvHitTestInfo
.pt
.y
= pt
.y
;
3730 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3732 lpLVItem
->mask
= LVIF_PARAM
;
3733 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3734 lpLVItem
->iSubItem
= 0;
3736 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3739 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3741 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3742 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3743 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3748 * Called when the mouse is being actively tracked and has hovered for a specified
3752 * [I] infoPtr : valid pointer to the listview structure
3753 * [I] fwKeys : key indicator
3754 * [I] x,y : mouse position
3757 * 0 if the message was processed, non-zero if there was an error
3760 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3761 * over the item for a certain period of time.
3764 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3768 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3770 if (LISTVIEW_IsHotTracking(infoPtr
))
3778 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3779 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3781 SetFocus(infoPtr
->hwndSelf
);
3787 #define SCROLL_LEFT 0x1
3788 #define SCROLL_RIGHT 0x2
3789 #define SCROLL_UP 0x4
3790 #define SCROLL_DOWN 0x8
3794 * Utility routine to draw and highlight items within a marquee selection rectangle.
3797 * [I] infoPtr : valid pointer to the listview structure
3798 * [I] coords_orig : original co-ordinates of the cursor
3799 * [I] coords_offs : offsetted coordinates of the cursor
3800 * [I] offset : offset amount
3801 * [I] scroll : Bitmask of which directions we should scroll, if at all
3806 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3807 const POINT
*coords_offs
, const POINT
*offset
,
3810 BOOL controlDown
= FALSE
;
3812 ITERATOR old_elems
, new_elems
;
3815 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3817 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3818 rect
.right
= coords_offs
->x
;
3822 rect
.left
= coords_offs
->x
;
3823 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3826 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3828 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3829 rect
.bottom
= coords_offs
->y
;
3833 rect
.top
= coords_offs
->y
;
3834 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3837 /* Cancel out the old marquee rectangle and draw the new one */
3838 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3840 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3841 the cursor is further away */
3843 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3844 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3846 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3847 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3849 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3850 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3852 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3853 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3855 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3857 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3859 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3860 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3862 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3863 iterator_remove_common_items(&old_elems
, &new_elems
);
3865 /* Iterate over no longer selected items */
3866 while (iterator_next(&old_elems
))
3868 if (old_elems
.nItem
> -1)
3870 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3873 item
.state
= LVIS_SELECTED
;
3875 item
.stateMask
= LVIS_SELECTED
;
3877 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3880 iterator_destroy(&old_elems
);
3883 /* Iterate over newly selected items */
3884 if (GetKeyState(VK_CONTROL
) & 0x8000)
3887 while (iterator_next(&new_elems
))
3889 if (new_elems
.nItem
> -1)
3891 /* If CTRL is pressed, invert. If not, always select the item. */
3892 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3895 item
.state
= LVIS_SELECTED
;
3897 item
.stateMask
= LVIS_SELECTED
;
3899 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3902 iterator_destroy(&new_elems
);
3904 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3909 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3910 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3913 * [I] hwnd : Handle to the listview
3914 * [I] uMsg : WM_TIMER (ignored)
3915 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3916 * [I] dwTimer : The elapsed time (ignored)
3921 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3923 LISTVIEW_INFO
*infoPtr
;
3924 SCROLLINFO scrollInfo
;
3930 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3935 /* Get the current cursor position and convert to client coordinates */
3936 GetCursorPos(&coords_orig
);
3937 ScreenToClient(hWnd
, &coords_orig
);
3939 /* Ensure coordinates are within client bounds */
3940 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3941 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3944 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3946 /* Offset coordinates by the appropriate amount */
3947 coords_offs
.x
-= offset
.x
;
3948 coords_offs
.y
-= offset
.y
;
3950 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3951 scrollInfo
.fMask
= SIF_ALL
;
3953 /* Work out in which directions we can scroll */
3954 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3956 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3957 scroll
|= SCROLL_UP
;
3959 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3960 scroll
|= SCROLL_DOWN
;
3963 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3965 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3966 scroll
|= SCROLL_LEFT
;
3968 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3969 scroll
|= SCROLL_RIGHT
;
3972 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3973 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3974 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3975 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3977 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3983 * Called whenever WM_MOUSEMOVE is received.
3986 * [I] infoPtr : valid pointer to the listview structure
3987 * [I] fwKeys : key indicator
3988 * [I] x,y : mouse position
3991 * 0 if the message is processed, non-zero if there was an error
3993 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3999 if (!(fwKeys
& MK_LBUTTON
))
4000 infoPtr
->bLButtonDown
= FALSE
;
4002 if (infoPtr
->bLButtonDown
)
4004 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4005 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4007 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4010 if (infoPtr
->bLButtonDown
)
4012 if (infoPtr
->bMarqueeSelect
)
4022 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4024 /* Ensure coordinates are within client bounds */
4025 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4026 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4028 /* Offset coordinates by the appropriate amount */
4029 coords_offs
.x
-= offset
.x
;
4030 coords_offs
.y
-= offset
.y
;
4032 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4033 move the mouse again */
4035 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4036 (y
>= infoPtr
->rcList
.bottom
))
4038 if (!infoPtr
->bScrolling
)
4040 infoPtr
->bScrolling
= TRUE
;
4041 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4046 infoPtr
->bScrolling
= FALSE
;
4047 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4050 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4058 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4060 /* reset item marker */
4061 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4062 infoPtr
->nLButtonDownItem
= -1;
4064 if (!PtInRect(&rect
, pt
))
4066 /* this path covers the following:
4067 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4068 2. change focus with keys
4069 3. move mouse over item from step 1 selects it and moves focus on it */
4070 if (infoPtr
->nLButtonDownItem
!= -1 &&
4071 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4075 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4076 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4078 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4079 infoPtr
->nLButtonDownItem
= -1;
4082 if (!infoPtr
->bDragging
)
4084 ht
.pt
= infoPtr
->ptClickPos
;
4085 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4087 /* If the click is outside the range of an item, begin a
4088 highlight. If not, begin an item drag. */
4093 /* If we're allowing multiple selections, send notification.
4094 If return value is non-zero, cancel. */
4095 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4097 /* Store the absolute coordinates of the click */
4099 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4101 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4102 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4104 /* Begin selection and capture mouse */
4105 infoPtr
->bMarqueeSelect
= TRUE
;
4106 SetCapture(infoPtr
->hwndSelf
);
4113 ZeroMemory(&nmlv
, sizeof(nmlv
));
4114 nmlv
.iItem
= ht
.iItem
;
4115 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4117 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4118 infoPtr
->bDragging
= TRUE
;
4126 /* see if we are supposed to be tracking mouse hovering */
4127 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4128 TRACKMOUSEEVENT trackinfo
;
4130 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4131 trackinfo
.dwFlags
= TME_QUERY
;
4133 /* see if we are already tracking this hwnd */
4134 _TrackMouseEvent(&trackinfo
);
4136 if(!(trackinfo
.dwFlags
& TME_HOVER
) || trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4137 trackinfo
.dwFlags
= TME_HOVER
;
4138 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4139 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4141 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4142 _TrackMouseEvent(&trackinfo
);
4151 * Tests whether the item is assignable to a list with style lStyle
4153 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4155 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4156 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4157 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4165 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4168 * [I] infoPtr : valid pointer to the listview structure
4169 * [I] lpLVItem : valid pointer to new item attributes
4170 * [I] isNew : the item being set is being inserted
4171 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4172 * [O] bChanged : will be set to TRUE if the item really changed
4178 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4184 /* stateMask is ignored for LVM_INSERTITEM */
4185 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4189 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4191 if (lpLVItem
->mask
== 0) return TRUE
;
4193 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4195 /* a virtual listview only stores selection and focus */
4196 if (lpLVItem
->mask
& ~LVIF_STATE
)
4202 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4203 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4207 /* we need to get the lParam and state of the item */
4208 item
.iItem
= lpLVItem
->iItem
;
4209 item
.iSubItem
= lpLVItem
->iSubItem
;
4210 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4211 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4215 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4217 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4218 /* determine what fields will change */
4219 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4220 uChanged
|= LVIF_STATE
;
4222 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4223 uChanged
|= LVIF_IMAGE
;
4225 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4226 uChanged
|= LVIF_PARAM
;
4228 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4229 uChanged
|= LVIF_INDENT
;
4231 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4232 uChanged
|= LVIF_TEXT
;
4234 TRACE("change mask=0x%x\n", uChanged
);
4236 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4237 nmlv
.iItem
= lpLVItem
->iItem
;
4238 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4239 nmlv
.uOldState
= item
.state
;
4240 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4241 nmlv
.lParam
= item
.lParam
;
4243 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4244 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4245 are enabled. Even nothing really changed we still need to send this,
4246 in this case uChanged mask is just set to passed item mask. */
4247 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4249 HWND hwndSelf
= infoPtr
->hwndSelf
;
4251 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4253 if (!IsWindow(hwndSelf
))
4257 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4258 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4259 /* this means we won't hit a focus change path later */
4260 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4262 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4263 infoPtr
->nFocusedItem
++;
4266 if (!uChanged
) return TRUE
;
4269 /* copy information */
4270 if (lpLVItem
->mask
& LVIF_TEXT
)
4271 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4273 if (lpLVItem
->mask
& LVIF_IMAGE
)
4274 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4276 if (lpLVItem
->mask
& LVIF_PARAM
)
4277 lpItem
->lParam
= lpLVItem
->lParam
;
4279 if (lpLVItem
->mask
& LVIF_INDENT
)
4280 lpItem
->iIndent
= lpLVItem
->iIndent
;
4282 if (uChanged
& LVIF_STATE
)
4284 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4286 lpItem
->state
&= ~stateMask
;
4287 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4289 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4291 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4292 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4294 else if (stateMask
& LVIS_SELECTED
)
4296 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4298 /* If we are asked to change focus, and we manage it, do it.
4299 It's important to have all new item data stored at this point,
4300 because changing existing focus could result in a redrawing operation,
4301 which in turn could ask for disp data, application should see all data
4302 for inserted item when processing LVN_GETDISPINFO.
4304 The way this works application will see nested item change notifications -
4305 changed item notifications interrupted by ones from item losing focus. */
4306 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4308 if (lpLVItem
->state
& LVIS_FOCUSED
)
4310 /* update selection mark */
4311 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4312 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4314 if (infoPtr
->nFocusedItem
!= -1)
4316 /* remove current focus */
4317 item
.mask
= LVIF_STATE
;
4319 item
.stateMask
= LVIS_FOCUSED
;
4321 /* recurse with redrawing an item */
4322 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4325 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4326 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4328 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4330 infoPtr
->nFocusedItem
= -1;
4335 /* if we're inserting the item, we're done */
4336 if (isNew
) return TRUE
;
4338 /* send LVN_ITEMCHANGED notification */
4339 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4340 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4347 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4350 * [I] infoPtr : valid pointer to the listview structure
4351 * [I] lpLVItem : valid pointer to new subitem attributes
4352 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4353 * [O] bChanged : will be set to TRUE if the item really changed
4359 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4362 SUBITEM_INFO
*lpSubItem
;
4364 /* we do not support subitems for virtual listviews */
4365 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4367 /* set subitem only if column is present */
4368 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4370 /* First do some sanity checks */
4371 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4372 particularly useful. We currently do not actually do anything with
4373 the flag on subitems.
4375 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4376 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4378 /* get the subitem structure, and create it if not there */
4379 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4380 assert (hdpaSubItems
);
4382 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4385 SUBITEM_INFO
*tmpSubItem
;
4388 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4389 if (!lpSubItem
) return FALSE
;
4390 /* we could binary search here, if need be...*/
4391 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4393 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4394 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4396 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4401 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4402 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4406 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4408 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4412 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4414 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4423 * Sets item attributes.
4426 * [I] infoPtr : valid pointer to the listview structure
4427 * [I] lpLVItem : new item attributes
4428 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4434 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4436 HWND hwndSelf
= infoPtr
->hwndSelf
;
4437 LPWSTR pszText
= NULL
;
4438 BOOL bResult
, bChanged
= FALSE
;
4441 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4443 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4446 /* Store old item area */
4447 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4449 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4450 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4452 pszText
= lpLVItem
->pszText
;
4453 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4456 /* actually set the fields */
4457 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4459 if (lpLVItem
->iSubItem
)
4460 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4462 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4463 if (!IsWindow(hwndSelf
))
4466 /* redraw item, if necessary */
4467 if (bChanged
&& !infoPtr
->bIsDrawing
)
4469 /* this little optimization eliminates some nasty flicker */
4470 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4471 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4472 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4473 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4476 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4477 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4483 textfreeT(lpLVItem
->pszText
, isW
);
4484 lpLVItem
->pszText
= pszText
;
4492 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4495 * [I] infoPtr : valid pointer to the listview structure
4500 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4503 SCROLLINFO scrollInfo
;
4505 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4506 scrollInfo
.fMask
= SIF_POS
;
4508 if (infoPtr
->uView
== LV_VIEW_LIST
)
4510 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4511 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4513 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4515 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4516 nItem
= scrollInfo
.nPos
;
4520 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4521 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4524 TRACE("nItem=%d\n", nItem
);
4532 * Erases the background of the given rectangle
4535 * [I] infoPtr : valid pointer to the listview structure
4536 * [I] hdc : device context handle
4537 * [I] lprcBox : clipping rectangle
4543 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4545 if (!infoPtr
->hBkBrush
) return FALSE
;
4547 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4549 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4552 /* Draw main item or subitem */
4553 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4555 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4560 /* now check if we need to update the focus rectangle */
4561 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4562 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4564 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4565 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4566 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4567 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4568 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4569 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4570 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4571 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4572 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4574 /* FIXME: temporary hack */
4575 rcSelect
.left
= rcLabel
.left
;
4577 /* in icon mode, the label rect is really what we want to draw the
4579 /* in detail mode, we want to paint background for label rect when
4580 * item is not selected or listview has full row select; otherwise paint
4581 * background for text only */
4582 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4583 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4584 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4587 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4588 ExtTextOutW(nmlvcd
->nmcd
.hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, NULL
, 0, NULL
);
4590 if (item
->state
& LVIS_FOCUSED
)
4592 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4594 /* we have to update left focus bound too if item isn't in leftmost column
4595 and reduce right box bound */
4596 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4600 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4602 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
4603 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4604 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4606 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, index
)->rcHeader
.right
+ Originx
;
4607 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4611 rcSelect
.right
= rcBox
.right
;
4614 /* store new focus rectangle */
4615 infoPtr
->rcFocus
= rcSelect
;
4619 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4621 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4624 TRACE("stateimage=%d\n", stateimage
);
4625 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4630 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4631 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4635 TRACE("iImage=%d\n", item
->iImage
);
4637 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4638 style
= ILD_SELECTED
;
4642 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4643 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4644 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4645 style
| (item
->state
& LVIS_OVERLAYMASK
));
4648 /* Don't bother painting item being edited */
4649 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4651 /* figure out the text drawing flags */
4652 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4653 if (infoPtr
->uView
== LV_VIEW_ICON
)
4654 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4655 else if (item
->iSubItem
)
4657 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4659 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4660 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4661 default: format
|= DT_LEFT
;
4664 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4666 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4667 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4669 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4671 /* for GRIDLINES reduce the bottom so the text formats correctly */
4672 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4675 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4683 * [I] infoPtr : valid pointer to the listview structure
4684 * [I] hdc : device context handle
4685 * [I] nItem : item index
4686 * [I] nSubItem : subitem index
4687 * [I] pos : item position in client coordinates
4688 * [I] cdmode : custom draw mode
4694 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4696 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4697 static WCHAR callbackW
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4698 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4700 NMLVCUSTOMDRAW nmlvcd
;
4703 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4705 /* get information needed for drawing the item */
4706 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4707 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4708 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4709 lvItem
.iItem
= nItem
;
4710 lvItem
.iSubItem
= 0;
4713 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4714 lvItem
.pszText
= szDispText
;
4715 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4716 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4717 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4719 /* now check if we need to update the focus rectangle */
4720 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4721 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4723 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4724 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4726 /* Full custom draw stage sequence looks like this:
4731 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4732 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item iself
4733 - CDDS_ITEMPOSTPAINT
4738 - CDDS_ITEMPOSTPAINT
4741 /* fill in the custom draw structure */
4742 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4743 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4744 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4745 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4749 while (iterator_next(subitems
))
4751 DWORD subitemstage
= CDRF_DODEFAULT
;
4753 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4754 if (subitems
->nItem
)
4756 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4757 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4758 lvItem
.iItem
= nItem
;
4759 lvItem
.iSubItem
= subitems
->nItem
;
4762 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4763 lvItem
.pszText
= szDispText
;
4764 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4765 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4766 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4767 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4768 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4770 /* update custom draw data */
4771 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4772 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4773 nmlvcd
.iSubItem
= subitems
->nItem
;
4776 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4777 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4780 nmlvcd
.clrTextBk
= infoPtr
->clrTextBk
;
4781 nmlvcd
.clrText
= infoPtr
->clrText
;
4784 if (subitems
->nItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4785 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4786 else if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4787 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4789 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4790 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4792 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4793 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4798 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4799 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4803 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4805 nmlvcd
.iSubItem
= 0;
4806 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4814 * Draws listview items when in owner draw mode.
4817 * [I] infoPtr : valid pointer to the listview structure
4818 * [I] hdc : device context handle
4823 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4825 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4826 DWORD cditemmode
= CDRF_DODEFAULT
;
4827 NMLVCUSTOMDRAW nmlvcd
;
4828 POINT Origin
, Position
;
4834 ZeroMemory(&dis
, sizeof(dis
));
4836 /* Get scroll info once before loop */
4837 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4839 /* iterate through the invalidated rows */
4840 while(iterator_next(i
))
4842 item
.iItem
= i
->nItem
;
4844 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4845 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4846 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4848 dis
.CtlType
= ODT_LISTVIEW
;
4850 dis
.itemID
= item
.iItem
;
4851 dis
.itemAction
= ODA_DRAWENTIRE
;
4853 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4854 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4855 dis
.hwndItem
= infoPtr
->hwndSelf
;
4857 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4858 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4859 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4860 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4861 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4862 dis
.itemData
= item
.lParam
;
4864 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4867 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4868 * structure for the rest. of the paint cycle
4870 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4871 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4872 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4874 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4876 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4877 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4880 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4881 notify_postpaint(infoPtr
, &nmlvcd
);
4887 * Draws listview items when in report display mode.
4890 * [I] infoPtr : valid pointer to the listview structure
4891 * [I] hdc : device context handle
4892 * [I] cdmode : custom draw mode
4897 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4900 RECT rcClip
, rcItem
;
4901 POINT Origin
, Position
;
4908 /* figure out what to draw */
4909 rgntype
= GetClipBox(hdc
, &rcClip
);
4910 if (rgntype
== NULLREGION
) return;
4912 /* Get scroll info once before loop */
4913 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4915 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4917 /* narrow down the columns we need to paint */
4918 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4920 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4922 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4923 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4924 ranges_additem(colRanges
, index
);
4926 iterator_rangesitems(&j
, colRanges
);
4928 /* in full row select, we _have_ to draw the main item */
4929 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4932 /* iterate through the invalidated rows */
4933 while(iterator_next(i
))
4938 SelectObject(hdc
, infoPtr
->hFont
);
4939 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4940 Position
.y
+= Origin
.y
;
4942 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4944 /* iterate through the invalidated columns */
4945 while(iterator_next(&j
))
4947 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4948 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4950 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4953 rcItem
.bottom
= infoPtr
->nItemHeight
;
4954 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4955 if (!RectVisible(hdc
, &rcItem
)) continue;
4958 ranges_additem(subitems
, j
.nItem
);
4961 iterator_rangesitems(&k
, subitems
);
4962 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
4963 iterator_destroy(&k
);
4965 iterator_destroy(&j
);
4970 * Draws the gridlines if necessary when in report display mode.
4973 * [I] infoPtr : valid pointer to the listview structure
4974 * [I] hdc : device context handle
4979 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4985 RECT rcClip
, rcItem
= {0};
4993 /* figure out what to draw */
4994 rgntype
= GetClipBox(hdc
, &rcClip
);
4995 if (rgntype
== NULLREGION
) return;
4997 /* Get scroll info once before loop */
4998 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5000 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5002 /* narrow down the columns we need to paint */
5003 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5005 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5007 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5008 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5009 ranges_additem(colRanges
, index
);
5012 /* is right most vertical line visible? */
5013 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5015 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5016 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5017 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5020 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5022 hOldPen
= SelectObject ( hdc
, hPen
);
5024 /* draw the vertical lines for the columns */
5025 iterator_rangesitems(&j
, colRanges
);
5026 while(iterator_next(&j
))
5028 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5029 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5030 rcItem
.left
+= Origin
.x
;
5031 rcItem
.right
+= Origin
.x
;
5032 rcItem
.top
= infoPtr
->rcList
.top
;
5033 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5034 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5035 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5036 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5038 iterator_destroy(&j
);
5039 /* draw rightmost grid line if visible */
5042 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5043 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5044 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5046 rcItem
.right
+= Origin
.x
;
5048 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5049 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5052 /* draw the horizontal lines for the rows */
5053 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5054 rcItem
.left
= infoPtr
->rcList
.left
;
5055 rcItem
.right
= infoPtr
->rcList
.right
;
5056 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5058 rcItem
.bottom
= rcItem
.top
= y
;
5059 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5060 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5061 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5064 SelectObject( hdc
, hOldPen
);
5065 DeleteObject( hPen
);
5068 ranges_destroy(colRanges
);
5073 * Draws listview items when in list display mode.
5076 * [I] infoPtr : valid pointer to the listview structure
5077 * [I] hdc : device context handle
5078 * [I] cdmode : custom draw mode
5083 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5085 POINT Origin
, Position
;
5087 /* Get scroll info once before loop */
5088 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5090 while(iterator_prev(i
))
5092 SelectObject(hdc
, infoPtr
->hFont
);
5093 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5094 Position
.x
+= Origin
.x
;
5095 Position
.y
+= Origin
.y
;
5097 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5104 * Draws listview items.
5107 * [I] infoPtr : valid pointer to the listview structure
5108 * [I] hdc : device context handle
5109 * [I] prcErase : rect to be erased before refresh (may be NULL)
5114 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5116 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5117 NMLVCUSTOMDRAW nmlvcd
;
5124 HBITMAP hbmp
= NULL
;
5127 LISTVIEW_DUMP(infoPtr
);
5129 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5130 TRACE("double buffering\n");
5132 hdc
= CreateCompatibleDC(hdcOrig
);
5134 ERR("Failed to create DC for backbuffer\n");
5137 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5138 infoPtr
->rcList
.bottom
);
5140 ERR("Failed to create bitmap for backbuffer\n");
5145 SelectObject(hdc
, hbmp
);
5146 SelectObject(hdc
, infoPtr
->hFont
);
5148 if(GetClipBox(hdcOrig
, &rcClient
))
5149 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5151 /* Save dc values we're gonna trash while drawing
5152 * FIXME: Should be done in LISTVIEW_DrawItem() */
5153 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5154 oldBkMode
= GetBkMode(hdc
);
5155 oldBkColor
= GetBkColor(hdc
);
5156 oldTextColor
= GetTextColor(hdc
);
5159 infoPtr
->bIsDrawing
= TRUE
;
5162 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5163 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5164 /* If no erasing was done (usually because RedrawWindow was called
5165 * with RDW_INVALIDATE only) we need to copy the old contents into
5166 * the backbuffer before continuing. */
5167 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5168 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5169 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5170 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5173 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5174 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5175 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5176 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5178 /* nothing to draw */
5179 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5181 /* figure out what we need to draw */
5182 iterator_visibleitems(&i
, infoPtr
, hdc
);
5183 range
= iterator_range(&i
);
5185 /* send cache hint notification */
5186 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5190 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5191 nmlv
.iFrom
= range
.lower
;
5192 nmlv
.iTo
= range
.upper
- 1;
5193 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5196 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5197 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5200 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5201 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5202 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5203 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5205 /* if we have a focus rect and it's visible, draw it */
5206 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5207 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5208 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5210 iterator_destroy(&i
);
5213 /* For LVS_EX_GRIDLINES go and draw lines */
5214 /* This includes the case where there were *no* items */
5215 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5216 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5218 /* Draw marquee rectangle if appropriate */
5219 if (infoPtr
->bMarqueeSelect
)
5220 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5222 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5223 notify_postpaint(infoPtr
, &nmlvcd
);
5226 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5227 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5228 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5229 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5234 SelectObject(hdc
, hOldFont
);
5235 SetBkMode(hdc
, oldBkMode
);
5236 SetBkColor(hdc
, oldBkColor
);
5237 SetTextColor(hdc
, oldTextColor
);
5240 infoPtr
->bIsDrawing
= FALSE
;
5246 * Calculates the approximate width and height of a given number of items.
5249 * [I] infoPtr : valid pointer to the listview structure
5250 * [I] nItemCount : number of items
5251 * [I] wWidth : width
5252 * [I] wHeight : height
5255 * Returns a DWORD. The width in the low word and the height in high word.
5257 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5258 WORD wWidth
, WORD wHeight
)
5260 DWORD dwViewRect
= 0;
5262 if (nItemCount
== -1)
5263 nItemCount
= infoPtr
->nItemCount
;
5265 if (infoPtr
->uView
== LV_VIEW_LIST
)
5267 INT nItemCountPerColumn
= 1;
5268 INT nColumnCount
= 0;
5270 if (wHeight
== 0xFFFF)
5272 /* use current height */
5273 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5276 if (wHeight
< infoPtr
->nItemHeight
)
5277 wHeight
= infoPtr
->nItemHeight
;
5281 if (infoPtr
->nItemHeight
> 0)
5283 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5284 if (nItemCountPerColumn
== 0)
5285 nItemCountPerColumn
= 1;
5287 if (nItemCount
% nItemCountPerColumn
!= 0)
5288 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5290 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5294 /* Microsoft padding magic */
5295 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5296 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5298 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5300 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5304 if (infoPtr
->nItemCount
> 0)
5306 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5307 wWidth
= rcBox
.right
- rcBox
.left
;
5308 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5312 /* use current height and width */
5313 if (wHeight
== 0xffff)
5314 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5315 if (wWidth
== 0xffff)
5316 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5319 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5321 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5327 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5328 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5330 if (wWidth
== 0xffff)
5331 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5333 if (wWidth
< nItemWidth
)
5334 wWidth
= nItemWidth
;
5336 cols
= wWidth
/ nItemWidth
;
5337 if (cols
> nItemCount
)
5344 rows
= nItemCount
/ cols
;
5345 if (nItemCount
% cols
)
5351 wHeight
= (nItemHeight
* rows
)+2;
5352 wWidth
= (nItemWidth
* cols
)+2;
5354 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5356 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5357 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5364 * Cancel edit label with saving item text.
5367 * [I] infoPtr : valid pointer to the listview structure
5370 * Always returns TRUE.
5372 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5374 if (infoPtr
->hwndEdit
)
5376 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5377 HWND edit
= infoPtr
->hwndEdit
;
5379 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5380 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5388 * Create a drag image list for the specified item.
5391 * [I] infoPtr : valid pointer to the listview structure
5392 * [I] iItem : index of item
5393 * [O] lppt : Upper-left corner of the image
5396 * Returns a handle to the image list if successful, NULL otherwise.
5398 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5404 HBITMAP hbmp
, hOldbmp
;
5406 HIMAGELIST dragList
= 0;
5407 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5409 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5412 rcItem
.left
= LVIR_BOUNDS
;
5413 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5416 lppt
->x
= rcItem
.left
;
5417 lppt
->y
= rcItem
.top
;
5419 size
.cx
= rcItem
.right
- rcItem
.left
;
5420 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5422 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5423 hdc
= CreateCompatibleDC(hdcOrig
);
5424 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5425 hOldbmp
= SelectObject(hdc
, hbmp
);
5426 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5428 rcItem
.left
= rcItem
.top
= 0;
5429 rcItem
.right
= size
.cx
;
5430 rcItem
.bottom
= size
.cy
;
5431 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5434 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5436 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5437 SelectObject(hdc
, hOldbmp
);
5438 ImageList_Add(dragList
, hbmp
, 0);
5441 SelectObject(hdc
, hOldbmp
);
5443 SelectObject(hdc
, hOldFont
);
5446 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5448 TRACE("ret=%p\n", dragList
);
5456 * Removes all listview items and subitems.
5459 * [I] infoPtr : valid pointer to the listview structure
5465 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5467 HDPA hdpaSubItems
= NULL
;
5468 BOOL suppress
= FALSE
;
5476 /* we do it directly, to avoid notifications */
5477 ranges_clear(infoPtr
->selectionRanges
);
5478 infoPtr
->nSelectionMark
= -1;
5479 infoPtr
->nFocusedItem
= -1;
5480 SetRectEmpty(&infoPtr
->rcFocus
);
5481 /* But we are supposed to leave nHotItem as is! */
5483 /* send LVN_DELETEALLITEMS notification */
5484 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5488 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5490 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5493 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5495 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5497 /* send LVN_DELETEITEM notification, if not suppressed
5498 and if it is not a virtual listview */
5499 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5500 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5501 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5502 /* free id struct */
5503 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5504 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5505 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5507 /* both item and subitem start with ITEMHDR header */
5508 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5510 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5511 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5514 DPA_Destroy(hdpaSubItems
);
5515 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5517 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5518 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5519 infoPtr
->nItemCount
--;
5524 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5525 LISTVIEW_UpdateScroll(infoPtr
);
5527 LISTVIEW_InvalidateList(infoPtr
);
5534 * Scrolls, and updates the columns, when a column is changing width.
5537 * [I] infoPtr : valid pointer to the listview structure
5538 * [I] nColumn : column to scroll
5539 * [I] dx : amount of scroll, in pixels
5544 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5546 COLUMN_INFO
*lpColumnInfo
;
5552 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5553 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5554 rcCol
= lpColumnInfo
->rcHeader
;
5555 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5556 rcCol
.left
= rcCol
.right
;
5558 /* adjust the other columns */
5559 hdi
.mask
= HDI_ORDER
;
5560 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5562 INT nOrder
= hdi
.iOrder
;
5563 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5565 hdi
.mask
= HDI_ORDER
;
5566 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5567 if (hdi
.iOrder
>= nOrder
) {
5568 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5569 lpColumnInfo
->rcHeader
.left
+= dx
;
5570 lpColumnInfo
->rcHeader
.right
+= dx
;
5575 /* do not update screen if not in report mode */
5576 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5578 /* Need to reset the item width when inserting a new column */
5579 infoPtr
->nItemWidth
+= dx
;
5581 LISTVIEW_UpdateScroll(infoPtr
);
5582 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5584 /* scroll to cover the deleted column, and invalidate for redraw */
5585 rcOld
= infoPtr
->rcList
;
5586 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5587 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5592 * Removes a column from the listview control.
5595 * [I] infoPtr : valid pointer to the listview structure
5596 * [I] nColumn : column index
5602 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5606 TRACE("nColumn=%d\n", nColumn
);
5608 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5609 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5611 /* While the MSDN specifically says that column zero should not be deleted,
5612 what actually happens is that the column itself is deleted but no items or subitems
5616 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5618 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5621 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5622 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5624 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5626 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5628 INT nItem
, nSubItem
, i
;
5630 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5632 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5635 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5637 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5638 if (lpSubItem
->iSubItem
== nColumn
)
5641 lpDelItem
= lpSubItem
;
5643 else if (lpSubItem
->iSubItem
> nColumn
)
5645 lpSubItem
->iSubItem
--;
5649 /* if we found our subitem, zap it */
5653 if (is_text(lpDelItem
->hdr
.pszText
))
5654 Free(lpDelItem
->hdr
.pszText
);
5659 /* free dpa memory */
5660 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5665 /* update the other column info */
5666 LISTVIEW_UpdateItemSize(infoPtr
);
5667 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5668 LISTVIEW_InvalidateList(infoPtr
);
5670 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5677 * Invalidates the listview after an item's insertion or deletion.
5680 * [I] infoPtr : valid pointer to the listview structure
5681 * [I] nItem : item index
5682 * [I] dir : -1 if deleting, 1 if inserting
5687 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5689 INT nPerCol
, nItemCol
, nItemRow
;
5693 /* if we don't refresh, what's the point of scrolling? */
5694 if (!is_redrawing(infoPtr
)) return;
5696 assert (abs(dir
) == 1);
5698 /* arrange icons if autoarrange is on */
5699 if (is_autoarrange(infoPtr
))
5701 BOOL arrange
= TRUE
;
5702 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5703 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5704 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5707 /* scrollbars need updating */
5708 LISTVIEW_UpdateScroll(infoPtr
);
5710 /* figure out the item's position */
5711 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5712 nPerCol
= infoPtr
->nItemCount
+ 1;
5713 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5714 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5715 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5718 nItemCol
= nItem
/ nPerCol
;
5719 nItemRow
= nItem
% nPerCol
;
5720 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5722 /* move the items below up a slot */
5723 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5724 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5725 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5726 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5727 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5728 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5729 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5731 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5732 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5735 /* report has only that column, so we're done */
5736 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5738 /* now for LISTs, we have to deal with the columns to the right */
5739 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5741 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5742 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5743 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5744 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5745 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5750 * Removes an item from the listview control.
5753 * [I] infoPtr : valid pointer to the listview structure
5754 * [I] nItem : item index
5760 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5763 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5764 INT focus
= infoPtr
->nFocusedItem
;
5766 TRACE("(nItem=%d)\n", nItem
);
5768 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5770 /* remove selection, and focus */
5772 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5773 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5775 /* send LVN_DELETEITEM notification. */
5776 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5778 /* we need to do this here, because we'll be deleting stuff */
5780 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5782 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5790 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5791 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5793 /* free id struct */
5794 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5795 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5796 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5798 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5800 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5801 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5804 DPA_Destroy(hdpaSubItems
);
5809 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5810 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5813 infoPtr
->nItemCount
--;
5814 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5815 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5817 /* now is the invalidation fun */
5819 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5826 * Callback implementation for editlabel control
5829 * [I] infoPtr : valid pointer to the listview structure
5830 * [I] storeText : store edit box text as item text
5831 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5837 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5839 HWND hwndSelf
= infoPtr
->hwndSelf
;
5840 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5841 NMLVDISPINFOW dispInfo
;
5842 INT editedItem
= infoPtr
->nEditLabelItem
;
5844 WCHAR
*pszText
= NULL
;
5849 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5853 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5855 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5856 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5861 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5863 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5864 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5865 dispInfo
.item
.iItem
= editedItem
;
5866 dispInfo
.item
.iSubItem
= 0;
5867 dispInfo
.item
.stateMask
= ~0;
5868 dispInfo
.item
.pszText
= szDispText
;
5869 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5870 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5877 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5880 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5881 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5882 textfreeT(tmp
, FALSE
);
5885 /* add the text from the edit in */
5886 dispInfo
.item
.mask
|= LVIF_TEXT
;
5887 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5888 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5890 /* Do we need to update the Item Text */
5891 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5893 infoPtr
->nEditLabelItem
= -1;
5894 infoPtr
->hwndEdit
= 0;
5896 if (!res
) goto cleanup
;
5898 if (!IsWindow(hwndSelf
))
5903 if (!pszText
) return TRUE
;
5910 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5912 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5913 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5914 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5916 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5922 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5923 dispInfo
.item
.mask
= LVIF_TEXT
;
5924 dispInfo
.item
.iItem
= editedItem
;
5925 dispInfo
.item
.iSubItem
= 0;
5926 dispInfo
.item
.pszText
= pszText
;
5927 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5928 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5938 * Subclassed edit control windproc function
5941 * [I] hwnd : the edit window handle
5942 * [I] uMsg : the message that is to be processed
5943 * [I] wParam : first message parameter
5944 * [I] lParam : second message parameter
5945 * [I] isW : TRUE if input is Unicode
5950 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5952 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5955 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5956 hwnd
, uMsg
, wParam
, lParam
, isW
);
5961 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5965 WNDPROC editProc
= infoPtr
->EditWndProc
;
5966 infoPtr
->EditWndProc
= 0;
5967 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5968 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5972 if (VK_ESCAPE
== (INT
)wParam
)
5977 else if (VK_RETURN
== (INT
)wParam
)
5981 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5985 if (infoPtr
->hwndEdit
)
5986 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
5988 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
5994 * Subclassed edit control Unicode windproc function
5997 * [I] hwnd : the edit window handle
5998 * [I] uMsg : the message that is to be processed
5999 * [I] wParam : first message parameter
6000 * [I] lParam : second message parameter
6004 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6006 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6011 * Subclassed edit control ANSI windproc function
6014 * [I] hwnd : the edit window handle
6015 * [I] uMsg : the message that is to be processed
6016 * [I] wParam : first message parameter
6017 * [I] lParam : second message parameter
6021 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6023 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6028 * Creates a subclassed edit control
6031 * [I] infoPtr : valid pointer to the listview structure
6032 * [I] text : initial text for the edit
6033 * [I] style : the window style
6034 * [I] isW : TRUE if input is Unicode
6038 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6040 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6041 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6044 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6046 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6048 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6050 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6052 if (!hedit
) return 0;
6054 infoPtr
->EditWndProc
= (WNDPROC
)
6055 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6056 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6058 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6059 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6066 * Begin in place editing of specified list view item
6069 * [I] infoPtr : valid pointer to the listview structure
6070 * [I] nItem : item index
6071 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6077 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6079 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6080 HWND hwndSelf
= infoPtr
->hwndSelf
;
6081 NMLVDISPINFOW dispInfo
;
6082 HFONT hOldFont
= NULL
;
6088 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6090 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6092 /* remove existing edit box */
6093 if (infoPtr
->hwndEdit
)
6095 SetFocus(infoPtr
->hwndSelf
);
6096 infoPtr
->hwndEdit
= 0;
6099 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6101 infoPtr
->nEditLabelItem
= nItem
;
6103 LISTVIEW_SetSelection(infoPtr
, nItem
);
6104 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6105 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6107 rect
.left
= LVIR_LABEL
;
6108 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6110 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6111 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6112 dispInfo
.item
.iItem
= nItem
;
6113 dispInfo
.item
.iSubItem
= 0;
6114 dispInfo
.item
.stateMask
= ~0;
6115 dispInfo
.item
.pszText
= disptextW
;
6116 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6117 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6119 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6120 if (!infoPtr
->hwndEdit
) return 0;
6122 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6124 if (!IsWindow(hwndSelf
))
6126 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6127 infoPtr
->hwndEdit
= 0;
6131 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6133 /* position and display edit box */
6134 hdc
= GetDC(infoPtr
->hwndSelf
);
6136 /* select the font to get appropriate metric dimensions */
6138 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6140 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6141 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6142 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6144 /* get string length in pixels */
6145 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6147 /* add extra spacing for the next character */
6148 GetTextMetricsW(hdc
, &tm
);
6149 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6152 SelectObject(hdc
, hOldFont
);
6154 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6156 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6159 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6160 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6161 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6162 SetFocus(infoPtr
->hwndEdit
);
6163 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6164 return infoPtr
->hwndEdit
;
6170 * Ensures the specified item is visible, scrolling into view if necessary.
6173 * [I] infoPtr : valid pointer to the listview structure
6174 * [I] nItem : item index
6175 * [I] bPartial : partially or entirely visible
6181 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6183 INT nScrollPosHeight
= 0;
6184 INT nScrollPosWidth
= 0;
6185 INT nHorzAdjust
= 0;
6186 INT nVertAdjust
= 0;
6189 RECT rcItem
, rcTemp
;
6191 rcItem
.left
= LVIR_BOUNDS
;
6192 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6194 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6196 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6198 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6199 if (infoPtr
->uView
== LV_VIEW_LIST
)
6200 nScrollPosWidth
= infoPtr
->nItemWidth
;
6201 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6202 nScrollPosWidth
= 1;
6204 if (rcItem
.left
< infoPtr
->rcList
.left
)
6207 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6212 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6216 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6218 /* scroll up/down, but not in LVS_LIST mode */
6219 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6220 nScrollPosHeight
= infoPtr
->nItemHeight
;
6221 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6222 nScrollPosHeight
= 1;
6224 if (rcItem
.top
< infoPtr
->rcList
.top
)
6227 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6232 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6236 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6238 if (nScrollPosWidth
)
6240 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6241 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6242 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6245 if (nScrollPosHeight
)
6247 INT diff
= nVertDiff
/ nScrollPosHeight
;
6248 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6249 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6257 * Searches for an item with specific characteristics.
6260 * [I] hwnd : window handle
6261 * [I] nStart : base item index
6262 * [I] lpFindInfo : item information to look for
6265 * SUCCESS : index of item
6268 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6269 const LVFINDINFOW
*lpFindInfo
)
6271 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6272 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6273 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6274 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6275 POINT Position
, Destination
;
6278 /* Search in virtual listviews should be done by application, not by
6279 listview control, so we just send LVN_ODFINDITEMW and return the result */
6280 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6284 nmlv
.iStart
= nStart
;
6285 nmlv
.lvfi
= *lpFindInfo
;
6286 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6289 if (!lpFindInfo
|| nItem
< 0) return -1;
6292 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6293 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6295 lvItem
.mask
|= LVIF_TEXT
;
6296 lvItem
.pszText
= szDispText
;
6297 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6300 if (lpFindInfo
->flags
& LVFI_WRAP
)
6303 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6304 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6309 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6310 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6311 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6312 switch(lpFindInfo
->vkDirection
)
6314 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6315 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6316 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6317 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6318 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6319 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6320 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6322 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6323 Destination
.x
= rcArea
.right
;
6324 Destination
.y
= rcArea
.bottom
;
6326 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6330 else Destination
.x
= Destination
.y
= 0;
6332 /* if LVFI_PARAM is specified, all other flags are ignored */
6333 if (lpFindInfo
->flags
& LVFI_PARAM
)
6335 lvItem
.mask
|= LVIF_PARAM
;
6337 lvItem
.mask
&= ~LVIF_TEXT
;
6341 for (; nItem
< nLast
; nItem
++)
6343 lvItem
.iItem
= nItem
;
6344 lvItem
.iSubItem
= 0;
6345 lvItem
.pszText
= szDispText
;
6346 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6348 if (lvItem
.mask
& LVIF_PARAM
)
6350 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6356 if (lvItem
.mask
& LVIF_TEXT
)
6358 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6360 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6361 if (!p
|| p
!= lvItem
.pszText
) continue;
6365 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6369 if (!bNearest
) return nItem
;
6371 /* This is very inefficient. To do a good job here,
6372 * we need a sorted array of (x,y) item positions */
6373 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6375 /* compute the distance^2 to the destination */
6376 xdist
= Destination
.x
- Position
.x
;
6377 ydist
= Destination
.y
- Position
.y
;
6378 dist
= xdist
* xdist
+ ydist
* ydist
;
6380 /* remember the distance, and item if it's closer */
6384 nNearestItem
= nItem
;
6391 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6396 return nNearestItem
;
6401 * Searches for an item with specific characteristics.
6404 * [I] hwnd : window handle
6405 * [I] nStart : base item index
6406 * [I] lpFindInfo : item information to look for
6409 * SUCCESS : index of item
6412 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6413 const LVFINDINFOA
*lpFindInfo
)
6415 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6416 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6421 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6422 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6423 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6424 textfreeT(strW
, FALSE
);
6430 * Retrieves column attributes.
6433 * [I] infoPtr : valid pointer to the listview structure
6434 * [I] nColumn : column index
6435 * [IO] lpColumn : column information
6436 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6437 * otherwise it is in fact a LPLVCOLUMNA
6443 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6445 COLUMN_INFO
*lpColumnInfo
;
6448 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6449 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6451 /* initialize memory */
6452 ZeroMemory(&hdi
, sizeof(hdi
));
6454 if (lpColumn
->mask
& LVCF_TEXT
)
6456 hdi
.mask
|= HDI_TEXT
;
6457 hdi
.pszText
= lpColumn
->pszText
;
6458 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6461 if (lpColumn
->mask
& LVCF_IMAGE
)
6462 hdi
.mask
|= HDI_IMAGE
;
6464 if (lpColumn
->mask
& LVCF_ORDER
)
6465 hdi
.mask
|= HDI_ORDER
;
6467 if (lpColumn
->mask
& LVCF_SUBITEM
)
6468 hdi
.mask
|= HDI_LPARAM
;
6470 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6472 if (lpColumn
->mask
& LVCF_FMT
)
6473 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6475 if (lpColumn
->mask
& LVCF_WIDTH
)
6476 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6478 if (lpColumn
->mask
& LVCF_IMAGE
)
6479 lpColumn
->iImage
= hdi
.iImage
;
6481 if (lpColumn
->mask
& LVCF_ORDER
)
6482 lpColumn
->iOrder
= hdi
.iOrder
;
6484 if (lpColumn
->mask
& LVCF_SUBITEM
)
6485 lpColumn
->iSubItem
= hdi
.lParam
;
6487 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6488 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6494 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6496 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
6501 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6506 * Retrieves the column width.
6509 * [I] infoPtr : valid pointer to the listview structure
6510 * [I] int : column index
6513 * SUCCESS : column width
6516 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6518 INT nColumnWidth
= 0;
6521 TRACE("nColumn=%d\n", nColumn
);
6523 /* we have a 'column' in LIST and REPORT mode only */
6524 switch(infoPtr
->uView
)
6527 nColumnWidth
= infoPtr
->nItemWidth
;
6529 case LV_VIEW_DETAILS
:
6530 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6531 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6532 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6534 * TODO: should we do the same in LVM_GETCOLUMN?
6536 hdItem
.mask
= HDI_WIDTH
;
6537 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6539 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6542 nColumnWidth
= hdItem
.cxy
;
6546 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6547 return nColumnWidth
;
6552 * In list or report display mode, retrieves the number of items that can fit
6553 * vertically in the visible area. In icon or small icon display mode,
6554 * retrieves the total number of visible items.
6557 * [I] infoPtr : valid pointer to the listview structure
6560 * Number of fully visible items.
6562 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6564 switch (infoPtr
->uView
)
6567 case LV_VIEW_SMALLICON
:
6568 return infoPtr
->nItemCount
;
6569 case LV_VIEW_DETAILS
:
6570 return LISTVIEW_GetCountPerColumn(infoPtr
);
6572 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6580 * Retrieves an image list handle.
6583 * [I] infoPtr : valid pointer to the listview structure
6584 * [I] nImageList : image list identifier
6587 * SUCCESS : image list handle
6590 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6594 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6595 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6596 case LVSIL_STATE
: return infoPtr
->himlState
;
6597 case LVSIL_GROUPHEADER
:
6598 FIXME("LVSIL_GROUPHEADER not supported\n");
6601 WARN("got unknown imagelist index - %d\n", nImageList
);
6606 /* LISTVIEW_GetISearchString */
6610 * Retrieves item attributes.
6613 * [I] hwnd : window handle
6614 * [IO] lpLVItem : item info
6615 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6616 * if FALSE, then lpLVItem is a LPLVITEMA.
6619 * This is the internal 'GetItem' interface -- it tries to
6620 * be smart and avoid text copies, if possible, by modifying
6621 * lpLVItem->pszText to point to the text string. Please note
6622 * that this is not always possible (e.g. OWNERDATA), so on
6623 * entry you *must* supply valid values for pszText, and cchTextMax.
6624 * The only difference to the documented interface is that upon
6625 * return, you should use *only* the lpLVItem->pszText, rather than
6626 * the buffer pointer you provided on input. Most code already does
6627 * that, so it's not a problem.
6628 * For the two cases when the text must be copied (that is,
6629 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6635 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6637 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6638 NMLVDISPINFOW dispInfo
;
6644 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6646 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6649 if (lpLVItem
->mask
== 0) return TRUE
;
6650 TRACE("mask=%x\n", lpLVItem
->mask
);
6652 /* make a local copy */
6653 isubitem
= lpLVItem
->iSubItem
;
6655 /* a quick optimization if all we're asked is the focus state
6656 * these queries are worth optimising since they are common,
6657 * and can be answered in constant time, without the heavy accesses */
6658 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6659 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6661 lpLVItem
->state
= 0;
6662 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6663 lpLVItem
->state
|= LVIS_FOCUSED
;
6667 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6669 /* if the app stores all the data, handle it separately */
6670 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6672 dispInfo
.item
.state
= 0;
6674 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6675 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6676 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6678 UINT mask
= lpLVItem
->mask
;
6680 /* NOTE: copy only fields which we _know_ are initialized, some apps
6681 * depend on the uninitialized fields being 0 */
6682 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6683 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6684 dispInfo
.item
.iSubItem
= isubitem
;
6685 if (lpLVItem
->mask
& LVIF_TEXT
)
6687 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6689 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6692 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6693 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6696 if (lpLVItem
->mask
& LVIF_STATE
)
6697 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6698 /* could be zeroed on LVIF_NORECOMPUTE case */
6699 if (dispInfo
.item
.mask
)
6701 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6702 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6703 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6705 /* full size structure expected - _WIN32IE >= 0x560 */
6706 *lpLVItem
= dispInfo
.item
;
6708 else if (lpLVItem
->mask
& LVIF_INDENT
)
6710 /* indent member expected - _WIN32IE >= 0x300 */
6711 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6715 /* minimal structure expected */
6716 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6718 lpLVItem
->mask
= mask
;
6719 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6723 /* make sure lParam is zeroed out */
6724 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6726 /* callback marked pointer required here */
6727 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6728 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6730 /* we store only a little state, so if we're not asked, we're done */
6731 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6733 /* if focus is handled by us, report it */
6734 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6736 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6737 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6738 lpLVItem
->state
|= LVIS_FOCUSED
;
6741 /* and do the same for selection, if we handle it */
6742 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6744 lpLVItem
->state
&= ~LVIS_SELECTED
;
6745 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6746 lpLVItem
->state
|= LVIS_SELECTED
;
6752 /* find the item and subitem structures before we proceed */
6753 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6754 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6759 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6760 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6763 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6768 pItemHdr
= &lpItem
->hdr
;
6770 /* Do we need to query the state from the app? */
6771 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6773 dispInfo
.item
.mask
|= LVIF_STATE
;
6774 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6777 /* Do we need to enquire about the image? */
6778 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6779 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6781 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6782 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6785 /* Only items support indentation */
6786 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6789 dispInfo
.item
.mask
|= LVIF_INDENT
;
6790 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6793 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6794 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6795 !is_text(pItemHdr
->pszText
))
6797 dispInfo
.item
.mask
|= LVIF_TEXT
;
6798 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6799 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6800 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6801 *dispInfo
.item
.pszText
= '\0';
6804 /* If we don't have all the requested info, query the application */
6805 if (dispInfo
.item
.mask
)
6807 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6808 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6809 dispInfo
.item
.lParam
= lpItem
->lParam
;
6810 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6811 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6814 /* we should not store values for subitems */
6815 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6817 /* Now, handle the iImage field */
6818 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6820 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6821 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6822 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6824 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6826 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6827 lpLVItem
->iImage
= pItemHdr
->iImage
;
6829 lpLVItem
->iImage
= 0;
6832 /* The pszText field */
6833 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6835 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6836 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6838 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6840 else if (lpLVItem
->mask
& LVIF_TEXT
)
6842 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6843 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6844 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6847 /* Next is the lParam field */
6848 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6850 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6851 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6852 lpItem
->lParam
= dispInfo
.item
.lParam
;
6854 else if (lpLVItem
->mask
& LVIF_PARAM
)
6855 lpLVItem
->lParam
= lpItem
->lParam
;
6857 /* if this is a subitem, we're done */
6858 if (isubitem
) return TRUE
;
6860 /* ... the state field (this one is different due to uCallbackmask) */
6861 if (lpLVItem
->mask
& LVIF_STATE
)
6863 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6864 if (dispInfo
.item
.mask
& LVIF_STATE
)
6866 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6867 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6869 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6871 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6872 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6873 lpLVItem
->state
|= LVIS_FOCUSED
;
6875 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6877 lpLVItem
->state
&= ~LVIS_SELECTED
;
6878 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6879 lpLVItem
->state
|= LVIS_SELECTED
;
6883 /* and last, but not least, the indent field */
6884 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6886 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6887 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6888 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6890 else if (lpLVItem
->mask
& LVIF_INDENT
)
6892 lpLVItem
->iIndent
= lpItem
->iIndent
;
6900 * Retrieves item attributes.
6903 * [I] hwnd : window handle
6904 * [IO] lpLVItem : item info
6905 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6906 * if FALSE, then lpLVItem is a LPLVITEMA.
6909 * This is the external 'GetItem' interface -- it properly copies
6910 * the text in the provided buffer.
6916 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6921 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6924 pszText
= lpLVItem
->pszText
;
6925 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6926 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6928 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6929 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6931 pszText
= LPSTR_TEXTCALLBACKW
;
6933 lpLVItem
->pszText
= pszText
;
6941 * Retrieves the position (upper-left) of the listview control item.
6942 * Note that for LVS_ICON style, the upper-left is that of the icon
6943 * and not the bounding box.
6946 * [I] infoPtr : valid pointer to the listview structure
6947 * [I] nItem : item index
6948 * [O] lpptPosition : coordinate information
6954 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6958 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6960 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6962 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6963 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6965 if (infoPtr
->uView
== LV_VIEW_ICON
)
6967 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6968 lpptPosition
->y
+= ICON_TOP_PADDING
;
6970 lpptPosition
->x
+= Origin
.x
;
6971 lpptPosition
->y
+= Origin
.y
;
6973 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6980 * Retrieves the bounding rectangle for a listview control item.
6983 * [I] infoPtr : valid pointer to the listview structure
6984 * [I] nItem : item index
6985 * [IO] lprc : bounding rectangle coordinates
6986 * lprc->left specifies the portion of the item for which the bounding
6987 * rectangle will be retrieved.
6989 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6990 * including the icon and label.
6993 * * Experiment shows that native control returns:
6994 * * width = min (48, length of text line)
6995 * * .left = position.x - (width - iconsize.cx)/2
6996 * * .right = .left + width
6997 * * height = #lines of text * ntmHeight + icon height + 8
6998 * * .top = position.y - 2
6999 * * .bottom = .top + height
7000 * * separation between items .y = itemSpacing.cy - height
7001 * * .x = itemSpacing.cx - width
7002 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7005 * * Experiment shows that native control returns:
7006 * * width = iconSize.cx + 16
7007 * * .left = position.x - (width - iconsize.cx)/2
7008 * * .right = .left + width
7009 * * height = iconSize.cy + 4
7010 * * .top = position.y - 2
7011 * * .bottom = .top + height
7012 * * separation between items .y = itemSpacing.cy - height
7013 * * .x = itemSpacing.cx - width
7014 * LVIR_LABEL Returns the bounding rectangle of the item text.
7017 * * Experiment shows that native control returns:
7018 * * width = text length
7019 * * .left = position.x - width/2
7020 * * .right = .left + width
7021 * * height = ntmH * linecount + 2
7022 * * .top = position.y + iconSize.cy + 6
7023 * * .bottom = .top + height
7024 * * separation between items .y = itemSpacing.cy - height
7025 * * .x = itemSpacing.cx - width
7026 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7027 * rectangles, but excludes columns in report view.
7034 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7035 * upon whether the window has the focus currently and on whether the item
7036 * is the one with the focus. Ensure that the control's record of which
7037 * item has the focus agrees with the items' records.
7039 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7041 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7042 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7043 POINT Position
, Origin
;
7047 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7049 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7051 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7052 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7054 /* Be smart and try to figure out the minimum we have to do */
7055 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7056 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7057 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7058 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7059 oversizedBox
= TRUE
;
7061 /* get what we need from the item before hand, so we make
7062 * only one request. This can speed up things, if data
7063 * is stored on the app side */
7065 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7066 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7067 lvItem
.iItem
= nItem
;
7068 lvItem
.iSubItem
= 0;
7069 lvItem
.pszText
= szDispText
;
7070 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7071 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7072 /* we got the state already up, simulate it here, to avoid a reget */
7073 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7075 lvItem
.mask
|= LVIF_STATE
;
7076 lvItem
.stateMask
= LVIS_FOCUSED
;
7077 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7080 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7081 lprc
->left
= LVIR_BOUNDS
;
7087 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7091 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7095 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7098 case LVIR_SELECTBOUNDS
:
7099 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7103 WARN("Unknown value: %d\n", lprc
->left
);
7107 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7109 if (mode
!= LVIR_BOUNDS
)
7110 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7111 Position
.y
+ Origin
.y
);
7113 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7116 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7118 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7125 * Retrieves the spacing between listview control items.
7128 * [I] infoPtr : valid pointer to the listview structure
7129 * [IO] lprc : rectangle to receive the output
7130 * on input, lprc->top = nSubItem
7131 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7133 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7134 * not only those of the first column.
7140 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7142 RECT rect
= { 0, 0, 0, 0 };
7146 if (!lprc
) return FALSE
;
7148 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7149 /* Subitem of '0' means item itself, and this works for all control view modes */
7151 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7153 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7155 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7156 /* this works for any item index, no matter if it exists or not */
7157 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7159 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7162 rect
.bottom
= infoPtr
->nItemHeight
;
7166 /* Native implementation is broken for this case and garbage is left for left and right fields,
7167 we zero them to get predictable output */
7168 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7169 lprc
->bottom
= infoPtr
->nItemHeight
;
7170 OffsetRect(lprc
, origin
.x
, y
);
7171 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7179 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7180 if (infoPtr
->himlSmall
)
7181 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7183 rect
.right
= rect
.left
;
7185 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7193 ERR("Unknown bounds=%d\n", lprc
->left
);
7197 OffsetRect(&rect
, origin
.x
, y
);
7199 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7206 * Retrieves the spacing between listview control items.
7209 * [I] infoPtr : valid pointer to the listview structure
7210 * [I] bSmall : flag for small or large icon
7213 * Horizontal + vertical spacing
7215 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7221 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7225 if (infoPtr
->uView
== LV_VIEW_ICON
)
7226 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7228 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7235 * Retrieves the state of a listview control item.
7238 * [I] infoPtr : valid pointer to the listview structure
7239 * [I] nItem : item index
7240 * [I] uMask : state mask
7243 * State specified by the mask.
7245 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7249 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7251 lvItem
.iItem
= nItem
;
7252 lvItem
.iSubItem
= 0;
7253 lvItem
.mask
= LVIF_STATE
;
7254 lvItem
.stateMask
= uMask
;
7255 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7257 return lvItem
.state
& uMask
;
7262 * Retrieves the text of a listview control item or subitem.
7265 * [I] hwnd : window handle
7266 * [I] nItem : item index
7267 * [IO] lpLVItem : item information
7268 * [I] isW : TRUE if lpLVItem is Unicode
7271 * SUCCESS : string length
7274 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7276 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7278 lpLVItem
->mask
= LVIF_TEXT
;
7279 lpLVItem
->iItem
= nItem
;
7280 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7282 return textlenT(lpLVItem
->pszText
, isW
);
7287 * Searches for an item based on properties + relationships.
7290 * [I] infoPtr : valid pointer to the listview structure
7291 * [I] nItem : item index
7292 * [I] uFlags : relationship flag
7295 * SUCCESS : item index
7298 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7301 LVFINDINFOW lvFindInfo
;
7302 INT nCountPerColumn
;
7306 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7307 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7309 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7311 if (uFlags
& LVNI_CUT
)
7314 if (uFlags
& LVNI_DROPHILITED
)
7315 uMask
|= LVIS_DROPHILITED
;
7317 if (uFlags
& LVNI_FOCUSED
)
7318 uMask
|= LVIS_FOCUSED
;
7320 if (uFlags
& LVNI_SELECTED
)
7321 uMask
|= LVIS_SELECTED
;
7323 /* if we're asked for the focused item, that's only one,
7324 * so it's worth optimizing */
7325 if (uFlags
& LVNI_FOCUSED
)
7327 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7328 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7331 if (uFlags
& LVNI_ABOVE
)
7333 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7338 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7344 /* Special case for autoarrange - move 'til the top of a list */
7345 if (is_autoarrange(infoPtr
))
7347 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7348 while (nItem
- nCountPerRow
>= 0)
7350 nItem
-= nCountPerRow
;
7351 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7356 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7357 lvFindInfo
.vkDirection
= VK_UP
;
7358 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7359 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7361 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7366 else if (uFlags
& LVNI_BELOW
)
7368 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7370 while (nItem
< infoPtr
->nItemCount
)
7373 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7379 /* Special case for autoarrange - move 'til the bottom of a list */
7380 if (is_autoarrange(infoPtr
))
7382 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7383 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7385 nItem
+= nCountPerRow
;
7386 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7391 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7392 lvFindInfo
.vkDirection
= VK_DOWN
;
7393 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7394 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7396 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7401 else if (uFlags
& LVNI_TOLEFT
)
7403 if (infoPtr
->uView
== LV_VIEW_LIST
)
7405 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7406 while (nItem
- nCountPerColumn
>= 0)
7408 nItem
-= nCountPerColumn
;
7409 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7413 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7415 /* Special case for autoarrange - move 'til the beginning of a row */
7416 if (is_autoarrange(infoPtr
))
7418 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7419 while (nItem
% nCountPerRow
> 0)
7422 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7427 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7428 lvFindInfo
.vkDirection
= VK_LEFT
;
7429 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7430 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7432 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7437 else if (uFlags
& LVNI_TORIGHT
)
7439 if (infoPtr
->uView
== LV_VIEW_LIST
)
7441 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7442 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7444 nItem
+= nCountPerColumn
;
7445 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7449 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7451 /* Special case for autoarrange - move 'til the end of a row */
7452 if (is_autoarrange(infoPtr
))
7454 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7455 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7458 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7463 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7464 lvFindInfo
.vkDirection
= VK_RIGHT
;
7465 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7466 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7468 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7477 /* search by index */
7478 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7480 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7488 /* LISTVIEW_GetNumberOfWorkAreas */
7492 * Retrieves the origin coordinates when in icon or small icon display mode.
7495 * [I] infoPtr : valid pointer to the listview structure
7496 * [O] lpptOrigin : coordinate information
7501 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7503 INT nHorzPos
= 0, nVertPos
= 0;
7504 SCROLLINFO scrollInfo
;
7506 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7507 scrollInfo
.fMask
= SIF_POS
;
7509 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7510 nHorzPos
= scrollInfo
.nPos
;
7511 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7512 nVertPos
= scrollInfo
.nPos
;
7514 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7516 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7517 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7518 if (infoPtr
->uView
== LV_VIEW_LIST
)
7519 nHorzPos
*= infoPtr
->nItemWidth
;
7520 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7521 nVertPos
*= infoPtr
->nItemHeight
;
7523 lpptOrigin
->x
-= nHorzPos
;
7524 lpptOrigin
->y
-= nVertPos
;
7526 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7531 * Retrieves the width of a string.
7534 * [I] hwnd : window handle
7535 * [I] lpszText : text string to process
7536 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7539 * SUCCESS : string width (in pixels)
7542 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7547 if (is_text(lpszText
))
7549 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7550 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7551 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7554 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7556 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7557 SelectObject(hdc
, hOldFont
);
7558 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7560 return stringSize
.cx
;
7565 * Determines which listview item is located at the specified position.
7568 * [I] infoPtr : valid pointer to the listview structure
7569 * [IO] lpht : hit test information
7570 * [I] subitem : fill out iSubItem.
7571 * [I] select : return the index only if the hit selects the item
7574 * (mm 20001022): We must not allow iSubItem to be touched, for
7575 * an app might pass only a structure with space up to iItem!
7576 * (MS Office 97 does that for instance in the file open dialog)
7579 * SUCCESS : item index
7582 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7584 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7585 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7586 POINT Origin
, Position
, opt
;
7592 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7596 if (subitem
) lpht
->iSubItem
= 0;
7598 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7600 /* set whole list relation flags */
7601 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7603 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7604 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7605 lpht
->flags
|= LVHT_TOLEFT
;
7607 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7608 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7612 if (infoPtr
->rcList
.bottom
< opt
.y
)
7613 lpht
->flags
|= LVHT_BELOW
;
7617 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7618 lpht
->flags
|= LVHT_TOLEFT
;
7619 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7620 lpht
->flags
|= LVHT_TORIGHT
;
7622 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7623 lpht
->flags
|= LVHT_ABOVE
;
7624 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7625 lpht
->flags
|= LVHT_BELOW
;
7628 /* even if item is invalid try to find subitem */
7629 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7634 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7636 lpht
->iSubItem
= -1;
7637 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7639 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7641 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7647 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7649 /* if we're outside horizontal columns bounds there's nothing to test further */
7650 if (lpht
->iSubItem
== -1)
7653 lpht
->flags
= LVHT_NOWHERE
;
7658 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7659 if (lpht
->flags
) return -1;
7661 lpht
->flags
|= LVHT_NOWHERE
;
7663 /* first deal with the large items */
7664 rcSearch
.left
= lpht
->pt
.x
;
7665 rcSearch
.top
= lpht
->pt
.y
;
7666 rcSearch
.right
= rcSearch
.left
+ 1;
7667 rcSearch
.bottom
= rcSearch
.top
+ 1;
7669 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7670 iterator_next(&i
); /* go to first item in the sequence */
7672 iterator_destroy(&i
);
7674 TRACE("lpht->iItem=%d\n", iItem
);
7675 if (iItem
== -1) return -1;
7677 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7678 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7679 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7680 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7681 lvItem
.iItem
= iItem
;
7682 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7683 lvItem
.pszText
= szDispText
;
7684 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7685 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7686 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7688 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7689 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7690 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7692 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7693 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7695 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7697 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7700 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7701 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7705 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7706 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7708 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7709 if (!PtInRect(&rcBounds
, opt
)) return -1;
7711 /* That's a special case - row rectangle is used as item rectangle and
7712 returned flags contain all item parts. */
7713 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7715 if (PtInRect(&rcIcon
, opt
))
7716 lpht
->flags
|= LVHT_ONITEMICON
;
7717 else if (PtInRect(&rcLabel
, opt
))
7718 lpht
->flags
|= LVHT_ONITEMLABEL
;
7719 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7720 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7721 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7723 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7725 if (lpht
->flags
& LVHT_ONITEM
)
7726 lpht
->flags
&= ~LVHT_NOWHERE
;
7727 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7729 if (select
&& !is_fullrow
)
7731 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7733 /* get main item bounds */
7734 lvItem
.iSubItem
= 0;
7735 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7736 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7737 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7739 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7741 return lpht
->iItem
= iItem
;
7746 * Inserts a new item in the listview control.
7749 * [I] infoPtr : valid pointer to the listview structure
7750 * [I] lpLVItem : item information
7751 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7754 * SUCCESS : new item index
7757 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7764 BOOL is_sorted
, has_changed
;
7766 HWND hwndSelf
= infoPtr
->hwndSelf
;
7768 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7770 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7772 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7773 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7775 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7777 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7779 /* insert item in listview control data structure */
7780 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7781 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7783 /* link with id struct */
7784 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7786 lpID
->item
= hdpaSubItems
;
7787 lpID
->id
= get_next_itemid(infoPtr
);
7788 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7790 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7791 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7793 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7795 /* calculate new item index */
7802 while (i
< infoPtr
->nItemCount
)
7804 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7805 item_s
= DPA_GetPtr(hItem
, 0);
7807 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7808 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7810 if (cmpv
>= 0) break;
7816 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7818 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7819 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7820 if (nItem
== -1) goto fail
;
7821 infoPtr
->nItemCount
++;
7823 /* shift indices first so they don't get tangled */
7824 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7826 /* set the item attributes */
7827 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7829 /* full size structure expected - _WIN32IE >= 0x560 */
7832 else if (lpLVItem
->mask
& LVIF_INDENT
)
7834 /* indent member expected - _WIN32IE >= 0x300 */
7835 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7839 /* minimal structure expected */
7840 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7843 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7845 item
.mask
|= LVIF_STATE
;
7846 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7847 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7848 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7851 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7853 /* make room for the position, if we are in the right mode */
7854 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7856 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7858 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7860 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7865 /* send LVN_INSERTITEM notification */
7866 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7868 nmlv
.lParam
= lpItem
->lParam
;
7869 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7870 if (!IsWindow(hwndSelf
))
7873 /* align items (set position of each item) */
7874 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7878 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7879 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7881 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7883 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7886 /* now is the invalidation fun */
7887 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7891 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7892 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7893 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7894 infoPtr
->nItemCount
--;
7896 DPA_DeletePtr(hdpaSubItems
, 0);
7897 DPA_Destroy (hdpaSubItems
);
7904 * Checks item visibility.
7907 * [I] infoPtr : valid pointer to the listview structure
7908 * [I] nFirst : item index to check for
7911 * Item visible : TRUE
7912 * Item invisible or failure : FALSE
7914 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7916 POINT Origin
, Position
;
7921 TRACE("nItem=%d\n", nItem
);
7923 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7925 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7926 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7927 rcItem
.left
= Position
.x
+ Origin
.x
;
7928 rcItem
.top
= Position
.y
+ Origin
.y
;
7929 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7930 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7932 hdc
= GetDC(infoPtr
->hwndSelf
);
7933 if (!hdc
) return FALSE
;
7934 ret
= RectVisible(hdc
, &rcItem
);
7935 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7942 * Redraws a range of items.
7945 * [I] infoPtr : valid pointer to the listview structure
7946 * [I] nFirst : first item
7947 * [I] nLast : last item
7953 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7957 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7958 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7961 for (i
= nFirst
; i
<= nLast
; i
++)
7962 LISTVIEW_InvalidateItem(infoPtr
, i
);
7969 * Scroll the content of a listview.
7972 * [I] infoPtr : valid pointer to the listview structure
7973 * [I] dx : horizontal scroll amount in pixels
7974 * [I] dy : vertical scroll amount in pixels
7981 * If the control is in report view (LV_VIEW_DETAILS) the control can
7982 * be scrolled only in line increments. "dy" will be rounded to the
7983 * nearest number of pixels that are a whole line. Ex: if line height
7984 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7985 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7987 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7989 switch(infoPtr
->uView
) {
7990 case LV_VIEW_DETAILS
:
7991 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7992 dy
/= infoPtr
->nItemHeight
;
7995 if (dy
!= 0) return FALSE
;
8001 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8002 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8009 * Sets the background color.
8012 * [I] infoPtr : valid pointer to the listview structure
8013 * [I] color : background color
8019 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8021 TRACE("(color=%x)\n", color
);
8023 if(infoPtr
->clrBk
!= color
) {
8024 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8025 infoPtr
->clrBk
= color
;
8026 if (color
== CLR_NONE
)
8027 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8030 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8031 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8038 /* LISTVIEW_SetBkImage */
8040 /*** Helper for {Insert,Set}ColumnT *only* */
8041 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8042 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8044 if (lpColumn
->mask
& LVCF_FMT
)
8046 /* format member is valid */
8047 lphdi
->mask
|= HDI_FORMAT
;
8049 /* set text alignment (leftmost column must be left-aligned) */
8050 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8051 lphdi
->fmt
|= HDF_LEFT
;
8052 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8053 lphdi
->fmt
|= HDF_RIGHT
;
8054 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8055 lphdi
->fmt
|= HDF_CENTER
;
8057 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8058 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8060 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8062 lphdi
->fmt
|= HDF_IMAGE
;
8063 lphdi
->iImage
= I_IMAGECALLBACK
;
8066 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8067 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8070 if (lpColumn
->mask
& LVCF_WIDTH
)
8072 lphdi
->mask
|= HDI_WIDTH
;
8073 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8075 /* make it fill the remainder of the controls width */
8079 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8081 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8082 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8085 /* retrieve the layout of the header */
8086 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8087 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8089 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8092 lphdi
->cxy
= lpColumn
->cx
;
8095 if (lpColumn
->mask
& LVCF_TEXT
)
8097 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8098 lphdi
->fmt
|= HDF_STRING
;
8099 lphdi
->pszText
= lpColumn
->pszText
;
8100 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8103 if (lpColumn
->mask
& LVCF_IMAGE
)
8105 lphdi
->mask
|= HDI_IMAGE
;
8106 lphdi
->iImage
= lpColumn
->iImage
;
8109 if (lpColumn
->mask
& LVCF_ORDER
)
8111 lphdi
->mask
|= HDI_ORDER
;
8112 lphdi
->iOrder
= lpColumn
->iOrder
;
8119 * Inserts a new column.
8122 * [I] infoPtr : valid pointer to the listview structure
8123 * [I] nColumn : column index
8124 * [I] lpColumn : column information
8125 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8128 * SUCCESS : new column index
8131 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8132 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8134 COLUMN_INFO
*lpColumnInfo
;
8138 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8140 if (!lpColumn
|| nColumn
< 0) return -1;
8141 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8143 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8144 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8147 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8148 * (can be seen in SPY) otherwise column never gets added.
8150 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8151 hdi
.mask
|= HDI_WIDTH
;
8156 * when the iSubItem is available Windows copies it to the header lParam. It seems
8157 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8159 if (lpColumn
->mask
& LVCF_SUBITEM
)
8161 hdi
.mask
|= HDI_LPARAM
;
8162 hdi
.lParam
= lpColumn
->iSubItem
;
8165 /* create header if not present */
8166 LISTVIEW_CreateHeader(infoPtr
);
8167 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8168 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8170 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8173 /* insert item in header control */
8174 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8175 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8176 nColumn
, (LPARAM
)&hdi
);
8177 if (nNewColumn
== -1) return -1;
8178 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8180 /* create our own column info */
8181 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8182 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8184 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8185 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8186 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8189 /* now we have to actually adjust the data */
8190 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8192 SUBITEM_INFO
*lpSubItem
;
8198 item
.iSubItem
= nNewColumn
;
8199 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8200 item
.iImage
= I_IMAGECALLBACK
;
8201 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8203 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8205 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8206 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8208 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8209 if (lpSubItem
->iSubItem
>= nNewColumn
)
8210 lpSubItem
->iSubItem
++;
8213 /* add new subitem for each item */
8215 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8219 /* make space for the new column */
8220 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8221 LISTVIEW_UpdateItemSize(infoPtr
);
8226 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8229 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8237 * Sets the attributes of a header item.
8240 * [I] infoPtr : valid pointer to the listview structure
8241 * [I] nColumn : column index
8242 * [I] lpColumn : column attributes
8243 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8249 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8250 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8252 HDITEMW hdi
, hdiget
;
8255 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8257 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8259 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8260 if (lpColumn
->mask
& LVCF_FMT
)
8262 hdi
.mask
|= HDI_FORMAT
;
8263 hdiget
.mask
= HDI_FORMAT
;
8264 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8265 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8267 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8269 /* set header item attributes */
8270 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8271 if (!bResult
) return FALSE
;
8273 if (lpColumn
->mask
& LVCF_FMT
)
8275 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8276 INT oldFmt
= lpColumnInfo
->fmt
;
8278 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8279 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8281 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8285 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8286 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8293 * Sets the column order array
8296 * [I] infoPtr : valid pointer to the listview structure
8297 * [I] iCount : number of elements in column order array
8298 * [I] lpiArray : pointer to column order array
8304 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8306 TRACE("iCount %d lpiArray %p\n", iCount
, lpiArray
);
8308 if (!lpiArray
|| !IsWindow(infoPtr
->hwndHeader
)) return FALSE
;
8310 infoPtr
->colRectsDirty
= TRUE
;
8312 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8317 * Sets the width of a column
8320 * [I] infoPtr : valid pointer to the listview structure
8321 * [I] nColumn : column index
8322 * [I] cx : column width
8328 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8330 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8334 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8336 /* set column width only if in report or list mode */
8337 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8339 /* take care of invalid cx values */
8340 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
8341 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
8343 /* resize all columns if in LV_VIEW_LIST mode */
8344 if(infoPtr
->uView
== LV_VIEW_LIST
)
8346 infoPtr
->nItemWidth
= cx
;
8347 LISTVIEW_InvalidateList(infoPtr
);
8351 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8353 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8358 lvItem
.mask
= LVIF_TEXT
;
8360 lvItem
.iSubItem
= nColumn
;
8361 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8362 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8364 lvItem
.pszText
= szDispText
;
8365 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8366 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8367 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8369 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8370 max_cx
+= infoPtr
->iconSize
.cx
;
8371 max_cx
+= TRAILING_LABEL_PADDING
;
8374 /* autosize based on listview items width */
8375 if(cx
== LVSCW_AUTOSIZE
)
8377 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8379 /* if iCol is the last column make it fill the remainder of the controls width */
8380 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8385 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8386 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8388 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8392 /* Despite what the MS docs say, if this is not the last
8393 column, then MS resizes the column to the width of the
8394 largest text string in the column, including headers
8395 and items. This is different from LVSCW_AUTOSIZE in that
8396 LVSCW_AUTOSIZE ignores the header string length. */
8399 /* retrieve header text */
8400 hdi
.mask
= HDI_TEXT
;
8401 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8402 hdi
.pszText
= szDispText
;
8403 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8405 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8406 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8409 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8410 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8411 /* FIXME: Take into account the header image, if one is present */
8412 SelectObject(hdc
, old_font
);
8413 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8415 cx
= max (cx
, max_cx
);
8419 if (cx
< 0) return FALSE
;
8421 /* call header to update the column change */
8422 hdi
.mask
= HDI_WIDTH
;
8423 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8424 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8425 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8429 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8432 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8435 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8437 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8438 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8441 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8442 ILC_COLOR
| ILC_MASK
, 2, 2);
8443 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8444 hdc
= CreateCompatibleDC(hdc_wnd
);
8445 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8446 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8447 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8449 rc
.left
= rc
.top
= 0;
8450 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
8451 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
8453 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8454 FillRect(hdc
, &rc
, hbr_white
);
8455 InflateRect(&rc
, -2, -2);
8456 FillRect(hdc
, &rc
, hbr_black
);
8458 SelectObject(hdc
, hbm_im
);
8459 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8460 SelectObject(hdc
, hbm_orig
);
8461 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8463 SelectObject(hdc
, hbm_im
);
8464 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8465 SelectObject(hdc
, hbm_orig
);
8466 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8468 DeleteObject(hbm_mask
);
8469 DeleteObject(hbm_im
);
8477 * Sets the extended listview style.
8480 * [I] infoPtr : valid pointer to the listview structure
8482 * [I] dwStyle : style
8485 * SUCCESS : previous style
8488 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8490 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8492 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8496 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8498 infoPtr
->dwLvExStyle
= ex_style
;
8500 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8502 HIMAGELIST himl
= 0;
8503 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8506 item
.mask
= LVIF_STATE
;
8507 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8508 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8509 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8511 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8512 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8513 ImageList_Destroy(infoPtr
->himlState
);
8515 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8516 /* checkbox list replaces previous custom list or... */
8517 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8518 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8519 /* ...previous was checkbox list */
8520 (old_ex_style
& LVS_EX_CHECKBOXES
))
8521 ImageList_Destroy(himl
);
8524 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8528 /* if not already created */
8529 LISTVIEW_CreateHeader(infoPtr
);
8531 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8532 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8533 style
|= HDS_DRAGDROP
;
8535 style
&= ~HDS_DRAGDROP
;
8536 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8539 /* GRIDLINES adds decoration at top so changes sizes */
8540 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8542 LISTVIEW_CreateHeader(infoPtr
);
8543 LISTVIEW_UpdateSize(infoPtr
);
8546 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8548 LISTVIEW_CreateHeader(infoPtr
);
8551 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8553 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8554 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8557 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8559 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8560 LISTVIEW_CreateHeader(infoPtr
);
8562 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8563 LISTVIEW_UpdateSize(infoPtr
);
8564 LISTVIEW_UpdateScroll(infoPtr
);
8567 LISTVIEW_InvalidateList(infoPtr
);
8568 return old_ex_style
;
8573 * Sets the new hot cursor used during hot tracking and hover selection.
8576 * [I] infoPtr : valid pointer to the listview structure
8577 * [I] hCursor : the new hot cursor handle
8580 * Returns the previous hot cursor
8582 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8584 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8586 infoPtr
->hHotCursor
= hCursor
;
8594 * Sets the hot item index.
8597 * [I] infoPtr : valid pointer to the listview structure
8598 * [I] iIndex : index
8601 * SUCCESS : previous hot item index
8602 * FAILURE : -1 (no hot item)
8604 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8606 INT iOldIndex
= infoPtr
->nHotItem
;
8608 infoPtr
->nHotItem
= iIndex
;
8616 * Sets the amount of time the cursor must hover over an item before it is selected.
8619 * [I] infoPtr : valid pointer to the listview structure
8620 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8623 * Returns the previous hover time
8625 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8627 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8629 infoPtr
->dwHoverTime
= dwHoverTime
;
8631 return oldHoverTime
;
8636 * Sets spacing for icons of LVS_ICON style.
8639 * [I] infoPtr : valid pointer to the listview structure
8640 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8641 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8644 * MAKELONG(oldcx, oldcy)
8646 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8648 INT iconWidth
= 0, iconHeight
= 0;
8649 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8651 TRACE("requested=(%d,%d)\n", cx
, cy
);
8653 /* set to defaults, if instructed to */
8654 if (cx
== -1 && cy
== -1)
8656 infoPtr
->autoSpacing
= TRUE
;
8657 if (infoPtr
->himlNormal
)
8658 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8659 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8660 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8663 infoPtr
->autoSpacing
= FALSE
;
8665 /* if 0 then keep width */
8667 infoPtr
->iconSpacing
.cx
= cx
;
8669 /* if 0 then keep height */
8671 infoPtr
->iconSpacing
.cy
= cy
;
8673 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8674 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8675 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8676 infoPtr
->ntmHeight
);
8678 /* these depend on the iconSpacing */
8679 LISTVIEW_UpdateItemSize(infoPtr
);
8684 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8688 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8695 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8696 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8705 * [I] infoPtr : valid pointer to the listview structure
8706 * [I] nType : image list type
8707 * [I] himl : image list handle
8710 * SUCCESS : old image list
8713 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8715 INT oldHeight
= infoPtr
->nItemHeight
;
8716 HIMAGELIST himlOld
= 0;
8718 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8723 himlOld
= infoPtr
->himlNormal
;
8724 infoPtr
->himlNormal
= himl
;
8725 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8726 if (infoPtr
->autoSpacing
)
8727 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8731 himlOld
= infoPtr
->himlSmall
;
8732 infoPtr
->himlSmall
= himl
;
8733 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8734 if (infoPtr
->hwndHeader
)
8735 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8739 himlOld
= infoPtr
->himlState
;
8740 infoPtr
->himlState
= himl
;
8741 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8742 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8746 ERR("Unknown icon type=%d\n", nType
);
8750 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8751 if (infoPtr
->nItemHeight
!= oldHeight
)
8752 LISTVIEW_UpdateScroll(infoPtr
);
8759 * Preallocates memory (does *not* set the actual count of items !)
8762 * [I] infoPtr : valid pointer to the listview structure
8763 * [I] nItems : item count (projected number of items to allocate)
8764 * [I] dwFlags : update flags
8770 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8772 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8774 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8776 INT nOldCount
= infoPtr
->nItemCount
;
8778 if (nItems
< nOldCount
)
8780 RANGE range
= { nItems
, nOldCount
};
8781 ranges_del(infoPtr
->selectionRanges
, range
);
8782 if (infoPtr
->nFocusedItem
>= nItems
)
8784 LISTVIEW_SetItemFocus(infoPtr
, -1);
8785 SetRectEmpty(&infoPtr
->rcFocus
);
8789 infoPtr
->nItemCount
= nItems
;
8790 LISTVIEW_UpdateScroll(infoPtr
);
8792 /* the flags are valid only in ownerdata report and list modes */
8793 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8795 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8796 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8798 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8799 LISTVIEW_InvalidateList(infoPtr
);
8806 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8807 nFrom
= min(nOldCount
, nItems
);
8808 nTo
= max(nOldCount
, nItems
);
8810 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8813 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8814 rcErase
.right
= infoPtr
->nItemWidth
;
8815 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8816 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8817 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8818 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8820 else /* LV_VIEW_LIST */
8822 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8824 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8825 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8826 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8827 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8828 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8829 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8830 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8832 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8834 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8835 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8836 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8837 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8838 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8844 /* According to MSDN for non-LVS_OWNERDATA this is just
8845 * a performance issue. The control allocates its internal
8846 * data structures for the number of items specified. It
8847 * cuts down on the number of memory allocations. Therefore
8848 * we will just issue a WARN here
8850 WARN("for non-ownerdata performance option not implemented.\n");
8858 * Sets the position of an item.
8861 * [I] infoPtr : valid pointer to the listview structure
8862 * [I] nItem : item index
8863 * [I] pt : coordinate
8869 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8873 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8875 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8876 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8879 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8881 /* This point value seems to be an undocumented feature.
8882 * The best guess is that it means either at the origin,
8883 * or at true beginning of the list. I will assume the origin. */
8884 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8887 if (infoPtr
->uView
== LV_VIEW_ICON
)
8889 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8890 Pt
.y
-= ICON_TOP_PADDING
;
8895 infoPtr
->bAutoarrange
= FALSE
;
8897 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8902 * Sets the state of one or many items.
8905 * [I] infoPtr : valid pointer to the listview structure
8906 * [I] nItem : item index
8907 * [I] item : item or subitem info
8913 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8918 if (!item
) return FALSE
;
8920 lvItem
.iItem
= nItem
;
8921 lvItem
.iSubItem
= 0;
8922 lvItem
.mask
= LVIF_STATE
;
8923 lvItem
.state
= item
->state
;
8924 lvItem
.stateMask
= item
->stateMask
;
8925 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8932 /* special case optimization for recurring attempt to deselect all */
8933 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8936 /* select all isn't allowed in LVS_SINGLESEL */
8937 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8940 /* focus all isn't allowed */
8941 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8943 notify
= infoPtr
->bDoChangeNotify
;
8944 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8946 infoPtr
->bDoChangeNotify
= FALSE
;
8947 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8948 oldstate
|= LVIS_SELECTED
;
8949 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
8952 /* apply to all items */
8953 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8954 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
8956 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8960 infoPtr
->bDoChangeNotify
= notify
;
8964 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
8965 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
8966 nmlv
.uChanged
= LVIF_STATE
;
8967 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
8970 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
8974 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8981 * Sets the text of an item or subitem.
8984 * [I] hwnd : window handle
8985 * [I] nItem : item index
8986 * [I] lpLVItem : item or subitem info
8987 * [I] isW : TRUE if input is Unicode
8993 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
8997 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
8998 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9000 lvItem
.iItem
= nItem
;
9001 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9002 lvItem
.mask
= LVIF_TEXT
;
9003 lvItem
.pszText
= lpLVItem
->pszText
;
9004 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9006 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9008 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9013 * Set item index that marks the start of a multiple selection.
9016 * [I] infoPtr : valid pointer to the listview structure
9017 * [I] nIndex : index
9020 * Index number or -1 if there is no selection mark.
9022 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9024 INT nOldIndex
= infoPtr
->nSelectionMark
;
9026 TRACE("(nIndex=%d)\n", nIndex
);
9028 infoPtr
->nSelectionMark
= nIndex
;
9035 * Sets the text background color.
9038 * [I] infoPtr : valid pointer to the listview structure
9039 * [I] color : text background color
9045 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9047 TRACE("(color=%x)\n", color
);
9049 infoPtr
->clrTextBk
= color
;
9055 * Sets the text foreground color.
9058 * [I] infoPtr : valid pointer to the listview structure
9059 * [I] color : text color
9065 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9067 TRACE("(color=%x)\n", color
);
9069 infoPtr
->clrText
= color
;
9075 * Sets new ToolTip window to ListView control.
9078 * [I] infoPtr : valid pointer to the listview structure
9079 * [I] hwndNewToolTip : handle to new ToolTip
9084 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9086 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9087 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9088 return hwndOldToolTip
;
9093 * sets the Unicode character format flag for the control
9095 * [I] infoPtr :valid pointer to the listview structure
9096 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9099 * Old Unicode Format
9101 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9103 SHORT rc
= infoPtr
->notifyFormat
;
9104 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9105 return rc
== NFR_UNICODE
;
9110 * sets the control view mode
9112 * [I] infoPtr :valid pointer to the listview structure
9113 * [I] nView :new view mode value
9119 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9123 if (infoPtr
->uView
== nView
) return 1;
9125 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9126 if (nView
== LV_VIEW_TILE
)
9128 FIXME("View LV_VIEW_TILE unimplemented\n");
9132 infoPtr
->uView
= nView
;
9134 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9135 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9137 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9138 SetRectEmpty(&infoPtr
->rcFocus
);
9140 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9141 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9146 case LV_VIEW_SMALLICON
:
9147 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9149 case LV_VIEW_DETAILS
:
9154 LISTVIEW_CreateHeader( infoPtr
);
9156 hl
.prc
= &infoPtr
->rcList
;
9158 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9159 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9160 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9167 LISTVIEW_UpdateItemSize(infoPtr
);
9168 LISTVIEW_UpdateSize(infoPtr
);
9169 LISTVIEW_UpdateScroll(infoPtr
);
9170 LISTVIEW_InvalidateList(infoPtr
);
9172 TRACE("nView=%d\n", nView
);
9177 /* LISTVIEW_SetWorkAreas */
9181 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9184 * [I] first : pointer to first ITEM_INFO to compare
9185 * [I] second : pointer to second ITEM_INFO to compare
9186 * [I] lParam : HWND of control
9189 * if first comes before second : negative
9190 * if first comes after second : positive
9191 * if first and second are equivalent : zero
9193 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9195 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9196 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9197 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9199 /* Forward the call to the client defined callback */
9200 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9205 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9208 * [I] first : pointer to first ITEM_INFO to compare
9209 * [I] second : pointer to second ITEM_INFO to compare
9210 * [I] lParam : HWND of control
9213 * if first comes before second : negative
9214 * if first comes after second : positive
9215 * if first and second are equivalent : zero
9217 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9219 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9220 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9221 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9223 /* Forward the call to the client defined callback */
9224 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9229 * Sorts the listview items.
9232 * [I] infoPtr : valid pointer to the listview structure
9233 * [I] pfnCompare : application-defined value
9234 * [I] lParamSort : pointer to comparison callback
9235 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9241 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9242 LPARAM lParamSort
, BOOL IsEx
)
9246 LPVOID selectionMarkItem
= NULL
;
9247 LPVOID focusedItem
= NULL
;
9250 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9252 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9254 if (!pfnCompare
) return FALSE
;
9255 if (!infoPtr
->hdpaItems
) return FALSE
;
9257 /* if there are 0 or 1 items, there is no need to sort */
9258 if (infoPtr
->nItemCount
< 2) return TRUE
;
9260 /* clear selection */
9261 ranges_clear(infoPtr
->selectionRanges
);
9263 /* save selection mark and focused item */
9264 if (infoPtr
->nSelectionMark
>= 0)
9265 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9266 if (infoPtr
->nFocusedItem
>= 0)
9267 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9269 infoPtr
->pfnCompare
= pfnCompare
;
9270 infoPtr
->lParamSort
= lParamSort
;
9272 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9274 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9276 /* restore selection ranges */
9277 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9279 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9280 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9282 if (lpItem
->state
& LVIS_SELECTED
)
9283 ranges_additem(infoPtr
->selectionRanges
, i
);
9285 /* restore selection mark and focused item */
9286 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9287 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9289 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9291 /* refresh the display */
9292 LISTVIEW_InvalidateList(infoPtr
);
9298 * Update theme handle after a theme change.
9301 * [I] infoPtr : valid pointer to the listview structure
9305 * FAILURE : something else
9307 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9309 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9310 CloseThemeData(theme
);
9311 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9317 * Updates an items or rearranges the listview control.
9320 * [I] infoPtr : valid pointer to the listview structure
9321 * [I] nItem : item index
9327 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9329 TRACE("(nItem=%d)\n", nItem
);
9331 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9333 /* rearrange with default alignment style */
9334 if (is_autoarrange(infoPtr
))
9335 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9337 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9344 * Draw the track line at the place defined in the infoPtr structure.
9345 * The line is drawn with a XOR pen so drawing the line for the second time
9346 * in the same place erases the line.
9349 * [I] infoPtr : valid pointer to the listview structure
9355 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9359 if (infoPtr
->xTrackLine
== -1)
9362 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9364 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9365 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9366 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9372 * Called when an edit control should be displayed. This function is called after
9373 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9376 * [I] hwnd : Handle to the listview
9377 * [I] uMsg : WM_TIMER (ignored)
9378 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9379 * [I] dwTimer : The elapsed time (ignored)
9384 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9386 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9387 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9389 KillTimer(hwnd
, idEvent
);
9390 editItem
->fEnabled
= FALSE
;
9391 /* check if the item is still selected */
9392 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9393 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9398 * Creates the listview control - the WM_NCCREATE phase.
9401 * [I] hwnd : window handle
9402 * [I] lpcs : the create parameters
9408 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9410 LISTVIEW_INFO
*infoPtr
;
9413 TRACE("(lpcs=%p)\n", lpcs
);
9415 /* initialize info pointer */
9416 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9417 if (!infoPtr
) return FALSE
;
9419 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9421 infoPtr
->hwndSelf
= hwnd
;
9422 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9423 map_style_view(infoPtr
);
9424 /* determine the type of structures to use */
9425 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9426 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9428 /* initialize color information */
9429 infoPtr
->clrBk
= CLR_NONE
;
9430 infoPtr
->clrText
= CLR_DEFAULT
;
9431 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9432 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9434 /* set default values */
9435 infoPtr
->nFocusedItem
= -1;
9436 infoPtr
->nSelectionMark
= -1;
9437 infoPtr
->nHotItem
= -1;
9438 infoPtr
->bRedraw
= TRUE
;
9439 infoPtr
->bNoItemMetrics
= TRUE
;
9440 infoPtr
->bDoChangeNotify
= TRUE
;
9441 infoPtr
->autoSpacing
= TRUE
;
9442 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9443 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9444 infoPtr
->nEditLabelItem
= -1;
9445 infoPtr
->nLButtonDownItem
= -1;
9446 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9447 infoPtr
->cWheelRemainder
= 0;
9448 infoPtr
->nMeasureItemHeight
= 0;
9449 infoPtr
->xTrackLine
= -1; /* no track line */
9450 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9451 infoPtr
->iVersion
= COMCTL32_VERSION
;
9452 infoPtr
->colRectsDirty
= FALSE
;
9454 /* get default font (icon title) */
9455 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9456 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9457 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9458 LISTVIEW_SaveTextMetrics(infoPtr
);
9460 /* allocate memory for the data structure */
9461 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9462 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9463 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9464 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9465 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9466 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9470 DestroyWindow(infoPtr
->hwndHeader
);
9471 ranges_destroy(infoPtr
->selectionRanges
);
9472 DPA_Destroy(infoPtr
->hdpaItems
);
9473 DPA_Destroy(infoPtr
->hdpaItemIds
);
9474 DPA_Destroy(infoPtr
->hdpaPosX
);
9475 DPA_Destroy(infoPtr
->hdpaPosY
);
9476 DPA_Destroy(infoPtr
->hdpaColumns
);
9483 * Creates the listview control - the WM_CREATE phase. Most of the data is
9484 * already set up in LISTVIEW_NCCreate
9487 * [I] hwnd : window handle
9488 * [I] lpcs : the create parameters
9494 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9496 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9498 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9500 infoPtr
->dwStyle
= lpcs
->style
;
9501 map_style_view(infoPtr
);
9503 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9504 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9505 /* on error defaulting to ANSI notifications */
9506 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9507 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9509 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9511 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9514 infoPtr
->hwndHeader
= 0;
9516 /* init item size to avoid division by 0 */
9517 LISTVIEW_UpdateItemSize (infoPtr
);
9518 LISTVIEW_UpdateSize (infoPtr
);
9520 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9522 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9524 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9526 LISTVIEW_UpdateScroll(infoPtr
);
9527 /* send WM_MEASUREITEM notification */
9528 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9531 OpenThemeData(hwnd
, themeClass
);
9533 /* initialize the icon sizes */
9534 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9535 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9541 * Destroys the listview control.
9544 * [I] infoPtr : valid pointer to the listview structure
9550 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9552 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9553 CloseThemeData(theme
);
9555 /* delete all items */
9556 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9563 * Enables the listview control.
9566 * [I] infoPtr : valid pointer to the listview structure
9567 * [I] bEnable : specifies whether to enable or disable the window
9573 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9575 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9576 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9582 * Erases the background of the listview control.
9585 * [I] infoPtr : valid pointer to the listview structure
9586 * [I] hdc : device context handle
9592 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9596 TRACE("(hdc=%p)\n", hdc
);
9598 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9600 if (infoPtr
->clrBk
== CLR_NONE
)
9602 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9603 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9604 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9606 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9609 /* for double buffered controls we need to do this during refresh */
9610 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9612 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9618 * Helper function for LISTVIEW_[HV]Scroll *only*.
9619 * Performs vertical/horizontal scrolling by a give amount.
9622 * [I] infoPtr : valid pointer to the listview structure
9623 * [I] dx : amount of horizontal scroll
9624 * [I] dy : amount of vertical scroll
9626 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9628 /* now we can scroll the list */
9629 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9630 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9631 /* if we have focus, adjust rect */
9632 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9633 UpdateWindow(infoPtr
->hwndSelf
);
9638 * Performs vertical scrolling.
9641 * [I] infoPtr : valid pointer to the listview structure
9642 * [I] nScrollCode : scroll code
9643 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9644 * [I] hScrollWnd : scrollbar control window handle
9650 * SB_LINEUP/SB_LINEDOWN:
9651 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9652 * for LVS_REPORT is 1 line
9653 * for LVS_LIST cannot occur
9656 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9659 INT nOldScrollPos
, nNewScrollPos
;
9660 SCROLLINFO scrollInfo
;
9663 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9664 debugscrollcode(nScrollCode
), nScrollDiff
);
9666 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9668 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9669 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9671 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9673 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9675 nOldScrollPos
= scrollInfo
.nPos
;
9676 switch (nScrollCode
)
9682 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9686 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9690 nScrollDiff
= -scrollInfo
.nPage
;
9694 nScrollDiff
= scrollInfo
.nPage
;
9697 case SB_THUMBPOSITION
:
9699 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9706 /* quit right away if pos isn't changing */
9707 if (nScrollDiff
== 0) return 0;
9709 /* calculate new position, and handle overflows */
9710 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9711 if (nScrollDiff
> 0) {
9712 if (nNewScrollPos
< nOldScrollPos
||
9713 nNewScrollPos
> scrollInfo
.nMax
)
9714 nNewScrollPos
= scrollInfo
.nMax
;
9716 if (nNewScrollPos
> nOldScrollPos
||
9717 nNewScrollPos
< scrollInfo
.nMin
)
9718 nNewScrollPos
= scrollInfo
.nMin
;
9721 /* set the new position, and reread in case it changed */
9722 scrollInfo
.fMask
= SIF_POS
;
9723 scrollInfo
.nPos
= nNewScrollPos
;
9724 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9726 /* carry on only if it really changed */
9727 if (nNewScrollPos
== nOldScrollPos
) return 0;
9729 /* now adjust to client coordinates */
9730 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9731 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9733 /* and scroll the window */
9734 scroll_list(infoPtr
, 0, nScrollDiff
);
9741 * Performs horizontal scrolling.
9744 * [I] infoPtr : valid pointer to the listview structure
9745 * [I] nScrollCode : scroll code
9746 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9747 * [I] hScrollWnd : scrollbar control window handle
9753 * SB_LINELEFT/SB_LINERIGHT:
9754 * for LVS_ICON, LVS_SMALLICON 1 pixel
9755 * for LVS_REPORT is 1 pixel
9756 * for LVS_LIST is 1 column --> which is a 1 because the
9757 * scroll is based on columns not pixels
9760 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9763 INT nOldScrollPos
, nNewScrollPos
;
9764 SCROLLINFO scrollInfo
;
9767 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9768 debugscrollcode(nScrollCode
), nScrollDiff
);
9770 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9772 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9773 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9775 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9777 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9779 nOldScrollPos
= scrollInfo
.nPos
;
9781 switch (nScrollCode
)
9787 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9791 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9795 nScrollDiff
= -scrollInfo
.nPage
;
9799 nScrollDiff
= scrollInfo
.nPage
;
9802 case SB_THUMBPOSITION
:
9804 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9811 /* quit right away if pos isn't changing */
9812 if (nScrollDiff
== 0) return 0;
9814 /* calculate new position, and handle overflows */
9815 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9816 if (nScrollDiff
> 0) {
9817 if (nNewScrollPos
< nOldScrollPos
||
9818 nNewScrollPos
> scrollInfo
.nMax
)
9819 nNewScrollPos
= scrollInfo
.nMax
;
9821 if (nNewScrollPos
> nOldScrollPos
||
9822 nNewScrollPos
< scrollInfo
.nMin
)
9823 nNewScrollPos
= scrollInfo
.nMin
;
9826 /* set the new position, and reread in case it changed */
9827 scrollInfo
.fMask
= SIF_POS
;
9828 scrollInfo
.nPos
= nNewScrollPos
;
9829 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9831 /* carry on only if it really changed */
9832 if (nNewScrollPos
== nOldScrollPos
) return 0;
9834 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9836 /* now adjust to client coordinates */
9837 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9838 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9840 /* and scroll the window */
9841 scroll_list(infoPtr
, nScrollDiff
, 0);
9846 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9848 UINT pulScrollLines
= 3;
9850 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9852 switch(infoPtr
->uView
)
9855 case LV_VIEW_SMALLICON
:
9857 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9858 * should be fixed in the future.
9860 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9861 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9864 case LV_VIEW_DETAILS
:
9865 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9867 /* if scrolling changes direction, ignore left overs */
9868 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9869 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9870 infoPtr
->cWheelRemainder
+= wheelDelta
;
9872 infoPtr
->cWheelRemainder
= wheelDelta
;
9873 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9876 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9877 cLineScroll
= pulScrollLines
* (float)infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9878 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
9879 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9884 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9895 * [I] infoPtr : valid pointer to the listview structure
9896 * [I] nVirtualKey : virtual key
9897 * [I] lKeyData : key data
9902 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9904 HWND hwndSelf
= infoPtr
->hwndSelf
;
9906 NMLVKEYDOWN nmKeyDown
;
9908 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9910 /* send LVN_KEYDOWN notification */
9911 nmKeyDown
.wVKey
= nVirtualKey
;
9912 nmKeyDown
.flags
= 0;
9913 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9914 if (!IsWindow(hwndSelf
))
9917 switch (nVirtualKey
)
9920 nItem
= infoPtr
->nFocusedItem
;
9921 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9922 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9926 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9928 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9929 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9934 if (infoPtr
->nItemCount
> 0)
9939 if (infoPtr
->nItemCount
> 0)
9940 nItem
= infoPtr
->nItemCount
- 1;
9944 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9948 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9952 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9956 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9960 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9962 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9963 if (infoPtr
->nFocusedItem
== topidx
)
9964 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9969 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9970 * LISTVIEW_GetCountPerRow(infoPtr
);
9971 if(nItem
< 0) nItem
= 0;
9975 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9977 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9978 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9979 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9980 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9982 nItem
= topidx
+ cnt
- 1;
9985 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9986 * LISTVIEW_GetCountPerRow(infoPtr
);
9987 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9991 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9992 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10002 * [I] infoPtr : valid pointer to the listview structure
10007 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10011 /* drop any left over scroll amount */
10012 infoPtr
->cWheelRemainder
= 0;
10014 /* if we did not have the focus, there's nothing more to do */
10015 if (!infoPtr
->bFocus
) return 0;
10017 /* send NM_KILLFOCUS notification */
10018 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10020 /* if we have a focus rectangle, get rid of it */
10021 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10023 /* if have a marquee selection, stop it */
10024 if (infoPtr
->bMarqueeSelect
)
10026 /* Remove the marquee rectangle and release our mouse capture */
10027 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10030 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10032 infoPtr
->bMarqueeSelect
= FALSE
;
10033 infoPtr
->bScrolling
= FALSE
;
10034 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10037 /* set window focus flag */
10038 infoPtr
->bFocus
= FALSE
;
10040 /* invalidate the selected items before resetting focus flag */
10041 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10048 * Processes double click messages (left mouse button).
10051 * [I] infoPtr : valid pointer to the listview structure
10052 * [I] wKey : key flag
10053 * [I] x,y : mouse coordinate
10058 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10060 LVHITTESTINFO htInfo
;
10062 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10064 /* Cancel the item edition if any */
10065 if (infoPtr
->itemEdit
.fEnabled
)
10067 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10068 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10071 /* send NM_RELEASEDCAPTURE notification */
10072 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10077 /* send NM_DBLCLK notification */
10078 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10079 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10081 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10082 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10087 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10092 r
.top
= r
.bottom
= pt
.y
;
10093 r
.left
= r
.right
= pt
.x
;
10095 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10097 SetCapture(infoPtr
->hwndSelf
);
10101 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10103 if (msg
.message
== WM_MOUSEMOVE
)
10105 pt
.x
= (short)LOWORD(msg
.lParam
);
10106 pt
.y
= (short)HIWORD(msg
.lParam
);
10107 if (PtInRect(&r
, pt
))
10115 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10116 msg
.message
<= WM_RBUTTONDBLCLK
)
10121 DispatchMessageW(&msg
);
10124 if (GetCapture() != infoPtr
->hwndSelf
)
10135 * Processes mouse down messages (left mouse button).
10138 * infoPtr [I ] valid pointer to the listview structure
10139 * wKey [I ] key flag
10140 * x,y [I ] mouse coordinate
10145 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10147 LVHITTESTINFO lvHitTestInfo
;
10148 static BOOL bGroupSelect
= TRUE
;
10149 POINT pt
= { x
, y
};
10152 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10154 /* send NM_RELEASEDCAPTURE notification */
10155 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10157 /* set left button down flag and record the click position */
10158 infoPtr
->bLButtonDown
= TRUE
;
10159 infoPtr
->ptClickPos
= pt
;
10160 infoPtr
->bDragging
= FALSE
;
10161 infoPtr
->bMarqueeSelect
= FALSE
;
10162 infoPtr
->bScrolling
= FALSE
;
10164 lvHitTestInfo
.pt
.x
= x
;
10165 lvHitTestInfo
.pt
.y
= y
;
10167 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10168 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10169 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10171 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10173 toggle_checkbox_state(infoPtr
, nItem
);
10177 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10179 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10180 infoPtr
->nEditLabelItem
= nItem
;
10182 LISTVIEW_SetSelection(infoPtr
, nItem
);
10186 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10190 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10191 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10192 infoPtr
->nSelectionMark
= nItem
;
10198 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10199 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10201 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10202 infoPtr
->nSelectionMark
= nItem
;
10205 else if (wKey
& MK_CONTROL
)
10209 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10211 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10212 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10213 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10214 infoPtr
->nSelectionMark
= nItem
;
10216 else if (wKey
& MK_SHIFT
)
10218 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10222 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10224 infoPtr
->nEditLabelItem
= nItem
;
10225 infoPtr
->nLButtonDownItem
= nItem
;
10227 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10230 /* set selection (clears other pre-existing selections) */
10231 LISTVIEW_SetSelection(infoPtr
, nItem
);
10235 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10236 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10240 if (!infoPtr
->bFocus
)
10241 SetFocus(infoPtr
->hwndSelf
);
10243 /* remove all selections */
10244 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10245 LISTVIEW_DeselectAll(infoPtr
);
10254 * Processes mouse up messages (left mouse button).
10257 * infoPtr [I ] valid pointer to the listview structure
10258 * wKey [I ] key flag
10259 * x,y [I ] mouse coordinate
10264 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10266 LVHITTESTINFO lvHitTestInfo
;
10268 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10270 if (!infoPtr
->bLButtonDown
) return 0;
10272 lvHitTestInfo
.pt
.x
= x
;
10273 lvHitTestInfo
.pt
.y
= y
;
10275 /* send NM_CLICK notification */
10276 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10277 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10279 /* set left button flag */
10280 infoPtr
->bLButtonDown
= FALSE
;
10282 /* set a single selection, reset others */
10283 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10284 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10285 infoPtr
->nLButtonDownItem
= -1;
10287 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10289 /* Remove the marquee rectangle and release our mouse capture */
10290 if (infoPtr
->bMarqueeSelect
)
10292 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10296 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10297 SetRect(&infoPtr
->marqueeDrawRect
, 0, 0, 0, 0);
10299 infoPtr
->bDragging
= FALSE
;
10300 infoPtr
->bMarqueeSelect
= FALSE
;
10301 infoPtr
->bScrolling
= FALSE
;
10303 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10307 /* if we clicked on a selected item, edit the label */
10308 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10310 /* we want to make sure the user doesn't want to do a double click. So we will
10311 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10313 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10314 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10315 SetTimer(infoPtr
->hwndSelf
,
10316 (UINT_PTR
)&infoPtr
->itemEdit
,
10317 GetDoubleClickTime(),
10318 LISTVIEW_DelayedEditItem
);
10321 if (!infoPtr
->bFocus
)
10322 SetFocus(infoPtr
->hwndSelf
);
10329 * Destroys the listview control (called after WM_DESTROY).
10332 * [I] infoPtr : valid pointer to the listview structure
10337 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10343 /* destroy data structure */
10344 DPA_Destroy(infoPtr
->hdpaItems
);
10345 DPA_Destroy(infoPtr
->hdpaItemIds
);
10346 DPA_Destroy(infoPtr
->hdpaPosX
);
10347 DPA_Destroy(infoPtr
->hdpaPosY
);
10349 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10350 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10351 DPA_Destroy(infoPtr
->hdpaColumns
);
10352 ranges_destroy(infoPtr
->selectionRanges
);
10354 /* destroy image lists */
10355 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10357 ImageList_Destroy(infoPtr
->himlNormal
);
10358 ImageList_Destroy(infoPtr
->himlSmall
);
10359 ImageList_Destroy(infoPtr
->himlState
);
10362 /* destroy font, bkgnd brush */
10363 infoPtr
->hFont
= 0;
10364 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10365 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10367 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10369 /* free listview info pointer*/
10377 * Handles notifications.
10380 * [I] infoPtr : valid pointer to the listview structure
10381 * [I] lpnmhdr : notification information
10386 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10390 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10392 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10394 /* remember: HDN_LAST < HDN_FIRST */
10395 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10396 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10398 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10400 switch (lpnmhdr
->code
)
10405 COLUMN_INFO
*lpColumnInfo
;
10409 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10412 /* remove the old line (if any) */
10413 LISTVIEW_DrawTrackLine(infoPtr
);
10415 /* compute & draw the new line */
10416 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10417 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10418 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10419 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10420 LISTVIEW_DrawTrackLine(infoPtr
);
10421 return notify_forward_header(infoPtr
, lpnmh
);
10424 case HDN_ENDTRACKA
:
10425 case HDN_ENDTRACKW
:
10426 /* remove the track line (if any) */
10427 LISTVIEW_DrawTrackLine(infoPtr
);
10428 infoPtr
->xTrackLine
= -1;
10429 return notify_forward_header(infoPtr
, lpnmh
);
10431 case HDN_BEGINDRAG
:
10432 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10433 return notify_forward_header(infoPtr
, lpnmh
);
10436 infoPtr
->colRectsDirty
= TRUE
;
10437 LISTVIEW_InvalidateList(infoPtr
);
10438 return notify_forward_header(infoPtr
, lpnmh
);
10440 case HDN_ITEMCHANGEDW
:
10441 case HDN_ITEMCHANGEDA
:
10443 COLUMN_INFO
*lpColumnInfo
;
10447 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10449 hdi
.mask
= HDI_WIDTH
;
10450 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10454 cxy
= lpnmh
->pitem
->cxy
;
10456 /* determine how much we change since the last know position */
10457 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10458 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10461 lpColumnInfo
->rcHeader
.right
+= dx
;
10463 hdi
.mask
= HDI_ORDER
;
10464 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10466 /* not the rightmost one */
10467 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10469 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10470 hdi
.iOrder
+ 1, 0);
10471 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10475 /* only needs to update the scrolls */
10476 infoPtr
->nItemWidth
+= dx
;
10477 LISTVIEW_UpdateScroll(infoPtr
);
10479 LISTVIEW_UpdateItemSize(infoPtr
);
10480 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10483 RECT rcCol
= lpColumnInfo
->rcHeader
;
10485 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10486 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10488 rcCol
.top
= infoPtr
->rcList
.top
;
10489 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10491 /* resizing left-aligned columns leaves most of the left side untouched */
10492 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10494 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10497 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10500 /* when shrinking the last column clear the now unused field */
10501 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10507 /* deal with right from rightmost column area */
10508 right
.left
= rcCol
.right
;
10509 right
.top
= rcCol
.top
;
10510 right
.bottom
= rcCol
.bottom
;
10511 right
.right
= infoPtr
->rcList
.right
;
10513 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10516 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10522 case HDN_ITEMCLICKW
:
10523 case HDN_ITEMCLICKA
:
10525 /* Handle sorting by Header Column */
10528 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10530 nmlv
.iSubItem
= lpnmh
->iItem
;
10531 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10532 return notify_forward_header(infoPtr
, lpnmh
);
10535 case HDN_DIVIDERDBLCLICKW
:
10536 case HDN_DIVIDERDBLCLICKA
:
10537 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10538 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10539 split needed for that */
10540 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10541 return notify_forward_header(infoPtr
, lpnmh
);
10548 * Paint non-client area of control.
10551 * [I] infoPtr : valid pointer to the listview structureof the sender
10552 * [I] region : update region
10555 * TRUE - frame was painted
10556 * FALSE - call default window proc
10558 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10560 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10564 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10565 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10568 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10570 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10572 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10573 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10574 if (region
!= (HRGN
)1)
10575 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10576 OffsetRect(&r
, -r
.left
, -r
.top
);
10578 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10579 OffsetRect(&r
, -r
.left
, -r
.top
);
10581 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10582 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10583 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10584 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10586 /* Call default proc to get the scrollbars etc. painted */
10587 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10594 * Determines the type of structure to use.
10597 * [I] infoPtr : valid pointer to the listview structureof the sender
10598 * [I] hwndFrom : listview window handle
10599 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10604 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10606 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10608 if (nCommand
== NF_REQUERY
)
10609 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10611 return infoPtr
->notifyFormat
;
10616 * Paints/Repaints the listview control. Internal use.
10619 * [I] infoPtr : valid pointer to the listview structure
10620 * [I] hdc : device context handle
10625 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10627 TRACE("(hdc=%p)\n", hdc
);
10629 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10631 infoPtr
->bNoItemMetrics
= FALSE
;
10632 LISTVIEW_UpdateItemSize(infoPtr
);
10633 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10634 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10635 LISTVIEW_UpdateScroll(infoPtr
);
10638 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10641 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10646 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10647 if (!hdc
) return 1;
10648 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10649 EndPaint(infoPtr
->hwndSelf
, &ps
);
10657 * Paints/Repaints the listview control, WM_PAINT handler.
10660 * [I] infoPtr : valid pointer to the listview structure
10661 * [I] hdc : device context handle
10666 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10668 TRACE("(hdc=%p)\n", hdc
);
10670 if (!is_redrawing(infoPtr
))
10671 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10673 return LISTVIEW_Paint(infoPtr
, hdc
);
10678 * Paints/Repaints the listview control.
10681 * [I] infoPtr : valid pointer to the listview structure
10682 * [I] hdc : device context handle
10683 * [I] options : drawing options
10688 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10690 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10692 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10695 if (options
& PRF_ERASEBKGND
)
10696 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10698 if (options
& PRF_CLIENT
)
10699 LISTVIEW_Paint(infoPtr
, hdc
);
10707 * Processes double click messages (right mouse button).
10710 * [I] infoPtr : valid pointer to the listview structure
10711 * [I] wKey : key flag
10712 * [I] x,y : mouse coordinate
10717 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10719 LVHITTESTINFO lvHitTestInfo
;
10721 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10723 /* send NM_RELEASEDCAPTURE notification */
10724 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10726 /* send NM_RDBLCLK notification */
10727 lvHitTestInfo
.pt
.x
= x
;
10728 lvHitTestInfo
.pt
.y
= y
;
10729 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10730 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10737 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10740 * [I] infoPtr : valid pointer to the listview structure
10741 * [I] wKey : key flag
10742 * [I] x, y : mouse coordinate
10747 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10752 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10754 /* send NM_RELEASEDCAPTURE notification */
10755 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10757 /* determine the index of the selected item */
10760 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10762 /* make sure the listview control window has the focus */
10763 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10765 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10767 LISTVIEW_SetItemFocus(infoPtr
, item
);
10768 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10769 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10770 LISTVIEW_SetSelection(infoPtr
, item
);
10773 LISTVIEW_DeselectAll(infoPtr
);
10775 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10777 if (ht
.iItem
!= -1)
10781 memset(&nmlv
, 0, sizeof(nmlv
));
10782 nmlv
.iItem
= ht
.iItem
;
10783 nmlv
.ptAction
= ht
.pt
;
10785 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10790 SetFocus(infoPtr
->hwndSelf
);
10794 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10796 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10798 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10799 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10800 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10812 * [I] infoPtr : valid pointer to the listview structure
10813 * [I] hwnd : window handle of window containing the cursor
10814 * [I] nHittest : hit-test code
10815 * [I] wMouseMsg : ideintifier of the mouse message
10818 * TRUE if cursor is set
10821 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10823 LVHITTESTINFO lvHitTestInfo
;
10825 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10827 if (!infoPtr
->hHotCursor
) goto forward
;
10829 GetCursorPos(&lvHitTestInfo
.pt
);
10830 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10832 SetCursor(infoPtr
->hHotCursor
);
10838 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10846 * [I] infoPtr : valid pointer to the listview structure
10847 * [I] hwndLoseFocus : handle of previously focused window
10852 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10854 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10856 /* if we have the focus already, there's nothing to do */
10857 if (infoPtr
->bFocus
) return 0;
10859 /* send NM_SETFOCUS notification */
10860 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10862 /* set window focus flag */
10863 infoPtr
->bFocus
= TRUE
;
10865 /* put the focus rect back on */
10866 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10868 /* redraw all visible selected items */
10869 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10879 * [I] infoPtr : valid pointer to the listview structure
10880 * [I] fRedraw : font handle
10881 * [I] fRedraw : redraw flag
10886 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10888 HFONT oldFont
= infoPtr
->hFont
;
10889 INT oldHeight
= infoPtr
->nItemHeight
;
10891 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10893 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10894 if (infoPtr
->hFont
== oldFont
) return 0;
10896 LISTVIEW_SaveTextMetrics(infoPtr
);
10898 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10900 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10902 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10903 LISTVIEW_UpdateSize(infoPtr
);
10904 LISTVIEW_UpdateScroll(infoPtr
);
10906 else if (infoPtr
->nItemHeight
!= oldHeight
)
10907 LISTVIEW_UpdateScroll(infoPtr
);
10909 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10916 * Message handling for WM_SETREDRAW.
10917 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10920 * [I] infoPtr : valid pointer to the listview structure
10921 * [I] bRedraw: state of redraw flag
10924 * DefWinProc return value
10926 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10928 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10930 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10931 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10933 infoPtr
->bRedraw
= bRedraw
;
10935 if(!bRedraw
) return 0;
10937 if (is_autoarrange(infoPtr
))
10938 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10939 LISTVIEW_UpdateScroll(infoPtr
);
10941 /* despite what the WM_SETREDRAW docs says, apps expect us
10942 * to invalidate the listview here... stupid! */
10943 LISTVIEW_InvalidateList(infoPtr
);
10950 * Resizes the listview control. This function processes WM_SIZE
10951 * messages. At this time, the width and height are not used.
10954 * [I] infoPtr : valid pointer to the listview structure
10955 * [I] Width : new width
10956 * [I] Height : new height
10961 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10963 RECT rcOld
= infoPtr
->rcList
;
10965 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10967 LISTVIEW_UpdateSize(infoPtr
);
10968 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10970 /* do not bother with display related stuff if we're not redrawing */
10971 if (!is_redrawing(infoPtr
)) return 0;
10973 if (is_autoarrange(infoPtr
))
10974 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10976 LISTVIEW_UpdateScroll(infoPtr
);
10978 /* refresh all only for lists whose height changed significantly */
10979 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10980 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10981 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10982 LISTVIEW_InvalidateList(infoPtr
);
10989 * Sets the size information.
10992 * [I] infoPtr : valid pointer to the listview structure
10997 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
10999 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11001 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11003 if (infoPtr
->uView
== LV_VIEW_LIST
)
11005 /* Apparently the "LIST" style is supposed to have the same
11006 * number of items in a column even if there is no scroll bar.
11007 * Since if a scroll bar already exists then the bottom is already
11008 * reduced, only reduce if the scroll bar does not currently exist.
11009 * The "2" is there to mimic the native control. I think it may be
11010 * related to either padding or edges. (GLA 7/2002)
11012 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11013 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11014 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11017 /* if control created invisible header isn't created */
11018 if (infoPtr
->hwndHeader
)
11023 hl
.prc
= &infoPtr
->rcList
;
11025 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11026 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11028 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11029 wp
.flags
|= SWP_SHOWWINDOW
;
11032 wp
.flags
|= SWP_HIDEWINDOW
;
11036 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11037 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11039 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11041 /* extra padding for grid */
11042 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11043 infoPtr
->rcList
.top
+= 2;
11045 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11050 * Processes WM_STYLECHANGED messages.
11053 * [I] infoPtr : valid pointer to the listview structure
11054 * [I] wStyleType : window style type (normal or extended)
11055 * [I] lpss : window style information
11060 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11061 const STYLESTRUCT
*lpss
)
11063 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11064 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11067 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11068 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11070 if (wStyleType
!= GWL_STYLE
) return 0;
11072 infoPtr
->dwStyle
= lpss
->styleNew
;
11073 map_style_view(infoPtr
);
11075 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11076 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11077 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11079 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11080 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11081 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11083 if (uNewView
!= uOldView
)
11087 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11088 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11090 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11091 SetRectEmpty(&infoPtr
->rcFocus
);
11093 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11094 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11096 if (uNewView
== LVS_REPORT
)
11101 LISTVIEW_CreateHeader( infoPtr
);
11103 hl
.prc
= &infoPtr
->rcList
;
11105 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11106 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11107 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11108 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11111 LISTVIEW_UpdateItemSize(infoPtr
);
11114 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11116 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11118 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11120 /* Turn off the header control */
11121 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11122 TRACE("Hide header control, was 0x%08x\n", style
);
11123 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11125 /* Turn on the header control */
11126 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11128 TRACE("Show header control, was 0x%08x\n", style
);
11129 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11135 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11136 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11137 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11139 /* update the size of the client area */
11140 LISTVIEW_UpdateSize(infoPtr
);
11142 /* add scrollbars if needed */
11143 LISTVIEW_UpdateScroll(infoPtr
);
11145 /* invalidate client area + erase background */
11146 LISTVIEW_InvalidateList(infoPtr
);
11153 * Processes WM_STYLECHANGING messages.
11156 * [I] wStyleType : window style type (normal or extended)
11157 * [I0] lpss : window style information
11162 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11165 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11166 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11168 /* don't forward LVS_OWNERDATA only if not already set to */
11169 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11171 if (lpss
->styleOld
& LVS_OWNERDATA
)
11172 lpss
->styleNew
|= LVS_OWNERDATA
;
11174 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11182 * Processes WM_SHOWWINDOW messages.
11185 * [I] infoPtr : valid pointer to the listview structure
11186 * [I] bShown : window is being shown (FALSE when hidden)
11187 * [I] iStatus : window show status
11192 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11194 /* header delayed creation */
11195 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11197 LISTVIEW_CreateHeader(infoPtr
);
11199 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11200 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11203 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11208 * Processes CCM_GETVERSION messages.
11211 * [I] infoPtr : valid pointer to the listview structure
11216 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11218 return infoPtr
->iVersion
;
11223 * Processes CCM_SETVERSION messages.
11226 * [I] infoPtr : valid pointer to the listview structure
11227 * [I] iVersion : version to be set
11230 * -1 when requested version is greater than DLL version;
11231 * previous version otherwise
11233 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11235 INT iOldVersion
= infoPtr
->iVersion
;
11237 if (iVersion
> COMCTL32_VERSION
)
11240 infoPtr
->iVersion
= iVersion
;
11242 TRACE("new version %d\n", iVersion
);
11244 return iOldVersion
;
11249 * Window procedure of the listview control.
11252 static LRESULT WINAPI
11253 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11255 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11257 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11259 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11260 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11264 case LVM_APPROXIMATEVIEWRECT
:
11265 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11266 LOWORD(lParam
), HIWORD(lParam
));
11268 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11270 case LVM_CANCELEDITLABEL
:
11271 return LISTVIEW_CancelEditLabel(infoPtr
);
11273 case LVM_CREATEDRAGIMAGE
:
11274 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11276 case LVM_DELETEALLITEMS
:
11277 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11279 case LVM_DELETECOLUMN
:
11280 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11282 case LVM_DELETEITEM
:
11283 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11285 case LVM_EDITLABELA
:
11286 case LVM_EDITLABELW
:
11287 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11288 uMsg
== LVM_EDITLABELW
);
11289 /* case LVM_ENABLEGROUPVIEW: */
11291 case LVM_ENSUREVISIBLE
:
11292 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11294 case LVM_FINDITEMW
:
11295 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11297 case LVM_FINDITEMA
:
11298 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11300 case LVM_GETBKCOLOR
:
11301 return infoPtr
->clrBk
;
11303 /* case LVM_GETBKIMAGE: */
11305 case LVM_GETCALLBACKMASK
:
11306 return infoPtr
->uCallbackMask
;
11308 case LVM_GETCOLUMNA
:
11309 case LVM_GETCOLUMNW
:
11310 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11311 uMsg
== LVM_GETCOLUMNW
);
11313 case LVM_GETCOLUMNORDERARRAY
:
11314 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11316 case LVM_GETCOLUMNWIDTH
:
11317 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11319 case LVM_GETCOUNTPERPAGE
:
11320 return LISTVIEW_GetCountPerPage(infoPtr
);
11322 case LVM_GETEDITCONTROL
:
11323 return (LRESULT
)infoPtr
->hwndEdit
;
11325 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11326 return infoPtr
->dwLvExStyle
;
11328 /* case LVM_GETGROUPINFO: */
11330 /* case LVM_GETGROUPMETRICS: */
11332 case LVM_GETHEADER
:
11333 return (LRESULT
)infoPtr
->hwndHeader
;
11335 case LVM_GETHOTCURSOR
:
11336 return (LRESULT
)infoPtr
->hHotCursor
;
11338 case LVM_GETHOTITEM
:
11339 return infoPtr
->nHotItem
;
11341 case LVM_GETHOVERTIME
:
11342 return infoPtr
->dwHoverTime
;
11344 case LVM_GETIMAGELIST
:
11345 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11347 /* case LVM_GETINSERTMARK: */
11349 /* case LVM_GETINSERTMARKCOLOR: */
11351 /* case LVM_GETINSERTMARKRECT: */
11353 case LVM_GETISEARCHSTRINGA
:
11354 case LVM_GETISEARCHSTRINGW
:
11355 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11360 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11362 case LVM_GETITEMCOUNT
:
11363 return infoPtr
->nItemCount
;
11365 case LVM_GETITEMPOSITION
:
11366 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11368 case LVM_GETITEMRECT
:
11369 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11371 case LVM_GETITEMSPACING
:
11372 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11374 case LVM_GETITEMSTATE
:
11375 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11377 case LVM_GETITEMTEXTA
:
11378 case LVM_GETITEMTEXTW
:
11379 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11380 uMsg
== LVM_GETITEMTEXTW
);
11382 case LVM_GETNEXTITEM
:
11383 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11385 case LVM_GETNUMBEROFWORKAREAS
:
11386 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11389 case LVM_GETORIGIN
:
11390 if (!lParam
) return FALSE
;
11391 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11392 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11393 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11396 /* case LVM_GETOUTLINECOLOR: */
11398 /* case LVM_GETSELECTEDCOLUMN: */
11400 case LVM_GETSELECTEDCOUNT
:
11401 return LISTVIEW_GetSelectedCount(infoPtr
);
11403 case LVM_GETSELECTIONMARK
:
11404 return infoPtr
->nSelectionMark
;
11406 case LVM_GETSTRINGWIDTHA
:
11407 case LVM_GETSTRINGWIDTHW
:
11408 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11409 uMsg
== LVM_GETSTRINGWIDTHW
);
11411 case LVM_GETSUBITEMRECT
:
11412 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11414 case LVM_GETTEXTBKCOLOR
:
11415 return infoPtr
->clrTextBk
;
11417 case LVM_GETTEXTCOLOR
:
11418 return infoPtr
->clrText
;
11420 /* case LVM_GETTILEINFO: */
11422 /* case LVM_GETTILEVIEWINFO: */
11424 case LVM_GETTOOLTIPS
:
11425 if( !infoPtr
->hwndToolTip
)
11426 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11427 return (LRESULT
)infoPtr
->hwndToolTip
;
11429 case LVM_GETTOPINDEX
:
11430 return LISTVIEW_GetTopIndex(infoPtr
);
11432 case LVM_GETUNICODEFORMAT
:
11433 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11436 return infoPtr
->uView
;
11438 case LVM_GETVIEWRECT
:
11439 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11441 case LVM_GETWORKAREAS
:
11442 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11445 /* case LVM_HASGROUP: */
11448 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11450 case LVM_INSERTCOLUMNA
:
11451 case LVM_INSERTCOLUMNW
:
11452 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11453 uMsg
== LVM_INSERTCOLUMNW
);
11455 /* case LVM_INSERTGROUP: */
11457 /* case LVM_INSERTGROUPSORTED: */
11459 case LVM_INSERTITEMA
:
11460 case LVM_INSERTITEMW
:
11461 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11463 /* case LVM_INSERTMARKHITTEST: */
11465 /* case LVM_ISGROUPVIEWENABLED: */
11467 case LVM_ISITEMVISIBLE
:
11468 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11470 case LVM_MAPIDTOINDEX
:
11471 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11473 case LVM_MAPINDEXTOID
:
11474 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11476 /* case LVM_MOVEGROUP: */
11478 /* case LVM_MOVEITEMTOGROUP: */
11480 case LVM_REDRAWITEMS
:
11481 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11483 /* case LVM_REMOVEALLGROUPS: */
11485 /* case LVM_REMOVEGROUP: */
11488 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11490 case LVM_SETBKCOLOR
:
11491 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11493 /* case LVM_SETBKIMAGE: */
11495 case LVM_SETCALLBACKMASK
:
11496 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11499 case LVM_SETCOLUMNA
:
11500 case LVM_SETCOLUMNW
:
11501 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11502 uMsg
== LVM_SETCOLUMNW
);
11504 case LVM_SETCOLUMNORDERARRAY
:
11505 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11507 case LVM_SETCOLUMNWIDTH
:
11508 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11510 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11511 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11513 /* case LVM_SETGROUPINFO: */
11515 /* case LVM_SETGROUPMETRICS: */
11517 case LVM_SETHOTCURSOR
:
11518 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11520 case LVM_SETHOTITEM
:
11521 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11523 case LVM_SETHOVERTIME
:
11524 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11526 case LVM_SETICONSPACING
:
11528 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11529 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11531 case LVM_SETIMAGELIST
:
11532 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11534 /* case LVM_SETINFOTIP: */
11536 /* case LVM_SETINSERTMARK: */
11538 /* case LVM_SETINSERTMARKCOLOR: */
11543 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11544 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11547 case LVM_SETITEMCOUNT
:
11548 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11550 case LVM_SETITEMPOSITION
:
11553 pt
.x
= (short)LOWORD(lParam
);
11554 pt
.y
= (short)HIWORD(lParam
);
11555 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11558 case LVM_SETITEMPOSITION32
:
11559 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11561 case LVM_SETITEMSTATE
:
11562 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11564 case LVM_SETITEMTEXTA
:
11565 case LVM_SETITEMTEXTW
:
11566 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11567 uMsg
== LVM_SETITEMTEXTW
);
11569 /* case LVM_SETOUTLINECOLOR: */
11571 /* case LVM_SETSELECTEDCOLUMN: */
11573 case LVM_SETSELECTIONMARK
:
11574 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11576 case LVM_SETTEXTBKCOLOR
:
11577 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11579 case LVM_SETTEXTCOLOR
:
11580 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11582 /* case LVM_SETTILEINFO: */
11584 /* case LVM_SETTILEVIEWINFO: */
11586 /* case LVM_SETTILEWIDTH: */
11588 case LVM_SETTOOLTIPS
:
11589 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11591 case LVM_SETUNICODEFORMAT
:
11592 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11595 return LISTVIEW_SetView(infoPtr
, wParam
);
11597 /* case LVM_SETWORKAREAS: */
11599 /* case LVM_SORTGROUPS: */
11601 case LVM_SORTITEMS
:
11602 case LVM_SORTITEMSEX
:
11603 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11604 uMsg
== LVM_SORTITEMSEX
);
11605 case LVM_SUBITEMHITTEST
:
11606 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11609 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11611 case CCM_GETVERSION
:
11612 return LISTVIEW_GetVersion(infoPtr
);
11614 case CCM_SETVERSION
:
11615 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11618 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11621 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11624 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11627 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11630 return LISTVIEW_Destroy(infoPtr
);
11633 return LISTVIEW_Enable(infoPtr
);
11635 case WM_ERASEBKGND
:
11636 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11638 case WM_GETDLGCODE
:
11639 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11642 return (LRESULT
)infoPtr
->hFont
;
11645 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11648 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11651 return LISTVIEW_KillFocus(infoPtr
);
11653 case WM_LBUTTONDBLCLK
:
11654 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11656 case WM_LBUTTONDOWN
:
11657 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11660 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11663 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11665 case WM_MOUSEHOVER
:
11666 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11669 return LISTVIEW_NCDestroy(infoPtr
);
11672 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11675 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11677 case WM_NOTIFYFORMAT
:
11678 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11680 case WM_PRINTCLIENT
:
11681 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11684 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11686 case WM_RBUTTONDBLCLK
:
11687 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11689 case WM_RBUTTONDOWN
:
11690 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11693 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11696 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11699 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11702 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11704 case WM_SHOWWINDOW
:
11705 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11707 case WM_STYLECHANGED
:
11708 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11710 case WM_STYLECHANGING
:
11711 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11713 case WM_SYSCOLORCHANGE
:
11714 COMCTL32_RefreshSysColors();
11717 /* case WM_TIMER: */
11718 case WM_THEMECHANGED
:
11719 return LISTVIEW_ThemeChanged(infoPtr
);
11722 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11724 case WM_MOUSEWHEEL
:
11725 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11726 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11727 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11729 case WM_WINDOWPOSCHANGED
:
11730 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11732 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11733 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11735 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11737 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11739 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11741 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11743 /* case WM_WININICHANGE: */
11746 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11747 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11749 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11756 * Registers the window class.
11764 void LISTVIEW_Register(void)
11766 WNDCLASSW wndClass
;
11768 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11769 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11770 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11771 wndClass
.cbClsExtra
= 0;
11772 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11773 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11774 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11775 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11776 RegisterClassW(&wndClass
);
11781 * Unregisters the window class.
11789 void LISTVIEW_Unregister(void)
11791 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11796 * Handle any WM_COMMAND messages
11799 * [I] infoPtr : valid pointer to the listview structure
11800 * [I] wParam : the first message parameter
11801 * [I] lParam : the second message parameter
11806 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11809 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11811 if (!infoPtr
->hwndEdit
) return 0;
11813 switch (HIWORD(wParam
))
11818 * Adjust the edit window size
11820 WCHAR buffer
[1024];
11821 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11822 HFONT hFont
, hOldFont
= 0;
11826 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11827 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11828 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11830 /* Select font to get the right dimension of the string */
11831 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11834 hOldFont
= SelectObject(hdc
, hFont
);
11837 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11839 TEXTMETRICW textMetric
;
11841 /* Add Extra spacing for the next character */
11842 GetTextMetricsW(hdc
, &textMetric
);
11843 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11845 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11846 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11849 SelectObject(hdc
, hOldFont
);
11851 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11857 LISTVIEW_CancelEditLabel(infoPtr
);
11862 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);