4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1999 Luc Tourangeau
6 * Copyright 2000 Jason Mawdsley
7 * Copyright 2001 CodeWeavers Inc.
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009-2015 Nikolay Sivov
10 * Copyright 2009 Owen Rudge for CodeWeavers
11 * Copyright 2012-2013 Daniel Jelinski
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 * Default Message Processing
30 * -- WM_CREATE: create the icon and small icon image lists at this point only if
31 * the LVS_SHAREIMAGELISTS style is not specified.
32 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
33 * or small icon and the LVS_AUTOARRANGE style is specified.
38 * -- Hot item handling, mouse hovering
39 * -- Workareas support
44 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
45 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
46 * -- LVA_SNAPTOGRID not implemented
47 * -- LISTVIEW_ApproximateViewRect partially implemented
48 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
51 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
52 * linear in the number of items in the list, and this is
53 * unacceptable for large lists.
54 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
55 * binary search to calculate item index (e.g. DPA_Search()).
56 * This requires sorted state to be reliably tracked in item modifiers.
57 * -- we should keep an ordered array of coordinates in iconic mode.
58 * This would allow framing items (iterator_frameditems),
59 * and finding the nearest item (LVFI_NEARESTXY) a lot more efficiently.
66 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
71 * -- LVS_NOSCROLL (see Q137520)
75 * -- LVS_EX_BORDERSELECT
79 * -- LVS_EX_MULTIWORKAREAS
81 * -- LVS_EX_SIMPLESELECT
82 * -- LVS_EX_TWOCLICKACTIVATE
83 * -- LVS_EX_UNDERLINECOLD
84 * -- LVS_EX_UNDERLINEHOT
87 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
93 * -- LVM_ENABLEGROUPVIEW
94 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
95 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
96 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
97 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
98 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
99 * -- LVM_GETINSERTMARKRECT
100 * -- LVM_GETNUMBEROFWORKAREAS
101 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
102 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
103 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
104 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
105 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
106 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
107 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
108 * -- LVM_INSERTGROUPSORTED
109 * -- LVM_INSERTMARKHITTEST
110 * -- LVM_ISGROUPVIEWENABLED
112 * -- LVM_MOVEITEMTOGROUP
114 * -- LVM_SETTILEWIDTH
118 * -- ListView_GetHoverTime, ListView_SetHoverTime
119 * -- ListView_GetISearchString
120 * -- ListView_GetNumberOfWorkAreas
121 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
140 #include "commctrl.h"
141 #include "comctl32.h"
144 #include "wine/debug.h"
146 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
148 typedef struct tagCOLUMN_INFO
150 RECT rcHeader
; /* tracks the header's rectangle */
151 INT fmt
; /* same as LVCOLUMN.fmt */
155 typedef struct tagITEMHDR
159 } ITEMHDR
, *LPITEMHDR
;
161 typedef struct tagSUBITEM_INFO
167 typedef struct tagITEM_ID ITEM_ID
;
169 typedef struct tagITEM_INFO
180 UINT id
; /* item id */
181 HDPA item
; /* link to item data */
184 typedef struct tagRANGE
190 typedef struct tagRANGES
195 typedef struct tagITERATOR
204 typedef struct tagDELAYED_ITEM_EDIT
210 enum notification_mask
212 NOTIFY_MASK_ITEM_CHANGE
= 0x1,
213 NOTIFY_MASK_END_LABEL_EDIT
= 0x2,
214 NOTIFY_MASK_UNMASK_ALL
= 0xffffffff
217 typedef struct tagLISTVIEW_INFO
221 RECT rcList
; /* This rectangle is really the window
222 * client rectangle possibly reduced by the
223 * horizontal scroll bar and/or header - see
224 * LISTVIEW_UpdateSize. This rectangle offset
225 * by the LISTVIEW_GetOrigin value is in
226 * client coordinates */
228 /* notification window */
238 INT nItemCount
; /* the number of items in the list */
239 HDPA hdpaItems
; /* array ITEM_INFO pointers */
240 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
241 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
242 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
243 RANGES selectionRanges
;
244 INT nSelectionMark
; /* item to start next multiselection from */
248 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
249 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
252 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
257 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
261 DWORD dwStyle
; /* the cached window GWL_STYLE */
262 DWORD dwLvExStyle
; /* extended listview style */
263 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
269 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
272 HIMAGELIST himlNormal
;
273 HIMAGELIST himlSmall
;
274 HIMAGELIST himlState
;
279 POINT currIconPos
; /* this is the position next icon will be placed */
283 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
285 /* marquee selection */
286 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
288 RECT marqueeRect
; /* absolute coordinates of marquee selection */
289 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
290 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
293 BOOL bFocus
; /* control has focus */
295 RECT rcFocus
; /* focus bounds */
306 INT ntmHeight
; /* Some cached metrics of the font used */
307 INT ntmMaxCharWidth
; /* by the listview to draw items */
310 /* mouse operation */
313 POINT ptClickPos
; /* point where the user clicked */
314 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
319 /* keyboard operation */
320 DWORD lastKeyPressTimestamp
;
322 INT nSearchParamLength
;
323 WCHAR szSearchParam
[ MAX_PATH
];
326 BOOL bIsDrawing
; /* Drawing in progress */
327 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
328 BOOL redraw
; /* WM_SETREDRAW switch */
331 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
337 /* How many we debug buffer to allocate */
338 #define DEBUG_BUFFERS 20
339 /* The size of a single debug buffer */
340 #define DEBUG_BUFFER_SIZE 256
342 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
343 #define SB_INTERNAL -1
345 /* maximum size of a label */
346 #define DISP_TEXT_SIZE 260
348 /* padding for items in list and small icon display modes */
349 #define WIDTH_PADDING 12
351 /* padding for items in list, report and small icon display modes */
352 #define HEIGHT_PADDING 1
354 /* offset of items in report display mode */
355 #define REPORT_MARGINX 2
357 /* padding for icon in large icon display mode
358 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
359 * that HITTEST will see.
360 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
361 * ICON_TOP_PADDING - sum of the two above.
362 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
363 * LABEL_HOR_PADDING - between text and sides of box
364 * LABEL_VERT_PADDING - between bottom of text and end of box
366 * ICON_LR_PADDING - additional width above icon size.
367 * ICON_LR_HALF - half of the above value
369 #define ICON_TOP_PADDING_NOTHITABLE 2
370 #define ICON_TOP_PADDING_HITABLE 2
371 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
372 #define ICON_BOTTOM_PADDING 4
373 #define LABEL_HOR_PADDING 5
374 #define LABEL_VERT_PADDING 7
375 #define ICON_LR_PADDING 16
376 #define ICON_LR_HALF (ICON_LR_PADDING/2)
378 /* default label width for items in list and small icon display modes */
379 #define DEFAULT_LABEL_WIDTH 40
380 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
381 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
383 /* default column width for items in list display mode */
384 #define DEFAULT_COLUMN_WIDTH 128
386 /* Size of "line" scroll for V & H scrolls */
387 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
389 /* Padding between image and label */
390 #define IMAGE_PADDING 2
392 /* Padding behind the label */
393 #define TRAILING_LABEL_PADDING 12
394 #define TRAILING_HEADER_PADDING 11
396 /* Border for the icon caption */
397 #define CAPTION_BORDER 2
399 /* Standard DrawText flags */
400 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
401 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
402 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
404 /* Image index from state */
405 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
407 /* The time in milliseconds to reset the search in the list */
408 #define KEY_DELAY 450
410 /* Dump the LISTVIEW_INFO structure to the debug channel */
411 #define LISTVIEW_DUMP(iP) do { \
412 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
413 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
414 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
415 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
416 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
417 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
418 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
419 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
420 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
421 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
424 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
427 * forward declarations
429 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
430 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
431 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
432 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
433 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
434 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
435 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
436 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
437 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
438 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
439 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
440 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
441 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
442 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
443 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
444 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
445 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
446 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
447 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
448 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
450 /******** Text handling functions *************************************/
452 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
453 * text string. The string may be ANSI or Unicode, in which case
454 * the boolean isW tells us the type of the string.
456 * The name of the function tell what type of strings it expects:
457 * W: Unicode, T: ANSI/Unicode - function of isW
460 static inline BOOL
is_text(LPCWSTR text
)
462 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
465 static inline int textlenT(LPCWSTR text
, BOOL isW
)
467 return !is_text(text
) ? 0 :
468 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
471 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
474 if (isSrcW
) lstrcpynW(dest
, src
, max
);
475 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
477 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
478 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
481 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
483 LPWSTR wstr
= (LPWSTR
)text
;
485 if (!isW
&& is_text(text
))
487 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
488 wstr
= Alloc(len
* sizeof(WCHAR
));
489 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
491 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
495 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
497 if (!isW
&& is_text(wstr
)) Free (wstr
);
501 * dest is a pointer to a Unicode string
502 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
504 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
508 if (src
== LPSTR_TEXTCALLBACKW
)
510 if (is_text(*dest
)) Free(*dest
);
511 *dest
= LPSTR_TEXTCALLBACKW
;
515 LPWSTR pszText
= textdupTtoW(src
, isW
);
516 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
517 bResult
= Str_SetPtrW(dest
, pszText
);
518 textfreeT(pszText
, isW
);
524 * compares a Unicode to a Unicode/ANSI text string
526 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
528 if (!aw
) return bt
? -1 : 0;
530 if (aw
== LPSTR_TEXTCALLBACKW
)
531 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
532 if (bt
!= LPSTR_TEXTCALLBACKW
)
534 LPWSTR bw
= textdupTtoW(bt
, isW
);
535 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
543 /******** Debugging functions *****************************************/
545 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
547 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
548 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
551 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
553 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
554 n
= min(textlenT(text
, isW
), n
);
555 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
558 static char* debug_getbuf(void)
560 static int index
= 0;
561 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
562 return buffers
[index
++ % DEBUG_BUFFERS
];
565 static inline const char* debugrange(const RANGE
*lprng
)
567 if (!lprng
) return "(null)";
568 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
571 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
573 char* buf
= debug_getbuf(), *text
= buf
;
574 int len
, size
= DEBUG_BUFFER_SIZE
;
576 if (pScrollInfo
== NULL
) return "(null)";
577 len
= snprintf(buf
, size
, "{cbSize=%u, ", pScrollInfo
->cbSize
);
578 if (len
== -1) goto end
;
579 buf
+= len
; size
-= len
;
580 if (pScrollInfo
->fMask
& SIF_RANGE
)
581 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
583 if (len
== -1) goto end
;
584 buf
+= len
; size
-= len
;
585 if (pScrollInfo
->fMask
& SIF_PAGE
)
586 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
588 if (len
== -1) goto end
;
589 buf
+= len
; size
-= len
;
590 if (pScrollInfo
->fMask
& SIF_POS
)
591 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
593 if (len
== -1) goto end
;
594 buf
+= len
; size
-= len
;
595 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
596 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
598 if (len
== -1) goto end
;
602 buf
= text
+ strlen(text
);
604 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
608 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
610 if (!plvnm
) return "(null)";
611 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
612 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
613 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
614 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
617 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
619 char* buf
= debug_getbuf(), *text
= buf
;
620 int len
, size
= DEBUG_BUFFER_SIZE
;
622 if (lpLVItem
== NULL
) return "(null)";
623 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
624 if (len
== -1) goto end
;
625 buf
+= len
; size
-= len
;
626 if (lpLVItem
->mask
& LVIF_STATE
)
627 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
629 if (len
== -1) goto end
;
630 buf
+= len
; size
-= len
;
631 if (lpLVItem
->mask
& LVIF_TEXT
)
632 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
634 if (len
== -1) goto end
;
635 buf
+= len
; size
-= len
;
636 if (lpLVItem
->mask
& LVIF_IMAGE
)
637 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
639 if (len
== -1) goto end
;
640 buf
+= len
; size
-= len
;
641 if (lpLVItem
->mask
& LVIF_PARAM
)
642 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
644 if (len
== -1) goto end
;
645 buf
+= len
; size
-= len
;
646 if (lpLVItem
->mask
& LVIF_INDENT
)
647 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
649 if (len
== -1) goto end
;
653 buf
= text
+ strlen(text
);
655 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
659 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
661 char* buf
= debug_getbuf(), *text
= buf
;
662 int len
, size
= DEBUG_BUFFER_SIZE
;
664 if (lpColumn
== NULL
) return "(null)";
665 len
= snprintf(buf
, size
, "{");
666 if (len
== -1) goto end
;
667 buf
+= len
; size
-= len
;
668 if (lpColumn
->mask
& LVCF_SUBITEM
)
669 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
671 if (len
== -1) goto end
;
672 buf
+= len
; size
-= len
;
673 if (lpColumn
->mask
& LVCF_FMT
)
674 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
676 if (len
== -1) goto end
;
677 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
;
682 buf
+= len
; size
-= len
;
683 if (lpColumn
->mask
& LVCF_TEXT
)
684 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
686 if (len
== -1) goto end
;
687 buf
+= len
; size
-= len
;
688 if (lpColumn
->mask
& LVCF_IMAGE
)
689 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
691 if (len
== -1) goto end
;
692 buf
+= len
; size
-= len
;
693 if (lpColumn
->mask
& LVCF_ORDER
)
694 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
696 if (len
== -1) goto end
;
700 buf
= text
+ strlen(text
);
702 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
706 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
708 if (!lpht
) return "(null)";
710 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
711 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
714 /* Return the corresponding text for a given scroll value */
715 static inline LPCSTR
debugscrollcode(int nScrollCode
)
719 case SB_LINELEFT
: return "SB_LINELEFT";
720 case SB_LINERIGHT
: return "SB_LINERIGHT";
721 case SB_PAGELEFT
: return "SB_PAGELEFT";
722 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
723 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
724 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
725 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
726 case SB_INTERNAL
: return "SB_INTERNAL";
727 default: return "unknown";
732 /******** Notification functions ************************************/
734 static int get_ansi_notification(UINT unicodeNotificationCode
)
736 switch (unicodeNotificationCode
)
738 case LVN_BEGINLABELEDITA
:
739 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
740 case LVN_ENDLABELEDITA
:
741 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
742 case LVN_GETDISPINFOA
:
743 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
744 case LVN_SETDISPINFOA
:
745 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
746 case LVN_ODFINDITEMA
:
747 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
748 case LVN_GETINFOTIPA
:
749 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
750 /* header forwards */
752 case HDN_TRACKW
: return HDN_TRACKA
;
754 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
755 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
756 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
757 case HDN_ITEMCHANGINGA
:
758 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
759 case HDN_ITEMCHANGEDA
:
760 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
762 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
763 case HDN_DIVIDERDBLCLICKA
:
764 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
767 FIXME("unknown notification %x\n", unicodeNotificationCode
);
768 return unicodeNotificationCode
;
771 /* forwards header notifications to listview parent */
772 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
774 LPCWSTR text
= NULL
, filter
= NULL
;
776 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
778 /* on unicode format exit earlier */
779 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
780 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
783 /* header always supplies unicode notifications,
784 all we have to do is to convert strings to ANSI */
787 /* convert item text */
788 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
790 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
791 lpnmh
->pitem
->pszText
= NULL
;
792 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
794 /* convert filter text */
795 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
796 lpnmh
->pitem
->pvFilter
)
798 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
799 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= NULL
;
800 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
803 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
805 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
811 Free(lpnmh
->pitem
->pszText
);
812 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
816 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
817 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
823 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
827 TRACE("(code=%d)\n", code
);
829 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
830 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
832 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
834 TRACE(" <= %ld\n", result
);
839 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
842 HWND hwnd
= infoPtr
->hwndSelf
;
843 notify_hdr(infoPtr
, code
, &nmh
);
844 return IsWindow(hwnd
);
847 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
857 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
858 item
.iItem
= htInfo
->iItem
;
860 item
.stateMask
= (UINT
)-1;
861 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
862 nmia
.lParam
= item
.lParam
;
863 nmia
.uOldState
= item
.state
;
864 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
865 nmia
.uChanged
= LVIF_STATE
;
868 nmia
.iItem
= htInfo
->iItem
;
869 nmia
.iSubItem
= htInfo
->iSubItem
;
870 nmia
.ptAction
= htInfo
->pt
;
872 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
873 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
874 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
876 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
879 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
881 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
882 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
885 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
886 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
890 HWND hwnd
= infoPtr
->hwndSelf
;
893 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
894 ZeroMemory(&nmia
, sizeof(nmia
));
895 nmia
.iItem
= lvht
->iItem
;
896 nmia
.iSubItem
= lvht
->iSubItem
;
897 nmia
.ptAction
= lvht
->pt
;
898 item
.mask
= LVIF_PARAM
;
899 item
.iItem
= lvht
->iItem
;
901 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
902 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
903 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
906 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
910 HWND hwnd
= infoPtr
->hwndSelf
;
912 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
914 item
.mask
= LVIF_PARAM
;
917 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
918 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
919 return IsWindow(hwnd
);
923 Send notification. depends on dispinfoW having same
924 structure as dispinfoA.
925 infoPtr : listview struct
926 code : *Unicode* notification code
927 pdi : dispinfo structure (can be unicode or ansi)
928 isW : TRUE if dispinfo is Unicode
930 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
932 INT length
= 0, ret_length
;
933 LPWSTR buffer
= NULL
, ret_text
;
934 BOOL return_ansi
= FALSE
;
935 BOOL return_unicode
= FALSE
;
938 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
940 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
941 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
944 ret_length
= pdi
->item
.cchTextMax
;
945 ret_text
= pdi
->item
.pszText
;
947 if (return_unicode
|| return_ansi
)
949 if (code
!= LVN_GETDISPINFOW
)
951 length
= return_ansi
?
952 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
953 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
957 length
= pdi
->item
.cchTextMax
;
958 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
961 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
962 if (!buffer
) return FALSE
;
965 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
968 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
971 pdi
->item
.pszText
= buffer
;
972 pdi
->item
.cchTextMax
= length
;
975 if (infoPtr
->notifyFormat
== NFR_ANSI
)
976 code
= get_ansi_notification(code
);
978 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
979 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
980 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
982 if (return_ansi
|| return_unicode
)
984 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
986 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
988 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
990 lstrcpyW(ret_text
, pdi
->item
.pszText
);
992 else if (return_ansi
) /* note : pointer can be changed by app ! */
994 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
995 ret_length
, NULL
, NULL
);
998 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
999 ret_text
, ret_length
);
1001 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
1002 pdi
->item
.cchTextMax
= ret_length
;
1008 /* if dispinfo holder changed notification code then convert */
1009 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1011 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1013 buffer
= Alloc(length
* sizeof(CHAR
));
1014 if (!buffer
) return FALSE
;
1016 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1017 ret_length
, NULL
, NULL
);
1019 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1026 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1027 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1029 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1030 lpnmlvcd
->nmcd
.hdc
= hdc
;
1031 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1032 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1033 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1034 if (!lplvItem
) return;
1035 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1036 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1037 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1038 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1039 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1040 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1043 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1045 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1048 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1049 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1050 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1051 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1052 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1053 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1057 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1059 COLORREF backcolor
, textcolor
;
1061 /* apparently, for selected items, we have to override the returned values */
1064 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1066 if (infoPtr
->bFocus
)
1068 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1069 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1071 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1073 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1074 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1079 backcolor
= lpnmlvcd
->clrTextBk
;
1080 textcolor
= lpnmlvcd
->clrText
;
1082 if (backcolor
== CLR_DEFAULT
)
1083 backcolor
= comctl32_color
.clrWindow
;
1084 if (textcolor
== CLR_DEFAULT
)
1085 textcolor
= comctl32_color
.clrWindowText
;
1087 /* Set the text attributes */
1088 if (backcolor
!= CLR_NONE
)
1090 SetBkMode(hdc
, OPAQUE
);
1091 SetBkColor(hdc
, backcolor
);
1094 SetBkMode(hdc
, TRANSPARENT
);
1095 SetTextColor(hdc
, textcolor
);
1098 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1100 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1103 /* returns TRUE when repaint needed, FALSE otherwise */
1104 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1106 MEASUREITEMSTRUCT mis
;
1107 mis
.CtlType
= ODT_LISTVIEW
;
1108 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1112 mis
.itemHeight
= infoPtr
->nItemHeight
;
1113 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1114 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1116 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1122 /******** Item iterator functions **********************************/
1124 static RANGES
ranges_create(int count
);
1125 static void ranges_destroy(RANGES ranges
);
1126 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1127 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1128 static void ranges_dump(RANGES ranges
);
1130 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1132 RANGE range
= { nItem
, nItem
+ 1 };
1134 return ranges_add(ranges
, range
);
1137 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1139 RANGE range
= { nItem
, nItem
+ 1 };
1141 return ranges_del(ranges
, range
);
1145 * ITERATOR DOCUMENTATION
1147 * The iterator functions allow for easy, and convenient iteration
1148 * over items of interest in the list. Typically, you create an
1149 * iterator, use it, and destroy it, as such:
1152 * iterator_xxxitems(&i, ...);
1153 * while (iterator_{prev,next}(&i)
1155 * //code which uses i.nItem
1157 * iterator_destroy(&i);
1159 * where xxx is either: framed, or visible.
1160 * Note that it is important that the code destroys the iterator
1161 * after it's done with it, as the creation of the iterator may
1162 * allocate memory, which thus needs to be freed.
1164 * You can iterate both forwards, and backwards through the list,
1165 * by using iterator_next or iterator_prev respectively.
1167 * Lower numbered items are draw on top of higher number items in
1168 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1169 * items may overlap). So, to test items, you should use
1171 * which lists the items top to bottom (in Z-order).
1172 * For drawing items, you should use
1174 * which lists the items bottom to top (in Z-order).
1175 * If you keep iterating over the items after the end-of-items
1176 * marker (-1) is returned, the iterator will start from the
1177 * beginning. Typically, you don't need to test for -1,
1178 * because iterator_{next,prev} will return TRUE if more items
1179 * are to be iterated over, or FALSE otherwise.
1181 * Note: the iterator is defined to be bidirectional. That is,
1182 * any number of prev followed by any number of next, or
1183 * five versa, should leave the iterator at the same item:
1184 * prev * n, next * n = next * n, prev * n
1186 * The iterator has a notion of an out-of-order, special item,
1187 * which sits at the start of the list. This is used in
1188 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1189 * which needs to be first, as it may overlap other items.
1191 * The code is a bit messy because we have:
1192 * - a special item to deal with
1193 * - simple range, or composite range
1195 * If you find bugs, or want to add features, please make sure you
1196 * always check/modify *both* iterator_prev, and iterator_next.
1200 * This function iterates through the items in increasing order,
1201 * but prefixed by the special item, then -1. That is:
1202 * special, 1, 2, 3, ..., n, -1.
1203 * Each item is listed only once.
1205 static inline BOOL
iterator_next(ITERATOR
* i
)
1209 i
->nItem
= i
->nSpecial
;
1210 if (i
->nItem
!= -1) return TRUE
;
1212 if (i
->nItem
== i
->nSpecial
)
1214 if (i
->ranges
) i
->index
= 0;
1220 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1221 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1226 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1227 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1230 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1232 i
->nItem
= i
->range
.lower
;
1233 if (i
->nItem
>= 0) goto testitem
;
1240 * This function iterates through the items in decreasing order,
1241 * followed by the special item, then -1. That is:
1242 * n, n-1, ..., 3, 2, 1, special, -1.
1243 * Each item is listed only once.
1245 static inline BOOL
iterator_prev(ITERATOR
* i
)
1252 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1255 if (i
->nItem
== i
->nSpecial
)
1263 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1264 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1270 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1273 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1275 i
->nItem
= i
->range
.upper
;
1276 if (i
->nItem
> 0) goto testitem
;
1278 return (i
->nItem
= i
->nSpecial
) != -1;
1281 static RANGE
iterator_range(const ITERATOR
*i
)
1285 if (!i
->ranges
) return i
->range
;
1287 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1289 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1290 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1292 else range
.lower
= range
.upper
= 0;
1298 * Releases resources associated with this iterator.
1300 static inline void iterator_destroy(const ITERATOR
*i
)
1302 ranges_destroy(i
->ranges
);
1306 * Create an empty iterator.
1308 static inline void iterator_empty(ITERATOR
* i
)
1310 ZeroMemory(i
, sizeof(*i
));
1311 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1315 * Create an iterator over a range.
1317 static inline void iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1324 * Create an iterator over a bunch of ranges.
1325 * Please note that the iterator will take ownership of the ranges,
1326 * and will free them upon destruction.
1328 static inline void 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
;
1343 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1345 /* in case we fail, we want to return an empty iterator */
1348 if (infoPtr
->nItemCount
== 0)
1351 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1355 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1357 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1358 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1359 i
->nSpecial
= infoPtr
->nFocusedItem
;
1361 if (!(ranges
= ranges_create(50))) return FALSE
;
1362 iterator_rangesitems(i
, ranges
);
1363 /* to do better here, we need to have PosX, and PosY sorted */
1364 TRACE("building icon ranges:\n");
1365 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1367 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1368 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1369 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1370 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1371 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1372 ranges_additem(i
->ranges
, nItem
);
1376 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1380 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1381 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1383 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1384 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1385 if (range
.upper
<= range
.lower
) return TRUE
;
1386 iterator_rangeitems(i
, range
);
1387 TRACE(" report=%s\n", debugrange(&i
->range
));
1391 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1392 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1393 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1400 if (infoPtr
->nItemWidth
)
1402 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1403 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1407 nFirstCol
= max(frame
->left
, 0);
1408 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1411 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1413 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1414 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1416 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1418 if (!(ranges
= ranges_create(nLastCol
- nFirstCol
+ 1))) return FALSE
;
1419 iterator_rangesitems(i
, ranges
);
1420 TRACE("building list ranges:\n");
1421 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1423 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1424 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1425 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1426 TRACE(" list=%s\n", debugrange(&item_range
));
1427 ranges_add(i
->ranges
, item_range
);
1435 * Creates an iterator over the items which intersect lprc.
1437 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1442 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1444 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1445 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1447 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1451 * Creates an iterator over the items which intersect the visible region of hdc.
1453 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1455 POINT Origin
, Position
;
1456 RECT rcItem
, rcClip
;
1459 rgntype
= GetClipBox(hdc
, &rcClip
);
1460 if (rgntype
== NULLREGION
)
1465 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1466 if (rgntype
== SIMPLEREGION
) return TRUE
;
1468 /* first deal with the special item */
1469 if (i
->nSpecial
!= -1)
1471 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1472 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1475 /* if we can't deal with the region, we'll just go with the simple range */
1476 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1477 TRACE("building visible range:\n");
1478 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1480 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1481 if (!ranges_add(i
->ranges
, i
->range
))
1483 ranges_destroy(i
->ranges
);
1489 /* now delete the invisible items from the list */
1490 while(iterator_next(i
))
1492 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1493 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1494 rcItem
.top
= Position
.y
+ Origin
.y
;
1495 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1496 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1497 if (!RectVisible(hdc
, &rcItem
))
1498 ranges_delitem(i
->ranges
, i
->nItem
);
1500 /* the iterator should restart on the next iterator_next */
1506 /* Remove common elements from two iterators */
1507 /* Passed iterators have to point on the first elements */
1508 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1510 if(!iter1
->ranges
|| !iter2
->ranges
) {
1513 if(iter1
->ranges
|| iter2
->ranges
||
1514 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1515 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1516 ERR("result is not a one range iterator\n");
1520 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1523 lower
= iter1
->range
.lower
;
1524 upper
= iter1
->range
.upper
;
1526 if(lower
< iter2
->range
.lower
)
1527 iter1
->range
.upper
= iter2
->range
.lower
;
1528 else if(upper
> iter2
->range
.upper
)
1529 iter1
->range
.lower
= iter2
->range
.upper
;
1531 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1533 if(iter2
->range
.lower
< lower
)
1534 iter2
->range
.upper
= lower
;
1535 else if(iter2
->range
.upper
> upper
)
1536 iter2
->range
.lower
= upper
;
1538 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1543 iterator_next(iter1
);
1544 iterator_next(iter2
);
1547 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1550 if(iter1
->nItem
== iter2
->nItem
) {
1551 int delete = iter1
->nItem
;
1553 iterator_prev(iter1
);
1554 iterator_prev(iter2
);
1555 ranges_delitem(iter1
->ranges
, delete);
1556 ranges_delitem(iter2
->ranges
, delete);
1557 iterator_next(iter1
);
1558 iterator_next(iter2
);
1559 } else if(iter1
->nItem
> iter2
->nItem
)
1560 iterator_next(iter2
);
1562 iterator_next(iter1
);
1565 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1566 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1570 /******** Misc helper functions ************************************/
1572 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1573 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1575 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1576 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1579 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1581 return (infoPtr
->dwStyle
& LVS_AUTOARRANGE
) &&
1582 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1585 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1587 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1588 if(state
== 1 || state
== 2)
1592 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1593 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1594 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1598 /* this should be called after window style got updated,
1599 it used to reset view state to match current window style */
1600 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1602 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1605 infoPtr
->uView
= LV_VIEW_ICON
;
1608 infoPtr
->uView
= LV_VIEW_DETAILS
;
1611 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1614 infoPtr
->uView
= LV_VIEW_LIST
;
1618 /* computes next item id value */
1619 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1621 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1625 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1626 return lpID
->id
+ 1;
1631 /******** Internal API functions ************************************/
1633 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1635 static COLUMN_INFO mainItem
;
1637 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1638 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1640 /* update cached column rectangles */
1641 if (infoPtr
->colRectsDirty
)
1644 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1647 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1648 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1649 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1651 Ptr
->colRectsDirty
= FALSE
;
1654 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1657 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1659 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1662 if (infoPtr
->hwndHeader
) return 0;
1664 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1666 /* setup creation flags */
1667 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1668 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1670 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1673 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1674 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1675 if (!infoPtr
->hwndHeader
) return -1;
1677 /* set header unicode format */
1678 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1680 /* set header font */
1681 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1683 /* set header image list */
1684 if (infoPtr
->himlSmall
)
1685 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1687 LISTVIEW_UpdateSize(infoPtr
);
1692 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1694 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1697 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1699 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1700 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1701 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1704 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1706 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1709 /* used to handle collapse main item column case */
1710 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1712 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1713 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1716 /* Listview invalidation functions: use _only_ these functions to invalidate */
1718 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1720 return infoPtr
->redraw
;
1723 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1725 if(!is_redrawing(infoPtr
)) return;
1726 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1727 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1730 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1734 if (!is_redrawing(infoPtr
) || nItem
< 0 || nItem
>= infoPtr
->nItemCount
)
1737 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1738 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1741 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1743 POINT Origin
, Position
;
1746 if(!is_redrawing(infoPtr
)) return;
1747 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1748 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1749 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1750 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1752 rcBox
.bottom
= infoPtr
->nItemHeight
;
1753 OffsetRect(&rcBox
, Origin
.x
, Origin
.y
+ Position
.y
);
1754 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1757 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1759 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1762 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1766 if(!is_redrawing(infoPtr
)) return;
1767 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1768 rcCol
.top
= infoPtr
->rcList
.top
;
1769 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1770 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1775 * Retrieves the number of items that can fit vertically in the client area.
1778 * [I] infoPtr : valid pointer to the listview structure
1781 * Number of items per row.
1783 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1785 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1787 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1792 * Retrieves the number of items that can fit horizontally in the client
1796 * [I] infoPtr : valid pointer to the listview structure
1799 * Number of items per column.
1801 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1803 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1805 return infoPtr
->nItemHeight
? max(nListHeight
/ infoPtr
->nItemHeight
, 1) : 0;
1809 /*************************************************************************
1810 * LISTVIEW_ProcessLetterKeys
1812 * Processes keyboard messages generated by pressing the letter keys
1814 * What this does is perform a case insensitive search from the
1815 * current position with the following quirks:
1816 * - If two chars or more are pressed in quick succession we search
1817 * for the corresponding string (e.g. 'abc').
1818 * - If there is a delay we wipe away the current search string and
1819 * restart with just that char.
1820 * - If the user keeps pressing the same character, whether slowly or
1821 * fast, so that the search string is entirely composed of this
1822 * character ('aaaaa' for instance), then we search for first item
1823 * that starting with that character.
1824 * - If the user types the above character in quick succession, then
1825 * we must also search for the corresponding string ('aaaaa'), and
1826 * go to that string if there is a match.
1829 * [I] hwnd : handle to the window
1830 * [I] charCode : the character code, the actual character
1831 * [I] keyData : key data
1839 * - The current implementation has a list of characters it will
1840 * accept and it ignores everything else. In particular it will
1841 * ignore accentuated characters which seems to match what
1842 * Windows does. But I'm not sure it makes sense to follow
1844 * - We don't sound a beep when the search fails.
1848 * TREEVIEW_ProcessLetterKeys
1850 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1852 WCHAR buffer
[MAX_PATH
];
1859 /* simple parameter checking */
1860 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1862 /* only allow the valid WM_CHARs through */
1863 if (!iswalnum(charCode
) &&
1864 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1865 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1866 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1867 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1868 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1869 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1870 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1871 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1872 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1875 /* update the search parameters */
1876 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1877 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1878 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1880 if (diff
>= 0 && diff
< KEY_DELAY
)
1882 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1883 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1885 if (infoPtr
->charCode
!= charCode
)
1886 infoPtr
->charCode
= charCode
= 0;
1890 infoPtr
->charCode
= charCode
;
1891 infoPtr
->szSearchParam
[0] = charCode
;
1892 infoPtr
->nSearchParamLength
= 1;
1895 /* should start from next after focused item, so next item that matches
1896 will be selected, if there isn't any and focused matches it will be selected
1897 on second search stage from beginning of the list */
1898 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1900 /* with some accumulated search data available start with current focus, otherwise
1901 it's excluded from search */
1902 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1903 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1908 /* let application handle this for virtual listview */
1909 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1913 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1914 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1915 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1916 nmlv
.iStart
= startidx
;
1918 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1920 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1924 int i
= startidx
, endidx
;
1926 /* and search from the current position */
1928 endidx
= infoPtr
->nItemCount
;
1930 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1933 /* start from first item if not found with >= startidx */
1934 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1940 for (i
= startidx
; i
< endidx
; i
++)
1943 item
.mask
= LVIF_TEXT
;
1946 item
.pszText
= buffer
;
1947 item
.cchTextMax
= MAX_PATH
;
1948 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1950 if (!wcsnicmp(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1955 /* this is used to find first char match when search string is not available yet,
1956 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1957 already waiting for user to complete a string */
1958 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !wcsnicmp(item
.pszText
, infoPtr
->szSearchParam
, 1))
1960 /* this would work but we must keep looking for a longer match */
1965 if ( nItem
!= -1 || /* found something */
1966 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1967 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1973 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1978 /*************************************************************************
1979 * LISTVIEW_UpdateHeaderSize [Internal]
1981 * Function to resize the header control
1984 * [I] hwnd : handle to a window
1985 * [I] nNewScrollPos : scroll pos to set
1990 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1995 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1997 if (!infoPtr
->hwndHeader
) return;
1999 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
2000 point
[0].x
= winRect
.left
;
2001 point
[0].y
= winRect
.top
;
2002 point
[1].x
= winRect
.right
;
2003 point
[1].y
= winRect
.bottom
;
2005 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
2006 point
[0].x
= -nNewScrollPos
;
2007 point
[1].x
+= nNewScrollPos
;
2009 SetWindowPos(infoPtr
->hwndHeader
,0,
2010 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
2011 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
2012 SWP_NOZORDER
| SWP_NOACTIVATE
);
2015 static INT
LISTVIEW_UpdateHScroll(LISTVIEW_INFO
*infoPtr
)
2017 SCROLLINFO horzInfo
;
2020 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2021 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2022 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2024 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2025 if (infoPtr
->uView
== LV_VIEW_LIST
)
2027 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2028 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2030 /* scroll by at least one column per page */
2031 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2032 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2034 if (infoPtr
->nItemWidth
)
2035 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2037 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2039 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2041 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2045 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2048 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2050 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2055 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2056 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2058 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2059 horzInfo
.nMax
= rcHeader
.right
;
2060 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2064 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2065 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2066 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2067 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2068 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2070 /* Update the Header Control */
2071 if (infoPtr
->hwndHeader
)
2073 horzInfo
.fMask
= SIF_POS
;
2074 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2075 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2078 LISTVIEW_UpdateSize(infoPtr
);
2082 static INT
LISTVIEW_UpdateVScroll(LISTVIEW_INFO
*infoPtr
)
2084 SCROLLINFO vertInfo
;
2087 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2088 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2089 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2091 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2093 vertInfo
.nMax
= infoPtr
->nItemCount
;
2095 /* scroll by at least one page */
2096 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2097 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2099 if (infoPtr
->nItemHeight
> 0)
2100 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2102 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2106 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2109 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2110 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2111 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2112 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2113 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2115 LISTVIEW_UpdateSize(infoPtr
);
2121 * Update the scrollbars. This function should be called whenever
2122 * the content, size or view changes.
2125 * [I] infoPtr : valid pointer to the listview structure
2130 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*infoPtr
)
2134 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2136 /* Setting the horizontal scroll can change the listview size
2137 * (and potentially everything else) so we need to recompute
2138 * everything again for the vertical scroll and vice-versa
2140 for (dx
= 0, dy
= 0, pass
= 0; pass
<= 1; pass
++)
2142 dx
+= LISTVIEW_UpdateHScroll(infoPtr
);
2143 dy
+= LISTVIEW_UpdateVScroll(infoPtr
);
2146 /* Change of the range may have changed the scroll pos. If so move the content */
2147 if (dx
!= 0 || dy
!= 0)
2150 listRect
= infoPtr
->rcList
;
2151 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2152 SW_ERASE
| SW_INVALIDATE
);
2159 * Shows/hides the focus rectangle.
2162 * [I] infoPtr : valid pointer to the listview structure
2163 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2168 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2172 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2174 if (infoPtr
->nFocusedItem
< 0) return;
2176 /* we need some gymnastics in ICON mode to handle large items */
2177 if (infoPtr
->uView
== LV_VIEW_ICON
)
2181 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2182 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2184 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2189 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2191 /* for some reason, owner draw should work only in report mode */
2192 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2197 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2198 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2200 item
.iItem
= infoPtr
->nFocusedItem
;
2202 item
.mask
= LVIF_PARAM
;
2203 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2205 ZeroMemory(&dis
, sizeof(dis
));
2206 dis
.CtlType
= ODT_LISTVIEW
;
2207 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2208 dis
.itemID
= item
.iItem
;
2209 dis
.itemAction
= ODA_FOCUS
;
2210 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2211 dis
.hwndItem
= infoPtr
->hwndSelf
;
2213 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2214 dis
.itemData
= item
.lParam
;
2216 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2218 SelectObject(hdc
, hOldFont
);
2221 LISTVIEW_InvalidateItem(infoPtr
, infoPtr
->nFocusedItem
);
2224 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2228 * Invalidates all visible selected items.
2230 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2234 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2235 while(iterator_next(&i
))
2237 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2238 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2240 iterator_destroy(&i
);
2245 * DESCRIPTION: [INTERNAL]
2246 * Computes an item's (left,top) corner, relative to rcView.
2247 * That is, the position has NOT been made relative to the Origin.
2248 * This is deliberate, to avoid computing the Origin over, and
2249 * over again, when this function is called in a loop. Instead,
2250 * one can factor the computation of the Origin before the loop,
2251 * and offset the value returned by this function, on every iteration.
2254 * [I] infoPtr : valid pointer to the listview structure
2255 * [I] nItem : item number
2256 * [O] lpptOrig : item top, left corner
2261 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2263 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2265 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2267 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2268 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2270 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2272 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2273 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2274 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2276 else /* LV_VIEW_DETAILS */
2278 lpptPosition
->x
= REPORT_MARGINX
;
2279 /* item is always at zero indexed column */
2280 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2281 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2282 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2287 * DESCRIPTION: [INTERNAL]
2288 * Compute the rectangles of an item. This is to localize all
2289 * the computations in one place. If you are not interested in some
2290 * of these values, simply pass in a NULL -- the function is smart
2291 * enough to compute only what's necessary. The function computes
2292 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2293 * one, the BOX rectangle. This rectangle is very cheap to compute,
2294 * and is guaranteed to contain all the other rectangles. Computing
2295 * the ICON rect is also cheap, but all the others are potentially
2296 * expensive. This gives an easy and effective optimization when
2297 * searching (like point inclusion, or rectangle intersection):
2298 * first test against the BOX, and if TRUE, test against the desired
2300 * If the function does not have all the necessary information
2301 * to computed the requested rectangles, will crash with a
2302 * failed assertion. This is done so we catch all programming
2303 * errors, given that the function is called only from our code.
2305 * We have the following 'special' meanings for a few fields:
2306 * * If LVIS_FOCUSED is set, we assume the item has the focus
2307 * This is important in ICON mode, where it might get a larger
2308 * then usual rectangle
2310 * Please note that subitem support works only in REPORT mode.
2313 * [I] infoPtr : valid pointer to the listview structure
2314 * [I] lpLVItem : item to compute the measures for
2315 * [O] lprcBox : ptr to Box rectangle
2316 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2317 * [0] lprcSelectBox : ptr to select box rectangle
2318 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2319 * [O] lprcIcon : ptr to Icon rectangle
2320 * Same as LVM_GETITEMRECT with LVIR_ICON
2321 * [O] lprcStateIcon: ptr to State Icon rectangle
2322 * [O] lprcLabel : ptr to Label rectangle
2323 * Same as LVM_GETITEMRECT with LVIR_LABEL
2328 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2329 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2330 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2332 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2333 RECT Box
, SelectBox
, Icon
, Label
;
2334 COLUMN_INFO
*lpColumnInfo
= NULL
;
2335 SIZE labelSize
= { 0, 0 };
2337 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2339 /* Be smart and try to figure out the minimum we have to do */
2340 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2341 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2343 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2344 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2346 if (lprcSelectBox
) doSelectBox
= TRUE
;
2347 if (lprcLabel
) doLabel
= TRUE
;
2348 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2355 /************************************************************/
2356 /* compute the box rectangle (it should be cheap to do) */
2357 /************************************************************/
2358 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2359 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2361 if (lpLVItem
->iSubItem
)
2363 Box
= lpColumnInfo
->rcHeader
;
2368 Box
.right
= infoPtr
->nItemWidth
;
2371 Box
.bottom
= infoPtr
->nItemHeight
;
2373 /******************************************************************/
2374 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2375 /******************************************************************/
2378 LONG state_width
= 0;
2380 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2381 state_width
= infoPtr
->iconStateSize
.cx
;
2383 if (infoPtr
->uView
== LV_VIEW_ICON
)
2385 Icon
.left
= Box
.left
+ state_width
;
2386 if (infoPtr
->himlNormal
)
2387 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2388 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2389 Icon
.right
= Icon
.left
;
2390 Icon
.bottom
= Icon
.top
;
2391 if (infoPtr
->himlNormal
)
2393 Icon
.right
+= infoPtr
->iconSize
.cx
;
2394 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2397 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2399 Icon
.left
= Box
.left
+ state_width
;
2401 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2403 /* we need the indent in report mode */
2404 assert(lpLVItem
->mask
& LVIF_INDENT
);
2405 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2409 Icon
.right
= Icon
.left
;
2410 if (infoPtr
->himlSmall
&&
2411 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2412 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2413 Icon
.right
+= infoPtr
->iconSize
.cx
;
2414 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2416 if(lprcIcon
) *lprcIcon
= Icon
;
2417 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2419 /* TODO: is this correct? */
2422 lprcStateIcon
->left
= Icon
.left
- state_width
;
2423 lprcStateIcon
->right
= Icon
.left
;
2424 lprcStateIcon
->top
= Icon
.top
;
2425 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2426 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2429 else Icon
.right
= 0;
2431 /************************************************************/
2432 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2433 /************************************************************/
2436 /* calculate how far to the right can the label stretch */
2437 Label
.right
= Box
.right
;
2438 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2440 if (lpLVItem
->iSubItem
== 0)
2442 /* we need a zero based rect here */
2443 Label
= lpColumnInfo
->rcHeader
;
2444 OffsetRect(&Label
, -Label
.left
, 0);
2448 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2450 labelSize
.cx
= infoPtr
->nItemWidth
;
2451 labelSize
.cy
= infoPtr
->nItemHeight
;
2455 /* we need the text in non owner draw mode */
2456 assert(lpLVItem
->mask
& LVIF_TEXT
);
2457 if (is_text(lpLVItem
->pszText
))
2459 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2460 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2461 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2465 /* compute rough rectangle where the label will go */
2466 SetRectEmpty(&rcText
);
2467 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2468 rcText
.bottom
= infoPtr
->nItemHeight
;
2469 if (infoPtr
->uView
== LV_VIEW_ICON
)
2470 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2472 /* now figure out the flags */
2473 if (infoPtr
->uView
== LV_VIEW_ICON
)
2474 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2476 uFormat
= LV_SL_DT_FLAGS
;
2478 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2480 if (rcText
.right
!= rcText
.left
)
2481 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2483 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2485 SelectObject(hdc
, hOldFont
);
2486 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2490 if (infoPtr
->uView
== LV_VIEW_ICON
)
2492 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2493 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2494 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2495 Label
.right
= Label
.left
+ labelSize
.cx
;
2496 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2497 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2499 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2500 labelSize
.cy
/= infoPtr
->ntmHeight
;
2501 labelSize
.cy
= max(labelSize
.cy
, 1);
2502 labelSize
.cy
*= infoPtr
->ntmHeight
;
2504 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2506 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2508 Label
.left
= Icon
.right
;
2509 Label
.top
= Box
.top
;
2510 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2511 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2512 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2514 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2516 Label
.left
= Icon
.right
;
2517 Label
.top
= Box
.top
;
2518 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2519 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2522 if (lprcLabel
) *lprcLabel
= Label
;
2523 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2526 /************************************************************/
2527 /* compute SELECT bounding box */
2528 /************************************************************/
2531 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2533 SelectBox
.left
= Icon
.left
;
2534 SelectBox
.top
= Box
.top
;
2535 SelectBox
.bottom
= Box
.bottom
;
2538 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2540 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2544 UnionRect(&SelectBox
, &Icon
, &Label
);
2546 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2547 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2550 /* Fix the Box if necessary */
2553 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2554 else *lprcBox
= Box
;
2556 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2560 * DESCRIPTION: [INTERNAL]
2563 * [I] infoPtr : valid pointer to the listview structure
2564 * [I] nItem : item number
2565 * [O] lprcBox : ptr to Box rectangle
2570 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2572 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2573 POINT Position
, Origin
;
2576 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2577 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2579 /* Be smart and try to figure out the minimum we have to do */
2581 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2582 lvItem
.mask
|= LVIF_TEXT
;
2583 lvItem
.iItem
= nItem
;
2584 lvItem
.iSubItem
= 0;
2585 lvItem
.pszText
= szDispText
;
2586 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2587 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2588 if (infoPtr
->uView
== LV_VIEW_ICON
)
2590 lvItem
.mask
|= LVIF_STATE
;
2591 lvItem
.stateMask
= LVIS_FOCUSED
;
2592 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2594 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2596 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2597 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2599 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2602 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2605 /* LISTVIEW_MapIdToIndex helper */
2606 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2608 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2609 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2611 if (id1
->id
== id2
->id
) return 0;
2613 return (id1
->id
< id2
->id
) ? -1 : 1;
2618 * Returns the item index for id specified.
2621 * [I] infoPtr : valid pointer to the listview structure
2622 * [I] iID : item id to get index for
2625 * Item index, or -1 on failure.
2627 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2632 TRACE("iID=%d\n", iID
);
2634 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2635 if (infoPtr
->nItemCount
== 0) return -1;
2638 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2642 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2643 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2651 * Returns the item id for index given.
2654 * [I] infoPtr : valid pointer to the listview structure
2655 * [I] iItem : item index to get id for
2660 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2665 TRACE("iItem=%d\n", iItem
);
2667 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2668 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2670 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2671 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2673 return lpItem
->id
->id
;
2678 * Returns the current icon position, and advances it along the top.
2679 * The returned position is not offset by Origin.
2682 * [I] infoPtr : valid pointer to the listview structure
2683 * [O] lpPos : will get the current icon position
2688 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2690 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2692 *lpPos
= infoPtr
->currIconPos
;
2694 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2695 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2697 infoPtr
->currIconPos
.x
= 0;
2698 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2704 * Returns the current icon position, and advances it down the left edge.
2705 * The returned position is not offset by Origin.
2708 * [I] infoPtr : valid pointer to the listview structure
2709 * [O] lpPos : will get the current icon position
2714 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2716 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2718 *lpPos
= infoPtr
->currIconPos
;
2720 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2721 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2723 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2724 infoPtr
->currIconPos
.y
= 0;
2730 * Moves an icon to the specified position.
2731 * It takes care of invalidating the item, etc.
2734 * [I] infoPtr : valid pointer to the listview structure
2735 * [I] nItem : the item to move
2736 * [I] lpPos : the new icon position
2737 * [I] isNew : flags the item as being new
2743 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2749 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2750 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2752 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2753 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2756 /* Allocating a POINTER for every item is too resource intensive,
2757 * so we'll keep the (x,y) in different arrays */
2758 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2759 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2761 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2768 * Arranges listview items in icon display mode.
2771 * [I] infoPtr : valid pointer to the listview structure
2772 * [I] nAlignCode : alignment code
2778 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2780 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2784 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2786 TRACE("nAlignCode=%d\n", nAlignCode
);
2788 if (nAlignCode
== LVA_DEFAULT
)
2790 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2791 else nAlignCode
= LVA_ALIGNTOP
;
2796 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2797 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2798 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2799 default: return FALSE
;
2802 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2803 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2805 next_pos(infoPtr
, &pos
);
2806 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2814 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2815 * For LVS_REPORT always returns empty rectangle.
2818 * [I] infoPtr : valid pointer to the listview structure
2819 * [O] lprcView : bounding rectangle
2825 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2829 SetRectEmpty(lprcView
);
2831 switch (infoPtr
->uView
)
2834 case LV_VIEW_SMALLICON
:
2835 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2837 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2838 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2839 lprcView
->right
= max(lprcView
->right
, x
);
2840 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2842 if (infoPtr
->nItemCount
> 0)
2844 lprcView
->right
+= infoPtr
->nItemWidth
;
2845 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2850 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2851 x
= infoPtr
->nItemCount
/ y
;
2852 if (infoPtr
->nItemCount
% y
) x
++;
2853 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2854 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2861 * Retrieves the bounding rectangle of all the items.
2864 * [I] infoPtr : valid pointer to the listview structure
2865 * [O] lprcView : bounding rectangle
2871 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2875 TRACE("(lprcView=%p)\n", lprcView
);
2877 if (!lprcView
) return FALSE
;
2879 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2881 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2883 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2884 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2887 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2894 * Retrieves the subitem pointer associated with the subitem index.
2897 * [I] hdpaSubItems : DPA handle for a specific item
2898 * [I] nSubItem : index of subitem
2901 * SUCCESS : subitem pointer
2904 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2906 SUBITEM_INFO
*lpSubItem
;
2909 /* we should binary search here if need be */
2910 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2912 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2913 if (lpSubItem
->iSubItem
== nSubItem
)
2923 * Calculates the desired item width.
2926 * [I] infoPtr : valid pointer to the listview structure
2929 * The desired item width.
2931 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2935 TRACE("uView=%d\n", infoPtr
->uView
);
2937 if (infoPtr
->uView
== LV_VIEW_ICON
)
2938 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2939 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2941 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2946 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2947 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2949 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2950 nItemWidth
= rcHeader
.right
;
2953 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2955 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2959 lvItem
.mask
= LVIF_TEXT
;
2960 lvItem
.iSubItem
= 0;
2962 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2965 lvItem
.pszText
= szDispText
;
2966 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2967 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2968 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2972 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2973 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2975 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2983 * Calculates the desired item height.
2986 * [I] infoPtr : valid pointer to the listview structure
2989 * The desired item height.
2991 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2995 TRACE("uView=%d\n", infoPtr
->uView
);
2997 if (infoPtr
->uView
== LV_VIEW_ICON
)
2998 nItemHeight
= infoPtr
->iconSpacing
.cy
;
3001 nItemHeight
= infoPtr
->ntmHeight
;
3002 if (infoPtr
->himlState
)
3003 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
3004 if (infoPtr
->himlSmall
)
3005 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
3006 nItemHeight
+= HEIGHT_PADDING
;
3007 if (infoPtr
->nMeasureItemHeight
> 0)
3008 nItemHeight
= infoPtr
->nMeasureItemHeight
;
3011 return max(nItemHeight
, 1);
3016 * Updates the width, and height of an item.
3019 * [I] infoPtr : valid pointer to the listview structure
3024 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
3026 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
3027 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3033 * Retrieves and saves important text metrics info for the current
3037 * [I] infoPtr : valid pointer to the listview structure
3040 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3042 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3043 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3044 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3048 if (GetTextMetricsW(hdc
, &tm
))
3050 infoPtr
->ntmHeight
= tm
.tmHeight
;
3051 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3054 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3055 infoPtr
->nEllipsisWidth
= sz
.cx
;
3057 SelectObject(hdc
, hOldFont
);
3058 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3060 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3065 * A compare function for ranges
3068 * [I] range1 : pointer to range 1;
3069 * [I] range2 : pointer to range 2;
3073 * > 0 : if range 1 > range 2
3074 * < 0 : if range 2 > range 1
3075 * = 0 : if range intersects range 2
3077 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3081 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3083 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3088 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3093 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3095 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3100 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3102 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3103 ranges_dump(ranges
);
3104 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3106 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3107 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3108 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3110 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3111 assert (prev
->upper
<= curr
->lower
);
3112 assert (curr
->lower
< curr
->upper
);
3116 TRACE("--- Done checking---\n");
3119 static RANGES
ranges_create(int count
)
3121 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3122 if (!ranges
) return NULL
;
3123 ranges
->hdpa
= DPA_Create(count
);
3124 if (ranges
->hdpa
) return ranges
;
3129 static void ranges_clear(RANGES ranges
)
3133 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3134 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3135 DPA_DeleteAllPtrs(ranges
->hdpa
);
3139 static void ranges_destroy(RANGES ranges
)
3141 if (!ranges
) return;
3142 ranges_clear(ranges
);
3143 DPA_Destroy(ranges
->hdpa
);
3147 static RANGES
ranges_clone(RANGES ranges
)
3152 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3154 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3156 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3157 if (!newrng
) goto fail
;
3158 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3159 if (!DPA_SetPtr(clone
->hdpa
, i
, newrng
))
3168 TRACE ("clone failed\n");
3169 ranges_destroy(clone
);
3173 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3177 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3178 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3183 static void ranges_dump(RANGES ranges
)
3187 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3188 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3191 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3193 RANGE srchrng
= { nItem
, nItem
+ 1 };
3195 TRACE("(nItem=%d)\n", nItem
);
3196 ranges_check(ranges
, "before contain");
3197 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3200 static INT
ranges_itemcount(RANGES ranges
)
3204 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3206 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3207 count
+= sel
->upper
- sel
->lower
;
3213 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3215 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3218 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3219 if (index
== -1) return TRUE
;
3221 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3223 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3224 if (chkrng
->lower
>= nItem
)
3225 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3226 if (chkrng
->upper
> nItem
)
3227 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3232 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3237 TRACE("(%s)\n", debugrange(&range
));
3238 ranges_check(ranges
, "before add");
3240 /* try find overlapping regions first */
3241 srchrgn
.lower
= range
.lower
- 1;
3242 srchrgn
.upper
= range
.upper
+ 1;
3243 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3249 TRACE("Adding new range\n");
3251 /* create the brand new range to insert */
3252 newrgn
= Alloc(sizeof(RANGE
));
3253 if(!newrgn
) goto fail
;
3256 /* figure out where to insert it */
3257 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3258 TRACE("index=%d\n", index
);
3259 if (index
== -1) index
= 0;
3261 /* and get it over with */
3262 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3270 RANGE
*chkrgn
, *mrgrgn
;
3271 INT fromindex
, mergeindex
;
3273 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3274 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3276 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3277 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3279 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3281 /* merge now common ranges */
3283 srchrgn
.lower
= chkrgn
->lower
- 1;
3284 srchrgn
.upper
= chkrgn
->upper
+ 1;
3288 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3289 if (mergeindex
== -1) break;
3290 if (mergeindex
== index
)
3292 fromindex
= index
+ 1;
3296 TRACE("Merge with index %i\n", mergeindex
);
3298 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3299 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3300 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3302 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3303 if (mergeindex
< index
) index
--;
3307 ranges_check(ranges
, "after add");
3311 ranges_check(ranges
, "failed add");
3315 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3320 TRACE("(%s)\n", debugrange(&range
));
3321 ranges_check(ranges
, "before del");
3323 /* we don't use DPAS_SORTED here, since we need *
3324 * to find the first overlapping range */
3325 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3328 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3330 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3332 /* case 1: Same range */
3333 if ( (chkrgn
->upper
== range
.upper
) &&
3334 (chkrgn
->lower
== range
.lower
) )
3336 DPA_DeletePtr(ranges
->hdpa
, index
);
3340 /* case 2: engulf */
3341 else if ( (chkrgn
->upper
<= range
.upper
) &&
3342 (chkrgn
->lower
>= range
.lower
) )
3344 DPA_DeletePtr(ranges
->hdpa
, index
);
3347 /* case 3: overlap upper */
3348 else if ( (chkrgn
->upper
<= range
.upper
) &&
3349 (chkrgn
->lower
< range
.lower
) )
3351 chkrgn
->upper
= range
.lower
;
3353 /* case 4: overlap lower */
3354 else if ( (chkrgn
->upper
> range
.upper
) &&
3355 (chkrgn
->lower
>= range
.lower
) )
3357 chkrgn
->lower
= range
.upper
;
3360 /* case 5: fully internal */
3365 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3366 newrgn
->lower
= chkrgn
->lower
;
3367 newrgn
->upper
= range
.lower
;
3368 chkrgn
->lower
= range
.upper
;
3369 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3377 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3380 ranges_check(ranges
, "after del");
3384 ranges_check(ranges
, "failed del");
3390 * Removes all selection ranges
3393 * [I] infoPtr : valid pointer to the listview structure
3394 * [I] toSkip : item range to skip removing the selection
3400 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3409 lvItem
.stateMask
= LVIS_SELECTED
;
3411 /* need to clone the DPA because callbacks can change it */
3412 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3413 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3414 while(iterator_next(&i
))
3415 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3416 /* note that the iterator destructor will free the cloned range */
3417 iterator_destroy(&i
);
3422 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3426 if (!(toSkip
= ranges_create(1))) return FALSE
;
3427 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3428 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3429 ranges_destroy(toSkip
);
3433 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3435 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3440 * Retrieves the number of items that are marked as selected.
3443 * [I] infoPtr : valid pointer to the listview structure
3446 * Number of items selected.
3448 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3450 INT nSelectedCount
= 0;
3452 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3455 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3457 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3462 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3464 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3465 return nSelectedCount
;
3470 * Manages the item focus.
3473 * [I] infoPtr : valid pointer to the listview structure
3474 * [I] nItem : item index
3477 * TRUE : focused item changed
3478 * FALSE : focused item has NOT changed
3480 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3482 INT oldFocus
= infoPtr
->nFocusedItem
;
3485 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3487 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3488 lvItem
.stateMask
= LVIS_FOCUSED
;
3489 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3491 return oldFocus
!= infoPtr
->nFocusedItem
;
3494 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3496 if (nShiftItem
< nItem
) return nShiftItem
;
3498 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3500 if (direction
> 0) return nShiftItem
+ direction
;
3502 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3505 /* This function updates focus index.
3508 focus : current focus index
3509 item : index of item to be added/removed
3510 direction : add/remove flag
3512 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3514 DWORD old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3516 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3517 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3518 if (focus
!= infoPtr
->nFocusedItem
)
3519 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3520 infoPtr
->notify_mask
|= old_mask
;
3525 * Updates the various indices after an item has been inserted or deleted.
3528 * [I] infoPtr : valid pointer to the listview structure
3529 * [I] nItem : item index
3530 * [I] direction : Direction of shift, +1 or -1.
3535 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3537 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3539 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3540 assert(abs(direction
) == 1);
3541 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3543 /* But we are not supposed to modify nHotItem! */
3548 * Adds a block of selections.
3551 * [I] infoPtr : valid pointer to the listview structure
3552 * [I] nItem : item index
3555 * Whether the window is still valid.
3557 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3559 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3560 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3561 HWND hwndSelf
= infoPtr
->hwndSelf
;
3562 NMLVODSTATECHANGE nmlv
;
3567 /* Temporarily disable change notification
3568 * If the control is LVS_OWNERDATA, we need to send
3569 * only one LVN_ODSTATECHANGED notification.
3570 * See MSDN documentation for LVN_ITEMCHANGED.
3572 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3573 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3574 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3576 if (nFirst
== -1) nFirst
= nItem
;
3578 item
.state
= LVIS_SELECTED
;
3579 item
.stateMask
= LVIS_SELECTED
;
3581 for (i
= nFirst
; i
<= nLast
; i
++)
3582 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3584 ZeroMemory(&nmlv
, sizeof(nmlv
));
3585 nmlv
.iFrom
= nFirst
;
3588 nmlv
.uNewState
= item
.state
;
3590 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3591 if (!IsWindow(hwndSelf
))
3593 infoPtr
->notify_mask
|= old_mask
;
3600 * Sets a single group selection.
3603 * [I] infoPtr : valid pointer to the listview structure
3604 * [I] nItem : item index
3609 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3616 if (!(selection
= ranges_create(100))) return;
3618 item
.state
= LVIS_SELECTED
;
3619 item
.stateMask
= LVIS_SELECTED
;
3621 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3623 if (infoPtr
->nSelectionMark
== -1)
3625 infoPtr
->nSelectionMark
= nItem
;
3626 ranges_additem(selection
, nItem
);
3632 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3633 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3634 ranges_add(selection
, sel
);
3639 RECT rcItem
, rcSel
, rcSelMark
;
3642 rcItem
.left
= LVIR_BOUNDS
;
3643 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3644 ranges_destroy (selection
);
3647 rcSelMark
.left
= LVIR_BOUNDS
;
3648 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3649 ranges_destroy (selection
);
3652 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3653 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3654 while(iterator_next(&i
))
3656 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3657 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3659 iterator_destroy(&i
);
3662 /* disable per item notifications on LVS_OWNERDATA style
3663 FIXME: single LVN_ODSTATECHANGED should be used */
3664 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3665 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3666 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3668 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3671 iterator_rangesitems(&i
, selection
);
3672 while(iterator_next(&i
))
3673 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3674 /* this will also destroy the selection */
3675 iterator_destroy(&i
);
3677 infoPtr
->notify_mask
|= old_mask
;
3678 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3683 * Sets a single selection.
3686 * [I] infoPtr : valid pointer to the listview structure
3687 * [I] nItem : item index
3692 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3696 TRACE("nItem=%d\n", nItem
);
3698 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3700 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3701 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3702 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3704 infoPtr
->nSelectionMark
= nItem
;
3709 * Set selection(s) with keyboard.
3712 * [I] infoPtr : valid pointer to the listview structure
3713 * [I] nItem : item index
3714 * [I] space : VK_SPACE code sent
3717 * SUCCESS : TRUE (needs to be repainted)
3718 * FAILURE : FALSE (nothing has changed)
3720 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3722 /* FIXME: pass in the state */
3723 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3724 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3725 BOOL bResult
= FALSE
;
3727 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3728 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3732 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3733 LISTVIEW_SetSelection(infoPtr
, nItem
);
3737 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3741 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3742 lvItem
.stateMask
= LVIS_SELECTED
;
3745 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3746 if (lvItem
.state
& LVIS_SELECTED
)
3747 infoPtr
->nSelectionMark
= nItem
;
3749 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3752 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3755 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3759 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3761 LVHITTESTINFO lvHitTestInfo
;
3763 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3764 lvHitTestInfo
.pt
.x
= pt
.x
;
3765 lvHitTestInfo
.pt
.y
= pt
.y
;
3767 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3769 lpLVItem
->mask
= LVIF_PARAM
;
3770 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3771 lpLVItem
->iSubItem
= 0;
3773 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3776 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3778 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3779 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3780 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3785 * Called when the mouse is being actively tracked and has hovered for a specified
3789 * [I] infoPtr : valid pointer to the listview structure
3790 * [I] fwKeys : key indicator
3791 * [I] x,y : mouse position
3794 * 0 if the message was processed, non-zero if there was an error
3797 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3798 * over the item for a certain period of time.
3801 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3805 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3807 if (LISTVIEW_IsHotTracking(infoPtr
))
3815 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3816 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3818 SetFocus(infoPtr
->hwndSelf
);
3824 #define SCROLL_LEFT 0x1
3825 #define SCROLL_RIGHT 0x2
3826 #define SCROLL_UP 0x4
3827 #define SCROLL_DOWN 0x8
3831 * Utility routine to draw and highlight items within a marquee selection rectangle.
3834 * [I] infoPtr : valid pointer to the listview structure
3835 * [I] coords_orig : original co-ordinates of the cursor
3836 * [I] coords_offs : offsetted coordinates of the cursor
3837 * [I] offset : offset amount
3838 * [I] scroll : Bitmask of which directions we should scroll, if at all
3843 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3846 BOOL controlDown
= FALSE
;
3848 ITERATOR old_elems
, new_elems
;
3850 POINT coords_offs
, offset
;
3852 /* Ensure coordinates are within client bounds */
3853 coords_offs
.x
= max(min(coords_orig
->x
, infoPtr
->rcList
.right
), 0);
3854 coords_offs
.y
= max(min(coords_orig
->y
, infoPtr
->rcList
.bottom
), 0);
3857 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3859 /* Offset coordinates by the appropriate amount */
3860 coords_offs
.x
-= offset
.x
;
3861 coords_offs
.y
-= offset
.y
;
3863 if (coords_offs
.x
> infoPtr
->marqueeOrigin
.x
)
3865 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3866 rect
.right
= coords_offs
.x
;
3870 rect
.left
= coords_offs
.x
;
3871 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3874 if (coords_offs
.y
> infoPtr
->marqueeOrigin
.y
)
3876 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3877 rect
.bottom
= coords_offs
.y
;
3881 rect
.top
= coords_offs
.y
;
3882 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3885 /* Cancel out the old marquee rectangle and draw the new one */
3886 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3888 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3889 the cursor is further away */
3891 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3892 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3894 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3895 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3897 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3898 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3900 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3901 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3903 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3905 infoPtr
->marqueeRect
= rect
;
3906 infoPtr
->marqueeDrawRect
= rect
;
3907 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
.x
, offset
.y
);
3909 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3910 iterator_remove_common_items(&old_elems
, &new_elems
);
3912 /* Iterate over no longer selected items */
3913 while (iterator_next(&old_elems
))
3915 if (old_elems
.nItem
> -1)
3917 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3920 item
.state
= LVIS_SELECTED
;
3922 item
.stateMask
= LVIS_SELECTED
;
3924 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3927 iterator_destroy(&old_elems
);
3930 /* Iterate over newly selected items */
3931 if (GetKeyState(VK_CONTROL
) & 0x8000)
3934 while (iterator_next(&new_elems
))
3936 if (new_elems
.nItem
> -1)
3938 /* If CTRL is pressed, invert. If not, always select the item. */
3939 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3942 item
.state
= LVIS_SELECTED
;
3944 item
.stateMask
= LVIS_SELECTED
;
3946 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3949 iterator_destroy(&new_elems
);
3951 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3956 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3957 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3960 * [I] hwnd : Handle to the listview
3961 * [I] uMsg : WM_TIMER (ignored)
3962 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3963 * [I] dwTimer : The elapsed time (ignored)
3968 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3970 LISTVIEW_INFO
*infoPtr
;
3971 SCROLLINFO scrollInfo
;
3975 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3980 /* Get the current cursor position and convert to client coordinates */
3981 GetCursorPos(&coords
);
3982 ScreenToClient(hWnd
, &coords
);
3984 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3985 scrollInfo
.fMask
= SIF_ALL
;
3987 /* Work out in which directions we can scroll */
3988 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3990 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3991 scroll
|= SCROLL_UP
;
3993 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3994 scroll
|= SCROLL_DOWN
;
3997 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3999 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
4000 scroll
|= SCROLL_LEFT
;
4002 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
4003 scroll
|= SCROLL_RIGHT
;
4006 if (((coords
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
4007 ((coords
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
4008 ((coords
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
4009 ((coords
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
4011 LISTVIEW_MarqueeHighlight(infoPtr
, &coords
, scroll
);
4017 * Called whenever WM_MOUSEMOVE is received.
4020 * [I] infoPtr : valid pointer to the listview structure
4021 * [I] fwKeys : key indicator
4022 * [I] x,y : mouse position
4025 * 0 if the message is processed, non-zero if there was an error
4027 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4036 if (!(fwKeys
& MK_LBUTTON
))
4037 infoPtr
->bLButtonDown
= FALSE
;
4039 if (infoPtr
->bLButtonDown
)
4041 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4042 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4044 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4046 if (infoPtr
->bMarqueeSelect
)
4048 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4049 move the mouse again */
4051 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4052 (y
>= infoPtr
->rcList
.bottom
))
4054 if (!infoPtr
->bScrolling
)
4056 infoPtr
->bScrolling
= TRUE
;
4057 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4062 infoPtr
->bScrolling
= FALSE
;
4063 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4066 LISTVIEW_MarqueeHighlight(infoPtr
, &pt
, 0);
4071 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4073 /* reset item marker */
4074 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4075 infoPtr
->nLButtonDownItem
= -1;
4077 if (!PtInRect(&rect
, pt
))
4079 /* this path covers the following:
4080 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4081 2. change focus with keys
4082 3. move mouse over item from step 1 selects it and moves focus on it */
4083 if (infoPtr
->nLButtonDownItem
!= -1 &&
4084 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4088 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4089 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4091 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4092 infoPtr
->nLButtonDownItem
= -1;
4095 if (!infoPtr
->bDragging
)
4097 ht
.pt
= infoPtr
->ptClickPos
;
4098 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4100 /* If the click is outside the range of an item, begin a
4101 highlight. If not, begin an item drag. */
4106 /* If we're allowing multiple selections, send notification.
4107 If return value is non-zero, cancel. */
4108 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4110 /* Store the absolute coordinates of the click */
4112 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4114 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4115 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4117 /* Begin selection and capture mouse */
4118 infoPtr
->bMarqueeSelect
= TRUE
;
4119 SetCapture(infoPtr
->hwndSelf
);
4126 ZeroMemory(&nmlv
, sizeof(nmlv
));
4127 nmlv
.iItem
= ht
.iItem
;
4128 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4130 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4131 infoPtr
->bDragging
= TRUE
;
4139 /* see if we are supposed to be tracking mouse hovering */
4140 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4141 TRACKMOUSEEVENT trackinfo
;
4144 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4145 trackinfo
.dwFlags
= TME_QUERY
;
4147 /* see if we are already tracking this hwnd */
4148 _TrackMouseEvent(&trackinfo
);
4151 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
4154 if((trackinfo
.dwFlags
& flags
) != flags
|| trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4155 trackinfo
.dwFlags
= flags
;
4156 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4157 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4159 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4160 _TrackMouseEvent(&trackinfo
);
4169 * Tests whether the item is assignable to a list with style lStyle
4171 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4173 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4174 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4175 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4183 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4186 * [I] infoPtr : valid pointer to the listview structure
4187 * [I] lpLVItem : valid pointer to new item attributes
4188 * [I] isNew : the item being set is being inserted
4189 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4190 * [O] bChanged : will be set to TRUE if the item really changed
4196 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4202 /* stateMask is ignored for LVM_INSERTITEM */
4203 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4207 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4209 if (lpLVItem
->mask
== 0) return TRUE
;
4211 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4213 /* a virtual listview only stores selection and focus */
4214 if (lpLVItem
->mask
& ~LVIF_STATE
)
4220 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4221 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4225 /* we need to get the lParam and state of the item */
4226 item
.iItem
= lpLVItem
->iItem
;
4227 item
.iSubItem
= lpLVItem
->iSubItem
;
4228 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4229 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4233 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4235 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4236 /* determine what fields will change */
4237 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4238 uChanged
|= LVIF_STATE
;
4240 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4241 uChanged
|= LVIF_IMAGE
;
4243 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4244 uChanged
|= LVIF_PARAM
;
4246 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4247 uChanged
|= LVIF_INDENT
;
4249 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4250 uChanged
|= LVIF_TEXT
;
4252 TRACE("change mask=0x%x\n", uChanged
);
4254 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4255 nmlv
.iItem
= lpLVItem
->iItem
;
4256 if (lpLVItem
->mask
& LVIF_STATE
)
4258 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4259 nmlv
.uOldState
= item
.state
;
4261 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4262 nmlv
.lParam
= item
.lParam
;
4264 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4265 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4266 are enabled. Even nothing really changed we still need to send this,
4267 in this case uChanged mask is just set to passed item mask. */
4268 if (lpItem
&& !isNew
&& (infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
))
4270 HWND hwndSelf
= infoPtr
->hwndSelf
;
4272 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4274 if (!IsWindow(hwndSelf
))
4278 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4279 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4280 /* this means we won't hit a focus change path later */
4281 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4283 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4284 infoPtr
->nFocusedItem
++;
4287 if (!uChanged
) return TRUE
;
4290 /* copy information */
4291 if (lpLVItem
->mask
& LVIF_TEXT
)
4292 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4294 if (lpLVItem
->mask
& LVIF_IMAGE
)
4295 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4297 if (lpLVItem
->mask
& LVIF_PARAM
)
4298 lpItem
->lParam
= lpLVItem
->lParam
;
4300 if (lpLVItem
->mask
& LVIF_INDENT
)
4301 lpItem
->iIndent
= lpLVItem
->iIndent
;
4303 if (uChanged
& LVIF_STATE
)
4305 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4307 lpItem
->state
&= ~stateMask
;
4308 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4310 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4312 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4313 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4315 else if (stateMask
& LVIS_SELECTED
)
4317 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4319 /* If we are asked to change focus, and we manage it, do it.
4320 It's important to have all new item data stored at this point,
4321 because changing existing focus could result in a redrawing operation,
4322 which in turn could ask for disp data, application should see all data
4323 for inserted item when processing LVN_GETDISPINFO.
4325 The way this works application will see nested item change notifications -
4326 changed item notifications interrupted by ones from item losing focus. */
4327 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4329 if (lpLVItem
->state
& LVIS_FOCUSED
)
4331 /* update selection mark */
4332 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4333 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4335 if (infoPtr
->nFocusedItem
!= -1)
4337 /* remove current focus */
4338 item
.mask
= LVIF_STATE
;
4340 item
.stateMask
= LVIS_FOCUSED
;
4342 /* recurse with redrawing an item */
4343 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4346 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4347 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4349 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4351 infoPtr
->nFocusedItem
= -1;
4356 /* if we're inserting the item, we're done */
4357 if (isNew
) return TRUE
;
4359 /* send LVN_ITEMCHANGED notification */
4360 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4361 if (infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
)
4362 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4369 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4372 * [I] infoPtr : valid pointer to the listview structure
4373 * [I] lpLVItem : valid pointer to new subitem attributes
4374 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4375 * [O] bChanged : will be set to TRUE if the item really changed
4381 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4384 SUBITEM_INFO
*lpSubItem
;
4386 /* we do not support subitems for virtual listviews */
4387 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4389 /* set subitem only if column is present */
4390 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4392 /* First do some sanity checks */
4393 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4394 particularly useful. We currently do not actually do anything with
4395 the flag on subitems.
4397 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4398 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4400 /* get the subitem structure, and create it if not there */
4401 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4402 assert (hdpaSubItems
);
4404 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4407 SUBITEM_INFO
*tmpSubItem
;
4410 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4411 if (!lpSubItem
) return FALSE
;
4412 /* we could binary search here, if need be...*/
4413 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4415 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4416 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4418 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4423 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4424 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4428 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4430 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4434 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4436 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4445 * Sets item attributes.
4448 * [I] infoPtr : valid pointer to the listview structure
4449 * [I] lpLVItem : new item attributes
4450 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4456 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4458 HWND hwndSelf
= infoPtr
->hwndSelf
;
4459 LPWSTR pszText
= NULL
;
4460 BOOL bResult
, bChanged
= FALSE
;
4463 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4465 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4468 /* Store old item area */
4469 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4471 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4472 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4474 pszText
= lpLVItem
->pszText
;
4475 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4478 /* actually set the fields */
4479 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4481 if (lpLVItem
->iSubItem
)
4482 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4484 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4485 if (!IsWindow(hwndSelf
))
4488 /* redraw item, if necessary */
4489 if (bChanged
&& !infoPtr
->bIsDrawing
)
4491 /* this little optimization eliminates some nasty flicker */
4492 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4493 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4494 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4495 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4498 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4499 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4505 textfreeT(lpLVItem
->pszText
, isW
);
4506 lpLVItem
->pszText
= pszText
;
4514 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4517 * [I] infoPtr : valid pointer to the listview structure
4522 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4525 SCROLLINFO scrollInfo
;
4527 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4528 scrollInfo
.fMask
= SIF_POS
;
4530 if (infoPtr
->uView
== LV_VIEW_LIST
)
4532 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4533 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4535 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4537 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4538 nItem
= scrollInfo
.nPos
;
4542 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4543 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4546 TRACE("nItem=%d\n", nItem
);
4554 * Erases the background of the given rectangle
4557 * [I] infoPtr : valid pointer to the listview structure
4558 * [I] hdc : device context handle
4559 * [I] lprcBox : clipping rectangle
4565 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4567 if (!infoPtr
->hBkBrush
) return FALSE
;
4569 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4571 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4574 /* Draw main item or subitem */
4575 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4577 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4578 const RECT
*background
;
4583 /* now check if we need to update the focus rectangle */
4584 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4585 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4587 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4588 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4589 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4590 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4591 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4592 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4593 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4594 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4595 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4597 /* FIXME: temporary hack */
4598 rcSelect
.left
= rcLabel
.left
;
4600 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4602 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4603 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4604 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4605 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4606 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4609 /* in icon mode, the label rect is really what we want to draw the
4611 /* in detail mode, we want to paint background for label rect when
4612 * item is not selected or listview has full row select; otherwise paint
4613 * background for text only */
4614 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4615 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4616 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4617 background
= &rcLabel
;
4619 background
= &rcSelect
;
4621 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4622 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4624 if (item
->state
& LVIS_FOCUSED
)
4626 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4628 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4630 /* we have to update left focus bound too if item isn't in leftmost column
4631 and reduce right box bound */
4632 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4636 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4638 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4639 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4640 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4642 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4643 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4646 rcSelect
.right
= rcBox
.right
;
4648 infoPtr
->rcFocus
= rcSelect
;
4651 infoPtr
->rcFocus
= rcLabel
;
4655 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4657 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4660 TRACE("stateimage=%d\n", stateimage
);
4661 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4666 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4667 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4671 TRACE("iImage=%d\n", item
->iImage
);
4673 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4674 style
= ILD_SELECTED
;
4678 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4679 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4680 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4681 style
| (item
->state
& LVIS_OVERLAYMASK
));
4684 /* Don't bother painting item being edited */
4685 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4687 /* figure out the text drawing flags */
4688 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4689 if (infoPtr
->uView
== LV_VIEW_ICON
)
4690 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4691 else if (item
->iSubItem
)
4693 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4695 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4696 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4697 default: format
|= DT_LEFT
;
4700 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4702 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4703 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4705 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4707 /* for GRIDLINES reduce the bottom so the text formats correctly */
4708 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4711 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4719 * [I] infoPtr : valid pointer to the listview structure
4720 * [I] hdc : device context handle
4721 * [I] nItem : item index
4722 * [I] nSubItem : subitem index
4723 * [I] pos : item position in client coordinates
4724 * [I] cdmode : custom draw mode
4730 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4732 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4733 static WCHAR callbackW
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4734 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4736 NMLVCUSTOMDRAW nmlvcd
;
4739 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4741 /* get information needed for drawing the item */
4742 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4743 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4744 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4745 lvItem
.iItem
= nItem
;
4746 lvItem
.iSubItem
= 0;
4749 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4750 lvItem
.pszText
= szDispText
;
4751 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4752 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4753 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4755 /* now check if we need to update the focus rectangle */
4756 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4757 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4759 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4760 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4762 /* Full custom draw stage sequence looks like this:
4767 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4768 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item itself
4769 - CDDS_ITEMPOSTPAINT
4774 - CDDS_ITEMPOSTPAINT
4777 /* fill in the custom draw structure */
4778 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4779 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4780 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4781 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4785 while (iterator_next(subitems
))
4787 DWORD subitemstage
= CDRF_DODEFAULT
;
4789 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4790 if (subitems
->nItem
)
4792 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4793 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4794 lvItem
.iItem
= nItem
;
4795 lvItem
.iSubItem
= subitems
->nItem
;
4798 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4799 lvItem
.pszText
= szDispText
;
4800 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4801 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4802 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4803 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4804 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4806 /* update custom draw data */
4807 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4808 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4809 nmlvcd
.iSubItem
= subitems
->nItem
;
4812 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4813 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4816 nmlvcd
.clrTextBk
= infoPtr
->clrTextBk
;
4817 nmlvcd
.clrText
= infoPtr
->clrText
;
4820 if (subitems
->nItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4821 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4822 else if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4823 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4825 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4826 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4828 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4829 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4834 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4835 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4839 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4841 nmlvcd
.iSubItem
= 0;
4842 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4850 * Draws listview items when in owner draw mode.
4853 * [I] infoPtr : valid pointer to the listview structure
4854 * [I] hdc : device context handle
4859 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4861 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4862 DWORD cditemmode
= CDRF_DODEFAULT
;
4863 NMLVCUSTOMDRAW nmlvcd
;
4864 POINT Origin
, Position
;
4870 ZeroMemory(&dis
, sizeof(dis
));
4872 /* Get scroll info once before loop */
4873 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4875 /* iterate through the invalidated rows */
4876 while(iterator_next(i
))
4878 item
.iItem
= i
->nItem
;
4880 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4881 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4882 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4884 dis
.CtlType
= ODT_LISTVIEW
;
4886 dis
.itemID
= item
.iItem
;
4887 dis
.itemAction
= ODA_DRAWENTIRE
;
4889 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4890 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4891 dis
.hwndItem
= infoPtr
->hwndSelf
;
4893 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4894 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4895 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4896 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4897 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4898 dis
.itemData
= item
.lParam
;
4900 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4903 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4904 * structure for the rest. of the paint cycle
4906 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4907 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4908 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4910 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4912 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4913 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4916 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4917 notify_postpaint(infoPtr
, &nmlvcd
);
4923 * Draws listview items when in report display mode.
4926 * [I] infoPtr : valid pointer to the listview structure
4927 * [I] hdc : device context handle
4928 * [I] cdmode : custom draw mode
4933 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4936 RECT rcClip
, rcItem
;
4944 /* figure out what to draw */
4945 rgntype
= GetClipBox(hdc
, &rcClip
);
4946 if (rgntype
== NULLREGION
) return;
4948 /* Get scroll info once before loop */
4949 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4951 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4953 /* narrow down the columns we need to paint */
4954 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4956 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4958 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4959 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4960 ranges_additem(colRanges
, index
);
4962 iterator_rangesitems(&j
, colRanges
);
4964 /* in full row select, we _have_ to draw the main item */
4965 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4968 /* iterate through the invalidated rows */
4969 while(iterator_next(i
))
4975 SelectObject(hdc
, infoPtr
->hFont
);
4976 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4977 Position
.x
= Origin
.x
;
4978 Position
.y
+= Origin
.y
;
4980 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4982 /* iterate through the invalidated columns */
4983 while(iterator_next(&j
))
4985 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4987 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4990 rcItem
.bottom
= infoPtr
->nItemHeight
;
4991 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4992 if (!RectVisible(hdc
, &rcItem
)) continue;
4995 ranges_additem(subitems
, j
.nItem
);
4998 iterator_rangesitems(&k
, subitems
);
4999 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
5000 iterator_destroy(&k
);
5002 iterator_destroy(&j
);
5007 * Draws the gridlines if necessary when in report display mode.
5010 * [I] infoPtr : valid pointer to the listview structure
5011 * [I] hdc : device context handle
5016 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
5022 RECT rcClip
, rcItem
= {0};
5030 /* figure out what to draw */
5031 rgntype
= GetClipBox(hdc
, &rcClip
);
5032 if (rgntype
== NULLREGION
) return;
5034 /* Get scroll info once before loop */
5035 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5037 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5039 /* narrow down the columns we need to paint */
5040 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5042 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5044 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5045 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5046 ranges_additem(colRanges
, index
);
5049 /* is right most vertical line visible? */
5050 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5052 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5053 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5054 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5057 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5059 hOldPen
= SelectObject ( hdc
, hPen
);
5061 /* draw the vertical lines for the columns */
5062 iterator_rangesitems(&j
, colRanges
);
5063 while(iterator_next(&j
))
5065 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5066 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5067 rcItem
.left
+= Origin
.x
;
5068 rcItem
.right
+= Origin
.x
;
5069 rcItem
.top
= infoPtr
->rcList
.top
;
5070 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5071 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5072 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5073 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5075 iterator_destroy(&j
);
5076 /* draw rightmost grid line if visible */
5079 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5080 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5081 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5083 rcItem
.right
+= Origin
.x
;
5085 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5086 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5089 /* draw the horizontal lines for the rows */
5090 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5091 rcItem
.left
= infoPtr
->rcList
.left
;
5092 rcItem
.right
= infoPtr
->rcList
.right
;
5093 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5095 rcItem
.bottom
= rcItem
.top
= y
;
5096 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5097 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5098 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5101 SelectObject( hdc
, hOldPen
);
5102 DeleteObject( hPen
);
5105 ranges_destroy(colRanges
);
5110 * Draws listview items when in list display mode.
5113 * [I] infoPtr : valid pointer to the listview structure
5114 * [I] hdc : device context handle
5115 * [I] cdmode : custom draw mode
5120 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5122 POINT Origin
, Position
;
5124 /* Get scroll info once before loop */
5125 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5127 while(iterator_prev(i
))
5129 SelectObject(hdc
, infoPtr
->hFont
);
5130 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5131 Position
.x
+= Origin
.x
;
5132 Position
.y
+= Origin
.y
;
5134 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5141 * Draws listview items.
5144 * [I] infoPtr : valid pointer to the listview structure
5145 * [I] hdc : device context handle
5146 * [I] prcErase : rect to be erased before refresh (may be NULL)
5151 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5153 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5154 NMLVCUSTOMDRAW nmlvcd
;
5161 HBITMAP hbmp
= NULL
;
5164 LISTVIEW_DUMP(infoPtr
);
5166 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5167 TRACE("double buffering\n");
5169 hdc
= CreateCompatibleDC(hdcOrig
);
5171 ERR("Failed to create DC for backbuffer\n");
5174 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5175 infoPtr
->rcList
.bottom
);
5177 ERR("Failed to create bitmap for backbuffer\n");
5182 SelectObject(hdc
, hbmp
);
5183 SelectObject(hdc
, infoPtr
->hFont
);
5185 if(GetClipBox(hdcOrig
, &rcClient
))
5186 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5188 /* Save dc values we're gonna trash while drawing
5189 * FIXME: Should be done in LISTVIEW_DrawItem() */
5190 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5191 oldBkMode
= GetBkMode(hdc
);
5192 oldBkColor
= GetBkColor(hdc
);
5193 oldTextColor
= GetTextColor(hdc
);
5196 infoPtr
->bIsDrawing
= TRUE
;
5199 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5200 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5201 /* If no erasing was done (usually because RedrawWindow was called
5202 * with RDW_INVALIDATE only) we need to copy the old contents into
5203 * the backbuffer before continuing. */
5204 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5205 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5206 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5207 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5210 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5211 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5212 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5213 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5215 /* nothing to draw */
5216 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5218 /* figure out what we need to draw */
5219 iterator_visibleitems(&i
, infoPtr
, hdc
);
5220 range
= iterator_range(&i
);
5222 /* send cache hint notification */
5223 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5227 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5228 nmlv
.iFrom
= range
.lower
;
5229 nmlv
.iTo
= range
.upper
- 1;
5230 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5233 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5234 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5237 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5238 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5239 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5240 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5242 /* if we have a focus rect and it's visible, draw it */
5243 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5244 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5245 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5247 iterator_destroy(&i
);
5250 /* For LVS_EX_GRIDLINES go and draw lines */
5251 /* This includes the case where there were *no* items */
5252 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5253 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5255 /* Draw marquee rectangle if appropriate */
5256 if (infoPtr
->bMarqueeSelect
)
5257 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5259 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5260 notify_postpaint(infoPtr
, &nmlvcd
);
5263 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5264 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5265 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5266 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5271 SelectObject(hdc
, hOldFont
);
5272 SetBkMode(hdc
, oldBkMode
);
5273 SetBkColor(hdc
, oldBkColor
);
5274 SetTextColor(hdc
, oldTextColor
);
5277 infoPtr
->bIsDrawing
= FALSE
;
5283 * Calculates the approximate width and height of a given number of items.
5286 * [I] infoPtr : valid pointer to the listview structure
5287 * [I] nItemCount : number of items
5288 * [I] wWidth : width
5289 * [I] wHeight : height
5292 * Returns a DWORD. The width in the low word and the height in high word.
5294 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5295 WORD wWidth
, WORD wHeight
)
5297 DWORD dwViewRect
= 0;
5299 if (nItemCount
== -1)
5300 nItemCount
= infoPtr
->nItemCount
;
5302 if (infoPtr
->uView
== LV_VIEW_LIST
)
5304 INT nItemCountPerColumn
= 1;
5305 INT nColumnCount
= 0;
5307 if (wHeight
== 0xFFFF)
5309 /* use current height */
5310 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5313 if (wHeight
< infoPtr
->nItemHeight
)
5314 wHeight
= infoPtr
->nItemHeight
;
5318 if (infoPtr
->nItemHeight
> 0)
5320 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5321 if (nItemCountPerColumn
== 0)
5322 nItemCountPerColumn
= 1;
5324 if (nItemCount
% nItemCountPerColumn
!= 0)
5325 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5327 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5331 /* Microsoft padding magic */
5332 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5333 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5335 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5337 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5341 if (infoPtr
->nItemCount
> 0)
5343 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5344 wWidth
= rcBox
.right
- rcBox
.left
;
5345 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5349 /* use current height and width */
5350 if (wHeight
== 0xffff)
5351 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5352 if (wWidth
== 0xffff)
5353 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5356 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5358 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5364 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5365 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5367 if (wWidth
== 0xffff)
5368 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5370 if (wWidth
< nItemWidth
)
5371 wWidth
= nItemWidth
;
5373 cols
= wWidth
/ nItemWidth
;
5374 if (cols
> nItemCount
)
5381 rows
= nItemCount
/ cols
;
5382 if (nItemCount
% cols
)
5388 wHeight
= (nItemHeight
* rows
)+2;
5389 wWidth
= (nItemWidth
* cols
)+2;
5391 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5393 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5394 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5401 * Cancel edit label with saving item text.
5404 * [I] infoPtr : valid pointer to the listview structure
5407 * Always returns TRUE.
5409 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5411 if (infoPtr
->hwndEdit
)
5413 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5414 HWND edit
= infoPtr
->hwndEdit
;
5416 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5417 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5425 * Create a drag image list for the specified item.
5428 * [I] infoPtr : valid pointer to the listview structure
5429 * [I] iItem : index of item
5430 * [O] lppt : Upper-left corner of the image
5433 * Returns a handle to the image list if successful, NULL otherwise.
5435 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5441 HBITMAP hbmp
, hOldbmp
;
5443 HIMAGELIST dragList
= 0;
5444 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5446 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5449 rcItem
.left
= LVIR_BOUNDS
;
5450 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5453 lppt
->x
= rcItem
.left
;
5454 lppt
->y
= rcItem
.top
;
5456 size
.cx
= rcItem
.right
- rcItem
.left
;
5457 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5459 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5460 hdc
= CreateCompatibleDC(hdcOrig
);
5461 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5462 hOldbmp
= SelectObject(hdc
, hbmp
);
5463 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5465 SetRect(&rcItem
, 0, 0, size
.cx
, size
.cy
);
5466 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5469 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5471 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5472 SelectObject(hdc
, hOldbmp
);
5473 ImageList_Add(dragList
, hbmp
, 0);
5476 SelectObject(hdc
, hOldbmp
);
5478 SelectObject(hdc
, hOldFont
);
5481 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5483 TRACE("ret=%p\n", dragList
);
5491 * Removes all listview items and subitems.
5494 * [I] infoPtr : valid pointer to the listview structure
5500 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5502 HDPA hdpaSubItems
= NULL
;
5503 BOOL suppress
= FALSE
;
5511 /* we do it directly, to avoid notifications */
5512 ranges_clear(infoPtr
->selectionRanges
);
5513 infoPtr
->nSelectionMark
= -1;
5514 infoPtr
->nFocusedItem
= -1;
5515 SetRectEmpty(&infoPtr
->rcFocus
);
5516 /* But we are supposed to leave nHotItem as is! */
5518 /* send LVN_DELETEALLITEMS notification */
5519 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5523 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5525 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5528 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5530 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5532 /* send LVN_DELETEITEM notification, if not suppressed
5533 and if it is not a virtual listview */
5534 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5535 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5536 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5537 /* free id struct */
5538 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5539 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5540 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5542 /* both item and subitem start with ITEMHDR header */
5543 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5545 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5546 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5549 DPA_Destroy(hdpaSubItems
);
5550 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5552 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5553 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5554 infoPtr
->nItemCount
--;
5559 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5560 LISTVIEW_UpdateScroll(infoPtr
);
5562 LISTVIEW_InvalidateList(infoPtr
);
5569 * Scrolls, and updates the columns, when a column is changing width.
5572 * [I] infoPtr : valid pointer to the listview structure
5573 * [I] nColumn : column to scroll
5574 * [I] dx : amount of scroll, in pixels
5579 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5581 COLUMN_INFO
*lpColumnInfo
;
5587 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5588 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5589 rcCol
= lpColumnInfo
->rcHeader
;
5590 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5591 rcCol
.left
= rcCol
.right
;
5593 /* adjust the other columns */
5594 hdi
.mask
= HDI_ORDER
;
5595 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5597 INT nOrder
= hdi
.iOrder
;
5598 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5600 hdi
.mask
= HDI_ORDER
;
5601 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5602 if (hdi
.iOrder
>= nOrder
) {
5603 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5604 lpColumnInfo
->rcHeader
.left
+= dx
;
5605 lpColumnInfo
->rcHeader
.right
+= dx
;
5610 /* do not update screen if not in report mode */
5611 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5613 /* Need to reset the item width when inserting a new column */
5614 infoPtr
->nItemWidth
+= dx
;
5616 LISTVIEW_UpdateScroll(infoPtr
);
5617 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5619 /* scroll to cover the deleted column, and invalidate for redraw */
5620 rcOld
= infoPtr
->rcList
;
5621 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5622 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5627 * Removes a column from the listview control.
5630 * [I] infoPtr : valid pointer to the listview structure
5631 * [I] nColumn : column index
5637 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5641 TRACE("nColumn=%d\n", nColumn
);
5643 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5646 /* While the MSDN specifically says that column zero should not be deleted,
5647 what actually happens is that the column itself is deleted but no items or subitems
5651 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5653 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5656 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5657 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5659 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5661 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5663 INT nItem
, nSubItem
, i
;
5665 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5667 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5670 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5672 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5673 if (lpSubItem
->iSubItem
== nColumn
)
5676 lpDelItem
= lpSubItem
;
5678 else if (lpSubItem
->iSubItem
> nColumn
)
5680 lpSubItem
->iSubItem
--;
5684 /* if we found our subitem, zap it */
5688 if (is_text(lpDelItem
->hdr
.pszText
))
5689 Free(lpDelItem
->hdr
.pszText
);
5694 /* free dpa memory */
5695 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5700 /* update the other column info */
5701 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5702 LISTVIEW_InvalidateList(infoPtr
);
5704 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5705 LISTVIEW_UpdateItemSize(infoPtr
);
5712 * Invalidates the listview after an item's insertion or deletion.
5715 * [I] infoPtr : valid pointer to the listview structure
5716 * [I] nItem : item index
5717 * [I] dir : -1 if deleting, 1 if inserting
5722 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5724 INT nPerCol
, nItemCol
, nItemRow
;
5728 /* if we don't refresh, what's the point of scrolling? */
5729 if (!is_redrawing(infoPtr
)) return;
5731 assert (abs(dir
) == 1);
5733 /* arrange icons if autoarrange is on */
5734 if (is_autoarrange(infoPtr
))
5736 BOOL arrange
= TRUE
;
5737 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5738 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5739 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5742 /* scrollbars need updating */
5743 LISTVIEW_UpdateScroll(infoPtr
);
5745 /* figure out the item's position */
5746 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5747 nPerCol
= infoPtr
->nItemCount
+ 1;
5748 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5749 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5750 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5753 nItemCol
= nItem
/ nPerCol
;
5754 nItemRow
= nItem
% nPerCol
;
5755 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5757 /* move the items below up a slot */
5758 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5759 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5760 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5761 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5762 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5763 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5764 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5766 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5767 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5770 /* report has only that column, so we're done */
5771 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5773 /* now for LISTs, we have to deal with the columns to the right */
5774 SetRect(&rcScroll
, (nItemCol
+ 1) * infoPtr
->nItemWidth
, 0,
5775 (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
,
5776 nPerCol
* infoPtr
->nItemHeight
);
5777 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5778 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5779 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5784 * Removes an item from the listview control.
5787 * [I] infoPtr : valid pointer to the listview structure
5788 * [I] nItem : item index
5794 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5797 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5798 INT focus
= infoPtr
->nFocusedItem
;
5800 TRACE("(nItem=%d)\n", nItem
);
5802 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5804 /* remove selection, and focus */
5806 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5807 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5809 /* send LVN_DELETEITEM notification. */
5810 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5812 /* we need to do this here, because we'll be deleting stuff */
5814 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5816 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5824 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5825 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5827 /* free id struct */
5828 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5829 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5830 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5832 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5834 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5835 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5838 DPA_Destroy(hdpaSubItems
);
5843 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5844 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5847 infoPtr
->nItemCount
--;
5848 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5849 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5851 /* now is the invalidation fun */
5853 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5860 * Callback implementation for editlabel control
5863 * [I] infoPtr : valid pointer to the listview structure
5864 * [I] storeText : store edit box text as item text
5865 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5871 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5873 HWND hwndSelf
= infoPtr
->hwndSelf
;
5874 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5875 NMLVDISPINFOW dispInfo
;
5876 INT editedItem
= infoPtr
->nEditLabelItem
;
5878 WCHAR
*pszText
= NULL
;
5883 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5887 if (!(pszText
= Alloc(len
* (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5891 GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
);
5893 GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
);
5897 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5899 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5900 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5901 dispInfo
.item
.iItem
= editedItem
;
5902 dispInfo
.item
.iSubItem
= 0;
5903 dispInfo
.item
.stateMask
= ~0;
5904 dispInfo
.item
.pszText
= szDispText
;
5905 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5906 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5913 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5916 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5917 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5918 textfreeT(tmp
, FALSE
);
5921 /* add the text from the edit in */
5922 dispInfo
.item
.mask
|= LVIF_TEXT
;
5923 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5924 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5926 infoPtr
->notify_mask
&= ~NOTIFY_MASK_END_LABEL_EDIT
;
5928 /* Do we need to update the Item Text */
5929 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5931 infoPtr
->notify_mask
|= NOTIFY_MASK_END_LABEL_EDIT
;
5933 infoPtr
->nEditLabelItem
= -1;
5934 infoPtr
->hwndEdit
= 0;
5936 if (!res
) goto cleanup
;
5938 if (!IsWindow(hwndSelf
))
5943 if (!pszText
) return TRUE
;
5950 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5952 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5953 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5954 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5956 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5962 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5963 dispInfo
.item
.mask
= LVIF_TEXT
;
5964 dispInfo
.item
.iItem
= editedItem
;
5965 dispInfo
.item
.iSubItem
= 0;
5966 dispInfo
.item
.pszText
= pszText
;
5967 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5968 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5978 * Subclassed edit control windproc function
5981 * [I] hwnd : the edit window handle
5982 * [I] uMsg : the message that is to be processed
5983 * [I] wParam : first message parameter
5984 * [I] lParam : second message parameter
5985 * [I] isW : TRUE if input is Unicode
5990 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5992 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5995 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5996 hwnd
, uMsg
, wParam
, lParam
, isW
);
6001 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
6005 WNDPROC editProc
= infoPtr
->EditWndProc
;
6006 infoPtr
->EditWndProc
= 0;
6007 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
6008 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6012 if (VK_ESCAPE
== (INT
)wParam
)
6017 else if (VK_RETURN
== (INT
)wParam
)
6021 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6025 if (infoPtr
->hwndEdit
)
6026 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
6028 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6034 * Subclassed edit control Unicode windproc function
6037 * [I] hwnd : the edit window handle
6038 * [I] uMsg : the message that is to be processed
6039 * [I] wParam : first message parameter
6040 * [I] lParam : second message parameter
6044 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6046 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6051 * Subclassed edit control ANSI windproc function
6054 * [I] hwnd : the edit window handle
6055 * [I] uMsg : the message that is to be processed
6056 * [I] wParam : first message parameter
6057 * [I] lParam : second message parameter
6061 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6063 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6068 * Creates a subclassed edit control
6071 * [I] infoPtr : valid pointer to the listview structure
6072 * [I] text : initial text for the edit
6073 * [I] style : the window style
6074 * [I] isW : TRUE if input is Unicode
6078 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6080 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6081 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6084 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6086 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6088 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6090 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6092 if (!hedit
) return 0;
6094 infoPtr
->EditWndProc
= (WNDPROC
)
6095 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6096 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6098 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6099 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6106 * Begin in place editing of specified list view item
6109 * [I] infoPtr : valid pointer to the listview structure
6110 * [I] nItem : item index
6111 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6117 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6119 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6120 HWND hwndSelf
= infoPtr
->hwndSelf
;
6121 NMLVDISPINFOW dispInfo
;
6122 HFONT hOldFont
= NULL
;
6128 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6130 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6132 /* remove existing edit box */
6133 if (infoPtr
->hwndEdit
)
6135 SetFocus(infoPtr
->hwndSelf
);
6136 infoPtr
->hwndEdit
= 0;
6139 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6141 infoPtr
->nEditLabelItem
= nItem
;
6143 LISTVIEW_SetSelection(infoPtr
, nItem
);
6144 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6145 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6147 rect
.left
= LVIR_LABEL
;
6148 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6150 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6151 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6152 dispInfo
.item
.iItem
= nItem
;
6153 dispInfo
.item
.iSubItem
= 0;
6154 dispInfo
.item
.stateMask
= ~0;
6155 dispInfo
.item
.pszText
= disptextW
;
6156 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6157 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6159 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6160 if (!infoPtr
->hwndEdit
) return 0;
6162 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6164 if (!IsWindow(hwndSelf
))
6166 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6167 infoPtr
->hwndEdit
= 0;
6171 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6173 /* position and display edit box */
6174 hdc
= GetDC(infoPtr
->hwndSelf
);
6176 /* select the font to get appropriate metric dimensions */
6178 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6180 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6181 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6182 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6184 /* get string length in pixels */
6185 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6187 /* add extra spacing for the next character */
6188 GetTextMetricsW(hdc
, &tm
);
6189 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6192 SelectObject(hdc
, hOldFont
);
6194 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6196 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6199 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6200 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6201 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6202 SetFocus(infoPtr
->hwndEdit
);
6203 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6204 return infoPtr
->hwndEdit
;
6210 * Ensures the specified item is visible, scrolling into view if necessary.
6213 * [I] infoPtr : valid pointer to the listview structure
6214 * [I] nItem : item index
6215 * [I] bPartial : partially or entirely visible
6221 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6223 INT nScrollPosHeight
= 0;
6224 INT nScrollPosWidth
= 0;
6225 INT nHorzAdjust
= 0;
6226 INT nVertAdjust
= 0;
6229 RECT rcItem
, rcTemp
;
6231 rcItem
.left
= LVIR_BOUNDS
;
6232 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6234 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6236 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6238 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6239 if (infoPtr
->uView
== LV_VIEW_LIST
)
6240 nScrollPosWidth
= infoPtr
->nItemWidth
;
6241 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6242 nScrollPosWidth
= 1;
6244 if (rcItem
.left
< infoPtr
->rcList
.left
)
6247 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6252 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6256 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6258 /* scroll up/down, but not in LVS_LIST mode */
6259 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6260 nScrollPosHeight
= infoPtr
->nItemHeight
;
6261 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6262 nScrollPosHeight
= 1;
6264 if (rcItem
.top
< infoPtr
->rcList
.top
)
6267 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6272 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6276 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6278 if (nScrollPosWidth
)
6280 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6281 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6282 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6285 if (nScrollPosHeight
)
6287 INT diff
= nVertDiff
/ nScrollPosHeight
;
6288 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6289 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6297 * Searches for an item with specific characteristics.
6300 * [I] hwnd : window handle
6301 * [I] nStart : base item index
6302 * [I] lpFindInfo : item information to look for
6305 * SUCCESS : index of item
6308 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6309 const LVFINDINFOW
*lpFindInfo
)
6311 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6312 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6313 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6314 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6315 POINT Position
, Destination
;
6318 /* Search in virtual listviews should be done by application, not by
6319 listview control, so we just send LVN_ODFINDITEMW and return the result */
6320 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6324 nmlv
.iStart
= nStart
;
6325 nmlv
.lvfi
= *lpFindInfo
;
6326 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6329 if (!lpFindInfo
|| nItem
< 0) return -1;
6332 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6334 lvItem
.mask
|= LVIF_TEXT
;
6335 lvItem
.pszText
= szDispText
;
6336 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6339 if (lpFindInfo
->flags
& LVFI_WRAP
)
6342 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6343 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6348 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6349 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6350 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6351 switch(lpFindInfo
->vkDirection
)
6353 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6354 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6355 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6356 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6357 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6358 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6359 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6361 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6362 Destination
.x
= rcArea
.right
;
6363 Destination
.y
= rcArea
.bottom
;
6365 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6369 else Destination
.x
= Destination
.y
= 0;
6371 /* if LVFI_PARAM is specified, all other flags are ignored */
6372 if (lpFindInfo
->flags
& LVFI_PARAM
)
6374 lvItem
.mask
|= LVIF_PARAM
;
6376 lvItem
.mask
&= ~LVIF_TEXT
;
6379 nItem
= bNearest
? -1 : nStart
+ 1;
6382 for (; nItem
< nLast
; nItem
++)
6384 lvItem
.iItem
= nItem
;
6385 lvItem
.iSubItem
= 0;
6386 lvItem
.pszText
= szDispText
;
6387 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6389 if (lvItem
.mask
& LVIF_PARAM
)
6391 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6397 if (lvItem
.mask
& LVIF_TEXT
)
6399 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6401 WCHAR
*p
= wcsstr(lvItem
.pszText
, lpFindInfo
->psz
);
6402 if (!p
|| p
!= lvItem
.pszText
) continue;
6406 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6410 if (!bNearest
) return nItem
;
6412 /* This is very inefficient. To do a good job here,
6413 * we need a sorted array of (x,y) item positions */
6414 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6416 /* compute the distance^2 to the destination */
6417 xdist
= Destination
.x
- Position
.x
;
6418 ydist
= Destination
.y
- Position
.y
;
6419 dist
= xdist
* xdist
+ ydist
* ydist
;
6421 /* remember the distance, and item if it's closer */
6425 nNearestItem
= nItem
;
6432 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6437 return nNearestItem
;
6442 * Searches for an item with specific characteristics.
6445 * [I] hwnd : window handle
6446 * [I] nStart : base item index
6447 * [I] lpFindInfo : item information to look for
6450 * SUCCESS : index of item
6453 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6454 const LVFINDINFOA
*lpFindInfo
)
6460 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6461 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6462 fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6463 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6464 textfreeT(strW
, FALSE
);
6470 * Retrieves column attributes.
6473 * [I] infoPtr : valid pointer to the listview structure
6474 * [I] nColumn : column index
6475 * [IO] lpColumn : column information
6476 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6477 * otherwise it is in fact a LPLVCOLUMNA
6483 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6485 COLUMN_INFO
*lpColumnInfo
;
6488 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6489 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6491 /* initialize memory */
6492 ZeroMemory(&hdi
, sizeof(hdi
));
6494 if (lpColumn
->mask
& LVCF_TEXT
)
6496 hdi
.mask
|= HDI_TEXT
;
6497 hdi
.pszText
= lpColumn
->pszText
;
6498 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6501 if (lpColumn
->mask
& LVCF_IMAGE
)
6502 hdi
.mask
|= HDI_IMAGE
;
6504 if (lpColumn
->mask
& LVCF_ORDER
)
6505 hdi
.mask
|= HDI_ORDER
;
6507 if (lpColumn
->mask
& LVCF_SUBITEM
)
6508 hdi
.mask
|= HDI_LPARAM
;
6510 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6512 if (lpColumn
->mask
& LVCF_FMT
)
6513 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6515 if (lpColumn
->mask
& LVCF_WIDTH
)
6516 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6518 if (lpColumn
->mask
& LVCF_IMAGE
)
6519 lpColumn
->iImage
= hdi
.iImage
;
6521 if (lpColumn
->mask
& LVCF_ORDER
)
6522 lpColumn
->iOrder
= hdi
.iOrder
;
6524 if (lpColumn
->mask
& LVCF_SUBITEM
)
6525 lpColumn
->iSubItem
= hdi
.lParam
;
6527 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6528 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6533 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6535 if (!infoPtr
->hwndHeader
) return FALSE
;
6536 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6541 * Retrieves the column width.
6544 * [I] infoPtr : valid pointer to the listview structure
6545 * [I] int : column index
6548 * SUCCESS : column width
6551 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6553 INT nColumnWidth
= 0;
6556 TRACE("nColumn=%d\n", nColumn
);
6558 /* we have a 'column' in LIST and REPORT mode only */
6559 switch(infoPtr
->uView
)
6562 nColumnWidth
= infoPtr
->nItemWidth
;
6564 case LV_VIEW_DETAILS
:
6565 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6566 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6567 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6569 hdItem
.mask
= HDI_WIDTH
;
6570 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6572 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6575 nColumnWidth
= hdItem
.cxy
;
6579 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6580 return nColumnWidth
;
6585 * In list or report display mode, retrieves the number of items that can fit
6586 * vertically in the visible area. In icon or small icon display mode,
6587 * retrieves the total number of visible items.
6590 * [I] infoPtr : valid pointer to the listview structure
6593 * Number of fully visible items.
6595 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6597 switch (infoPtr
->uView
)
6600 case LV_VIEW_SMALLICON
:
6601 return infoPtr
->nItemCount
;
6602 case LV_VIEW_DETAILS
:
6603 return LISTVIEW_GetCountPerColumn(infoPtr
);
6605 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6613 * Retrieves an image list handle.
6616 * [I] infoPtr : valid pointer to the listview structure
6617 * [I] nImageList : image list identifier
6620 * SUCCESS : image list handle
6623 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6627 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6628 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6629 case LVSIL_STATE
: return infoPtr
->himlState
;
6630 case LVSIL_GROUPHEADER
:
6631 FIXME("LVSIL_GROUPHEADER not supported\n");
6634 WARN("got unknown imagelist index - %d\n", nImageList
);
6639 /* LISTVIEW_GetISearchString */
6643 * Retrieves item attributes.
6646 * [I] hwnd : window handle
6647 * [IO] lpLVItem : item info
6648 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6649 * if FALSE, then lpLVItem is a LPLVITEMA.
6652 * This is the internal 'GetItem' interface -- it tries to
6653 * be smart and avoid text copies, if possible, by modifying
6654 * lpLVItem->pszText to point to the text string. Please note
6655 * that this is not always possible (e.g. OWNERDATA), so on
6656 * entry you *must* supply valid values for pszText, and cchTextMax.
6657 * The only difference to the documented interface is that upon
6658 * return, you should use *only* the lpLVItem->pszText, rather than
6659 * the buffer pointer you provided on input. Most code already does
6660 * that, so it's not a problem.
6661 * For the two cases when the text must be copied (that is,
6662 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6668 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6670 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6671 BOOL is_subitem_invalid
= FALSE
;
6672 NMLVDISPINFOW dispInfo
;
6677 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6679 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6682 if (lpLVItem
->mask
== 0) return TRUE
;
6683 TRACE("mask=%x\n", lpLVItem
->mask
);
6685 if (lpLVItem
->iSubItem
&& (lpLVItem
->mask
& LVIF_STATE
))
6686 lpLVItem
->state
= 0;
6688 /* a quick optimization if all we're asked is the focus state
6689 * these queries are worth optimising since they are common,
6690 * and can be answered in constant time, without the heavy accesses */
6691 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6692 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6694 lpLVItem
->state
= 0;
6695 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
&& !lpLVItem
->iSubItem
)
6696 lpLVItem
->state
|= LVIS_FOCUSED
;
6700 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6702 /* if the app stores all the data, handle it separately */
6703 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6705 dispInfo
.item
.state
= 0;
6707 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6708 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6709 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6711 UINT mask
= lpLVItem
->mask
;
6713 /* NOTE: copy only fields which we _know_ are initialized, some apps
6714 * depend on the uninitialized fields being 0 */
6715 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6716 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6717 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
6718 if (lpLVItem
->mask
& LVIF_TEXT
)
6720 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6722 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6725 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6726 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6729 if (lpLVItem
->mask
& LVIF_STATE
)
6730 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6731 /* could be zeroed on LVIF_NORECOMPUTE case */
6732 if (dispInfo
.item
.mask
)
6734 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6735 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6736 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6738 /* full size structure expected - _WIN32IE >= 0x560 */
6739 *lpLVItem
= dispInfo
.item
;
6741 else if (lpLVItem
->mask
& LVIF_INDENT
)
6743 /* indent member expected - _WIN32IE >= 0x300 */
6744 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6748 /* minimal structure expected */
6749 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6751 lpLVItem
->mask
= mask
;
6752 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6756 /* make sure lParam is zeroed out */
6757 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6759 /* callback marked pointer required here */
6760 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6761 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6763 /* we store only a little state, so if we're not asked, we're done */
6764 if (!(lpLVItem
->mask
& LVIF_STATE
) || lpLVItem
->iSubItem
) return TRUE
;
6766 /* if focus is handled by us, report it */
6767 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6769 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6770 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6771 lpLVItem
->state
|= LVIS_FOCUSED
;
6774 /* and do the same for selection, if we handle it */
6775 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6777 lpLVItem
->state
&= ~LVIS_SELECTED
;
6778 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6779 lpLVItem
->state
|= LVIS_SELECTED
;
6785 /* find the item and subitem structures before we proceed */
6786 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6787 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6790 if (lpLVItem
->iSubItem
)
6792 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
6794 pItemHdr
= &lpSubItem
->hdr
;
6797 pItemHdr
= &callbackHdr
;
6798 is_subitem_invalid
= TRUE
;
6802 pItemHdr
= &lpItem
->hdr
;
6804 /* Do we need to query the state from the app? */
6805 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& (!lpLVItem
->iSubItem
|| is_subitem_invalid
))
6807 dispInfo
.item
.mask
|= LVIF_STATE
;
6808 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6811 /* Do we need to enquire about the image? */
6812 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6813 (!lpLVItem
->iSubItem
|| (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6815 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6816 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6819 /* Only items support indentation */
6820 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&& !lpLVItem
->iSubItem
)
6822 dispInfo
.item
.mask
|= LVIF_INDENT
;
6823 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6826 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6827 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6828 !is_text(pItemHdr
->pszText
))
6830 dispInfo
.item
.mask
|= LVIF_TEXT
;
6831 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6832 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6833 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6834 *dispInfo
.item
.pszText
= '\0';
6837 /* If we don't have all the requested info, query the application */
6838 if (dispInfo
.item
.mask
)
6840 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6841 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
6842 dispInfo
.item
.lParam
= lpItem
->lParam
;
6843 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6844 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6847 /* we should not store values for subitems */
6848 if (lpLVItem
->iSubItem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6850 /* Now, handle the iImage field */
6851 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6853 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6854 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6855 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6857 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6859 if (!lpLVItem
->iSubItem
|| (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6860 lpLVItem
->iImage
= pItemHdr
->iImage
;
6862 lpLVItem
->iImage
= 0;
6865 /* The pszText field */
6866 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6868 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6869 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6871 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6873 else if (lpLVItem
->mask
& LVIF_TEXT
)
6875 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6876 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6877 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6880 /* Next is the lParam field */
6881 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6883 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6884 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6885 lpItem
->lParam
= dispInfo
.item
.lParam
;
6887 else if (lpLVItem
->mask
& LVIF_PARAM
)
6888 lpLVItem
->lParam
= lpItem
->lParam
;
6890 /* if this is a subitem, we're done */
6891 if (lpLVItem
->iSubItem
) return TRUE
;
6893 /* ... the state field (this one is different due to uCallbackmask) */
6894 if (lpLVItem
->mask
& LVIF_STATE
)
6896 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6897 if (dispInfo
.item
.mask
& LVIF_STATE
)
6899 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6900 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6902 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6904 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6905 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6906 lpLVItem
->state
|= LVIS_FOCUSED
;
6908 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6910 lpLVItem
->state
&= ~LVIS_SELECTED
;
6911 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6912 lpLVItem
->state
|= LVIS_SELECTED
;
6916 /* and last, but not least, the indent field */
6917 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6919 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6920 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6921 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6923 else if (lpLVItem
->mask
& LVIF_INDENT
)
6925 lpLVItem
->iIndent
= lpItem
->iIndent
;
6933 * Retrieves item attributes.
6936 * [I] hwnd : window handle
6937 * [IO] lpLVItem : item info
6938 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6939 * if FALSE, then lpLVItem is a LPLVITEMA.
6942 * This is the external 'GetItem' interface -- it properly copies
6943 * the text in the provided buffer.
6949 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6954 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6957 pszText
= lpLVItem
->pszText
;
6958 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6959 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6961 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6962 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6964 pszText
= LPSTR_TEXTCALLBACKW
;
6966 lpLVItem
->pszText
= pszText
;
6974 * Retrieves the position (upper-left) of the listview control item.
6975 * Note that for LVS_ICON style, the upper-left is that of the icon
6976 * and not the bounding box.
6979 * [I] infoPtr : valid pointer to the listview structure
6980 * [I] nItem : item index
6981 * [O] lpptPosition : coordinate information
6987 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6991 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6993 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6995 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6996 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6998 if (infoPtr
->uView
== LV_VIEW_ICON
)
7000 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
7001 lpptPosition
->y
+= ICON_TOP_PADDING
;
7003 lpptPosition
->x
+= Origin
.x
;
7004 lpptPosition
->y
+= Origin
.y
;
7006 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
7013 * Retrieves the bounding rectangle for a listview control item.
7016 * [I] infoPtr : valid pointer to the listview structure
7017 * [I] nItem : item index
7018 * [IO] lprc : bounding rectangle coordinates
7019 * lprc->left specifies the portion of the item for which the bounding
7020 * rectangle will be retrieved.
7022 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
7023 * including the icon and label.
7026 * * Experiment shows that native control returns:
7027 * * width = min (48, length of text line)
7028 * * .left = position.x - (width - iconsize.cx)/2
7029 * * .right = .left + width
7030 * * height = #lines of text * ntmHeight + icon height + 8
7031 * * .top = position.y - 2
7032 * * .bottom = .top + height
7033 * * separation between items .y = itemSpacing.cy - height
7034 * * .x = itemSpacing.cx - width
7035 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7038 * * Experiment shows that native control returns:
7039 * * width = iconSize.cx + 16
7040 * * .left = position.x - (width - iconsize.cx)/2
7041 * * .right = .left + width
7042 * * height = iconSize.cy + 4
7043 * * .top = position.y - 2
7044 * * .bottom = .top + height
7045 * * separation between items .y = itemSpacing.cy - height
7046 * * .x = itemSpacing.cx - width
7047 * LVIR_LABEL Returns the bounding rectangle of the item text.
7050 * * Experiment shows that native control returns:
7051 * * width = text length
7052 * * .left = position.x - width/2
7053 * * .right = .left + width
7054 * * height = ntmH * linecount + 2
7055 * * .top = position.y + iconSize.cy + 6
7056 * * .bottom = .top + height
7057 * * separation between items .y = itemSpacing.cy - height
7058 * * .x = itemSpacing.cx - width
7059 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7060 * rectangles, but excludes columns in report view.
7067 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7068 * upon whether the window has the focus currently and on whether the item
7069 * is the one with the focus. Ensure that the control's record of which
7070 * item has the focus agrees with the items' records.
7072 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7074 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7075 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7076 POINT Position
, Origin
;
7080 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7082 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7084 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7085 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7087 /* Be smart and try to figure out the minimum we have to do */
7088 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7089 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7090 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7091 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7092 oversizedBox
= TRUE
;
7094 /* get what we need from the item before hand, so we make
7095 * only one request. This can speed up things, if data
7096 * is stored on the app side */
7098 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7099 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7100 lvItem
.iItem
= nItem
;
7101 lvItem
.iSubItem
= 0;
7102 lvItem
.pszText
= szDispText
;
7103 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7104 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7105 /* we got the state already up, simulate it here, to avoid a reget */
7106 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7108 lvItem
.mask
|= LVIF_STATE
;
7109 lvItem
.stateMask
= LVIS_FOCUSED
;
7110 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7113 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7114 lprc
->left
= LVIR_BOUNDS
;
7120 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7124 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7128 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7131 case LVIR_SELECTBOUNDS
:
7132 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7136 WARN("Unknown value: %d\n", lprc
->left
);
7140 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7142 if (mode
!= LVIR_BOUNDS
)
7143 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7144 Position
.y
+ Origin
.y
);
7146 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7149 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7151 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7158 * Retrieves the spacing between listview control items.
7161 * [I] infoPtr : valid pointer to the listview structure
7162 * [IO] lprc : rectangle to receive the output
7163 * on input, lprc->top = nSubItem
7164 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7166 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7167 * not only those of the first column.
7173 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7175 RECT rect
= { 0, 0, 0, 0 };
7179 if (!lprc
) return FALSE
;
7181 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7182 /* Subitem of '0' means item itself, and this works for all control view modes */
7184 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7186 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7188 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7189 /* this works for any item index, no matter if it exists or not */
7190 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7192 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7195 rect
.bottom
= infoPtr
->nItemHeight
;
7199 /* Native implementation is broken for this case and garbage is left for left and right fields,
7200 we zero them to get predictable output */
7201 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7202 lprc
->bottom
= infoPtr
->nItemHeight
;
7203 OffsetRect(lprc
, origin
.x
, y
);
7204 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7212 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7213 if (infoPtr
->himlSmall
)
7214 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7216 rect
.right
= rect
.left
;
7218 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7226 ERR("Unknown bounds=%d\n", lprc
->left
);
7230 OffsetRect(&rect
, origin
.x
, y
);
7232 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7239 * Retrieves the spacing between listview control items.
7242 * [I] infoPtr : valid pointer to the listview structure
7243 * [I] bSmall : flag for small or large icon
7246 * Horizontal + vertical spacing
7248 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7254 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7258 if (infoPtr
->uView
== LV_VIEW_ICON
)
7259 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7261 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7268 * Retrieves the state of a listview control item.
7271 * [I] infoPtr : valid pointer to the listview structure
7272 * [I] nItem : item index
7273 * [I] uMask : state mask
7276 * State specified by the mask.
7278 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7282 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7284 lvItem
.iItem
= nItem
;
7285 lvItem
.iSubItem
= 0;
7286 lvItem
.mask
= LVIF_STATE
;
7287 lvItem
.stateMask
= uMask
;
7288 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7290 return lvItem
.state
& uMask
;
7295 * Retrieves the text of a listview control item or subitem.
7298 * [I] hwnd : window handle
7299 * [I] nItem : item index
7300 * [IO] lpLVItem : item information
7301 * [I] isW : TRUE if lpLVItem is Unicode
7304 * SUCCESS : string length
7307 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7309 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7311 lpLVItem
->mask
= LVIF_TEXT
;
7312 lpLVItem
->iItem
= nItem
;
7313 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7315 return textlenT(lpLVItem
->pszText
, isW
);
7320 * Searches for an item based on properties + relationships.
7323 * [I] infoPtr : valid pointer to the listview structure
7324 * [I] nItem : item index
7325 * [I] uFlags : relationship flag
7328 * SUCCESS : item index
7331 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7334 LVFINDINFOW lvFindInfo
;
7335 INT nCountPerColumn
;
7339 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7340 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7342 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7344 if (uFlags
& LVNI_CUT
)
7347 if (uFlags
& LVNI_DROPHILITED
)
7348 uMask
|= LVIS_DROPHILITED
;
7350 if (uFlags
& LVNI_FOCUSED
)
7351 uMask
|= LVIS_FOCUSED
;
7353 if (uFlags
& LVNI_SELECTED
)
7354 uMask
|= LVIS_SELECTED
;
7356 /* if we're asked for the focused item, that's only one,
7357 * so it's worth optimizing */
7358 if (uFlags
& LVNI_FOCUSED
)
7360 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7361 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7364 if (uFlags
& LVNI_ABOVE
)
7366 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7371 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7377 /* Special case for autoarrange - move 'til the top of a list */
7378 if (is_autoarrange(infoPtr
))
7380 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7381 while (nItem
- nCountPerRow
>= 0)
7383 nItem
-= nCountPerRow
;
7384 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7389 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7390 lvFindInfo
.vkDirection
= VK_UP
;
7391 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7392 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7394 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7399 else if (uFlags
& LVNI_BELOW
)
7401 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7403 while (nItem
< infoPtr
->nItemCount
)
7406 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7412 /* Special case for autoarrange - move 'til the bottom of a list */
7413 if (is_autoarrange(infoPtr
))
7415 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7416 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7418 nItem
+= nCountPerRow
;
7419 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7424 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7425 lvFindInfo
.vkDirection
= VK_DOWN
;
7426 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7427 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7429 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7434 else if (uFlags
& LVNI_TOLEFT
)
7436 if (infoPtr
->uView
== LV_VIEW_LIST
)
7438 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7439 while (nItem
- nCountPerColumn
>= 0)
7441 nItem
-= nCountPerColumn
;
7442 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7446 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7448 /* Special case for autoarrange - move 'til the beginning of a row */
7449 if (is_autoarrange(infoPtr
))
7451 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7452 while (nItem
% nCountPerRow
> 0)
7455 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7460 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7461 lvFindInfo
.vkDirection
= VK_LEFT
;
7462 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7463 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7465 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7470 else if (uFlags
& LVNI_TORIGHT
)
7472 if (infoPtr
->uView
== LV_VIEW_LIST
)
7474 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7475 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7477 nItem
+= nCountPerColumn
;
7478 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7482 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7484 /* Special case for autoarrange - move 'til the end of a row */
7485 if (is_autoarrange(infoPtr
))
7487 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7488 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7491 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7496 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7497 lvFindInfo
.vkDirection
= VK_RIGHT
;
7498 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7499 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7501 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7510 /* search by index */
7511 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7513 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7521 /* LISTVIEW_GetNumberOfWorkAreas */
7525 * Retrieves the origin coordinates when in icon or small icon display mode.
7528 * [I] infoPtr : valid pointer to the listview structure
7529 * [O] lpptOrigin : coordinate information
7534 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7536 INT nHorzPos
= 0, nVertPos
= 0;
7537 SCROLLINFO scrollInfo
;
7539 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7540 scrollInfo
.fMask
= SIF_POS
;
7542 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7543 nHorzPos
= scrollInfo
.nPos
;
7544 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7545 nVertPos
= scrollInfo
.nPos
;
7547 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7549 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7550 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7551 if (infoPtr
->uView
== LV_VIEW_LIST
)
7552 nHorzPos
*= infoPtr
->nItemWidth
;
7553 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7554 nVertPos
*= infoPtr
->nItemHeight
;
7556 lpptOrigin
->x
-= nHorzPos
;
7557 lpptOrigin
->y
-= nVertPos
;
7559 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7564 * Retrieves the width of a string.
7567 * [I] hwnd : window handle
7568 * [I] lpszText : text string to process
7569 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7572 * SUCCESS : string width (in pixels)
7575 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7580 if (is_text(lpszText
))
7582 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7583 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7584 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7587 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7589 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7590 SelectObject(hdc
, hOldFont
);
7591 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7593 return stringSize
.cx
;
7598 * Determines which listview item is located at the specified position.
7601 * [I] infoPtr : valid pointer to the listview structure
7602 * [IO] lpht : hit test information
7603 * [I] subitem : fill out iSubItem.
7604 * [I] select : return the index only if the hit selects the item
7607 * (mm 20001022): We must not allow iSubItem to be touched, for
7608 * an app might pass only a structure with space up to iItem!
7609 * (MS Office 97 does that for instance in the file open dialog)
7612 * SUCCESS : item index
7615 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7617 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7618 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7619 POINT Origin
, Position
, opt
;
7625 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7629 if (subitem
) lpht
->iSubItem
= 0;
7631 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7633 /* set whole list relation flags */
7634 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7636 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7637 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7638 lpht
->flags
|= LVHT_TOLEFT
;
7640 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7641 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7645 if (infoPtr
->rcList
.bottom
< opt
.y
)
7646 lpht
->flags
|= LVHT_BELOW
;
7650 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7651 lpht
->flags
|= LVHT_TOLEFT
;
7652 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7653 lpht
->flags
|= LVHT_TORIGHT
;
7655 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7656 lpht
->flags
|= LVHT_ABOVE
;
7657 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7658 lpht
->flags
|= LVHT_BELOW
;
7661 /* even if item is invalid try to find subitem */
7662 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7667 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7669 lpht
->iSubItem
= -1;
7670 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7672 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7674 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7680 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7682 /* if we're outside horizontal columns bounds there's nothing to test further */
7683 if (lpht
->iSubItem
== -1)
7686 lpht
->flags
= LVHT_NOWHERE
;
7691 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7692 if (lpht
->flags
) return -1;
7694 lpht
->flags
|= LVHT_NOWHERE
;
7696 /* first deal with the large items */
7697 rcSearch
.left
= lpht
->pt
.x
;
7698 rcSearch
.top
= lpht
->pt
.y
;
7699 rcSearch
.right
= rcSearch
.left
+ 1;
7700 rcSearch
.bottom
= rcSearch
.top
+ 1;
7702 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7703 iterator_next(&i
); /* go to first item in the sequence */
7705 iterator_destroy(&i
);
7707 TRACE("lpht->iItem=%d\n", iItem
);
7708 if (iItem
== -1) return -1;
7710 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7711 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7712 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7713 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7714 lvItem
.iItem
= iItem
;
7715 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7716 lvItem
.pszText
= szDispText
;
7717 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7718 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7719 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7721 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7722 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7723 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7725 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7726 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7728 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7730 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7733 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7734 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7738 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7739 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7741 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7742 if (!PtInRect(&rcBounds
, opt
)) return -1;
7744 /* That's a special case - row rectangle is used as item rectangle and
7745 returned flags contain all item parts. */
7746 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7748 if (PtInRect(&rcIcon
, opt
))
7749 lpht
->flags
|= LVHT_ONITEMICON
;
7750 else if (PtInRect(&rcLabel
, opt
))
7751 lpht
->flags
|= LVHT_ONITEMLABEL
;
7752 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7753 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7754 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7756 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7758 if (lpht
->flags
& LVHT_ONITEM
)
7759 lpht
->flags
&= ~LVHT_NOWHERE
;
7760 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7762 if (select
&& !is_fullrow
)
7764 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7766 /* get main item bounds */
7767 lvItem
.iSubItem
= 0;
7768 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7769 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7770 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7772 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7774 return lpht
->iItem
= iItem
;
7779 * Inserts a new item in the listview control.
7782 * [I] infoPtr : valid pointer to the listview structure
7783 * [I] lpLVItem : item information
7784 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7787 * SUCCESS : new item index
7790 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7797 BOOL is_sorted
, has_changed
;
7799 HWND hwndSelf
= infoPtr
->hwndSelf
;
7801 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7803 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7805 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7806 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7808 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7810 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7812 /* insert item in listview control data structure */
7813 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7814 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7816 /* link with id struct */
7817 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7819 lpID
->item
= hdpaSubItems
;
7820 lpID
->id
= get_next_itemid(infoPtr
);
7821 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7823 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7824 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7826 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7828 /* calculate new item index */
7836 textW
= textdupTtoW(lpLVItem
->pszText
, isW
);
7838 while (i
< infoPtr
->nItemCount
)
7840 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7841 item_s
= DPA_GetPtr(hItem
, 0);
7843 cmpv
= textcmpWT(item_s
->hdr
.pszText
, textW
, TRUE
);
7844 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7846 if (cmpv
>= 0) break;
7850 textfreeT(textW
, isW
);
7855 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7857 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7858 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7859 if (nItem
== -1) goto fail
;
7860 infoPtr
->nItemCount
++;
7862 /* shift indices first so they don't get tangled */
7863 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7865 /* set the item attributes */
7866 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7868 /* full size structure expected - _WIN32IE >= 0x560 */
7871 else if (lpLVItem
->mask
& LVIF_INDENT
)
7873 /* indent member expected - _WIN32IE >= 0x300 */
7874 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7878 /* minimal structure expected */
7879 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7882 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7884 if (item
.mask
& LVIF_STATE
)
7886 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7887 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7888 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7892 item
.mask
|= LVIF_STATE
;
7893 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7894 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7898 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7900 /* make room for the position, if we are in the right mode */
7901 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7903 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7905 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7907 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7912 /* send LVN_INSERTITEM notification */
7913 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7915 nmlv
.lParam
= lpItem
->lParam
;
7916 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7917 if (!IsWindow(hwndSelf
))
7920 /* align items (set position of each item) */
7921 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7925 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7926 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7928 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7930 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7933 /* now is the invalidation fun */
7934 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7938 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7939 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7940 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7941 infoPtr
->nItemCount
--;
7943 DPA_DeletePtr(hdpaSubItems
, 0);
7944 DPA_Destroy (hdpaSubItems
);
7951 * Checks item visibility.
7954 * [I] infoPtr : valid pointer to the listview structure
7955 * [I] nFirst : item index to check for
7958 * Item visible : TRUE
7959 * Item invisible or failure : FALSE
7961 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7963 POINT Origin
, Position
;
7968 TRACE("nItem=%d\n", nItem
);
7970 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7972 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7973 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7974 rcItem
.left
= Position
.x
+ Origin
.x
;
7975 rcItem
.top
= Position
.y
+ Origin
.y
;
7976 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7977 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7979 hdc
= GetDC(infoPtr
->hwndSelf
);
7980 if (!hdc
) return FALSE
;
7981 ret
= RectVisible(hdc
, &rcItem
);
7982 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7989 * Redraws a range of items.
7992 * [I] infoPtr : valid pointer to the listview structure
7993 * [I] nFirst : first item
7994 * [I] nLast : last item
8000 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
8004 for (i
= max(nFirst
, 0); i
<= min(nLast
, infoPtr
->nItemCount
- 1); i
++)
8005 LISTVIEW_InvalidateItem(infoPtr
, i
);
8012 * Scroll the content of a listview.
8015 * [I] infoPtr : valid pointer to the listview structure
8016 * [I] dx : horizontal scroll amount in pixels
8017 * [I] dy : vertical scroll amount in pixels
8024 * If the control is in report view (LV_VIEW_DETAILS) the control can
8025 * be scrolled only in line increments. "dy" will be rounded to the
8026 * nearest number of pixels that are a whole line. Ex: if line height
8027 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
8028 * is passed, then the scroll will be 0. (per MSDN 7/2002)
8030 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8032 switch(infoPtr
->uView
) {
8033 case LV_VIEW_DETAILS
:
8034 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
8035 dy
/= infoPtr
->nItemHeight
;
8038 if (dy
!= 0) return FALSE
;
8044 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8045 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8052 * Sets the background color.
8055 * [I] infoPtr : valid pointer to the listview structure
8056 * [I] color : background color
8062 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8064 TRACE("(color=%x)\n", color
);
8066 if(infoPtr
->clrBk
!= color
) {
8067 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8068 infoPtr
->clrBk
= color
;
8069 if (color
== CLR_NONE
)
8070 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8073 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8074 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8081 /* LISTVIEW_SetBkImage */
8083 /*** Helper for {Insert,Set}ColumnT *only* */
8084 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8085 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8087 if (lpColumn
->mask
& LVCF_FMT
)
8089 /* format member is valid */
8090 lphdi
->mask
|= HDI_FORMAT
;
8092 /* set text alignment (leftmost column must be left-aligned) */
8093 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8094 lphdi
->fmt
|= HDF_LEFT
;
8095 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8096 lphdi
->fmt
|= HDF_RIGHT
;
8097 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8098 lphdi
->fmt
|= HDF_CENTER
;
8100 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8101 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8103 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8105 lphdi
->fmt
|= HDF_IMAGE
;
8106 lphdi
->iImage
= I_IMAGECALLBACK
;
8109 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8110 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8113 if (lpColumn
->mask
& LVCF_WIDTH
)
8115 lphdi
->mask
|= HDI_WIDTH
;
8116 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8118 /* make it fill the remainder of the controls width */
8122 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8124 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8125 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8128 /* retrieve the layout of the header */
8129 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8130 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8132 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8135 lphdi
->cxy
= lpColumn
->cx
;
8138 if (lpColumn
->mask
& LVCF_TEXT
)
8140 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8141 lphdi
->fmt
|= HDF_STRING
;
8142 lphdi
->pszText
= lpColumn
->pszText
;
8143 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8146 if (lpColumn
->mask
& LVCF_IMAGE
)
8148 lphdi
->mask
|= HDI_IMAGE
;
8149 lphdi
->iImage
= lpColumn
->iImage
;
8152 if (lpColumn
->mask
& LVCF_ORDER
)
8154 lphdi
->mask
|= HDI_ORDER
;
8155 lphdi
->iOrder
= lpColumn
->iOrder
;
8162 * Inserts a new column.
8165 * [I] infoPtr : valid pointer to the listview structure
8166 * [I] nColumn : column index
8167 * [I] lpColumn : column information
8168 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8171 * SUCCESS : new column index
8174 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8175 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8177 COLUMN_INFO
*lpColumnInfo
;
8181 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8183 if (!lpColumn
|| nColumn
< 0) return -1;
8184 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8186 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8187 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8190 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8191 * (can be seen in SPY) otherwise column never gets added.
8193 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8194 hdi
.mask
|= HDI_WIDTH
;
8199 * when the iSubItem is available Windows copies it to the header lParam. It seems
8200 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8202 if (lpColumn
->mask
& LVCF_SUBITEM
)
8204 hdi
.mask
|= HDI_LPARAM
;
8205 hdi
.lParam
= lpColumn
->iSubItem
;
8208 /* create header if not present */
8209 LISTVIEW_CreateHeader(infoPtr
);
8210 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8211 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8213 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8216 /* insert item in header control */
8217 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8218 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8219 nColumn
, (LPARAM
)&hdi
);
8220 if (nNewColumn
== -1) return -1;
8221 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8223 /* create our own column info */
8224 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8225 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8227 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8228 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8229 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8232 /* now we have to actually adjust the data */
8233 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8235 SUBITEM_INFO
*lpSubItem
;
8241 item
.iSubItem
= nNewColumn
;
8242 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8243 item
.iImage
= I_IMAGECALLBACK
;
8244 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8246 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8248 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8249 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8251 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8252 if (lpSubItem
->iSubItem
>= nNewColumn
)
8253 lpSubItem
->iSubItem
++;
8256 /* add new subitem for each item */
8258 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8262 /* make space for the new column */
8263 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8264 LISTVIEW_UpdateItemSize(infoPtr
);
8269 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8272 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8280 * Sets the attributes of a header item.
8283 * [I] infoPtr : valid pointer to the listview structure
8284 * [I] nColumn : column index
8285 * [I] lpColumn : column attributes
8286 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8292 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8293 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8295 HDITEMW hdi
, hdiget
;
8298 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8300 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8302 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8303 if (lpColumn
->mask
& LVCF_FMT
)
8305 hdi
.mask
|= HDI_FORMAT
;
8306 hdiget
.mask
= HDI_FORMAT
;
8307 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8308 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8310 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8312 /* set header item attributes */
8313 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8314 if (!bResult
) return FALSE
;
8316 if (lpColumn
->mask
& LVCF_FMT
)
8318 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8319 INT oldFmt
= lpColumnInfo
->fmt
;
8321 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8322 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8324 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8328 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8329 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8336 * Sets the column order array
8339 * [I] infoPtr : valid pointer to the listview structure
8340 * [I] iCount : number of elements in column order array
8341 * [I] lpiArray : pointer to column order array
8347 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8349 if (!infoPtr
->hwndHeader
) return FALSE
;
8350 infoPtr
->colRectsDirty
= TRUE
;
8351 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8356 * Sets the width of a column
8359 * [I] infoPtr : valid pointer to the listview structure
8360 * [I] nColumn : column index
8361 * [I] cx : column width
8367 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8369 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8373 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8375 /* set column width only if in report or list mode */
8376 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8378 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8379 with _USEHEADER being the lowest */
8380 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8381 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8383 /* resize all columns if in LV_VIEW_LIST mode */
8384 if(infoPtr
->uView
== LV_VIEW_LIST
)
8386 infoPtr
->nItemWidth
= cx
;
8387 LISTVIEW_InvalidateList(infoPtr
);
8391 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8393 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8398 lvItem
.mask
= LVIF_TEXT
;
8400 lvItem
.iSubItem
= nColumn
;
8401 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8402 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8404 lvItem
.pszText
= szDispText
;
8405 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8406 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8407 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8409 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8410 max_cx
+= infoPtr
->iconSize
.cx
;
8411 max_cx
+= TRAILING_LABEL_PADDING
;
8412 if (nColumn
== 0 && (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
))
8413 max_cx
+= GetSystemMetrics(SM_CXSMICON
);
8416 /* autosize based on listview items width */
8417 if(cx
== LVSCW_AUTOSIZE
)
8419 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8421 /* if iCol is the last column make it fill the remainder of the controls width */
8422 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8427 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8428 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8430 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8434 /* Despite what the MS docs say, if this is not the last
8435 column, then MS resizes the column to the width of the
8436 largest text string in the column, including headers
8437 and items. This is different from LVSCW_AUTOSIZE in that
8438 LVSCW_AUTOSIZE ignores the header string length. */
8441 /* retrieve header text */
8442 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8443 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8444 hdi
.pszText
= szDispText
;
8445 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8447 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8448 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8449 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8450 INT bitmap_margin
= 0;
8453 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8454 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8456 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8457 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8459 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8461 INT icon_cx
, icon_cy
;
8463 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8464 cx
+= icon_cx
+ 2*bitmap_margin
;
8466 else if (hdi
.fmt
& HDF_BITMAP
)
8470 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8471 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8474 SelectObject(hdc
, old_font
);
8475 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8477 cx
= max (cx
, max_cx
);
8481 if (cx
< 0) return FALSE
;
8483 /* call header to update the column change */
8484 hdi
.mask
= HDI_WIDTH
;
8485 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8486 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8487 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8491 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8494 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8497 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8499 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8500 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8503 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8504 ILC_COLOR
| ILC_MASK
, 2, 2);
8505 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8506 hdc
= CreateCompatibleDC(hdc_wnd
);
8507 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8508 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8509 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8511 SetRect(&rc
, 0, 0, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8512 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8513 FillRect(hdc
, &rc
, hbr_white
);
8514 InflateRect(&rc
, -2, -2);
8515 FillRect(hdc
, &rc
, hbr_black
);
8517 SelectObject(hdc
, hbm_im
);
8518 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8519 SelectObject(hdc
, hbm_orig
);
8520 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8522 SelectObject(hdc
, hbm_im
);
8523 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8524 SelectObject(hdc
, hbm_orig
);
8525 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8527 DeleteObject(hbm_mask
);
8528 DeleteObject(hbm_im
);
8536 * Sets the extended listview style.
8539 * [I] infoPtr : valid pointer to the listview structure
8541 * [I] dwStyle : style
8544 * SUCCESS : previous style
8547 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8549 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8551 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8555 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8557 infoPtr
->dwLvExStyle
= ex_style
;
8559 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8561 HIMAGELIST himl
= 0;
8562 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8565 item
.mask
= LVIF_STATE
;
8566 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8567 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8568 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8570 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8571 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8572 ImageList_Destroy(infoPtr
->himlState
);
8574 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8575 /* checkbox list replaces previous custom list or... */
8576 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8577 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8578 /* ...previous was checkbox list */
8579 (old_ex_style
& LVS_EX_CHECKBOXES
))
8580 ImageList_Destroy(himl
);
8583 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8587 /* if not already created */
8588 LISTVIEW_CreateHeader(infoPtr
);
8590 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8591 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8592 style
|= HDS_DRAGDROP
;
8594 style
&= ~HDS_DRAGDROP
;
8595 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8598 /* GRIDLINES adds decoration at top so changes sizes */
8599 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8601 LISTVIEW_CreateHeader(infoPtr
);
8602 LISTVIEW_UpdateSize(infoPtr
);
8605 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8607 LISTVIEW_CreateHeader(infoPtr
);
8610 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8612 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8613 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8616 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8618 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8619 LISTVIEW_CreateHeader(infoPtr
);
8621 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8622 LISTVIEW_UpdateSize(infoPtr
);
8623 LISTVIEW_UpdateScroll(infoPtr
);
8626 LISTVIEW_InvalidateList(infoPtr
);
8627 return old_ex_style
;
8632 * Sets the new hot cursor used during hot tracking and hover selection.
8635 * [I] infoPtr : valid pointer to the listview structure
8636 * [I] hCursor : the new hot cursor handle
8639 * Returns the previous hot cursor
8641 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8643 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8645 infoPtr
->hHotCursor
= hCursor
;
8653 * Sets the hot item index.
8656 * [I] infoPtr : valid pointer to the listview structure
8657 * [I] iIndex : index
8660 * SUCCESS : previous hot item index
8661 * FAILURE : -1 (no hot item)
8663 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8665 INT iOldIndex
= infoPtr
->nHotItem
;
8667 infoPtr
->nHotItem
= iIndex
;
8675 * Sets the amount of time the cursor must hover over an item before it is selected.
8678 * [I] infoPtr : valid pointer to the listview structure
8679 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8682 * Returns the previous hover time
8684 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8686 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8688 infoPtr
->dwHoverTime
= dwHoverTime
;
8690 return oldHoverTime
;
8695 * Sets spacing for icons of LVS_ICON style.
8698 * [I] infoPtr : valid pointer to the listview structure
8699 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8700 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8703 * MAKELONG(oldcx, oldcy)
8705 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8707 INT iconWidth
= 0, iconHeight
= 0;
8708 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8710 TRACE("requested=(%d,%d)\n", cx
, cy
);
8712 /* set to defaults, if instructed to */
8713 if (cx
== -1 && cy
== -1)
8715 infoPtr
->autoSpacing
= TRUE
;
8716 if (infoPtr
->himlNormal
)
8717 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8718 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8719 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8722 infoPtr
->autoSpacing
= FALSE
;
8724 /* if 0 then keep width */
8726 infoPtr
->iconSpacing
.cx
= cx
;
8728 /* if 0 then keep height */
8730 infoPtr
->iconSpacing
.cy
= cy
;
8732 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8733 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8734 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8735 infoPtr
->ntmHeight
);
8737 /* these depend on the iconSpacing */
8738 LISTVIEW_UpdateItemSize(infoPtr
);
8743 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8747 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8754 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8755 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8764 * [I] infoPtr : valid pointer to the listview structure
8765 * [I] nType : image list type
8766 * [I] himl : image list handle
8769 * SUCCESS : old image list
8772 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8774 INT oldHeight
= infoPtr
->nItemHeight
;
8775 HIMAGELIST himlOld
= 0;
8777 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8782 himlOld
= infoPtr
->himlNormal
;
8783 infoPtr
->himlNormal
= himl
;
8784 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8785 if (infoPtr
->autoSpacing
)
8786 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8790 himlOld
= infoPtr
->himlSmall
;
8791 infoPtr
->himlSmall
= himl
;
8792 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8793 if (infoPtr
->hwndHeader
)
8794 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8798 himlOld
= infoPtr
->himlState
;
8799 infoPtr
->himlState
= himl
;
8800 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8801 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8805 ERR("Unknown icon type=%d\n", nType
);
8809 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8810 if (infoPtr
->nItemHeight
!= oldHeight
)
8811 LISTVIEW_UpdateScroll(infoPtr
);
8818 * Preallocates memory (does *not* set the actual count of items !)
8821 * [I] infoPtr : valid pointer to the listview structure
8822 * [I] nItems : item count (projected number of items to allocate)
8823 * [I] dwFlags : update flags
8829 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8831 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8833 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8835 INT nOldCount
= infoPtr
->nItemCount
;
8836 infoPtr
->nItemCount
= nItems
;
8838 if (nItems
< nOldCount
)
8840 RANGE range
= { nItems
, nOldCount
};
8841 ranges_del(infoPtr
->selectionRanges
, range
);
8842 if (infoPtr
->nFocusedItem
>= nItems
)
8844 LISTVIEW_SetItemFocus(infoPtr
, -1);
8845 infoPtr
->nFocusedItem
= -1;
8846 SetRectEmpty(&infoPtr
->rcFocus
);
8850 LISTVIEW_UpdateScroll(infoPtr
);
8852 /* the flags are valid only in ownerdata report and list modes */
8853 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8855 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8856 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8858 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8859 LISTVIEW_InvalidateList(infoPtr
);
8866 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8867 nFrom
= min(nOldCount
, nItems
);
8868 nTo
= max(nOldCount
, nItems
);
8870 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8872 SetRect(&rcErase
, 0, nFrom
* infoPtr
->nItemHeight
, infoPtr
->nItemWidth
,
8873 nTo
* infoPtr
->nItemHeight
);
8874 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8875 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8876 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8878 else /* LV_VIEW_LIST */
8880 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8882 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8883 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8884 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8885 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8886 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8887 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8888 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8890 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8892 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8893 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8894 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8895 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8896 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8902 /* According to MSDN for non-LVS_OWNERDATA this is just
8903 * a performance issue. The control allocates its internal
8904 * data structures for the number of items specified. It
8905 * cuts down on the number of memory allocations. Therefore
8906 * we will just issue a WARN here
8908 WARN("for non-ownerdata performance option not implemented.\n");
8916 * Sets the position of an item.
8919 * [I] infoPtr : valid pointer to the listview structure
8920 * [I] nItem : item index
8921 * [I] pt : coordinate
8927 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8931 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8933 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8934 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8937 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8939 /* This point value seems to be an undocumented feature.
8940 * The best guess is that it means either at the origin,
8941 * or at true beginning of the list. I will assume the origin. */
8942 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8945 if (infoPtr
->uView
== LV_VIEW_ICON
)
8947 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8948 Pt
.y
-= ICON_TOP_PADDING
;
8953 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8958 * Sets the state of one or many items.
8961 * [I] infoPtr : valid pointer to the listview structure
8962 * [I] nItem : item index
8963 * [I] item : item or subitem info
8969 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8974 if (!item
) return FALSE
;
8976 lvItem
.iItem
= nItem
;
8977 lvItem
.iSubItem
= 0;
8978 lvItem
.mask
= LVIF_STATE
;
8979 lvItem
.state
= item
->state
;
8980 lvItem
.stateMask
= item
->stateMask
;
8981 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8988 /* special case optimization for recurring attempt to deselect all */
8989 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8992 /* select all isn't allowed in LVS_SINGLESEL */
8993 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8996 /* focus all isn't allowed */
8997 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8999 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
9000 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9002 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
9003 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
9004 oldstate
|= LVIS_SELECTED
;
9005 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
9008 /* apply to all items */
9009 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
9010 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
9012 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9016 infoPtr
->notify_mask
|= old_mask
;
9020 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
9021 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
9022 nmlv
.uChanged
= LVIF_STATE
;
9023 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
9026 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
9030 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9037 * Sets the text of an item or subitem.
9040 * [I] hwnd : window handle
9041 * [I] nItem : item index
9042 * [I] lpLVItem : item or subitem info
9043 * [I] isW : TRUE if input is Unicode
9049 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9053 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9054 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9056 lvItem
.iItem
= nItem
;
9057 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9058 lvItem
.mask
= LVIF_TEXT
;
9059 lvItem
.pszText
= lpLVItem
->pszText
;
9060 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9062 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9064 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9069 * Set item index that marks the start of a multiple selection.
9072 * [I] infoPtr : valid pointer to the listview structure
9073 * [I] nIndex : index
9076 * Index number or -1 if there is no selection mark.
9078 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9080 INT nOldIndex
= infoPtr
->nSelectionMark
;
9082 TRACE("(nIndex=%d)\n", nIndex
);
9084 if (nIndex
>= -1 && nIndex
< infoPtr
->nItemCount
)
9085 infoPtr
->nSelectionMark
= nIndex
;
9092 * Sets the text background color.
9095 * [I] infoPtr : valid pointer to the listview structure
9096 * [I] color : text background color
9102 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9104 TRACE("(color=%x)\n", color
);
9106 infoPtr
->clrTextBk
= color
;
9112 * Sets the text foreground color.
9115 * [I] infoPtr : valid pointer to the listview structure
9116 * [I] color : text color
9122 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9124 TRACE("(color=%x)\n", color
);
9126 infoPtr
->clrText
= color
;
9132 * Sets new ToolTip window to ListView control.
9135 * [I] infoPtr : valid pointer to the listview structure
9136 * [I] hwndNewToolTip : handle to new ToolTip
9141 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9143 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9144 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9145 return hwndOldToolTip
;
9150 * sets the Unicode character format flag for the control
9152 * [I] infoPtr :valid pointer to the listview structure
9153 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9156 * Old Unicode Format
9158 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9160 SHORT rc
= infoPtr
->notifyFormat
;
9161 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9162 return rc
== NFR_UNICODE
;
9167 * sets the control view mode
9169 * [I] infoPtr :valid pointer to the listview structure
9170 * [I] nView :new view mode value
9176 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9180 if (infoPtr
->uView
== nView
) return 1;
9182 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9183 if (nView
== LV_VIEW_TILE
)
9185 FIXME("View LV_VIEW_TILE unimplemented\n");
9189 infoPtr
->uView
= nView
;
9191 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9192 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9194 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9195 SetRectEmpty(&infoPtr
->rcFocus
);
9197 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9198 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9203 case LV_VIEW_SMALLICON
:
9204 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9206 case LV_VIEW_DETAILS
:
9211 LISTVIEW_CreateHeader( infoPtr
);
9213 hl
.prc
= &infoPtr
->rcList
;
9215 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9216 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9217 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9224 LISTVIEW_UpdateItemSize(infoPtr
);
9225 LISTVIEW_UpdateSize(infoPtr
);
9226 LISTVIEW_UpdateScroll(infoPtr
);
9227 LISTVIEW_InvalidateList(infoPtr
);
9229 TRACE("nView=%d\n", nView
);
9234 /* LISTVIEW_SetWorkAreas */
9238 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9241 * [I] first : pointer to first ITEM_INFO to compare
9242 * [I] second : pointer to second ITEM_INFO to compare
9243 * [I] lParam : HWND of control
9246 * if first comes before second : negative
9247 * if first comes after second : positive
9248 * if first and second are equivalent : zero
9250 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9252 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9253 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9254 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9256 /* Forward the call to the client defined callback */
9257 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9262 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9265 * [I] first : pointer to first ITEM_INFO to compare
9266 * [I] second : pointer to second ITEM_INFO to compare
9267 * [I] lParam : HWND of control
9270 * if first comes before second : negative
9271 * if first comes after second : positive
9272 * if first and second are equivalent : zero
9274 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9276 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9277 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9278 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9280 /* Forward the call to the client defined callback */
9281 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9286 * Sorts the listview items.
9289 * [I] infoPtr : valid pointer to the listview structure
9290 * [I] pfnCompare : application-defined value
9291 * [I] lParamSort : pointer to comparison callback
9292 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9298 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9299 LPARAM lParamSort
, BOOL IsEx
)
9303 LPVOID selectionMarkItem
= NULL
;
9304 LPVOID focusedItem
= NULL
;
9307 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9309 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9311 if (!pfnCompare
) return FALSE
;
9312 if (!infoPtr
->hdpaItems
) return FALSE
;
9314 /* if there are 0 or 1 items, there is no need to sort */
9315 if (infoPtr
->nItemCount
< 2) return TRUE
;
9317 /* clear selection */
9318 ranges_clear(infoPtr
->selectionRanges
);
9320 /* save selection mark and focused item */
9321 if (infoPtr
->nSelectionMark
>= 0)
9322 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9323 if (infoPtr
->nFocusedItem
>= 0)
9324 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9326 infoPtr
->pfnCompare
= pfnCompare
;
9327 infoPtr
->lParamSort
= lParamSort
;
9329 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9331 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9333 /* restore selection ranges */
9334 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9336 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9337 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9339 if (lpItem
->state
& LVIS_SELECTED
)
9340 ranges_additem(infoPtr
->selectionRanges
, i
);
9342 /* restore selection mark and focused item */
9343 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9344 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9346 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9348 /* refresh the display */
9349 LISTVIEW_InvalidateList(infoPtr
);
9355 * Update theme handle after a theme change.
9358 * [I] infoPtr : valid pointer to the listview structure
9362 * FAILURE : something else
9364 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9366 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9367 CloseThemeData(theme
);
9368 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9374 * Updates an items or rearranges the listview control.
9377 * [I] infoPtr : valid pointer to the listview structure
9378 * [I] nItem : item index
9384 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9386 TRACE("(nItem=%d)\n", nItem
);
9388 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9390 /* rearrange with default alignment style */
9391 if (is_autoarrange(infoPtr
))
9392 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9394 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9401 * Draw the track line at the place defined in the infoPtr structure.
9402 * The line is drawn with a XOR pen so drawing the line for the second time
9403 * in the same place erases the line.
9406 * [I] infoPtr : valid pointer to the listview structure
9412 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9416 if (infoPtr
->xTrackLine
== -1)
9419 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9421 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9422 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9423 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9429 * Called when an edit control should be displayed. This function is called after
9430 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9433 * [I] hwnd : Handle to the listview
9434 * [I] uMsg : WM_TIMER (ignored)
9435 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9436 * [I] dwTimer : The elapsed time (ignored)
9441 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9443 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9444 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9446 KillTimer(hwnd
, idEvent
);
9447 editItem
->fEnabled
= FALSE
;
9448 /* check if the item is still selected */
9449 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9450 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9455 * Creates the listview control - the WM_NCCREATE phase.
9458 * [I] hwnd : window handle
9459 * [I] lpcs : the create parameters
9465 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
9467 LISTVIEW_INFO
*infoPtr
;
9470 TRACE("(lpcs=%p)\n", lpcs
);
9472 /* initialize info pointer */
9473 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9474 if (!infoPtr
) return FALSE
;
9476 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9478 infoPtr
->hwndSelf
= hwnd
;
9479 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9480 map_style_view(infoPtr
);
9481 /* determine the type of structures to use */
9482 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9483 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9485 /* initialize color information */
9486 infoPtr
->clrBk
= CLR_NONE
;
9487 infoPtr
->clrText
= CLR_DEFAULT
;
9488 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9489 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9491 /* set default values */
9492 infoPtr
->nFocusedItem
= -1;
9493 infoPtr
->nSelectionMark
= -1;
9494 infoPtr
->nHotItem
= -1;
9495 infoPtr
->redraw
= TRUE
;
9496 infoPtr
->bNoItemMetrics
= TRUE
;
9497 infoPtr
->notify_mask
= NOTIFY_MASK_UNMASK_ALL
;
9498 infoPtr
->autoSpacing
= TRUE
;
9499 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9500 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9501 infoPtr
->nEditLabelItem
= -1;
9502 infoPtr
->nLButtonDownItem
= -1;
9503 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9504 infoPtr
->cWheelRemainder
= 0;
9505 infoPtr
->nMeasureItemHeight
= 0;
9506 infoPtr
->xTrackLine
= -1; /* no track line */
9507 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9508 infoPtr
->iVersion
= COMCTL32_VERSION
;
9509 infoPtr
->colRectsDirty
= FALSE
;
9511 /* get default font (icon title) */
9512 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9513 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9514 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9515 LISTVIEW_SaveTextMetrics(infoPtr
);
9517 /* allocate memory for the data structure */
9518 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9519 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9520 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9521 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9522 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9523 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9525 return DefWindowProcW(hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
9528 DestroyWindow(infoPtr
->hwndHeader
);
9529 ranges_destroy(infoPtr
->selectionRanges
);
9530 DPA_Destroy(infoPtr
->hdpaItems
);
9531 DPA_Destroy(infoPtr
->hdpaItemIds
);
9532 DPA_Destroy(infoPtr
->hdpaPosX
);
9533 DPA_Destroy(infoPtr
->hdpaPosY
);
9534 DPA_Destroy(infoPtr
->hdpaColumns
);
9541 * Creates the listview control - the WM_CREATE phase. Most of the data is
9542 * already set up in LISTVIEW_NCCreate
9545 * [I] hwnd : window handle
9546 * [I] lpcs : the create parameters
9552 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9554 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9556 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9558 infoPtr
->dwStyle
= lpcs
->style
;
9559 map_style_view(infoPtr
);
9561 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9562 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9563 /* on error defaulting to ANSI notifications */
9564 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9565 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9567 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9569 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9572 infoPtr
->hwndHeader
= 0;
9574 /* init item size to avoid division by 0 */
9575 LISTVIEW_UpdateItemSize (infoPtr
);
9576 LISTVIEW_UpdateSize (infoPtr
);
9578 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9580 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9582 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9584 LISTVIEW_UpdateScroll(infoPtr
);
9585 /* send WM_MEASUREITEM notification */
9586 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9589 OpenThemeData(hwnd
, themeClass
);
9591 /* initialize the icon sizes */
9592 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9593 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9599 * Destroys the listview control.
9602 * [I] infoPtr : valid pointer to the listview structure
9608 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9610 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9611 CloseThemeData(theme
);
9613 /* delete all items */
9614 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9621 * Enables the listview control.
9624 * [I] infoPtr : valid pointer to the listview structure
9625 * [I] bEnable : specifies whether to enable or disable the window
9631 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9633 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9634 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9640 * Erases the background of the listview control.
9643 * [I] infoPtr : valid pointer to the listview structure
9644 * [I] hdc : device context handle
9650 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9654 TRACE("(hdc=%p)\n", hdc
);
9656 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9658 if (infoPtr
->clrBk
== CLR_NONE
)
9660 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9661 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9662 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9664 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9667 /* for double buffered controls we need to do this during refresh */
9668 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9670 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9676 * Helper function for LISTVIEW_[HV]Scroll *only*.
9677 * Performs vertical/horizontal scrolling by a give amount.
9680 * [I] infoPtr : valid pointer to the listview structure
9681 * [I] dx : amount of horizontal scroll
9682 * [I] dy : amount of vertical scroll
9684 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9686 /* now we can scroll the list */
9687 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9688 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9689 /* if we have focus, adjust rect */
9690 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9691 UpdateWindow(infoPtr
->hwndSelf
);
9696 * Performs vertical scrolling.
9699 * [I] infoPtr : valid pointer to the listview structure
9700 * [I] nScrollCode : scroll code
9701 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9702 * [I] hScrollWnd : scrollbar control window handle
9708 * SB_LINEUP/SB_LINEDOWN:
9709 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9710 * for LVS_REPORT is 1 line
9711 * for LVS_LIST cannot occur
9714 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9717 INT nOldScrollPos
, nNewScrollPos
;
9718 SCROLLINFO scrollInfo
;
9721 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9722 debugscrollcode(nScrollCode
), nScrollDiff
);
9724 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9726 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9727 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9729 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9731 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9733 nOldScrollPos
= scrollInfo
.nPos
;
9734 switch (nScrollCode
)
9740 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9744 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9748 nScrollDiff
= -scrollInfo
.nPage
;
9752 nScrollDiff
= scrollInfo
.nPage
;
9755 case SB_THUMBPOSITION
:
9757 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9764 /* quit right away if pos isn't changing */
9765 if (nScrollDiff
== 0) return 0;
9767 /* calculate new position, and handle overflows */
9768 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9769 if (nScrollDiff
> 0) {
9770 if (nNewScrollPos
< nOldScrollPos
||
9771 nNewScrollPos
> scrollInfo
.nMax
)
9772 nNewScrollPos
= scrollInfo
.nMax
;
9774 if (nNewScrollPos
> nOldScrollPos
||
9775 nNewScrollPos
< scrollInfo
.nMin
)
9776 nNewScrollPos
= scrollInfo
.nMin
;
9779 /* set the new position, and reread in case it changed */
9780 scrollInfo
.fMask
= SIF_POS
;
9781 scrollInfo
.nPos
= nNewScrollPos
;
9782 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9784 /* carry on only if it really changed */
9785 if (nNewScrollPos
== nOldScrollPos
) return 0;
9787 /* now adjust to client coordinates */
9788 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9789 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9791 /* and scroll the window */
9792 scroll_list(infoPtr
, 0, nScrollDiff
);
9799 * Performs horizontal scrolling.
9802 * [I] infoPtr : valid pointer to the listview structure
9803 * [I] nScrollCode : scroll code
9804 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9805 * [I] hScrollWnd : scrollbar control window handle
9811 * SB_LINELEFT/SB_LINERIGHT:
9812 * for LVS_ICON, LVS_SMALLICON 1 pixel
9813 * for LVS_REPORT is 1 pixel
9814 * for LVS_LIST is 1 column --> which is a 1 because the
9815 * scroll is based on columns not pixels
9818 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9821 INT nOldScrollPos
, nNewScrollPos
;
9822 SCROLLINFO scrollInfo
;
9825 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9826 debugscrollcode(nScrollCode
), nScrollDiff
);
9828 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9830 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9831 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9833 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9835 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9837 nOldScrollPos
= scrollInfo
.nPos
;
9839 switch (nScrollCode
)
9845 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9849 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9853 nScrollDiff
= -scrollInfo
.nPage
;
9857 nScrollDiff
= scrollInfo
.nPage
;
9860 case SB_THUMBPOSITION
:
9862 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9869 /* quit right away if pos isn't changing */
9870 if (nScrollDiff
== 0) return 0;
9872 /* calculate new position, and handle overflows */
9873 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9874 if (nScrollDiff
> 0) {
9875 if (nNewScrollPos
< nOldScrollPos
||
9876 nNewScrollPos
> scrollInfo
.nMax
)
9877 nNewScrollPos
= scrollInfo
.nMax
;
9879 if (nNewScrollPos
> nOldScrollPos
||
9880 nNewScrollPos
< scrollInfo
.nMin
)
9881 nNewScrollPos
= scrollInfo
.nMin
;
9884 /* set the new position, and reread in case it changed */
9885 scrollInfo
.fMask
= SIF_POS
;
9886 scrollInfo
.nPos
= nNewScrollPos
;
9887 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9889 /* carry on only if it really changed */
9890 if (nNewScrollPos
== nOldScrollPos
) return 0;
9892 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9894 /* now adjust to client coordinates */
9895 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9896 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9898 /* and scroll the window */
9899 scroll_list(infoPtr
, nScrollDiff
, 0);
9904 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9906 INT pulScrollLines
= 3;
9908 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9910 switch(infoPtr
->uView
)
9913 case LV_VIEW_SMALLICON
:
9915 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9916 * should be fixed in the future.
9918 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9919 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9922 case LV_VIEW_DETAILS
:
9923 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9925 /* if scrolling changes direction, ignore left overs */
9926 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9927 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9928 infoPtr
->cWheelRemainder
+= wheelDelta
;
9930 infoPtr
->cWheelRemainder
= wheelDelta
;
9931 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9934 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9935 cLineScroll
= pulScrollLines
* infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9936 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ pulScrollLines
;
9937 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9942 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9953 * [I] infoPtr : valid pointer to the listview structure
9954 * [I] nVirtualKey : virtual key
9955 * [I] lKeyData : key data
9960 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9962 HWND hwndSelf
= infoPtr
->hwndSelf
;
9964 NMLVKEYDOWN nmKeyDown
;
9966 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9968 /* send LVN_KEYDOWN notification */
9969 nmKeyDown
.wVKey
= nVirtualKey
;
9970 nmKeyDown
.flags
= 0;
9971 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9972 if (!IsWindow(hwndSelf
))
9975 switch (nVirtualKey
)
9978 nItem
= infoPtr
->nFocusedItem
;
9979 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9980 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9984 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9986 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9987 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9992 if (infoPtr
->nItemCount
> 0)
9997 if (infoPtr
->nItemCount
> 0)
9998 nItem
= infoPtr
->nItemCount
- 1;
10002 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
10006 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
10010 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
10014 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
10018 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10020 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10021 if (infoPtr
->nFocusedItem
== topidx
)
10022 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
10027 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
10028 * LISTVIEW_GetCountPerRow(infoPtr
);
10029 if(nItem
< 0) nItem
= 0;
10033 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10035 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10036 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10037 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10038 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10040 nItem
= topidx
+ cnt
- 1;
10043 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10044 * LISTVIEW_GetCountPerRow(infoPtr
);
10045 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10049 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10050 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10060 * [I] infoPtr : valid pointer to the listview structure
10065 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10069 /* drop any left over scroll amount */
10070 infoPtr
->cWheelRemainder
= 0;
10072 /* if we did not have the focus, there's nothing more to do */
10073 if (!infoPtr
->bFocus
) return 0;
10075 /* send NM_KILLFOCUS notification */
10076 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10078 /* if we have a focus rectangle, get rid of it */
10079 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10081 /* if have a marquee selection, stop it */
10082 if (infoPtr
->bMarqueeSelect
)
10084 /* Remove the marquee rectangle and release our mouse capture */
10085 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10088 SetRectEmpty(&infoPtr
->marqueeRect
);
10090 infoPtr
->bMarqueeSelect
= FALSE
;
10091 infoPtr
->bScrolling
= FALSE
;
10092 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10095 /* set window focus flag */
10096 infoPtr
->bFocus
= FALSE
;
10098 /* invalidate the selected items before resetting focus flag */
10099 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10106 * Processes double click messages (left mouse button).
10109 * [I] infoPtr : valid pointer to the listview structure
10110 * [I] wKey : key flag
10111 * [I] x,y : mouse coordinate
10116 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10118 LVHITTESTINFO htInfo
;
10120 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10122 /* Cancel the item edition if any */
10123 if (infoPtr
->itemEdit
.fEnabled
)
10125 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10126 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10129 /* send NM_RELEASEDCAPTURE notification */
10130 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10135 /* send NM_DBLCLK notification */
10136 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10137 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10139 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10140 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10145 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10150 r
.top
= r
.bottom
= pt
.y
;
10151 r
.left
= r
.right
= pt
.x
;
10153 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10155 SetCapture(infoPtr
->hwndSelf
);
10159 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10161 if (msg
.message
== WM_MOUSEMOVE
)
10163 pt
.x
= (short)LOWORD(msg
.lParam
);
10164 pt
.y
= (short)HIWORD(msg
.lParam
);
10165 if (PtInRect(&r
, pt
))
10173 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10174 msg
.message
<= WM_RBUTTONDBLCLK
)
10179 DispatchMessageW(&msg
);
10182 if (GetCapture() != infoPtr
->hwndSelf
)
10193 * Processes mouse down messages (left mouse button).
10196 * infoPtr [I ] valid pointer to the listview structure
10197 * wKey [I ] key flag
10198 * x,y [I ] mouse coordinate
10203 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10205 LVHITTESTINFO lvHitTestInfo
;
10206 static BOOL bGroupSelect
= TRUE
;
10207 POINT pt
= { x
, y
};
10210 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10212 /* send NM_RELEASEDCAPTURE notification */
10213 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10215 /* set left button down flag and record the click position */
10216 infoPtr
->bLButtonDown
= TRUE
;
10217 infoPtr
->ptClickPos
= pt
;
10218 infoPtr
->bDragging
= FALSE
;
10219 infoPtr
->bMarqueeSelect
= FALSE
;
10220 infoPtr
->bScrolling
= FALSE
;
10222 lvHitTestInfo
.pt
.x
= x
;
10223 lvHitTestInfo
.pt
.y
= y
;
10225 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10226 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10227 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10229 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10231 notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
);
10232 toggle_checkbox_state(infoPtr
, nItem
);
10233 infoPtr
->bLButtonDown
= FALSE
;
10237 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10239 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10240 infoPtr
->nEditLabelItem
= nItem
;
10242 LISTVIEW_SetSelection(infoPtr
, nItem
);
10246 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10250 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10251 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10252 infoPtr
->nSelectionMark
= nItem
;
10258 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10259 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10261 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10262 infoPtr
->nSelectionMark
= nItem
;
10265 else if (wKey
& MK_CONTROL
)
10269 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10271 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10272 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10273 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10274 infoPtr
->nSelectionMark
= nItem
;
10276 else if (wKey
& MK_SHIFT
)
10278 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10282 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10284 infoPtr
->nEditLabelItem
= nItem
;
10285 infoPtr
->nLButtonDownItem
= nItem
;
10287 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10290 /* set selection (clears other pre-existing selections) */
10291 LISTVIEW_SetSelection(infoPtr
, nItem
);
10295 if (!infoPtr
->bFocus
)
10296 SetFocus(infoPtr
->hwndSelf
);
10298 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10299 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10303 if (!infoPtr
->bFocus
)
10304 SetFocus(infoPtr
->hwndSelf
);
10306 /* remove all selections */
10307 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10308 LISTVIEW_DeselectAll(infoPtr
);
10317 * Processes mouse up messages (left mouse button).
10320 * infoPtr [I ] valid pointer to the listview structure
10321 * wKey [I ] key flag
10322 * x,y [I ] mouse coordinate
10327 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10329 LVHITTESTINFO lvHitTestInfo
;
10331 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10333 if (!infoPtr
->bLButtonDown
) return 0;
10335 lvHitTestInfo
.pt
.x
= x
;
10336 lvHitTestInfo
.pt
.y
= y
;
10338 /* send NM_CLICK notification */
10339 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10340 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10342 /* set left button flag */
10343 infoPtr
->bLButtonDown
= FALSE
;
10345 /* set a single selection, reset others */
10346 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10347 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10348 infoPtr
->nLButtonDownItem
= -1;
10350 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10352 /* Remove the marquee rectangle and release our mouse capture */
10353 if (infoPtr
->bMarqueeSelect
)
10355 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10359 SetRectEmpty(&infoPtr
->marqueeRect
);
10360 SetRectEmpty(&infoPtr
->marqueeDrawRect
);
10362 infoPtr
->bDragging
= FALSE
;
10363 infoPtr
->bMarqueeSelect
= FALSE
;
10364 infoPtr
->bScrolling
= FALSE
;
10366 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10370 /* if we clicked on a selected item, edit the label */
10371 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10373 /* we want to make sure the user doesn't want to do a double click. So we will
10374 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10376 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10377 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10378 SetTimer(infoPtr
->hwndSelf
,
10379 (UINT_PTR
)&infoPtr
->itemEdit
,
10380 GetDoubleClickTime(),
10381 LISTVIEW_DelayedEditItem
);
10389 * Destroys the listview control (called after WM_DESTROY).
10392 * [I] infoPtr : valid pointer to the listview structure
10397 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10403 /* destroy data structure */
10404 DPA_Destroy(infoPtr
->hdpaItems
);
10405 DPA_Destroy(infoPtr
->hdpaItemIds
);
10406 DPA_Destroy(infoPtr
->hdpaPosX
);
10407 DPA_Destroy(infoPtr
->hdpaPosY
);
10409 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10410 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10411 DPA_Destroy(infoPtr
->hdpaColumns
);
10412 ranges_destroy(infoPtr
->selectionRanges
);
10414 /* destroy image lists */
10415 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10417 ImageList_Destroy(infoPtr
->himlNormal
);
10418 ImageList_Destroy(infoPtr
->himlSmall
);
10419 ImageList_Destroy(infoPtr
->himlState
);
10422 /* destroy font, bkgnd brush */
10423 infoPtr
->hFont
= 0;
10424 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10425 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10427 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10429 /* free listview info pointer*/
10437 * Handles notifications.
10440 * [I] infoPtr : valid pointer to the listview structure
10441 * [I] lpnmhdr : notification information
10446 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10450 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10452 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10454 /* remember: HDN_LAST < HDN_FIRST */
10455 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10456 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10458 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10460 switch (lpnmhdr
->code
)
10465 COLUMN_INFO
*lpColumnInfo
;
10469 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10472 /* remove the old line (if any) */
10473 LISTVIEW_DrawTrackLine(infoPtr
);
10475 /* compute & draw the new line */
10476 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10477 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10478 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10479 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10480 LISTVIEW_DrawTrackLine(infoPtr
);
10481 return notify_forward_header(infoPtr
, lpnmh
);
10484 case HDN_ENDTRACKA
:
10485 case HDN_ENDTRACKW
:
10486 /* remove the track line (if any) */
10487 LISTVIEW_DrawTrackLine(infoPtr
);
10488 infoPtr
->xTrackLine
= -1;
10489 return notify_forward_header(infoPtr
, lpnmh
);
10491 case HDN_BEGINDRAG
:
10492 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10493 return notify_forward_header(infoPtr
, lpnmh
);
10496 infoPtr
->colRectsDirty
= TRUE
;
10497 LISTVIEW_InvalidateList(infoPtr
);
10498 return notify_forward_header(infoPtr
, lpnmh
);
10500 case HDN_ITEMCHANGEDW
:
10501 case HDN_ITEMCHANGEDA
:
10503 COLUMN_INFO
*lpColumnInfo
;
10507 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10509 hdi
.mask
= HDI_WIDTH
;
10510 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10514 cxy
= lpnmh
->pitem
->cxy
;
10516 /* determine how much we change since the last know position */
10517 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10518 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10521 lpColumnInfo
->rcHeader
.right
+= dx
;
10523 hdi
.mask
= HDI_ORDER
;
10524 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10526 /* not the rightmost one */
10527 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10529 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10530 hdi
.iOrder
+ 1, 0);
10531 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10535 /* only needs to update the scrolls */
10536 infoPtr
->nItemWidth
+= dx
;
10537 LISTVIEW_UpdateScroll(infoPtr
);
10539 LISTVIEW_UpdateItemSize(infoPtr
);
10540 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10543 RECT rcCol
= lpColumnInfo
->rcHeader
;
10545 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10546 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10548 rcCol
.top
= infoPtr
->rcList
.top
;
10549 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10551 /* resizing left-aligned columns leaves most of the left side untouched */
10552 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10554 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10557 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10560 /* when shrinking the last column clear the now unused field */
10561 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10567 /* deal with right from rightmost column area */
10568 right
.left
= rcCol
.right
;
10569 right
.top
= rcCol
.top
;
10570 right
.bottom
= rcCol
.bottom
;
10571 right
.right
= infoPtr
->rcList
.right
;
10573 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10576 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10582 case HDN_ITEMCLICKW
:
10583 case HDN_ITEMCLICKA
:
10585 /* Handle sorting by Header Column */
10588 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10590 nmlv
.iSubItem
= lpnmh
->iItem
;
10591 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10592 return notify_forward_header(infoPtr
, lpnmh
);
10595 case HDN_DIVIDERDBLCLICKW
:
10596 case HDN_DIVIDERDBLCLICKA
:
10597 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10598 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10599 split needed for that */
10600 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10601 return notify_forward_header(infoPtr
, lpnmh
);
10608 * Paint non-client area of control.
10611 * [I] infoPtr : valid pointer to the listview structureof the sender
10612 * [I] region : update region
10615 * TRUE - frame was painted
10616 * FALSE - call default window proc
10618 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10620 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10624 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10625 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10628 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10630 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10632 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10633 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10634 if (region
!= (HRGN
)1)
10635 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10636 OffsetRect(&r
, -r
.left
, -r
.top
);
10638 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10639 OffsetRect(&r
, -r
.left
, -r
.top
);
10641 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10642 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10643 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10644 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10646 /* Call default proc to get the scrollbars etc. painted */
10647 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10654 * Determines the type of structure to use.
10657 * [I] infoPtr : valid pointer to the listview structureof the sender
10658 * [I] hwndFrom : listview window handle
10659 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10664 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10666 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10668 if (nCommand
== NF_REQUERY
)
10669 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10671 return infoPtr
->notifyFormat
;
10676 * Paints/Repaints the listview control. Internal use.
10679 * [I] infoPtr : valid pointer to the listview structure
10680 * [I] hdc : device context handle
10685 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10687 TRACE("(hdc=%p)\n", hdc
);
10689 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10691 infoPtr
->bNoItemMetrics
= FALSE
;
10692 LISTVIEW_UpdateItemSize(infoPtr
);
10693 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10694 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10695 LISTVIEW_UpdateScroll(infoPtr
);
10698 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10701 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10706 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10707 if (!hdc
) return 1;
10708 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10709 EndPaint(infoPtr
->hwndSelf
, &ps
);
10717 * Paints/Repaints the listview control, WM_PAINT handler.
10720 * [I] infoPtr : valid pointer to the listview structure
10721 * [I] hdc : device context handle
10726 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10728 TRACE("(hdc=%p)\n", hdc
);
10730 if (!is_redrawing(infoPtr
))
10731 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10733 return LISTVIEW_Paint(infoPtr
, hdc
);
10738 * Paints/Repaints the listview control.
10741 * [I] infoPtr : valid pointer to the listview structure
10742 * [I] hdc : device context handle
10743 * [I] options : drawing options
10748 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10750 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10753 if (options
& ~(PRF_ERASEBKGND
|PRF_CLIENT
))
10754 FIXME("(hdc=%p options=0x%08x) partial stub\n", hdc
, options
);
10756 if (options
& PRF_ERASEBKGND
)
10757 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10759 if (options
& PRF_CLIENT
)
10760 LISTVIEW_Paint(infoPtr
, hdc
);
10768 * Processes double click messages (right mouse button).
10771 * [I] infoPtr : valid pointer to the listview structure
10772 * [I] wKey : key flag
10773 * [I] x,y : mouse coordinate
10778 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10780 LVHITTESTINFO lvHitTestInfo
;
10782 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10784 /* send NM_RELEASEDCAPTURE notification */
10785 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10787 /* send NM_RDBLCLK notification */
10788 lvHitTestInfo
.pt
.x
= x
;
10789 lvHitTestInfo
.pt
.y
= y
;
10790 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10791 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10798 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10801 * [I] infoPtr : valid pointer to the listview structure
10802 * [I] wKey : key flag
10803 * [I] x, y : mouse coordinate
10808 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10813 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10815 /* send NM_RELEASEDCAPTURE notification */
10816 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10818 /* determine the index of the selected item */
10821 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10823 /* make sure the listview control window has the focus */
10824 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10826 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10828 LISTVIEW_SetItemFocus(infoPtr
, item
);
10829 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10830 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10831 LISTVIEW_SetSelection(infoPtr
, item
);
10834 LISTVIEW_DeselectAll(infoPtr
);
10836 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10838 if (ht
.iItem
!= -1)
10842 memset(&nmlv
, 0, sizeof(nmlv
));
10843 nmlv
.iItem
= ht
.iItem
;
10844 nmlv
.ptAction
= ht
.pt
;
10846 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10851 SetFocus(infoPtr
->hwndSelf
);
10855 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10857 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10859 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10860 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10861 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10873 * [I] infoPtr : valid pointer to the listview structure
10874 * [I] hwnd : window handle of window containing the cursor
10875 * [I] nHittest : hit-test code
10876 * [I] wMouseMsg : ideintifier of the mouse message
10879 * TRUE if cursor is set
10882 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10884 LVHITTESTINFO lvHitTestInfo
;
10886 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10888 if (!infoPtr
->hHotCursor
) goto forward
;
10890 GetCursorPos(&lvHitTestInfo
.pt
);
10891 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10893 SetCursor(infoPtr
->hHotCursor
);
10899 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10907 * [I] infoPtr : valid pointer to the listview structure
10908 * [I] hwndLoseFocus : handle of previously focused window
10913 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10915 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10917 /* if we have the focus already, there's nothing to do */
10918 if (infoPtr
->bFocus
) return 0;
10920 /* send NM_SETFOCUS notification */
10921 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10923 /* set window focus flag */
10924 infoPtr
->bFocus
= TRUE
;
10926 /* put the focus rect back on */
10927 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10929 /* redraw all visible selected items */
10930 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10940 * [I] infoPtr : valid pointer to the listview structure
10941 * [I] fRedraw : font handle
10942 * [I] fRedraw : redraw flag
10947 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10949 HFONT oldFont
= infoPtr
->hFont
;
10950 INT oldHeight
= infoPtr
->nItemHeight
;
10952 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10954 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10955 if (infoPtr
->hFont
== oldFont
) return 0;
10957 LISTVIEW_SaveTextMetrics(infoPtr
);
10959 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10961 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10963 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10964 LISTVIEW_UpdateSize(infoPtr
);
10965 LISTVIEW_UpdateScroll(infoPtr
);
10967 else if (infoPtr
->nItemHeight
!= oldHeight
)
10968 LISTVIEW_UpdateScroll(infoPtr
);
10970 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10977 * Message handling for WM_SETREDRAW.
10978 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10981 * [I] infoPtr : valid pointer to the listview structure
10982 * [I] redraw: state of redraw flag
10987 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL redraw
)
10989 TRACE("old=%d, new=%d\n", infoPtr
->redraw
, redraw
);
10991 if (infoPtr
->redraw
== !!redraw
)
10994 if (!(infoPtr
->redraw
= !!redraw
))
10997 if (is_autoarrange(infoPtr
))
10998 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10999 LISTVIEW_UpdateScroll(infoPtr
);
11001 /* despite what the WM_SETREDRAW docs says, apps expect us
11002 * to invalidate the listview here... stupid! */
11003 LISTVIEW_InvalidateList(infoPtr
);
11010 * Resizes the listview control. This function processes WM_SIZE
11011 * messages. At this time, the width and height are not used.
11014 * [I] infoPtr : valid pointer to the listview structure
11015 * [I] Width : new width
11016 * [I] Height : new height
11021 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
11023 RECT rcOld
= infoPtr
->rcList
;
11025 TRACE("(width=%d, height=%d)\n", Width
, Height
);
11027 LISTVIEW_UpdateSize(infoPtr
);
11028 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
11030 /* do not bother with display related stuff if we're not redrawing */
11031 if (!is_redrawing(infoPtr
)) return 0;
11033 if (is_autoarrange(infoPtr
))
11034 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11036 LISTVIEW_UpdateScroll(infoPtr
);
11038 /* refresh all only for lists whose height changed significantly */
11039 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11040 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11041 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11042 LISTVIEW_InvalidateList(infoPtr
);
11049 * Sets the size information.
11052 * [I] infoPtr : valid pointer to the listview structure
11057 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11059 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11061 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11063 if (infoPtr
->uView
== LV_VIEW_LIST
)
11065 /* Apparently the "LIST" style is supposed to have the same
11066 * number of items in a column even if there is no scroll bar.
11067 * Since if a scroll bar already exists then the bottom is already
11068 * reduced, only reduce if the scroll bar does not currently exist.
11069 * The "2" is there to mimic the native control. I think it may be
11070 * related to either padding or edges. (GLA 7/2002)
11072 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11073 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11074 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11077 /* When ListView control is created invisible, header isn't created right away. */
11078 if (infoPtr
->hwndHeader
)
11085 LISTVIEW_GetOrigin(infoPtr
, &origin
);
11087 rect
= infoPtr
->rcList
;
11088 rect
.left
+= origin
.x
;
11092 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11093 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11095 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11096 wp
.flags
|= SWP_SHOWWINDOW
;
11099 wp
.flags
|= SWP_HIDEWINDOW
;
11103 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11104 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11106 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11108 /* extra padding for grid */
11109 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11110 infoPtr
->rcList
.top
+= 2;
11112 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11117 * Processes WM_STYLECHANGED messages.
11120 * [I] infoPtr : valid pointer to the listview structure
11121 * [I] wStyleType : window style type (normal or extended)
11122 * [I] lpss : window style information
11127 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11128 const STYLESTRUCT
*lpss
)
11130 UINT uNewView
, uOldView
;
11133 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11134 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11136 if (wStyleType
!= GWL_STYLE
|| lpss
->styleNew
== infoPtr
->dwStyle
) return 0;
11138 infoPtr
->dwStyle
= lpss
->styleNew
;
11140 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11141 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11142 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11144 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11145 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11146 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11148 uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11149 uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11151 if (uNewView
!= uOldView
)
11155 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11156 changing style updates current view only when view bits change. */
11157 map_style_view(infoPtr
);
11158 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11159 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11161 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11162 SetRectEmpty(&infoPtr
->rcFocus
);
11164 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11165 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11167 if (uNewView
== LVS_REPORT
)
11172 LISTVIEW_CreateHeader( infoPtr
);
11174 hl
.prc
= &infoPtr
->rcList
;
11176 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11177 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11178 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11179 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11182 LISTVIEW_UpdateItemSize(infoPtr
);
11185 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11187 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11189 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11191 /* Turn off the header control */
11192 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11193 TRACE("Hide header control, was 0x%08x\n", style
);
11194 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11196 /* Turn on the header control */
11197 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11199 TRACE("Show header control, was 0x%08x\n", style
);
11200 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11206 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11207 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11208 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11210 /* update the size of the client area */
11211 LISTVIEW_UpdateSize(infoPtr
);
11213 /* add scrollbars if needed */
11214 LISTVIEW_UpdateScroll(infoPtr
);
11216 /* invalidate client area + erase background */
11217 LISTVIEW_InvalidateList(infoPtr
);
11224 * Processes WM_STYLECHANGING messages.
11227 * [I] wStyleType : window style type (normal or extended)
11228 * [I0] lpss : window style information
11233 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11236 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11237 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11239 /* don't forward LVS_OWNERDATA only if not already set to */
11240 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11242 if (lpss
->styleOld
& LVS_OWNERDATA
)
11243 lpss
->styleNew
|= LVS_OWNERDATA
;
11245 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11253 * Processes WM_SHOWWINDOW messages.
11256 * [I] infoPtr : valid pointer to the listview structure
11257 * [I] bShown : window is being shown (FALSE when hidden)
11258 * [I] iStatus : window show status
11263 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11265 /* header delayed creation */
11266 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11268 LISTVIEW_CreateHeader(infoPtr
);
11270 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11271 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11274 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11279 * Processes CCM_GETVERSION messages.
11282 * [I] infoPtr : valid pointer to the listview structure
11287 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11289 return infoPtr
->iVersion
;
11294 * Processes CCM_SETVERSION messages.
11297 * [I] infoPtr : valid pointer to the listview structure
11298 * [I] iVersion : version to be set
11301 * -1 when requested version is greater than DLL version;
11302 * previous version otherwise
11304 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11306 INT iOldVersion
= infoPtr
->iVersion
;
11308 if (iVersion
> COMCTL32_VERSION
)
11311 infoPtr
->iVersion
= iVersion
;
11313 TRACE("new version %d\n", iVersion
);
11315 return iOldVersion
;
11320 * Window procedure of the listview control.
11323 static LRESULT WINAPI
11324 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11326 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11328 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11330 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11331 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11335 case LVM_APPROXIMATEVIEWRECT
:
11336 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11337 LOWORD(lParam
), HIWORD(lParam
));
11339 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11341 case LVM_CANCELEDITLABEL
:
11342 return LISTVIEW_CancelEditLabel(infoPtr
);
11344 case LVM_CREATEDRAGIMAGE
:
11345 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11347 case LVM_DELETEALLITEMS
:
11348 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11350 case LVM_DELETECOLUMN
:
11351 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11353 case LVM_DELETEITEM
:
11354 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11356 case LVM_EDITLABELA
:
11357 case LVM_EDITLABELW
:
11358 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11359 uMsg
== LVM_EDITLABELW
);
11360 /* case LVM_ENABLEGROUPVIEW: */
11362 case LVM_ENSUREVISIBLE
:
11363 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11365 case LVM_FINDITEMW
:
11366 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11368 case LVM_FINDITEMA
:
11369 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11371 case LVM_GETBKCOLOR
:
11372 return infoPtr
->clrBk
;
11374 /* case LVM_GETBKIMAGE: */
11376 case LVM_GETCALLBACKMASK
:
11377 return infoPtr
->uCallbackMask
;
11379 case LVM_GETCOLUMNA
:
11380 case LVM_GETCOLUMNW
:
11381 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11382 uMsg
== LVM_GETCOLUMNW
);
11384 case LVM_GETCOLUMNORDERARRAY
:
11385 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11387 case LVM_GETCOLUMNWIDTH
:
11388 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11390 case LVM_GETCOUNTPERPAGE
:
11391 return LISTVIEW_GetCountPerPage(infoPtr
);
11393 case LVM_GETEDITCONTROL
:
11394 return (LRESULT
)infoPtr
->hwndEdit
;
11396 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11397 return infoPtr
->dwLvExStyle
;
11399 /* case LVM_GETGROUPINFO: */
11401 /* case LVM_GETGROUPMETRICS: */
11403 case LVM_GETHEADER
:
11404 return (LRESULT
)infoPtr
->hwndHeader
;
11406 case LVM_GETHOTCURSOR
:
11407 return (LRESULT
)infoPtr
->hHotCursor
;
11409 case LVM_GETHOTITEM
:
11410 return infoPtr
->nHotItem
;
11412 case LVM_GETHOVERTIME
:
11413 return infoPtr
->dwHoverTime
;
11415 case LVM_GETIMAGELIST
:
11416 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11418 /* case LVM_GETINSERTMARK: */
11420 /* case LVM_GETINSERTMARKCOLOR: */
11422 /* case LVM_GETINSERTMARKRECT: */
11424 case LVM_GETISEARCHSTRINGA
:
11425 case LVM_GETISEARCHSTRINGW
:
11426 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11431 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11433 case LVM_GETITEMCOUNT
:
11434 return infoPtr
->nItemCount
;
11436 case LVM_GETITEMPOSITION
:
11437 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11439 case LVM_GETITEMRECT
:
11440 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11442 case LVM_GETITEMSPACING
:
11443 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11445 case LVM_GETITEMSTATE
:
11446 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11448 case LVM_GETITEMTEXTA
:
11449 case LVM_GETITEMTEXTW
:
11450 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11451 uMsg
== LVM_GETITEMTEXTW
);
11453 case LVM_GETNEXTITEM
:
11454 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11456 case LVM_GETNUMBEROFWORKAREAS
:
11457 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11460 case LVM_GETORIGIN
:
11461 if (!lParam
) return FALSE
;
11462 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11463 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11464 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11467 /* case LVM_GETOUTLINECOLOR: */
11469 /* case LVM_GETSELECTEDCOLUMN: */
11471 case LVM_GETSELECTEDCOUNT
:
11472 return LISTVIEW_GetSelectedCount(infoPtr
);
11474 case LVM_GETSELECTIONMARK
:
11475 return infoPtr
->nSelectionMark
;
11477 case LVM_GETSTRINGWIDTHA
:
11478 case LVM_GETSTRINGWIDTHW
:
11479 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11480 uMsg
== LVM_GETSTRINGWIDTHW
);
11482 case LVM_GETSUBITEMRECT
:
11483 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11485 case LVM_GETTEXTBKCOLOR
:
11486 return infoPtr
->clrTextBk
;
11488 case LVM_GETTEXTCOLOR
:
11489 return infoPtr
->clrText
;
11491 /* case LVM_GETTILEINFO: */
11493 /* case LVM_GETTILEVIEWINFO: */
11495 case LVM_GETTOOLTIPS
:
11496 if( !infoPtr
->hwndToolTip
)
11497 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11498 return (LRESULT
)infoPtr
->hwndToolTip
;
11500 case LVM_GETTOPINDEX
:
11501 return LISTVIEW_GetTopIndex(infoPtr
);
11503 case LVM_GETUNICODEFORMAT
:
11504 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11507 return infoPtr
->uView
;
11509 case LVM_GETVIEWRECT
:
11510 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11512 case LVM_GETWORKAREAS
:
11513 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11516 /* case LVM_HASGROUP: */
11519 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11521 case LVM_INSERTCOLUMNA
:
11522 case LVM_INSERTCOLUMNW
:
11523 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11524 uMsg
== LVM_INSERTCOLUMNW
);
11526 /* case LVM_INSERTGROUP: */
11528 /* case LVM_INSERTGROUPSORTED: */
11530 case LVM_INSERTITEMA
:
11531 case LVM_INSERTITEMW
:
11532 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11534 /* case LVM_INSERTMARKHITTEST: */
11536 /* case LVM_ISGROUPVIEWENABLED: */
11538 case LVM_ISITEMVISIBLE
:
11539 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11541 case LVM_MAPIDTOINDEX
:
11542 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11544 case LVM_MAPINDEXTOID
:
11545 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11547 /* case LVM_MOVEGROUP: */
11549 /* case LVM_MOVEITEMTOGROUP: */
11551 case LVM_REDRAWITEMS
:
11552 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11554 /* case LVM_REMOVEALLGROUPS: */
11556 /* case LVM_REMOVEGROUP: */
11559 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11561 case LVM_SETBKCOLOR
:
11562 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11564 /* case LVM_SETBKIMAGE: */
11566 case LVM_SETCALLBACKMASK
:
11567 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11570 case LVM_SETCOLUMNA
:
11571 case LVM_SETCOLUMNW
:
11572 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11573 uMsg
== LVM_SETCOLUMNW
);
11575 case LVM_SETCOLUMNORDERARRAY
:
11576 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11578 case LVM_SETCOLUMNWIDTH
:
11579 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11581 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11582 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11584 /* case LVM_SETGROUPINFO: */
11586 /* case LVM_SETGROUPMETRICS: */
11588 case LVM_SETHOTCURSOR
:
11589 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11591 case LVM_SETHOTITEM
:
11592 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11594 case LVM_SETHOVERTIME
:
11595 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11597 case LVM_SETICONSPACING
:
11599 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11600 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11602 case LVM_SETIMAGELIST
:
11603 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11605 /* case LVM_SETINFOTIP: */
11607 /* case LVM_SETINSERTMARK: */
11609 /* case LVM_SETINSERTMARKCOLOR: */
11614 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11615 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11618 case LVM_SETITEMCOUNT
:
11619 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11621 case LVM_SETITEMPOSITION
:
11624 pt
.x
= (short)LOWORD(lParam
);
11625 pt
.y
= (short)HIWORD(lParam
);
11626 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11629 case LVM_SETITEMPOSITION32
:
11630 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11632 case LVM_SETITEMSTATE
:
11633 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11635 case LVM_SETITEMTEXTA
:
11636 case LVM_SETITEMTEXTW
:
11637 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11638 uMsg
== LVM_SETITEMTEXTW
);
11640 /* case LVM_SETOUTLINECOLOR: */
11642 /* case LVM_SETSELECTEDCOLUMN: */
11644 case LVM_SETSELECTIONMARK
:
11645 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11647 case LVM_SETTEXTBKCOLOR
:
11648 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11650 case LVM_SETTEXTCOLOR
:
11651 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11653 /* case LVM_SETTILEINFO: */
11655 /* case LVM_SETTILEVIEWINFO: */
11657 /* case LVM_SETTILEWIDTH: */
11659 case LVM_SETTOOLTIPS
:
11660 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11662 case LVM_SETUNICODEFORMAT
:
11663 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11666 return LISTVIEW_SetView(infoPtr
, wParam
);
11668 /* case LVM_SETWORKAREAS: */
11670 /* case LVM_SORTGROUPS: */
11672 case LVM_SORTITEMS
:
11673 case LVM_SORTITEMSEX
:
11674 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11675 uMsg
== LVM_SORTITEMSEX
);
11676 case LVM_SUBITEMHITTEST
:
11677 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11680 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11682 case CCM_GETVERSION
:
11683 return LISTVIEW_GetVersion(infoPtr
);
11685 case CCM_SETVERSION
:
11686 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11689 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11692 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11695 return LISTVIEW_NCCreate(hwnd
, wParam
, (LPCREATESTRUCTW
)lParam
);
11698 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11701 return LISTVIEW_Destroy(infoPtr
);
11704 return LISTVIEW_Enable(infoPtr
);
11706 case WM_ERASEBKGND
:
11707 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11709 case WM_GETDLGCODE
:
11710 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11713 return (LRESULT
)infoPtr
->hFont
;
11716 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11719 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11722 return LISTVIEW_KillFocus(infoPtr
);
11724 case WM_LBUTTONDBLCLK
:
11725 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11727 case WM_LBUTTONDOWN
:
11728 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11731 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11734 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11736 case WM_MOUSEHOVER
:
11737 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11740 return LISTVIEW_NCDestroy(infoPtr
);
11743 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11746 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11748 case WM_NOTIFYFORMAT
:
11749 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11751 case WM_PRINTCLIENT
:
11752 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11755 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11757 case WM_RBUTTONDBLCLK
:
11758 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11760 case WM_RBUTTONDOWN
:
11761 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11764 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11767 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11770 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11773 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11775 case WM_SHOWWINDOW
:
11776 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11778 case WM_STYLECHANGED
:
11779 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11781 case WM_STYLECHANGING
:
11782 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11784 case WM_SYSCOLORCHANGE
:
11785 COMCTL32_RefreshSysColors();
11788 /* case WM_TIMER: */
11789 case WM_THEMECHANGED
:
11790 return LISTVIEW_ThemeChanged(infoPtr
);
11793 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11795 case WM_MOUSEWHEEL
:
11796 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11797 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11798 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11800 case WM_WINDOWPOSCHANGED
:
11801 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11803 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11804 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11806 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11808 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11810 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11812 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11814 /* case WM_WININICHANGE: */
11817 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11818 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11820 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11827 * Registers the window class.
11835 void LISTVIEW_Register(void)
11837 WNDCLASSW wndClass
;
11839 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11840 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11841 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11842 wndClass
.cbClsExtra
= 0;
11843 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11844 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11845 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11846 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11847 RegisterClassW(&wndClass
);
11852 * Unregisters the window class.
11860 void LISTVIEW_Unregister(void)
11862 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11867 * Handle any WM_COMMAND messages
11870 * [I] infoPtr : valid pointer to the listview structure
11871 * [I] wParam : the first message parameter
11872 * [I] lParam : the second message parameter
11877 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11880 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11882 if (!infoPtr
->hwndEdit
) return 0;
11884 switch (HIWORD(wParam
))
11889 * Adjust the edit window size
11891 WCHAR buffer
[1024];
11892 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11893 HFONT hFont
, hOldFont
= 0;
11897 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11898 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, ARRAY_SIZE(buffer
));
11899 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11901 /* Select font to get the right dimension of the string */
11902 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11905 hOldFont
= SelectObject(hdc
, hFont
);
11908 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11910 TEXTMETRICW textMetric
;
11912 /* Add Extra spacing for the next character */
11913 GetTextMetricsW(hdc
, &textMetric
);
11914 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11916 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11917 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11920 SelectObject(hdc
, hOldFont
);
11922 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11928 if (infoPtr
->notify_mask
& NOTIFY_MASK_END_LABEL_EDIT
)
11929 LISTVIEW_CancelEditLabel(infoPtr
);
11934 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);