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
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_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
103 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
104 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
105 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
106 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
107 * -- LVM_INSERTGROUPSORTED
108 * -- LVM_INSERTMARKHITTEST
109 * -- LVM_ISGROUPVIEWENABLED
111 * -- LVM_MOVEITEMTOGROUP
113 * -- LVM_SETTILEWIDTH
117 * -- ListView_GetHoverTime, ListView_SetHoverTime
118 * -- ListView_GetISearchString
119 * -- ListView_GetNumberOfWorkAreas
120 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
139 #include "commctrl.h"
140 #include "comctl32.h"
145 #include "wine/debug.h"
147 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
149 typedef struct tagCOLUMN_INFO
151 RECT rcHeader
; /* tracks the header's rectangle */
152 INT fmt
; /* same as LVCOLUMN.fmt */
156 typedef struct tagITEMHDR
160 } ITEMHDR
, *LPITEMHDR
;
162 typedef struct tagSUBITEM_INFO
168 typedef struct tagITEM_ID ITEM_ID
;
170 typedef struct tagITEM_INFO
181 UINT id
; /* item id */
182 HDPA item
; /* link to item data */
185 typedef struct tagRANGE
191 typedef struct tagRANGES
196 typedef struct tagITERATOR
205 typedef struct tagDELAYED_ITEM_EDIT
211 enum notification_mask
213 NOTIFY_MASK_ITEM_CHANGE
= 0x1,
214 NOTIFY_MASK_END_LABEL_EDIT
= 0x2,
215 NOTIFY_MASK_UNMASK_ALL
= 0xffffffff
218 typedef struct tagLISTVIEW_INFO
222 RECT rcList
; /* This rectangle is really the window
223 * client rectangle possibly reduced by the
224 * horizontal scroll bar and/or header - see
225 * LISTVIEW_UpdateSize. This rectangle offset
226 * by the LISTVIEW_GetOrigin value is in
227 * client coordinates */
229 /* notification window */
239 INT nItemCount
; /* the number of items in the list */
240 HDPA hdpaItems
; /* array ITEM_INFO pointers */
241 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
242 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
243 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
244 RANGES selectionRanges
;
245 INT nSelectionMark
; /* item to start next multiselection from */
249 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
250 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
251 INT selected_column
; /* index for LVM_SETSELECTEDCOLUMN/LVM_GETSELECTEDCOLUMN */
254 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
259 DWORD dwStyle
; /* the cached window GWL_STYLE */
260 DWORD dwLvExStyle
; /* extended listview style */
261 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
267 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
270 HIMAGELIST himlNormal
;
271 HIMAGELIST himlSmall
;
272 HIMAGELIST himlState
;
277 POINT currIconPos
; /* this is the position next icon will be placed */
281 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
283 /* marquee selection */
284 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
286 RECT marqueeRect
; /* absolute coordinates of marquee selection */
287 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
288 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
291 BOOL bFocus
; /* control has focus */
293 RECT rcFocus
; /* focus bounds */
305 INT ntmHeight
; /* Some cached metrics of the font used */
306 INT ntmMaxCharWidth
; /* by the listview to draw items */
309 /* mouse operation */
312 POINT ptClickPos
; /* point where the user clicked */
313 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
318 /* keyboard operation */
319 DWORD lastKeyPressTimestamp
;
321 INT nSearchParamLength
;
322 WCHAR szSearchParam
[ MAX_PATH
];
325 BOOL bIsDrawing
; /* Drawing in progress */
326 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
327 BOOL redraw
; /* WM_SETREDRAW switch */
330 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
336 /* How many we debug buffer to allocate */
337 #define DEBUG_BUFFERS 20
338 /* The size of a single debug buffer */
339 #define DEBUG_BUFFER_SIZE 256
341 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
342 #define SB_INTERNAL -1
344 /* maximum size of a label */
345 #define DISP_TEXT_SIZE 260
347 /* padding for items in list and small icon display modes */
348 #define WIDTH_PADDING 12
350 /* padding for items in list, report and small icon display modes */
351 #define HEIGHT_PADDING 1
353 /* offset of items in report display mode */
354 #define REPORT_MARGINX 2
356 /* padding for icon in large icon display mode
357 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
358 * that HITTEST will see.
359 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
360 * ICON_TOP_PADDING - sum of the two above.
361 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
362 * LABEL_HOR_PADDING - between text and sides of box
363 * LABEL_VERT_PADDING - between bottom of text and end of box
365 * ICON_LR_PADDING - additional width above icon size.
366 * ICON_LR_HALF - half of the above value
368 #define ICON_TOP_PADDING_NOTHITABLE 2
369 #define ICON_TOP_PADDING_HITABLE 2
370 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
371 #define ICON_BOTTOM_PADDING 4
372 #define LABEL_HOR_PADDING 5
373 #define LABEL_VERT_PADDING 7
374 #define ICON_LR_PADDING 16
375 #define ICON_LR_HALF (ICON_LR_PADDING/2)
377 /* default label width for items in list and small icon display modes */
378 #define DEFAULT_LABEL_WIDTH 40
379 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
380 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
382 /* default column width for items in list display mode */
383 #define DEFAULT_COLUMN_WIDTH 128
385 /* Size of "line" scroll for V & H scrolls */
386 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
388 /* Padding between image and label */
389 #define IMAGE_PADDING 2
391 /* Padding behind the label */
392 #define TRAILING_LABEL_PADDING 12
393 #define TRAILING_HEADER_PADDING 11
395 /* Border for the icon caption */
396 #define CAPTION_BORDER 2
398 /* Standard DrawText flags */
399 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
400 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
401 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
403 /* Image index from state */
404 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
406 /* The time in milliseconds to reset the search in the list */
407 #define KEY_DELAY 450
409 /* Dump the LISTVIEW_INFO structure to the debug channel */
410 #define LISTVIEW_DUMP(iP) do { \
411 TRACE("hwndSelf=%p, clrBk=%#lx, clrText=%#lx, clrTextBk=%#lx, ItemHeight=%d, ItemWidth=%d, Style=%#lx\n", \
412 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
413 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
414 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=%#lx, Focus=%d\n", \
415 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
416 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
417 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%ld, icSz.cy=%ld, icSp.cx=%ld, icSp.cy=%ld, notifyFmt=%d\n", \
418 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
419 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
420 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
423 static const WCHAR themeClass
[] = L
"ListView";
426 * forward declarations
428 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
429 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
430 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
431 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
432 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
433 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
434 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
435 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
436 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
437 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
438 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
439 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
440 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
441 static VOID
LISTVIEW_SetOwnerDataState(LISTVIEW_INFO
*, INT
, 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=%Id",
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=%Ix, ", 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(" <= %Id\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( length
* (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) );
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
, const NMLVCUSTOMDRAW
*cd
, BOOL SubItem
)
1059 COLORREF backcolor
, textcolor
;
1061 backcolor
= cd
->clrTextBk
;
1062 textcolor
= cd
->clrText
;
1064 /* apparently, for selected items, we have to override the returned values */
1067 if (cd
->nmcd
.uItemState
& CDIS_SELECTED
)
1069 if (infoPtr
->bFocus
)
1071 backcolor
= comctl32_color
.clrHighlight
;
1072 textcolor
= comctl32_color
.clrHighlightText
;
1074 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1076 backcolor
= comctl32_color
.clr3dFace
;
1077 textcolor
= comctl32_color
.clrBtnText
;
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("view %ld\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("view %ld\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(*ranges
));
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(*newrng
));
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(*newrgn
));
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(*newrgn
)))) 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 /* Only send one deselect all (-1) notification for LVS_OWNERDATA style */
3412 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3414 LISTVIEW_SetItemState(infoPtr
, -1, &lvItem
);
3418 /* need to clone the DPA because callbacks can change it */
3419 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3420 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3421 while(iterator_next(&i
))
3422 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3423 /* note that the iterator destructor will free the cloned range */
3424 iterator_destroy(&i
);
3429 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3433 if (!(toSkip
= ranges_create(1))) return FALSE
;
3434 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3435 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3436 ranges_destroy(toSkip
);
3440 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3442 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3447 * Retrieves the number of items that are marked as selected.
3450 * [I] infoPtr : valid pointer to the listview structure
3453 * Number of items selected.
3455 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3457 INT nSelectedCount
= 0;
3459 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3462 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3464 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3469 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3471 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3472 return nSelectedCount
;
3477 * Manages the item focus.
3480 * [I] infoPtr : valid pointer to the listview structure
3481 * [I] nItem : item index
3484 * TRUE : focused item changed
3485 * FALSE : focused item has NOT changed
3487 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3489 INT oldFocus
= infoPtr
->nFocusedItem
;
3492 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3494 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3495 lvItem
.stateMask
= LVIS_FOCUSED
;
3496 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3498 return oldFocus
!= infoPtr
->nFocusedItem
;
3501 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3503 if (nShiftItem
< nItem
) return nShiftItem
;
3505 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3507 if (direction
> 0) return nShiftItem
+ direction
;
3509 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3512 /* This function updates focus index.
3515 focus : current focus index
3516 item : index of item to be added/removed
3517 direction : add/remove flag
3519 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3521 DWORD old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3523 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3524 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3525 if (focus
!= infoPtr
->nFocusedItem
)
3526 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3527 infoPtr
->notify_mask
|= old_mask
;
3532 * Updates the various indices after an item has been inserted or deleted.
3535 * [I] infoPtr : valid pointer to the listview structure
3536 * [I] nItem : item index
3537 * [I] direction : Direction of shift, +1 or -1.
3542 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3544 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3546 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3547 assert(abs(direction
) == 1);
3548 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3550 /* But we are not supposed to modify nHotItem! */
3555 * Adds a block of selections.
3558 * [I] infoPtr : valid pointer to the listview structure
3559 * [I] nItem : item index
3562 * Whether the window is still valid.
3564 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3566 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3567 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3568 HWND hwndSelf
= infoPtr
->hwndSelf
;
3573 /* Temporarily disable change notification
3574 * If the control is LVS_OWNERDATA, we need to send
3575 * only one LVN_ODSTATECHANGED notification.
3576 * See MSDN documentation for LVN_ITEMCHANGED.
3578 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3579 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3580 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3582 if (nFirst
== -1) nFirst
= nItem
;
3584 item
.state
= LVIS_SELECTED
;
3585 item
.stateMask
= LVIS_SELECTED
;
3587 for (i
= nFirst
; i
<= nLast
; i
++)
3588 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3590 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3591 LISTVIEW_SetOwnerDataState(infoPtr
, nFirst
, nLast
, &item
);
3593 if (!IsWindow(hwndSelf
))
3595 infoPtr
->notify_mask
|= old_mask
;
3602 * Sets a single group selection.
3605 * [I] infoPtr : valid pointer to the listview structure
3606 * [I] nItem : item index
3611 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3613 INT nFirst
= -1, nLast
= -1;
3619 if (!(selection
= ranges_create(100))) return;
3621 item
.state
= LVIS_SELECTED
;
3622 item
.stateMask
= LVIS_SELECTED
;
3624 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3626 if (infoPtr
->nSelectionMark
== -1)
3628 infoPtr
->nSelectionMark
= nItem
;
3629 ranges_additem(selection
, nItem
);
3635 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3636 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3637 ranges_add(selection
, sel
);
3642 RECT rcItem
, rcSel
, rcSelMark
;
3645 rcItem
.left
= LVIR_BOUNDS
;
3646 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3647 ranges_destroy (selection
);
3650 rcSelMark
.left
= LVIR_BOUNDS
;
3651 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3652 ranges_destroy (selection
);
3655 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3656 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3657 while(iterator_next(&i
))
3659 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3660 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3662 iterator_destroy(&i
);
3665 /* Disable per item notifications on LVS_OWNERDATA style */
3666 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3667 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3668 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3670 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3672 iterator_rangesitems(&i
, selection
);
3673 while(iterator_next(&i
))
3675 /* Find the range for LVN_ODSTATECHANGED */
3679 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3681 /* this will also destroy the selection */
3682 iterator_destroy(&i
);
3684 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3685 LISTVIEW_SetOwnerDataState(infoPtr
, nFirst
, nLast
, &item
);
3687 infoPtr
->notify_mask
|= old_mask
;
3688 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3693 * Sets a single selection.
3696 * [I] infoPtr : valid pointer to the listview structure
3697 * [I] nItem : item index
3702 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3706 TRACE("nItem=%d\n", nItem
);
3708 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3710 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3711 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3712 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3714 infoPtr
->nSelectionMark
= nItem
;
3719 * Set selection(s) with keyboard.
3722 * [I] infoPtr : valid pointer to the listview structure
3723 * [I] nItem : item index
3724 * [I] space : VK_SPACE code sent
3727 * SUCCESS : TRUE (needs to be repainted)
3728 * FAILURE : FALSE (nothing has changed)
3730 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3732 /* FIXME: pass in the state */
3733 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3734 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3735 BOOL bResult
= FALSE
;
3737 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3738 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3742 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3743 LISTVIEW_SetSelection(infoPtr
, nItem
);
3747 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3751 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3752 lvItem
.stateMask
= LVIS_SELECTED
;
3755 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3756 if (lvItem
.state
& LVIS_SELECTED
)
3757 infoPtr
->nSelectionMark
= nItem
;
3759 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3762 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3765 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3769 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3771 LVHITTESTINFO lvHitTestInfo
;
3773 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3774 lvHitTestInfo
.pt
.x
= pt
.x
;
3775 lvHitTestInfo
.pt
.y
= pt
.y
;
3777 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3779 lpLVItem
->mask
= LVIF_PARAM
;
3780 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3781 lpLVItem
->iSubItem
= 0;
3783 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3786 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3788 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3789 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3790 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3795 * Called when the mouse is being actively tracked and has hovered for a specified
3799 * [I] infoPtr : valid pointer to the listview structure
3800 * [I] fwKeys : key indicator
3801 * [I] x,y : mouse position
3804 * 0 if the message was processed, non-zero if there was an error
3807 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3808 * over the item for a certain period of time.
3811 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3815 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3817 if (LISTVIEW_IsHotTracking(infoPtr
))
3825 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3826 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3828 SetFocus(infoPtr
->hwndSelf
);
3834 #define SCROLL_LEFT 0x1
3835 #define SCROLL_RIGHT 0x2
3836 #define SCROLL_UP 0x4
3837 #define SCROLL_DOWN 0x8
3841 * Utility routine to draw and highlight items within a marquee selection rectangle.
3844 * [I] infoPtr : valid pointer to the listview structure
3845 * [I] coords_orig : original co-ordinates of the cursor
3846 * [I] coords_offs : offsetted coordinates of the cursor
3847 * [I] offset : offset amount
3848 * [I] scroll : Bitmask of which directions we should scroll, if at all
3853 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3856 BOOL controlDown
= FALSE
;
3858 ITERATOR old_elems
, new_elems
;
3860 POINT coords_offs
, offset
;
3862 /* Ensure coordinates are within client bounds */
3863 coords_offs
.x
= max(min(coords_orig
->x
, infoPtr
->rcList
.right
), 0);
3864 coords_offs
.y
= max(min(coords_orig
->y
, infoPtr
->rcList
.bottom
), 0);
3867 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3869 /* Offset coordinates by the appropriate amount */
3870 coords_offs
.x
-= offset
.x
;
3871 coords_offs
.y
-= offset
.y
;
3873 if (coords_offs
.x
> infoPtr
->marqueeOrigin
.x
)
3875 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3876 rect
.right
= coords_offs
.x
;
3880 rect
.left
= coords_offs
.x
;
3881 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3884 if (coords_offs
.y
> infoPtr
->marqueeOrigin
.y
)
3886 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3887 rect
.bottom
= coords_offs
.y
;
3891 rect
.top
= coords_offs
.y
;
3892 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3895 /* Cancel out the old marquee rectangle and draw the new one */
3896 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3898 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3899 the cursor is further away */
3901 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3902 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3904 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3905 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3907 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3908 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3910 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3911 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3913 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3915 infoPtr
->marqueeRect
= rect
;
3916 infoPtr
->marqueeDrawRect
= rect
;
3917 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
.x
, offset
.y
);
3919 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3920 iterator_remove_common_items(&old_elems
, &new_elems
);
3922 /* Iterate over no longer selected items */
3923 while (iterator_next(&old_elems
))
3925 if (old_elems
.nItem
> -1)
3927 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3930 item
.state
= LVIS_SELECTED
;
3932 item
.stateMask
= LVIS_SELECTED
;
3934 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3937 iterator_destroy(&old_elems
);
3940 /* Iterate over newly selected items */
3941 if (GetKeyState(VK_CONTROL
) & 0x8000)
3944 while (iterator_next(&new_elems
))
3946 if (new_elems
.nItem
> -1)
3948 /* If CTRL is pressed, invert. If not, always select the item. */
3949 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3952 item
.state
= LVIS_SELECTED
;
3954 item
.stateMask
= LVIS_SELECTED
;
3956 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3959 iterator_destroy(&new_elems
);
3961 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3966 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3967 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3970 * [I] hwnd : Handle to the listview
3971 * [I] uMsg : WM_TIMER (ignored)
3972 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3973 * [I] dwTimer : The elapsed time (ignored)
3978 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3980 LISTVIEW_INFO
*infoPtr
;
3981 SCROLLINFO scrollInfo
;
3985 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3990 /* Get the current cursor position and convert to client coordinates */
3991 GetCursorPos(&coords
);
3992 ScreenToClient(hWnd
, &coords
);
3994 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3995 scrollInfo
.fMask
= SIF_ALL
;
3997 /* Work out in which directions we can scroll */
3998 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4000 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
4001 scroll
|= SCROLL_UP
;
4003 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
4004 scroll
|= SCROLL_DOWN
;
4007 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4009 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
4010 scroll
|= SCROLL_LEFT
;
4012 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
4013 scroll
|= SCROLL_RIGHT
;
4016 if (((coords
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
4017 ((coords
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
4018 ((coords
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
4019 ((coords
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
4021 LISTVIEW_MarqueeHighlight(infoPtr
, &coords
, scroll
);
4027 * Called whenever WM_MOUSEMOVE is received.
4030 * [I] infoPtr : valid pointer to the listview structure
4031 * [I] fwKeys : key indicator
4032 * [I] x,y : mouse position
4035 * 0 if the message is processed, non-zero if there was an error
4037 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4046 if (!(fwKeys
& MK_LBUTTON
))
4047 infoPtr
->bLButtonDown
= FALSE
;
4049 if (infoPtr
->bLButtonDown
)
4051 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4052 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4054 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4056 if (infoPtr
->bMarqueeSelect
)
4058 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4059 move the mouse again */
4061 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4062 (y
>= infoPtr
->rcList
.bottom
))
4064 if (!infoPtr
->bScrolling
)
4066 infoPtr
->bScrolling
= TRUE
;
4067 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4072 infoPtr
->bScrolling
= FALSE
;
4073 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4076 LISTVIEW_MarqueeHighlight(infoPtr
, &pt
, 0);
4081 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4083 /* reset item marker */
4084 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4085 infoPtr
->nLButtonDownItem
= -1;
4087 if (!PtInRect(&rect
, pt
))
4089 /* this path covers the following:
4090 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4091 2. change focus with keys
4092 3. move mouse over item from step 1 selects it and moves focus on it */
4093 if (infoPtr
->nLButtonDownItem
!= -1 &&
4094 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4098 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4099 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4101 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4102 infoPtr
->nLButtonDownItem
= -1;
4105 if (!infoPtr
->bDragging
)
4107 ht
.pt
= infoPtr
->ptClickPos
;
4108 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4110 /* If the click is outside the range of an item, begin a
4111 highlight. If not, begin an item drag. */
4116 /* If we're allowing multiple selections, send notification.
4117 If return value is non-zero, cancel. */
4118 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4120 /* Store the absolute coordinates of the click */
4122 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4124 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4125 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4127 /* Begin selection and capture mouse */
4128 infoPtr
->bMarqueeSelect
= TRUE
;
4129 infoPtr
->marqueeRect
= rect
;
4130 SetCapture(infoPtr
->hwndSelf
);
4137 ZeroMemory(&nmlv
, sizeof(nmlv
));
4138 nmlv
.iItem
= ht
.iItem
;
4139 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4141 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4142 infoPtr
->bDragging
= TRUE
;
4150 /* see if we are supposed to be tracking mouse hovering */
4151 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4152 TRACKMOUSEEVENT trackinfo
;
4155 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4156 trackinfo
.dwFlags
= TME_QUERY
;
4158 /* see if we are already tracking this hwnd */
4159 _TrackMouseEvent(&trackinfo
);
4162 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
4165 if((trackinfo
.dwFlags
& flags
) != flags
|| trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4166 trackinfo
.dwFlags
= flags
;
4167 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4168 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4170 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4171 _TrackMouseEvent(&trackinfo
);
4180 * Tests whether the item is assignable to a list with style lStyle
4182 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4184 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4185 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4186 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4194 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4197 * [I] infoPtr : valid pointer to the listview structure
4198 * [I] lpLVItem : valid pointer to new item attributes
4199 * [I] isNew : the item being set is being inserted
4200 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4201 * [O] bChanged : will be set to TRUE if the item really changed
4207 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4213 /* stateMask is ignored for LVM_INSERTITEM */
4214 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4215 BOOL send_change_notification
;
4219 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4221 if (lpLVItem
->mask
== 0) return TRUE
;
4223 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4225 /* a virtual listview only stores selection and focus */
4226 if (lpLVItem
->mask
& ~LVIF_STATE
)
4232 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4233 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4237 /* we need to get the lParam and state of the item */
4238 item
.iItem
= lpLVItem
->iItem
;
4239 item
.iSubItem
= lpLVItem
->iSubItem
;
4240 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4241 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4245 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4247 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4248 /* determine what fields will change */
4249 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4250 uChanged
|= LVIF_STATE
;
4252 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4253 uChanged
|= LVIF_IMAGE
;
4255 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4256 uChanged
|= LVIF_PARAM
;
4258 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4259 uChanged
|= LVIF_INDENT
;
4261 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4262 uChanged
|= LVIF_TEXT
;
4264 TRACE("change mask=0x%x\n", uChanged
);
4266 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4267 nmlv
.iItem
= lpLVItem
->iItem
;
4268 if (lpLVItem
->mask
& LVIF_STATE
)
4270 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4271 nmlv
.uOldState
= item
.state
;
4273 nmlv
.uChanged
= isNew
? LVIF_STATE
: (uChanged
? uChanged
: lpLVItem
->mask
);
4274 nmlv
.lParam
= item
.lParam
;
4276 /* Send change notification if the item is not being inserted, or inserted (selected|focused),
4277 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4278 are enabled. Even if nothing really changed we still need to send this,
4279 in this case uChanged mask is just set to passed item mask. */
4281 send_change_notification
= !isNew
;
4282 send_change_notification
|= (uChanged
& LVIF_STATE
) && (lpLVItem
->state
& (LVIS_FOCUSED
| LVIS_SELECTED
));
4283 send_change_notification
&= !!(infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
);
4285 if (lpItem
&& send_change_notification
)
4287 HWND hwndSelf
= infoPtr
->hwndSelf
;
4289 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4291 if (!IsWindow(hwndSelf
))
4295 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4296 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4297 /* this means we won't hit a focus change path later */
4298 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4300 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4301 infoPtr
->nFocusedItem
++;
4304 if (!uChanged
) return TRUE
;
4307 /* copy information */
4308 if (lpLVItem
->mask
& LVIF_TEXT
)
4309 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4311 if (lpLVItem
->mask
& LVIF_IMAGE
)
4312 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4314 if (lpLVItem
->mask
& LVIF_PARAM
)
4315 lpItem
->lParam
= lpLVItem
->lParam
;
4317 if (lpLVItem
->mask
& LVIF_INDENT
)
4318 lpItem
->iIndent
= lpLVItem
->iIndent
;
4320 if (uChanged
& LVIF_STATE
)
4322 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4324 lpItem
->state
&= ~stateMask
;
4325 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4327 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4329 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4330 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4332 else if (stateMask
& LVIS_SELECTED
)
4334 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4336 /* If we are asked to change focus, and we manage it, do it.
4337 It's important to have all new item data stored at this point,
4338 because changing existing focus could result in a redrawing operation,
4339 which in turn could ask for disp data, application should see all data
4340 for inserted item when processing LVN_GETDISPINFO.
4342 The way this works application will see nested item change notifications -
4343 changed item notifications interrupted by ones from item losing focus. */
4344 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4346 if (lpLVItem
->state
& LVIS_FOCUSED
)
4348 /* update selection mark */
4349 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4350 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4352 if (infoPtr
->nFocusedItem
!= -1)
4354 /* remove current focus */
4355 item
.mask
= LVIF_STATE
;
4357 item
.stateMask
= LVIS_FOCUSED
;
4359 /* recurse with redrawing an item */
4360 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4363 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4364 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4366 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4368 infoPtr
->nFocusedItem
= -1;
4373 if (send_change_notification
)
4375 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4376 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4384 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4387 * [I] infoPtr : valid pointer to the listview structure
4388 * [I] lpLVItem : valid pointer to new subitem attributes
4389 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4390 * [O] bChanged : will be set to TRUE if the item really changed
4396 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4399 SUBITEM_INFO
*lpSubItem
;
4401 /* we do not support subitems for virtual listviews */
4402 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4404 /* set subitem only if column is present */
4405 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4407 /* First do some sanity checks */
4408 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4409 particularly useful. We currently do not actually do anything with
4410 the flag on subitems.
4412 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4413 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4415 /* get the subitem structure, and create it if not there */
4416 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4417 assert (hdpaSubItems
);
4419 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4422 SUBITEM_INFO
*tmpSubItem
;
4425 lpSubItem
= Alloc(sizeof(*lpSubItem
));
4426 if (!lpSubItem
) return FALSE
;
4427 /* we could binary search here, if need be...*/
4428 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4430 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4431 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4433 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4438 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4439 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4443 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4445 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4449 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4451 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4460 * Sets item attributes.
4463 * [I] infoPtr : valid pointer to the listview structure
4464 * [I] lpLVItem : new item attributes
4465 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4471 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4473 HWND hwndSelf
= infoPtr
->hwndSelf
;
4474 LPWSTR pszText
= NULL
;
4475 BOOL bResult
, bChanged
= FALSE
;
4478 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4480 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4483 /* Store old item area */
4484 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4486 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4487 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4489 pszText
= lpLVItem
->pszText
;
4490 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4493 /* actually set the fields */
4494 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4496 if (lpLVItem
->iSubItem
)
4497 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4499 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4500 if (!IsWindow(hwndSelf
))
4503 /* redraw item, if necessary */
4504 if (bChanged
&& !infoPtr
->bIsDrawing
)
4506 /* this little optimization eliminates some nasty flicker */
4507 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4508 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4509 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4510 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4513 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4514 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4520 textfreeT(lpLVItem
->pszText
, isW
);
4521 lpLVItem
->pszText
= pszText
;
4529 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4532 * [I] infoPtr : valid pointer to the listview structure
4537 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4540 SCROLLINFO scrollInfo
;
4542 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4543 scrollInfo
.fMask
= SIF_POS
;
4545 if (infoPtr
->uView
== LV_VIEW_LIST
)
4547 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4548 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4550 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4552 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4553 nItem
= scrollInfo
.nPos
;
4557 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4558 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4561 TRACE("nItem=%d\n", nItem
);
4566 static void LISTVIEW_DrawBackgroundBitmap(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4570 if (!infoPtr
->hBkBitmap
)
4573 TRACE("(hdc=%p, lprcBox=%s, hBkBitmap=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBitmap
);
4575 mem_hdc
= CreateCompatibleDC(hdc
);
4576 SelectObject(mem_hdc
, infoPtr
->hBkBitmap
);
4577 BitBlt(hdc
, lprcBox
->left
, lprcBox
->top
, lprcBox
->right
- lprcBox
->left
,
4578 lprcBox
->bottom
- lprcBox
->top
, mem_hdc
, lprcBox
->left
, lprcBox
->top
, SRCCOPY
);
4584 * Erases the background of the given rectangle
4587 * [I] infoPtr : valid pointer to the listview structure
4588 * [I] hdc : device context handle
4589 * [I] lprcBox : clipping rectangle
4595 static BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4597 if (infoPtr
->hBkBrush
)
4599 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4601 FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4604 LISTVIEW_DrawBackgroundBitmap(infoPtr
, hdc
, lprcBox
);
4608 /* Draw main item or subitem */
4609 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4611 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4612 const RECT
*background
;
4617 /* now check if we need to update the focus rectangle */
4618 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4619 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4621 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4622 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4623 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4624 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4625 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4626 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4627 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4628 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4629 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4631 /* FIXME: temporary hack */
4632 rcSelect
.left
= rcLabel
.left
;
4634 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4636 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4637 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4638 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4639 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4640 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4643 /* in icon mode, the label rect is really what we want to draw the
4645 /* in detail mode, we want to paint background for label rect when
4646 * item is not selected or listview has full row select; otherwise paint
4647 * background for text only */
4648 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4649 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4650 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4651 background
= &rcLabel
;
4653 background
= &rcSelect
;
4655 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4656 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4658 if (item
->state
& LVIS_FOCUSED
)
4660 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4662 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4664 /* we have to update left focus bound too if item isn't in leftmost column
4665 and reduce right box bound */
4666 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4670 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4672 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4673 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4674 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4676 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4677 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4680 rcSelect
.right
= rcBox
.right
;
4682 infoPtr
->rcFocus
= rcSelect
;
4685 infoPtr
->rcFocus
= rcLabel
;
4689 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4691 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4694 TRACE("stateimage=%d\n", stateimage
);
4695 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4700 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4701 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4705 TRACE("iImage=%d\n", item
->iImage
);
4707 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4708 style
= ILD_SELECTED
;
4712 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4713 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4714 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4715 style
| (item
->state
& LVIS_OVERLAYMASK
));
4718 /* Don't bother painting item being edited */
4719 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4721 /* figure out the text drawing flags */
4722 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4723 if (infoPtr
->uView
== LV_VIEW_ICON
)
4724 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4725 else if (item
->iSubItem
)
4727 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4729 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4730 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4731 default: format
|= DT_LEFT
;
4734 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4736 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4737 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4739 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4741 /* for GRIDLINES reduce the bottom so the text formats correctly */
4742 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4745 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4753 * [I] infoPtr : valid pointer to the listview structure
4754 * [I] hdc : device context handle
4755 * [I] nItem : item index
4756 * [I] nSubItem : subitem index
4757 * [I] pos : item position in client coordinates
4758 * [I] cdmode : custom draw mode
4764 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4766 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4767 static WCHAR callbackW
[] = L
"(callback)";
4768 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4770 NMLVCUSTOMDRAW nmlvcd
;
4773 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4775 /* get information needed for drawing the item */
4776 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4777 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4778 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4779 lvItem
.iItem
= nItem
;
4780 lvItem
.iSubItem
= 0;
4783 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4784 lvItem
.pszText
= szDispText
;
4785 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4786 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4787 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4789 /* now check if we need to update the focus rectangle */
4790 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4791 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4793 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4794 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4796 /* Full custom draw stage sequence looks like this:
4801 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4802 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item itself
4803 - CDDS_ITEMPOSTPAINT
4808 - CDDS_ITEMPOSTPAINT
4811 /* fill in the custom draw structure */
4812 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4813 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4814 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4815 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4819 while (iterator_next(subitems
))
4821 DWORD subitemstage
= CDRF_DODEFAULT
;
4823 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4824 if (subitems
->nItem
)
4826 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4827 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4828 lvItem
.iItem
= nItem
;
4829 lvItem
.iSubItem
= subitems
->nItem
;
4832 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4833 lvItem
.pszText
= szDispText
;
4835 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4836 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4837 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4838 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4839 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4841 /* update custom draw data */
4842 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4843 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4844 nmlvcd
.iSubItem
= subitems
->nItem
;
4847 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4848 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4850 if (subitems
->nItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4851 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4852 else if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4853 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4855 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4856 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4858 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4859 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4864 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4865 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4869 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4871 nmlvcd
.iSubItem
= 0;
4872 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4880 * Draws listview items when in owner draw mode.
4883 * [I] infoPtr : valid pointer to the listview structure
4884 * [I] hdc : device context handle
4889 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4891 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4892 DWORD cditemmode
= CDRF_DODEFAULT
;
4893 NMLVCUSTOMDRAW nmlvcd
;
4894 POINT Origin
, Position
;
4900 ZeroMemory(&dis
, sizeof(dis
));
4902 /* Get scroll info once before loop */
4903 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4905 /* iterate through the invalidated rows */
4906 while(iterator_next(i
))
4908 item
.iItem
= i
->nItem
;
4910 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4911 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4912 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4914 dis
.CtlType
= ODT_LISTVIEW
;
4916 dis
.itemID
= item
.iItem
;
4917 dis
.itemAction
= ODA_DRAWENTIRE
;
4919 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4920 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4921 dis
.hwndItem
= infoPtr
->hwndSelf
;
4923 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4924 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4925 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4926 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4927 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4928 dis
.itemData
= item
.lParam
;
4930 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4933 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4934 * structure for the rest. of the paint cycle
4936 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4937 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4938 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4940 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4942 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4943 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4946 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4947 notify_postpaint(infoPtr
, &nmlvcd
);
4953 * Draws listview items when in report display mode.
4956 * [I] infoPtr : valid pointer to the listview structure
4957 * [I] hdc : device context handle
4958 * [I] cdmode : custom draw mode
4963 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4966 RECT rcClip
, rcItem
;
4974 /* figure out what to draw */
4975 rgntype
= GetClipBox(hdc
, &rcClip
);
4976 if (rgntype
== NULLREGION
) return;
4978 /* Get scroll info once before loop */
4979 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4981 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4983 /* narrow down the columns we need to paint */
4984 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4986 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4988 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4989 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4990 ranges_additem(colRanges
, index
);
4992 iterator_rangesitems(&j
, colRanges
);
4994 /* in full row select, we _have_ to draw the main item */
4995 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4998 /* iterate through the invalidated rows */
4999 while(iterator_next(i
))
5005 SelectObject(hdc
, infoPtr
->hFont
);
5006 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5007 Position
.x
= Origin
.x
;
5008 Position
.y
+= Origin
.y
;
5010 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5012 /* iterate through the invalidated columns */
5013 while(iterator_next(&j
))
5015 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5017 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
5020 rcItem
.bottom
= infoPtr
->nItemHeight
;
5021 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
5022 if (!RectVisible(hdc
, &rcItem
)) continue;
5025 ranges_additem(subitems
, j
.nItem
);
5028 iterator_rangesitems(&k
, subitems
);
5029 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
5030 iterator_destroy(&k
);
5032 iterator_destroy(&j
);
5037 * Draws the gridlines if necessary when in report display mode.
5040 * [I] infoPtr : valid pointer to the listview structure
5041 * [I] hdc : device context handle
5046 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
5052 RECT rcClip
, rcItem
= {0};
5060 /* figure out what to draw */
5061 rgntype
= GetClipBox(hdc
, &rcClip
);
5062 if (rgntype
== NULLREGION
) return;
5064 /* Get scroll info once before loop */
5065 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5067 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5069 /* narrow down the columns we need to paint */
5070 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5072 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5074 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5075 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5076 ranges_additem(colRanges
, index
);
5079 /* is right most vertical line visible? */
5080 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5082 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5083 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5084 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5087 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5089 hOldPen
= SelectObject ( hdc
, hPen
);
5091 /* draw the vertical lines for the columns */
5092 iterator_rangesitems(&j
, colRanges
);
5093 while(iterator_next(&j
))
5095 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5096 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5097 rcItem
.left
+= Origin
.x
;
5098 rcItem
.right
+= Origin
.x
;
5099 rcItem
.top
= infoPtr
->rcList
.top
;
5100 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5101 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5102 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5103 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5105 iterator_destroy(&j
);
5106 /* draw rightmost grid line if visible */
5109 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5110 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5111 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5113 rcItem
.right
+= Origin
.x
;
5115 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5116 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5119 /* draw the horizontal lines for the rows */
5120 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5121 rcItem
.left
= infoPtr
->rcList
.left
;
5122 rcItem
.right
= infoPtr
->rcList
.right
;
5123 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5125 rcItem
.bottom
= rcItem
.top
= y
;
5126 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5127 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5128 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5131 SelectObject( hdc
, hOldPen
);
5132 DeleteObject( hPen
);
5135 ranges_destroy(colRanges
);
5140 * Draws listview items when in list display mode.
5143 * [I] infoPtr : valid pointer to the listview structure
5144 * [I] hdc : device context handle
5145 * [I] cdmode : custom draw mode
5150 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5152 POINT Origin
, Position
;
5154 /* Get scroll info once before loop */
5155 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5157 while(iterator_prev(i
))
5159 SelectObject(hdc
, infoPtr
->hFont
);
5160 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5161 Position
.x
+= Origin
.x
;
5162 Position
.y
+= Origin
.y
;
5164 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5171 * Draws listview items.
5174 * [I] infoPtr : valid pointer to the listview structure
5175 * [I] hdc : device context handle
5176 * [I] prcErase : rect to be erased before refresh (may be NULL)
5181 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5183 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5184 NMLVCUSTOMDRAW nmlvcd
;
5191 HBITMAP hbmp
= NULL
;
5194 LISTVIEW_DUMP(infoPtr
);
5196 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5197 TRACE("double buffering\n");
5199 hdc
= CreateCompatibleDC(hdcOrig
);
5201 ERR("Failed to create DC for backbuffer\n");
5204 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5205 infoPtr
->rcList
.bottom
);
5207 ERR("Failed to create bitmap for backbuffer\n");
5212 SelectObject(hdc
, hbmp
);
5213 SelectObject(hdc
, infoPtr
->hFont
);
5215 if(GetClipBox(hdcOrig
, &rcClient
))
5216 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5218 /* Save dc values we're gonna trash while drawing
5219 * FIXME: Should be done in LISTVIEW_DrawItem() */
5220 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5221 oldBkMode
= GetBkMode(hdc
);
5222 oldBkColor
= GetBkColor(hdc
);
5223 oldTextColor
= GetTextColor(hdc
);
5226 infoPtr
->bIsDrawing
= TRUE
;
5229 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5230 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5231 /* If no erasing was done (usually because RedrawWindow was called
5232 * with RDW_INVALIDATE only) we need to copy the old contents into
5233 * the backbuffer before continuing. */
5234 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5235 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5236 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5237 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5240 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5241 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5242 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5243 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5245 /* nothing to draw */
5246 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5248 /* figure out what we need to draw */
5249 iterator_visibleitems(&i
, infoPtr
, hdc
);
5250 range
= iterator_range(&i
);
5252 /* send cache hint notification */
5253 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5257 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5258 nmlv
.iFrom
= range
.lower
;
5259 nmlv
.iTo
= range
.upper
- 1;
5260 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5263 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5264 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5267 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5268 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5269 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5270 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5272 /* if we have a focus rect and it's visible, draw it */
5273 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5274 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5275 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5277 iterator_destroy(&i
);
5280 /* For LVS_EX_GRIDLINES go and draw lines */
5281 /* This includes the case where there were *no* items */
5282 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5283 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5285 /* Draw marquee rectangle if appropriate */
5286 if (infoPtr
->bMarqueeSelect
)
5287 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5289 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5290 notify_postpaint(infoPtr
, &nmlvcd
);
5293 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5294 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5295 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5296 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5301 SelectObject(hdc
, hOldFont
);
5302 SetBkMode(hdc
, oldBkMode
);
5303 SetBkColor(hdc
, oldBkColor
);
5304 SetTextColor(hdc
, oldTextColor
);
5307 infoPtr
->bIsDrawing
= FALSE
;
5313 * Calculates the approximate width and height of a given number of items.
5316 * [I] infoPtr : valid pointer to the listview structure
5317 * [I] nItemCount : number of items
5318 * [I] wWidth : width
5319 * [I] wHeight : height
5322 * Returns a DWORD. The width in the low word and the height in high word.
5324 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5325 WORD wWidth
, WORD wHeight
)
5327 DWORD dwViewRect
= 0;
5329 if (nItemCount
== -1)
5330 nItemCount
= infoPtr
->nItemCount
;
5332 if (infoPtr
->uView
== LV_VIEW_LIST
)
5334 INT nItemCountPerColumn
= 1;
5335 INT nColumnCount
= 0;
5337 if (wHeight
== 0xFFFF)
5339 /* use current height */
5340 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5343 if (wHeight
< infoPtr
->nItemHeight
)
5344 wHeight
= infoPtr
->nItemHeight
;
5348 if (infoPtr
->nItemHeight
> 0)
5350 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5351 if (nItemCountPerColumn
== 0)
5352 nItemCountPerColumn
= 1;
5354 if (nItemCount
% nItemCountPerColumn
!= 0)
5355 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5357 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5361 /* Microsoft padding magic */
5362 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5363 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5365 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5367 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5371 if (infoPtr
->nItemCount
> 0)
5373 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5374 wWidth
= rcBox
.right
- rcBox
.left
;
5375 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5379 /* use current height and width */
5380 if (wHeight
== 0xffff)
5381 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5382 if (wWidth
== 0xffff)
5383 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5386 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5388 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5394 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5395 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5397 if (wWidth
== 0xffff)
5398 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5400 if (wWidth
< nItemWidth
)
5401 wWidth
= nItemWidth
;
5403 cols
= wWidth
/ nItemWidth
;
5404 if (cols
> nItemCount
)
5411 rows
= nItemCount
/ cols
;
5412 if (nItemCount
% cols
)
5418 wHeight
= (nItemHeight
* rows
)+2;
5419 wWidth
= (nItemWidth
* cols
)+2;
5421 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5423 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5424 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5431 * Cancel edit label with saving item text.
5434 * [I] infoPtr : valid pointer to the listview structure
5437 * Always returns TRUE.
5439 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5441 if (infoPtr
->hwndEdit
)
5443 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5444 HWND edit
= infoPtr
->hwndEdit
;
5446 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5447 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5455 * Create a drag image list for the specified item.
5458 * [I] infoPtr : valid pointer to the listview structure
5459 * [I] iItem : index of item
5460 * [O] lppt : Upper-left corner of the image
5463 * Returns a handle to the image list if successful, NULL otherwise.
5465 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5471 HBITMAP hbmp
, hOldbmp
;
5473 HIMAGELIST dragList
= 0;
5474 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5476 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5479 rcItem
.left
= LVIR_BOUNDS
;
5480 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5483 lppt
->x
= rcItem
.left
;
5484 lppt
->y
= rcItem
.top
;
5486 size
.cx
= rcItem
.right
- rcItem
.left
;
5487 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5489 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5490 hdc
= CreateCompatibleDC(hdcOrig
);
5491 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5492 hOldbmp
= SelectObject(hdc
, hbmp
);
5493 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5495 SetRect(&rcItem
, 0, 0, size
.cx
, size
.cy
);
5496 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5499 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5501 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5502 SelectObject(hdc
, hOldbmp
);
5503 ImageList_Add(dragList
, hbmp
, 0);
5506 SelectObject(hdc
, hOldbmp
);
5508 SelectObject(hdc
, hOldFont
);
5511 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5513 TRACE("ret=%p\n", dragList
);
5521 * Removes all listview items and subitems.
5524 * [I] infoPtr : valid pointer to the listview structure
5530 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5532 HDPA hdpaSubItems
= NULL
;
5533 BOOL suppress
= FALSE
;
5541 /* we do it directly, to avoid notifications */
5542 ranges_clear(infoPtr
->selectionRanges
);
5543 infoPtr
->nSelectionMark
= -1;
5544 infoPtr
->nFocusedItem
= -1;
5545 SetRectEmpty(&infoPtr
->rcFocus
);
5546 /* But we are supposed to leave nHotItem as is! */
5548 /* send LVN_DELETEALLITEMS notification */
5549 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5553 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5555 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5558 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5560 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5562 /* send LVN_DELETEITEM notification, if not suppressed
5563 and if it is not a virtual listview */
5564 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5565 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5566 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5567 /* free id struct */
5568 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5569 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5570 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5572 /* both item and subitem start with ITEMHDR header */
5573 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5575 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5576 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5579 DPA_Destroy(hdpaSubItems
);
5580 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5582 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5583 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5584 infoPtr
->nItemCount
--;
5589 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5590 LISTVIEW_UpdateScroll(infoPtr
);
5592 LISTVIEW_InvalidateList(infoPtr
);
5593 infoPtr
->bNoItemMetrics
= TRUE
;
5600 * Scrolls, and updates the columns, when a column is changing width.
5603 * [I] infoPtr : valid pointer to the listview structure
5604 * [I] nColumn : column to scroll
5605 * [I] dx : amount of scroll, in pixels
5610 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5612 COLUMN_INFO
*lpColumnInfo
;
5618 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5619 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5620 rcCol
= lpColumnInfo
->rcHeader
;
5621 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5622 rcCol
.left
= rcCol
.right
;
5624 /* adjust the other columns */
5625 hdi
.mask
= HDI_ORDER
;
5626 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5628 INT nOrder
= hdi
.iOrder
;
5629 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5631 hdi
.mask
= HDI_ORDER
;
5632 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5633 if (hdi
.iOrder
>= nOrder
) {
5634 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5635 lpColumnInfo
->rcHeader
.left
+= dx
;
5636 lpColumnInfo
->rcHeader
.right
+= dx
;
5641 /* do not update screen if not in report mode */
5642 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5644 /* Need to reset the item width when inserting a new column */
5645 infoPtr
->nItemWidth
+= dx
;
5647 LISTVIEW_UpdateScroll(infoPtr
);
5648 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5650 /* scroll to cover the deleted column, and invalidate for redraw */
5651 rcOld
= infoPtr
->rcList
;
5652 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5653 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5658 * Removes a column from the listview control.
5661 * [I] infoPtr : valid pointer to the listview structure
5662 * [I] nColumn : column index
5668 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5672 TRACE("nColumn=%d\n", nColumn
);
5674 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5677 /* While the MSDN specifically says that column zero should not be deleted,
5678 what actually happens is that the column itself is deleted but no items or subitems
5682 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5684 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5687 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5688 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5690 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5692 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5694 INT nItem
, nSubItem
, i
;
5696 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5698 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5701 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5703 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5704 if (lpSubItem
->iSubItem
== nColumn
)
5707 lpDelItem
= lpSubItem
;
5709 else if (lpSubItem
->iSubItem
> nColumn
)
5711 lpSubItem
->iSubItem
--;
5715 /* if we found our subitem, zap it */
5719 if (is_text(lpDelItem
->hdr
.pszText
))
5720 Free(lpDelItem
->hdr
.pszText
);
5725 /* free dpa memory */
5726 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5731 /* update the other column info */
5732 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5733 LISTVIEW_InvalidateList(infoPtr
);
5735 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5736 LISTVIEW_UpdateItemSize(infoPtr
);
5743 * Invalidates the listview after an item's insertion or deletion.
5746 * [I] infoPtr : valid pointer to the listview structure
5747 * [I] nItem : item index
5748 * [I] dir : -1 if deleting, 1 if inserting
5753 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5755 INT nPerCol
, nItemCol
, nItemRow
;
5759 /* if we don't refresh, what's the point of scrolling? */
5760 if (!is_redrawing(infoPtr
)) return;
5762 assert (abs(dir
) == 1);
5764 /* arrange icons if autoarrange is on */
5765 if (is_autoarrange(infoPtr
))
5767 BOOL arrange
= TRUE
;
5768 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5769 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5770 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5773 /* scrollbars need updating */
5774 LISTVIEW_UpdateScroll(infoPtr
);
5776 /* figure out the item's position */
5777 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5778 nPerCol
= infoPtr
->nItemCount
+ 1;
5779 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5780 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5781 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5784 nItemCol
= nItem
/ nPerCol
;
5785 nItemRow
= nItem
% nPerCol
;
5786 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5788 /* move the items below up a slot */
5789 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5790 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5791 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5792 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5793 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5794 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5795 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5797 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5798 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5801 /* report has only that column, so we're done */
5802 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5804 /* now for LISTs, we have to deal with the columns to the right */
5805 SetRect(&rcScroll
, (nItemCol
+ 1) * infoPtr
->nItemWidth
, 0,
5806 (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
,
5807 nPerCol
* infoPtr
->nItemHeight
);
5808 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5809 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5810 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5815 * Removes an item from the listview control.
5818 * [I] infoPtr : valid pointer to the listview structure
5819 * [I] nItem : item index
5825 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5828 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5829 INT focus
= infoPtr
->nFocusedItem
;
5831 TRACE("(nItem=%d)\n", nItem
);
5833 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5835 /* remove selection, and focus */
5837 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5838 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5840 /* send LVN_DELETEITEM notification. */
5841 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5843 /* we need to do this here, because we'll be deleting stuff */
5845 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5847 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5855 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5856 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5858 /* free id struct */
5859 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5860 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5861 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5863 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5865 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5866 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5869 DPA_Destroy(hdpaSubItems
);
5874 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5875 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5878 infoPtr
->nItemCount
--;
5879 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5880 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5882 /* now is the invalidation fun */
5884 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5891 * Callback implementation for editlabel control
5894 * [I] infoPtr : valid pointer to the listview structure
5895 * [I] storeText : store edit box text as item text
5896 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5902 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5904 HWND hwndSelf
= infoPtr
->hwndSelf
;
5905 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5906 NMLVDISPINFOW dispInfo
;
5907 INT editedItem
= infoPtr
->nEditLabelItem
;
5909 WCHAR
*pszText
= NULL
;
5914 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5918 if (!(pszText
= Alloc(len
* (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5922 GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
);
5924 GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
);
5928 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5930 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5931 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5932 dispInfo
.item
.iItem
= editedItem
;
5933 dispInfo
.item
.iSubItem
= 0;
5934 dispInfo
.item
.stateMask
= ~0;
5935 dispInfo
.item
.pszText
= szDispText
;
5936 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5937 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5944 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5947 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5948 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5949 textfreeT(tmp
, FALSE
);
5952 /* add the text from the edit in */
5953 dispInfo
.item
.mask
|= LVIF_TEXT
;
5954 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5955 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5957 infoPtr
->notify_mask
&= ~NOTIFY_MASK_END_LABEL_EDIT
;
5959 /* Do we need to update the Item Text */
5960 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5962 infoPtr
->notify_mask
|= NOTIFY_MASK_END_LABEL_EDIT
;
5964 infoPtr
->nEditLabelItem
= -1;
5965 infoPtr
->hwndEdit
= 0;
5967 if (!res
) goto cleanup
;
5969 if (!IsWindow(hwndSelf
))
5974 if (!pszText
) return TRUE
;
5981 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5983 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5984 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5985 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5987 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5993 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5994 dispInfo
.item
.mask
= LVIF_TEXT
;
5995 dispInfo
.item
.iItem
= editedItem
;
5996 dispInfo
.item
.iSubItem
= 0;
5997 dispInfo
.item
.pszText
= pszText
;
5998 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5999 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
6007 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
6009 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
6012 TRACE("hwnd %p, uMsg %x, wParam %Ix, lParam %Ix, isW %d\n", hwnd
, uMsg
, wParam
, lParam
, isW
);
6017 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
6021 WNDPROC editProc
= infoPtr
->EditWndProc
;
6022 infoPtr
->EditWndProc
= 0;
6023 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
6024 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6028 if (VK_ESCAPE
== (INT
)wParam
)
6033 else if (VK_RETURN
== (INT
)wParam
)
6037 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6041 if (infoPtr
->hwndEdit
)
6042 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
6044 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6048 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6050 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6053 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6055 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6058 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6060 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6061 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6064 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6066 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6068 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6070 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6072 if (!hedit
) return 0;
6074 infoPtr
->EditWndProc
= (WNDPROC
)
6075 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6076 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6078 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6079 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6084 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6086 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6087 HWND hwndSelf
= infoPtr
->hwndSelf
;
6088 NMLVDISPINFOW dispInfo
;
6089 HFONT hOldFont
= NULL
;
6095 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6097 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6099 /* remove existing edit box */
6100 if (infoPtr
->hwndEdit
)
6102 SetFocus(infoPtr
->hwndSelf
);
6103 infoPtr
->hwndEdit
= 0;
6106 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6108 infoPtr
->nEditLabelItem
= nItem
;
6110 LISTVIEW_SetSelection(infoPtr
, nItem
);
6111 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6112 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6114 rect
.left
= LVIR_LABEL
;
6115 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6117 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6118 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6119 dispInfo
.item
.iItem
= nItem
;
6120 dispInfo
.item
.iSubItem
= 0;
6121 dispInfo
.item
.stateMask
= ~0;
6122 dispInfo
.item
.pszText
= disptextW
;
6123 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6124 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6126 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6127 if (!infoPtr
->hwndEdit
) return 0;
6129 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6131 if (!IsWindow(hwndSelf
))
6133 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6134 infoPtr
->hwndEdit
= 0;
6138 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6140 /* position and display edit box */
6141 hdc
= GetDC(infoPtr
->hwndSelf
);
6143 /* select the font to get appropriate metric dimensions */
6145 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6147 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6148 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6149 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6151 /* get string length in pixels */
6152 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6154 /* add extra spacing for the next character */
6155 GetTextMetricsW(hdc
, &tm
);
6156 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6159 SelectObject(hdc
, hOldFont
);
6161 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6163 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6166 TRACE("moving edit (%ld,%ld)-(%ld,%ld)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6167 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6168 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6169 SetFocus(infoPtr
->hwndEdit
);
6170 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6171 return infoPtr
->hwndEdit
;
6177 * Ensures the specified item is visible, scrolling into view if necessary.
6180 * [I] infoPtr : valid pointer to the listview structure
6181 * [I] nItem : item index
6182 * [I] bPartial : partially or entirely visible
6188 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6190 INT nScrollPosHeight
= 0;
6191 INT nScrollPosWidth
= 0;
6192 INT nHorzAdjust
= 0;
6193 INT nVertAdjust
= 0;
6196 RECT rcItem
, rcTemp
;
6198 rcItem
.left
= LVIR_BOUNDS
;
6199 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6201 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6203 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6205 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6206 if (infoPtr
->uView
== LV_VIEW_LIST
)
6207 nScrollPosWidth
= infoPtr
->nItemWidth
;
6208 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6209 nScrollPosWidth
= 1;
6211 if (rcItem
.left
< infoPtr
->rcList
.left
)
6214 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6219 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6223 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6225 /* scroll up/down, but not in LVS_LIST mode */
6226 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6227 nScrollPosHeight
= infoPtr
->nItemHeight
;
6228 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6229 nScrollPosHeight
= 1;
6231 if (rcItem
.top
< infoPtr
->rcList
.top
)
6234 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6239 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6243 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6245 if (nScrollPosWidth
)
6247 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6248 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6249 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6252 if (nScrollPosHeight
)
6254 INT diff
= nVertDiff
/ nScrollPosHeight
;
6255 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6256 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6264 * Searches for an item with specific characteristics.
6267 * [I] hwnd : window handle
6268 * [I] nStart : base item index
6269 * [I] lpFindInfo : item information to look for
6272 * SUCCESS : index of item
6275 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6276 const LVFINDINFOW
*lpFindInfo
)
6278 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6279 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6280 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6281 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6282 POINT Position
, Destination
;
6286 /* Search in virtual listviews should be done by application, not by
6287 listview control, so we just send LVN_ODFINDITEMW and return the result */
6288 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6292 nmlv
.iStart
= nStart
;
6293 nmlv
.lvfi
= *lpFindInfo
;
6294 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6297 if (!lpFindInfo
|| nItem
< 0) return -1;
6300 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6302 lvItem
.mask
|= LVIF_TEXT
;
6303 lvItem
.pszText
= szDispText
;
6304 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6307 if (lpFindInfo
->flags
& LVFI_WRAP
)
6310 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6311 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6316 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6317 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6318 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6319 switch(lpFindInfo
->vkDirection
)
6321 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6322 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6323 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6324 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6325 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6326 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6327 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6329 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6330 Destination
.x
= rcArea
.right
;
6331 Destination
.y
= rcArea
.bottom
;
6333 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6337 else Destination
.x
= Destination
.y
= 0;
6339 /* if LVFI_PARAM is specified, all other flags are ignored */
6340 if (lpFindInfo
->flags
& LVFI_PARAM
)
6342 lvItem
.mask
|= LVIF_PARAM
;
6344 lvItem
.mask
&= ~LVIF_TEXT
;
6347 nItem
= bNearest
? -1 : nStart
+ 1;
6349 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6350 search_len
= lstrlenW(lpFindInfo
->psz
);
6353 for (; nItem
< nLast
; nItem
++)
6355 lvItem
.iItem
= nItem
;
6356 lvItem
.iSubItem
= 0;
6357 lvItem
.pszText
= szDispText
;
6358 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6360 if (lvItem
.mask
& LVIF_PARAM
)
6362 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6368 if (lvItem
.mask
& LVIF_TEXT
)
6370 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6372 if (StrCmpNIW(lvItem
.pszText
, lpFindInfo
->psz
, search_len
)) continue;
6376 if (StrCmpIW(lvItem
.pszText
, lpFindInfo
->psz
)) continue;
6380 if (!bNearest
) return nItem
;
6382 /* This is very inefficient. To do a good job here,
6383 * we need a sorted array of (x,y) item positions */
6384 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6386 /* compute the distance^2 to the destination */
6387 xdist
= Destination
.x
- Position
.x
;
6388 ydist
= Destination
.y
- Position
.y
;
6389 dist
= xdist
* xdist
+ ydist
* ydist
;
6391 /* remember the distance, and item if it's closer */
6395 nNearestItem
= nItem
;
6402 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6407 return nNearestItem
;
6412 * Searches for an item with specific characteristics.
6415 * [I] hwnd : window handle
6416 * [I] nStart : base item index
6417 * [I] lpFindInfo : item information to look for
6420 * SUCCESS : index of item
6423 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6424 const LVFINDINFOA
*lpFindInfo
)
6430 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6431 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6432 fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6433 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6434 textfreeT(strW
, FALSE
);
6440 * Retrieves column attributes.
6443 * [I] infoPtr : valid pointer to the listview structure
6444 * [I] nColumn : column index
6445 * [IO] lpColumn : column information
6446 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6447 * otherwise it is in fact a LPLVCOLUMNA
6453 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6455 COLUMN_INFO
*lpColumnInfo
;
6458 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6459 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6461 /* initialize memory */
6462 ZeroMemory(&hdi
, sizeof(hdi
));
6464 if (lpColumn
->mask
& LVCF_TEXT
)
6466 hdi
.mask
|= HDI_TEXT
;
6467 hdi
.pszText
= lpColumn
->pszText
;
6468 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6471 if (lpColumn
->mask
& LVCF_IMAGE
)
6472 hdi
.mask
|= HDI_IMAGE
;
6474 if (lpColumn
->mask
& LVCF_ORDER
)
6475 hdi
.mask
|= HDI_ORDER
;
6477 if (lpColumn
->mask
& LVCF_SUBITEM
)
6478 hdi
.mask
|= HDI_LPARAM
;
6480 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6482 if (lpColumn
->mask
& LVCF_FMT
)
6483 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6485 if (lpColumn
->mask
& LVCF_WIDTH
)
6486 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6488 if (lpColumn
->mask
& LVCF_IMAGE
)
6489 lpColumn
->iImage
= hdi
.iImage
;
6491 if (lpColumn
->mask
& LVCF_ORDER
)
6492 lpColumn
->iOrder
= hdi
.iOrder
;
6494 if (lpColumn
->mask
& LVCF_SUBITEM
)
6495 lpColumn
->iSubItem
= hdi
.lParam
;
6497 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6498 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6503 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6505 if (!infoPtr
->hwndHeader
) return FALSE
;
6506 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6511 * Retrieves the column width.
6514 * [I] infoPtr : valid pointer to the listview structure
6515 * [I] int : column index
6518 * SUCCESS : column width
6521 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6523 INT nColumnWidth
= 0;
6526 TRACE("nColumn=%d\n", nColumn
);
6528 /* we have a 'column' in LIST and REPORT mode only */
6529 switch(infoPtr
->uView
)
6532 nColumnWidth
= infoPtr
->nItemWidth
;
6534 case LV_VIEW_DETAILS
:
6535 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6536 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6537 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6539 hdItem
.mask
= HDI_WIDTH
;
6540 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6542 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6545 nColumnWidth
= hdItem
.cxy
;
6549 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6550 return nColumnWidth
;
6555 * In list or report display mode, retrieves the number of items that can fit
6556 * vertically in the visible area. In icon or small icon display mode,
6557 * retrieves the total number of visible items.
6560 * [I] infoPtr : valid pointer to the listview structure
6563 * Number of fully visible items.
6565 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6567 switch (infoPtr
->uView
)
6570 case LV_VIEW_SMALLICON
:
6571 return infoPtr
->nItemCount
;
6572 case LV_VIEW_DETAILS
:
6573 return LISTVIEW_GetCountPerColumn(infoPtr
);
6575 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6583 * Retrieves an image list handle.
6586 * [I] infoPtr : valid pointer to the listview structure
6587 * [I] nImageList : image list identifier
6590 * SUCCESS : image list handle
6593 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6597 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6598 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6599 case LVSIL_STATE
: return infoPtr
->himlState
;
6600 case LVSIL_GROUPHEADER
:
6601 FIXME("LVSIL_GROUPHEADER not supported\n");
6604 WARN("got unknown imagelist index - %d\n", nImageList
);
6609 /* LISTVIEW_GetISearchString */
6613 * Retrieves item attributes.
6616 * [I] hwnd : window handle
6617 * [IO] lpLVItem : item info
6618 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6619 * if FALSE, then lpLVItem is a LPLVITEMA.
6622 * This is the internal 'GetItem' interface -- it tries to
6623 * be smart and avoid text copies, if possible, by modifying
6624 * lpLVItem->pszText to point to the text string. Please note
6625 * that this is not always possible (e.g. OWNERDATA), so on
6626 * entry you *must* supply valid values for pszText, and cchTextMax.
6627 * The only difference to the documented interface is that upon
6628 * return, you should use *only* the lpLVItem->pszText, rather than
6629 * the buffer pointer you provided on input. Most code already does
6630 * that, so it's not a problem.
6631 * For the two cases when the text must be copied (that is,
6632 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6638 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6640 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6641 BOOL is_subitem_invalid
= FALSE
;
6642 NMLVDISPINFOW dispInfo
;
6647 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6649 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6652 if (lpLVItem
->mask
== 0) return TRUE
;
6653 TRACE("mask=%x\n", lpLVItem
->mask
);
6655 if (lpLVItem
->iSubItem
&& (lpLVItem
->mask
& LVIF_STATE
))
6656 lpLVItem
->state
= 0;
6658 /* a quick optimization if all we're asked is the focus state
6659 * these queries are worth optimising since they are common,
6660 * and can be answered in constant time, without the heavy accesses */
6661 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6662 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6664 lpLVItem
->state
= 0;
6665 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
&& !lpLVItem
->iSubItem
)
6666 lpLVItem
->state
|= LVIS_FOCUSED
;
6670 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6672 /* if the app stores all the data, handle it separately */
6673 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6675 dispInfo
.item
.state
= 0;
6677 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6678 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6679 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6681 UINT mask
= lpLVItem
->mask
;
6683 /* NOTE: copy only fields which we _know_ are initialized, some apps
6684 * depend on the uninitialized fields being 0 */
6685 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6686 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6687 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
6688 if (lpLVItem
->mask
& LVIF_TEXT
)
6690 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6692 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6695 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6696 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6699 if (lpLVItem
->mask
& LVIF_STATE
)
6700 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6701 /* could be zeroed on LVIF_NORECOMPUTE case */
6702 if (dispInfo
.item
.mask
)
6704 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6705 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6706 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6708 /* full size structure expected - _WIN32IE >= 0x560 */
6709 *lpLVItem
= dispInfo
.item
;
6711 else if (lpLVItem
->mask
& LVIF_INDENT
)
6713 /* indent member expected - _WIN32IE >= 0x300 */
6714 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6718 /* minimal structure expected */
6719 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6721 lpLVItem
->mask
= mask
;
6722 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6726 /* make sure lParam is zeroed out */
6727 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6729 /* callback marked pointer required here */
6730 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6731 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6733 /* we store only a little state, so if we're not asked, we're done */
6734 if (!(lpLVItem
->mask
& LVIF_STATE
) || lpLVItem
->iSubItem
) return TRUE
;
6736 /* if focus is handled by us, report it */
6737 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6739 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6740 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6741 lpLVItem
->state
|= LVIS_FOCUSED
;
6744 /* and do the same for selection, if we handle it */
6745 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6747 lpLVItem
->state
&= ~LVIS_SELECTED
;
6748 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6749 lpLVItem
->state
|= LVIS_SELECTED
;
6755 /* find the item and subitem structures before we proceed */
6756 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6757 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6760 if (lpLVItem
->iSubItem
)
6762 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
6764 pItemHdr
= &lpSubItem
->hdr
;
6767 pItemHdr
= &callbackHdr
;
6768 is_subitem_invalid
= TRUE
;
6772 pItemHdr
= &lpItem
->hdr
;
6774 /* Do we need to query the state from the app? */
6775 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& (!lpLVItem
->iSubItem
|| is_subitem_invalid
))
6777 dispInfo
.item
.mask
|= LVIF_STATE
;
6778 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6781 /* Do we need to enquire about the image? */
6782 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6783 (!lpLVItem
->iSubItem
|| (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6785 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6786 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6789 /* Only items support indentation */
6790 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&& !lpLVItem
->iSubItem
)
6792 dispInfo
.item
.mask
|= LVIF_INDENT
;
6793 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6796 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6797 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6798 !is_text(pItemHdr
->pszText
))
6800 dispInfo
.item
.mask
|= LVIF_TEXT
;
6801 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6802 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6803 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6804 *dispInfo
.item
.pszText
= '\0';
6807 /* If we don't have all the requested info, query the application */
6808 if (dispInfo
.item
.mask
)
6810 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6811 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
6812 dispInfo
.item
.lParam
= lpItem
->lParam
;
6813 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6814 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6817 /* we should not store values for subitems */
6818 if (lpLVItem
->iSubItem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6820 /* Now, handle the iImage field */
6821 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6823 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6824 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6825 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6827 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6829 if (!lpLVItem
->iSubItem
|| (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6830 lpLVItem
->iImage
= pItemHdr
->iImage
;
6832 lpLVItem
->iImage
= 0;
6835 /* The pszText field */
6836 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6838 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6839 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6841 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6843 else if (lpLVItem
->mask
& LVIF_TEXT
)
6845 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6846 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6847 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6850 /* Next is the lParam field */
6851 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6853 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6854 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6855 lpItem
->lParam
= dispInfo
.item
.lParam
;
6857 else if (lpLVItem
->mask
& LVIF_PARAM
)
6858 lpLVItem
->lParam
= lpItem
->lParam
;
6860 /* if this is a subitem, we're done */
6861 if (lpLVItem
->iSubItem
) return TRUE
;
6863 /* ... the state field (this one is different due to uCallbackmask) */
6864 if (lpLVItem
->mask
& LVIF_STATE
)
6866 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6867 if (dispInfo
.item
.mask
& LVIF_STATE
)
6869 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6870 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6872 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6874 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6875 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6876 lpLVItem
->state
|= LVIS_FOCUSED
;
6878 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6880 lpLVItem
->state
&= ~LVIS_SELECTED
;
6881 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6882 lpLVItem
->state
|= LVIS_SELECTED
;
6886 /* and last, but not least, the indent field */
6887 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6889 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6890 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6891 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6893 else if (lpLVItem
->mask
& LVIF_INDENT
)
6895 lpLVItem
->iIndent
= lpItem
->iIndent
;
6903 * Retrieves item attributes.
6906 * [I] hwnd : window handle
6907 * [IO] lpLVItem : item info
6908 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6909 * if FALSE, then lpLVItem is a LPLVITEMA.
6912 * This is the external 'GetItem' interface -- it properly copies
6913 * the text in the provided buffer.
6919 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6924 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6927 pszText
= lpLVItem
->pszText
;
6928 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6929 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6931 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6932 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6934 pszText
= LPSTR_TEXTCALLBACKW
;
6936 lpLVItem
->pszText
= pszText
;
6944 * Retrieves the position (upper-left) of the listview control item.
6945 * Note that for LVS_ICON style, the upper-left is that of the icon
6946 * and not the bounding box.
6949 * [I] infoPtr : valid pointer to the listview structure
6950 * [I] nItem : item index
6951 * [O] lpptPosition : coordinate information
6957 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6961 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6963 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6965 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6966 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6968 if (infoPtr
->uView
== LV_VIEW_ICON
)
6970 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6971 lpptPosition
->y
+= ICON_TOP_PADDING
;
6973 lpptPosition
->x
+= Origin
.x
;
6974 lpptPosition
->y
+= Origin
.y
;
6976 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6983 * Retrieves the bounding rectangle for a listview control item.
6986 * [I] infoPtr : valid pointer to the listview structure
6987 * [I] nItem : item index
6988 * [IO] lprc : bounding rectangle coordinates
6989 * lprc->left specifies the portion of the item for which the bounding
6990 * rectangle will be retrieved.
6992 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6993 * including the icon and label.
6996 * * Experiment shows that native control returns:
6997 * * width = min (48, length of text line)
6998 * * .left = position.x - (width - iconsize.cx)/2
6999 * * .right = .left + width
7000 * * height = #lines of text * ntmHeight + icon height + 8
7001 * * .top = position.y - 2
7002 * * .bottom = .top + height
7003 * * separation between items .y = itemSpacing.cy - height
7004 * * .x = itemSpacing.cx - width
7005 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7008 * * Experiment shows that native control returns:
7009 * * width = iconSize.cx + 16
7010 * * .left = position.x - (width - iconsize.cx)/2
7011 * * .right = .left + width
7012 * * height = iconSize.cy + 4
7013 * * .top = position.y - 2
7014 * * .bottom = .top + height
7015 * * separation between items .y = itemSpacing.cy - height
7016 * * .x = itemSpacing.cx - width
7017 * LVIR_LABEL Returns the bounding rectangle of the item text.
7020 * * Experiment shows that native control returns:
7021 * * width = text length
7022 * * .left = position.x - width/2
7023 * * .right = .left + width
7024 * * height = ntmH * linecount + 2
7025 * * .top = position.y + iconSize.cy + 6
7026 * * .bottom = .top + height
7027 * * separation between items .y = itemSpacing.cy - height
7028 * * .x = itemSpacing.cx - width
7029 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7030 * rectangles, but excludes columns in report view.
7037 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7038 * upon whether the window has the focus currently and on whether the item
7039 * is the one with the focus. Ensure that the control's record of which
7040 * item has the focus agrees with the items' records.
7042 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7044 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7045 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7046 POINT Position
, Origin
;
7050 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7052 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7054 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7055 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7057 /* Be smart and try to figure out the minimum we have to do */
7058 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7059 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7060 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7061 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7062 oversizedBox
= TRUE
;
7064 /* get what we need from the item before hand, so we make
7065 * only one request. This can speed up things, if data
7066 * is stored on the app side */
7068 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7069 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7070 lvItem
.iItem
= nItem
;
7071 lvItem
.iSubItem
= 0;
7072 lvItem
.pszText
= szDispText
;
7073 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7074 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7075 /* we got the state already up, simulate it here, to avoid a reget */
7076 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7078 lvItem
.mask
|= LVIF_STATE
;
7079 lvItem
.stateMask
= LVIS_FOCUSED
;
7080 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7083 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7084 lprc
->left
= LVIR_BOUNDS
;
7090 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7094 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7098 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7101 case LVIR_SELECTBOUNDS
:
7102 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7106 WARN("Unknown value: %ld\n", lprc
->left
);
7110 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7112 if (mode
!= LVIR_BOUNDS
)
7113 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7114 Position
.y
+ Origin
.y
);
7116 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7119 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7121 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7128 * Retrieves the spacing between listview control items.
7131 * [I] infoPtr : valid pointer to the listview structure
7132 * [IO] lprc : rectangle to receive the output
7133 * on input, lprc->top = nSubItem
7134 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7136 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7137 * not only those of the first column.
7143 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7145 RECT rect
= { 0, 0, 0, 0 };
7149 if (!lprc
) return FALSE
;
7151 TRACE("item %d, subitem %ld, type %ld\n", item
, lprc
->top
, lprc
->left
);
7153 /* Subitem of '0' means item itself, and this works for all control view modes */
7155 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7157 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7159 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7160 /* this works for any item index, no matter if it exists or not */
7161 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7163 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7166 rect
.bottom
= infoPtr
->nItemHeight
;
7170 /* Native implementation is broken for this case and garbage is left for left and right fields,
7171 we zero them to get predictable output */
7172 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7173 lprc
->bottom
= infoPtr
->nItemHeight
;
7174 OffsetRect(lprc
, origin
.x
, y
);
7175 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7183 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7184 if (infoPtr
->himlSmall
)
7185 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7187 rect
.right
= rect
.left
;
7189 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7197 ERR("Unknown bounds %ld\n", lprc
->left
);
7201 OffsetRect(&rect
, origin
.x
, y
);
7203 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7210 * Retrieves the spacing between listview control items.
7213 * [I] infoPtr : valid pointer to the listview structure
7214 * [I] bSmall : flag for small or large icon
7217 * Horizontal + vertical spacing
7219 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7225 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7229 if (infoPtr
->uView
== LV_VIEW_ICON
)
7230 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7232 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7239 * Retrieves the state of a listview control item.
7242 * [I] infoPtr : valid pointer to the listview structure
7243 * [I] nItem : item index
7244 * [I] uMask : state mask
7247 * State specified by the mask.
7249 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7253 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7255 lvItem
.iItem
= nItem
;
7256 lvItem
.iSubItem
= 0;
7257 lvItem
.mask
= LVIF_STATE
;
7258 lvItem
.stateMask
= uMask
;
7259 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7261 return lvItem
.state
& uMask
;
7266 * Retrieves the text of a listview control item or subitem.
7269 * [I] hwnd : window handle
7270 * [I] nItem : item index
7271 * [IO] lpLVItem : item information
7272 * [I] isW : TRUE if lpLVItem is Unicode
7275 * SUCCESS : string length
7278 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7280 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7282 lpLVItem
->mask
= LVIF_TEXT
;
7283 lpLVItem
->iItem
= nItem
;
7284 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7286 return textlenT(lpLVItem
->pszText
, isW
);
7291 * Searches for an item based on properties + relationships.
7294 * [I] infoPtr : valid pointer to the listview structure
7295 * [I] nItem : item index
7296 * [I] uFlags : relationship flag
7299 * SUCCESS : item index
7302 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7305 LVFINDINFOW lvFindInfo
;
7306 INT nCountPerColumn
;
7310 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7311 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7313 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7315 if (uFlags
& LVNI_CUT
)
7318 if (uFlags
& LVNI_DROPHILITED
)
7319 uMask
|= LVIS_DROPHILITED
;
7321 if (uFlags
& LVNI_FOCUSED
)
7322 uMask
|= LVIS_FOCUSED
;
7324 if (uFlags
& LVNI_SELECTED
)
7325 uMask
|= LVIS_SELECTED
;
7327 /* if we're asked for the focused item, that's only one,
7328 * so it's worth optimizing */
7329 if (uFlags
& LVNI_FOCUSED
)
7331 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7332 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7335 if (uFlags
& LVNI_ABOVE
)
7337 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7342 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7348 /* Special case for autoarrange - move 'til the top of a list */
7349 if (is_autoarrange(infoPtr
))
7351 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7352 while (nItem
- nCountPerRow
>= 0)
7354 nItem
-= nCountPerRow
;
7355 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7360 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7361 lvFindInfo
.vkDirection
= VK_UP
;
7362 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7363 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7365 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7370 else if (uFlags
& LVNI_BELOW
)
7372 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7374 while (nItem
< infoPtr
->nItemCount
)
7377 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7383 /* Special case for autoarrange - move 'til the bottom of a list */
7384 if (is_autoarrange(infoPtr
))
7386 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7387 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7389 nItem
+= nCountPerRow
;
7390 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7395 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7396 lvFindInfo
.vkDirection
= VK_DOWN
;
7397 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7398 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7400 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7405 else if (uFlags
& LVNI_TOLEFT
)
7407 if (infoPtr
->uView
== LV_VIEW_LIST
)
7409 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7410 while (nItem
- nCountPerColumn
>= 0)
7412 nItem
-= nCountPerColumn
;
7413 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7417 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7419 /* Special case for autoarrange - move 'til the beginning of a row */
7420 if (is_autoarrange(infoPtr
))
7422 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7423 while (nItem
% nCountPerRow
> 0)
7426 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7431 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7432 lvFindInfo
.vkDirection
= VK_LEFT
;
7433 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7434 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7436 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7441 else if (uFlags
& LVNI_TORIGHT
)
7443 if (infoPtr
->uView
== LV_VIEW_LIST
)
7445 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7446 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7448 nItem
+= nCountPerColumn
;
7449 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7453 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7455 /* Special case for autoarrange - move 'til the end of a row */
7456 if (is_autoarrange(infoPtr
))
7458 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7459 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7462 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7467 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7468 lvFindInfo
.vkDirection
= VK_RIGHT
;
7469 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7470 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7472 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7481 /* search by index */
7482 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7484 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7492 static BOOL
LISTVIEW_GetNextItemIndex(const LISTVIEW_INFO
*infoPtr
, LVITEMINDEX
*index
, UINT flags
)
7494 /* FIXME: specified item group is ignored */
7499 index
->iItem
= LISTVIEW_GetNextItem(infoPtr
, index
->iItem
, flags
);
7500 return index
->iItem
!= -1;
7503 /* LISTVIEW_GetNumberOfWorkAreas */
7507 * Retrieves the origin coordinates when in icon or small icon display mode.
7510 * [I] infoPtr : valid pointer to the listview structure
7511 * [O] lpptOrigin : coordinate information
7516 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7518 INT nHorzPos
= 0, nVertPos
= 0;
7519 SCROLLINFO scrollInfo
;
7521 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7522 scrollInfo
.fMask
= SIF_POS
;
7524 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7525 nHorzPos
= scrollInfo
.nPos
;
7526 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7527 nVertPos
= scrollInfo
.nPos
;
7529 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7531 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7532 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7533 if (infoPtr
->uView
== LV_VIEW_LIST
)
7534 nHorzPos
*= infoPtr
->nItemWidth
;
7535 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7536 nVertPos
*= infoPtr
->nItemHeight
;
7538 lpptOrigin
->x
-= nHorzPos
;
7539 lpptOrigin
->y
-= nVertPos
;
7541 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7546 * Retrieves the width of a string.
7549 * [I] hwnd : window handle
7550 * [I] lpszText : text string to process
7551 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7554 * SUCCESS : string width (in pixels)
7557 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7562 if (is_text(lpszText
))
7564 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7565 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7566 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7569 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7571 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7572 SelectObject(hdc
, hOldFont
);
7573 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7575 return stringSize
.cx
;
7580 * Determines which listview item is located at the specified position.
7583 * [I] infoPtr : valid pointer to the listview structure
7584 * [IO] lpht : hit test information
7585 * [I] subitem : fill out iSubItem.
7586 * [I] select : return the index only if the hit selects the item
7589 * (mm 20001022): We must not allow iSubItem to be touched, for
7590 * an app might pass only a structure with space up to iItem!
7591 * (MS Office 97 does that for instance in the file open dialog)
7594 * SUCCESS : item index
7597 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7599 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7600 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7601 POINT Origin
, Position
, opt
;
7607 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7611 if (subitem
) lpht
->iSubItem
= 0;
7613 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7615 /* set whole list relation flags */
7616 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7618 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7619 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7620 lpht
->flags
|= LVHT_TOLEFT
;
7622 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7623 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7627 if (infoPtr
->rcList
.bottom
< opt
.y
)
7628 lpht
->flags
|= LVHT_BELOW
;
7632 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7633 lpht
->flags
|= LVHT_TOLEFT
;
7634 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7635 lpht
->flags
|= LVHT_TORIGHT
;
7637 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7638 lpht
->flags
|= LVHT_ABOVE
;
7639 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7640 lpht
->flags
|= LVHT_BELOW
;
7643 /* even if item is invalid try to find subitem */
7644 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7649 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7651 lpht
->iSubItem
= -1;
7652 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7654 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7656 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7662 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7664 /* if we're outside horizontal columns bounds there's nothing to test further */
7665 if (lpht
->iSubItem
== -1)
7668 lpht
->flags
= LVHT_NOWHERE
;
7673 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7674 if (lpht
->flags
) return -1;
7676 lpht
->flags
|= LVHT_NOWHERE
;
7678 /* first deal with the large items */
7679 rcSearch
.left
= lpht
->pt
.x
;
7680 rcSearch
.top
= lpht
->pt
.y
;
7681 rcSearch
.right
= rcSearch
.left
+ 1;
7682 rcSearch
.bottom
= rcSearch
.top
+ 1;
7684 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7685 iterator_next(&i
); /* go to first item in the sequence */
7687 iterator_destroy(&i
);
7689 TRACE("lpht->iItem=%d\n", iItem
);
7690 if (iItem
== -1) return -1;
7692 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7693 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7694 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7695 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7696 lvItem
.iItem
= iItem
;
7697 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7698 lvItem
.pszText
= szDispText
;
7699 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7700 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7701 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7703 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7704 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7705 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7707 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7708 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7710 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7712 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7715 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7716 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7720 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7721 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7723 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7724 if (!PtInRect(&rcBounds
, opt
)) return -1;
7726 /* That's a special case - row rectangle is used as item rectangle and
7727 returned flags contain all item parts. */
7728 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7730 if (PtInRect(&rcIcon
, opt
))
7731 lpht
->flags
|= LVHT_ONITEMICON
;
7732 else if (PtInRect(&rcLabel
, opt
))
7733 lpht
->flags
|= LVHT_ONITEMLABEL
;
7734 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7735 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7736 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7738 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7740 if (lpht
->flags
& LVHT_ONITEM
)
7741 lpht
->flags
&= ~LVHT_NOWHERE
;
7742 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7744 if (select
&& !is_fullrow
)
7746 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7748 /* get main item bounds */
7749 lvItem
.iSubItem
= 0;
7750 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7751 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7752 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7754 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7756 return lpht
->iItem
= iItem
;
7761 * Inserts a new item in the listview control.
7764 * [I] infoPtr : valid pointer to the listview structure
7765 * [I] lpLVItem : item information
7766 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7769 * SUCCESS : new item index
7772 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7779 BOOL is_sorted
, has_changed
;
7781 HWND hwndSelf
= infoPtr
->hwndSelf
;
7783 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7785 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7787 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7788 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7790 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7792 if (!(lpItem
= Alloc(sizeof(*lpItem
)))) return -1;
7794 /* insert item in listview control data structure */
7795 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7796 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7798 /* link with id struct */
7799 if (!(lpID
= Alloc(sizeof(*lpID
)))) goto fail
;
7801 lpID
->item
= hdpaSubItems
;
7802 lpID
->id
= get_next_itemid(infoPtr
);
7803 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7805 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7806 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7808 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7810 /* calculate new item index */
7818 textW
= textdupTtoW(lpLVItem
->pszText
, isW
);
7820 while (i
< infoPtr
->nItemCount
)
7822 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7823 item_s
= DPA_GetPtr(hItem
, 0);
7825 cmpv
= textcmpWT(item_s
->hdr
.pszText
, textW
, TRUE
);
7826 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7828 if (cmpv
>= 0) break;
7832 textfreeT(textW
, isW
);
7837 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7839 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7840 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7841 if (nItem
== -1) goto fail
;
7842 infoPtr
->nItemCount
++;
7844 /* shift indices first so they don't get tangled */
7845 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7847 /* set the item attributes */
7848 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7850 /* full size structure expected - _WIN32IE >= 0x560 */
7853 else if (lpLVItem
->mask
& LVIF_INDENT
)
7855 /* indent member expected - _WIN32IE >= 0x300 */
7856 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7860 /* minimal structure expected */
7861 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7864 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7866 if (item
.mask
& LVIF_STATE
)
7868 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7869 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7870 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7874 item
.mask
|= LVIF_STATE
;
7875 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7876 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7880 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7882 /* make room for the position, if we are in the right mode */
7883 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7885 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7887 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7889 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7894 /* send LVN_INSERTITEM notification */
7895 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7897 nmlv
.lParam
= lpItem
->lParam
;
7898 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7899 if (!IsWindow(hwndSelf
))
7902 /* align items (set position of each item) */
7903 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7907 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7908 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7910 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7912 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7915 /* now is the invalidation fun */
7916 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7920 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7921 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7922 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7923 infoPtr
->nItemCount
--;
7925 DPA_DeletePtr(hdpaSubItems
, 0);
7926 DPA_Destroy (hdpaSubItems
);
7933 * Checks item visibility.
7936 * [I] infoPtr : valid pointer to the listview structure
7937 * [I] nFirst : item index to check for
7940 * Item visible : TRUE
7941 * Item invisible or failure : FALSE
7943 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7945 POINT Origin
, Position
;
7950 TRACE("nItem=%d\n", nItem
);
7952 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7954 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7955 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7956 rcItem
.left
= Position
.x
+ Origin
.x
;
7957 rcItem
.top
= Position
.y
+ Origin
.y
;
7958 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7959 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7961 hdc
= GetDC(infoPtr
->hwndSelf
);
7962 if (!hdc
) return FALSE
;
7963 ret
= RectVisible(hdc
, &rcItem
);
7964 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7971 * Redraws a range of items.
7974 * [I] infoPtr : valid pointer to the listview structure
7975 * [I] nFirst : first item
7976 * [I] nLast : last item
7982 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7986 for (i
= max(nFirst
, 0); i
<= min(nLast
, infoPtr
->nItemCount
- 1); i
++)
7987 LISTVIEW_InvalidateItem(infoPtr
, i
);
7994 * Scroll the content of a listview.
7997 * [I] infoPtr : valid pointer to the listview structure
7998 * [I] dx : horizontal scroll amount in pixels
7999 * [I] dy : vertical scroll amount in pixels
8006 * If the control is in report view (LV_VIEW_DETAILS) the control can
8007 * be scrolled only in line increments. "dy" will be rounded to the
8008 * nearest number of pixels that are a whole line. Ex: if line height
8009 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
8010 * is passed, then the scroll will be 0. (per MSDN 7/2002)
8012 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8014 switch(infoPtr
->uView
) {
8015 case LV_VIEW_DETAILS
:
8016 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
8017 dy
/= infoPtr
->nItemHeight
;
8020 if (dy
!= 0) return FALSE
;
8026 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8027 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8034 * Sets the background color.
8037 * [I] infoPtr : valid pointer to the listview structure
8038 * [I] color : background color
8044 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8046 TRACE("color %lx\n", color
);
8048 if(infoPtr
->clrBk
!= color
) {
8049 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8050 infoPtr
->clrBk
= color
;
8051 if (color
== CLR_NONE
)
8052 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8055 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8056 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8063 static BOOL
LISTVIEW_SetBkImage(LISTVIEW_INFO
*infoPtr
, const LVBKIMAGEW
*image
, BOOL isW
)
8065 TRACE("%08lx, %p, %p, %u, %d, %d\n", image
->ulFlags
, image
->hbm
, image
->pszImage
,
8066 image
->cchImageMax
, image
->xOffsetPercent
, image
->yOffsetPercent
);
8068 if (image
->ulFlags
& ~LVBKIF_SOURCE_MASK
)
8069 FIXME("unsupported flags %08lx\n", image
->ulFlags
& ~LVBKIF_SOURCE_MASK
);
8071 if (image
->xOffsetPercent
|| image
->yOffsetPercent
)
8072 FIXME("unsupported offset %d,%d\n", image
->xOffsetPercent
, image
->yOffsetPercent
);
8074 switch (image
->ulFlags
& LVBKIF_SOURCE_MASK
)
8076 case LVBKIF_SOURCE_NONE
:
8077 if (infoPtr
->hBkBitmap
)
8079 DeleteObject(infoPtr
->hBkBitmap
);
8080 infoPtr
->hBkBitmap
= NULL
;
8082 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
8085 case LVBKIF_SOURCE_HBITMAP
:
8089 if (infoPtr
->hBkBitmap
)
8091 DeleteObject(infoPtr
->hBkBitmap
);
8092 infoPtr
->hBkBitmap
= NULL
;
8094 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
8095 if (GetObjectW(image
->hbm
, sizeof(bm
), &bm
) == sizeof(bm
))
8097 infoPtr
->hBkBitmap
= image
->hbm
;
8103 case LVBKIF_SOURCE_URL
:
8104 FIXME("LVBKIF_SOURCE_URL: %s\n", isW
? debugstr_w(image
->pszImage
) : debugstr_a((LPCSTR
)image
->pszImage
));
8111 /*** Helper for {Insert,Set}ColumnT *only* */
8112 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8113 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8115 if (lpColumn
->mask
& LVCF_FMT
)
8117 /* format member is valid */
8118 lphdi
->mask
|= HDI_FORMAT
;
8120 /* set text alignment (leftmost column must be left-aligned) */
8121 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8122 lphdi
->fmt
|= HDF_LEFT
;
8123 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8124 lphdi
->fmt
|= HDF_RIGHT
;
8125 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8126 lphdi
->fmt
|= HDF_CENTER
;
8128 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8129 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8131 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8133 lphdi
->fmt
|= HDF_IMAGE
;
8134 lphdi
->iImage
= I_IMAGECALLBACK
;
8137 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8138 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8141 if (lpColumn
->mask
& LVCF_WIDTH
)
8143 lphdi
->mask
|= HDI_WIDTH
;
8144 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8146 /* make it fill the remainder of the controls width */
8150 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8152 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8153 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8156 /* retrieve the layout of the header */
8157 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8158 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8160 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8163 lphdi
->cxy
= lpColumn
->cx
;
8166 if (lpColumn
->mask
& LVCF_TEXT
)
8168 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8169 lphdi
->fmt
|= HDF_STRING
;
8170 lphdi
->pszText
= lpColumn
->pszText
;
8171 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8174 if (lpColumn
->mask
& LVCF_IMAGE
)
8176 lphdi
->mask
|= HDI_IMAGE
;
8177 lphdi
->iImage
= lpColumn
->iImage
;
8180 if (lpColumn
->mask
& LVCF_ORDER
)
8182 lphdi
->mask
|= HDI_ORDER
;
8183 lphdi
->iOrder
= lpColumn
->iOrder
;
8190 * Inserts a new column.
8193 * [I] infoPtr : valid pointer to the listview structure
8194 * [I] nColumn : column index
8195 * [I] lpColumn : column information
8196 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8199 * SUCCESS : new column index
8202 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8203 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8205 COLUMN_INFO
*lpColumnInfo
;
8209 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8211 if (!lpColumn
|| nColumn
< 0) return -1;
8212 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8214 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8215 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8218 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8219 * (can be seen in SPY) otherwise column never gets added.
8221 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8222 hdi
.mask
|= HDI_WIDTH
;
8227 * when the iSubItem is available Windows copies it to the header lParam. It seems
8228 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8230 if (lpColumn
->mask
& LVCF_SUBITEM
)
8232 hdi
.mask
|= HDI_LPARAM
;
8233 hdi
.lParam
= lpColumn
->iSubItem
;
8236 /* create header if not present */
8237 LISTVIEW_CreateHeader(infoPtr
);
8238 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8239 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8241 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8244 /* insert item in header control */
8245 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8246 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8247 nColumn
, (LPARAM
)&hdi
);
8248 if (nNewColumn
== -1) return -1;
8249 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8251 /* create our own column info */
8252 if (!(lpColumnInfo
= Alloc(sizeof(*lpColumnInfo
)))) goto fail
;
8253 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8255 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8256 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8257 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8260 /* now we have to actually adjust the data */
8261 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8263 SUBITEM_INFO
*lpSubItem
;
8269 item
.iSubItem
= nNewColumn
;
8270 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8271 item
.iImage
= I_IMAGECALLBACK
;
8272 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8274 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8276 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8277 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8279 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8280 if (lpSubItem
->iSubItem
>= nNewColumn
)
8281 lpSubItem
->iSubItem
++;
8284 /* add new subitem for each item */
8286 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8290 /* make space for the new column */
8291 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8292 LISTVIEW_UpdateItemSize(infoPtr
);
8297 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8300 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8308 * Sets the attributes of a header item.
8311 * [I] infoPtr : valid pointer to the listview structure
8312 * [I] nColumn : column index
8313 * [I] lpColumn : column attributes
8314 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8320 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8321 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8323 HDITEMW hdi
, hdiget
;
8326 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8328 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8330 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8331 if (lpColumn
->mask
& LVCF_FMT
)
8333 hdi
.mask
|= HDI_FORMAT
;
8334 hdiget
.mask
= HDI_FORMAT
;
8335 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8336 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8338 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8340 /* set header item attributes */
8341 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8342 if (!bResult
) return FALSE
;
8344 if (lpColumn
->mask
& LVCF_FMT
)
8346 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8347 INT oldFmt
= lpColumnInfo
->fmt
;
8349 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8350 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8352 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8356 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8357 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8364 * Sets the column order array
8367 * [I] infoPtr : valid pointer to the listview structure
8368 * [I] iCount : number of elements in column order array
8369 * [I] lpiArray : pointer to column order array
8375 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8377 if (!infoPtr
->hwndHeader
) return FALSE
;
8378 infoPtr
->colRectsDirty
= TRUE
;
8379 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8384 * Sets the width of a column
8387 * [I] infoPtr : valid pointer to the listview structure
8388 * [I] nColumn : column index
8389 * [I] cx : column width
8395 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8397 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8401 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8403 /* set column width only if in report or list mode */
8404 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8406 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8407 with _USEHEADER being the lowest */
8408 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8409 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8411 /* resize all columns if in LV_VIEW_LIST mode */
8412 if(infoPtr
->uView
== LV_VIEW_LIST
)
8414 infoPtr
->nItemWidth
= cx
;
8415 LISTVIEW_InvalidateList(infoPtr
);
8419 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8421 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8426 lvItem
.mask
= LVIF_TEXT
;
8428 lvItem
.iSubItem
= nColumn
;
8429 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8430 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8432 lvItem
.pszText
= szDispText
;
8433 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8434 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8435 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8437 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8438 max_cx
+= infoPtr
->iconSize
.cx
;
8439 max_cx
+= TRAILING_LABEL_PADDING
;
8440 if (nColumn
== 0 && (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
))
8441 max_cx
+= GetSystemMetrics(SM_CXSMICON
);
8444 /* autosize based on listview items width */
8445 if(cx
== LVSCW_AUTOSIZE
)
8447 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8449 /* if iCol is the last column make it fill the remainder of the controls width */
8450 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8455 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8456 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8458 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8462 /* Despite what the MS docs say, if this is not the last
8463 column, then MS resizes the column to the width of the
8464 largest text string in the column, including headers
8465 and items. This is different from LVSCW_AUTOSIZE in that
8466 LVSCW_AUTOSIZE ignores the header string length. */
8469 /* retrieve header text */
8470 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8471 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8472 hdi
.pszText
= szDispText
;
8473 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8475 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8476 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8477 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8478 INT bitmap_margin
= 0;
8481 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8482 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8484 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8485 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8487 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8489 INT icon_cx
, icon_cy
;
8491 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8492 cx
+= icon_cx
+ 2*bitmap_margin
;
8494 else if (hdi
.fmt
& HDF_BITMAP
)
8498 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8499 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8502 SelectObject(hdc
, old_font
);
8503 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8505 cx
= max (cx
, max_cx
);
8509 if (cx
< 0) return FALSE
;
8511 /* call header to update the column change */
8512 hdi
.mask
= HDI_WIDTH
;
8513 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8514 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8515 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8519 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8522 static HIMAGELIST
LISTVIEW_CreateThemedCheckBoxImageList(const LISTVIEW_INFO
*info
)
8524 HBITMAP bitmap
, old_bitmap
;
8525 HIMAGELIST image_list
;
8531 if (!GetWindowTheme(info
->hwndSelf
))
8534 theme
= OpenThemeDataForDpi(NULL
, L
"Button", GetDpiForWindow(info
->hwndSelf
));
8538 hdc
= GetDC(info
->hwndSelf
);
8539 GetThemePartSize(theme
, hdc
, BP_CHECKBOX
, 0, NULL
, TS_DRAW
, &size
);
8540 SetRect(&rect
, 0, 0, size
.cx
, size
.cy
);
8541 image_list
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR32
, 2, 2);
8542 mem_hdc
= CreateCompatibleDC(hdc
);
8543 bitmap
= CreateCompatibleBitmap(hdc
, size
.cx
, size
.cy
);
8544 old_bitmap
= SelectObject(mem_hdc
, bitmap
);
8545 ReleaseDC(info
->hwndSelf
, hdc
);
8547 if (IsThemeBackgroundPartiallyTransparent(theme
, BP_CHECKBOX
, CBS_UNCHECKEDNORMAL
))
8548 FillRect(mem_hdc
, &rect
, (HBRUSH
)(COLOR_WINDOW
+ 1));
8549 DrawThemeBackground(theme
, mem_hdc
, BP_CHECKBOX
, CBS_UNCHECKEDNORMAL
, &rect
, NULL
);
8550 ImageList_Add(image_list
, bitmap
, NULL
);
8552 if (IsThemeBackgroundPartiallyTransparent(theme
, BP_CHECKBOX
, CBS_CHECKEDNORMAL
))
8553 FillRect(mem_hdc
, &rect
, (HBRUSH
)(COLOR_WINDOW
+ 1));
8554 DrawThemeBackground(theme
, mem_hdc
, BP_CHECKBOX
, CBS_CHECKEDNORMAL
, &rect
, NULL
);
8555 ImageList_Add(image_list
, bitmap
, NULL
);
8557 SelectObject(mem_hdc
, old_bitmap
);
8558 DeleteObject(bitmap
);
8560 CloseThemeData(theme
);
8564 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8567 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8569 HBRUSH hbr_white
, hbr_black
;
8572 himl
= LISTVIEW_CreateThemedCheckBoxImageList(infoPtr
);
8576 hbr_white
= GetStockObject(WHITE_BRUSH
);
8577 hbr_black
= GetStockObject(BLACK_BRUSH
);
8578 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8579 ILC_COLOR
| ILC_MASK
, 2, 2);
8580 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8581 hdc
= CreateCompatibleDC(hdc_wnd
);
8582 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8583 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8584 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8586 SetRect(&rc
, 0, 0, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8587 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8588 FillRect(hdc
, &rc
, hbr_white
);
8589 InflateRect(&rc
, -2, -2);
8590 FillRect(hdc
, &rc
, hbr_black
);
8592 SelectObject(hdc
, hbm_im
);
8593 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8594 SelectObject(hdc
, hbm_orig
);
8595 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8597 SelectObject(hdc
, hbm_im
);
8598 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8599 SelectObject(hdc
, hbm_orig
);
8600 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8602 DeleteObject(hbm_mask
);
8603 DeleteObject(hbm_im
);
8611 * Sets the extended listview style.
8614 * [I] infoPtr : valid pointer to the listview structure
8616 * [I] dwStyle : style
8619 * SUCCESS : previous style
8622 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8624 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8626 TRACE("mask %#lx, ex_style %#lx\n", mask
, ex_style
);
8630 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8632 infoPtr
->dwLvExStyle
= ex_style
;
8634 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8636 HIMAGELIST himl
= 0;
8637 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8640 item
.mask
= LVIF_STATE
;
8641 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8642 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8643 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8645 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8646 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8647 ImageList_Destroy(infoPtr
->himlState
);
8649 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8650 /* checkbox list replaces previous custom list or... */
8651 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8652 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8653 /* ...previous was checkbox list */
8654 (old_ex_style
& LVS_EX_CHECKBOXES
))
8655 ImageList_Destroy(himl
);
8658 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8662 /* if not already created */
8663 LISTVIEW_CreateHeader(infoPtr
);
8665 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8666 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8667 style
|= HDS_DRAGDROP
;
8669 style
&= ~HDS_DRAGDROP
;
8670 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8673 /* GRIDLINES adds decoration at top so changes sizes */
8674 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8676 LISTVIEW_CreateHeader(infoPtr
);
8677 LISTVIEW_UpdateSize(infoPtr
);
8680 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8682 LISTVIEW_CreateHeader(infoPtr
);
8685 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8687 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8688 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8691 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8693 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8694 LISTVIEW_CreateHeader(infoPtr
);
8696 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8697 LISTVIEW_UpdateSize(infoPtr
);
8698 LISTVIEW_UpdateScroll(infoPtr
);
8701 LISTVIEW_InvalidateList(infoPtr
);
8702 return old_ex_style
;
8707 * Sets the new hot cursor used during hot tracking and hover selection.
8710 * [I] infoPtr : valid pointer to the listview structure
8711 * [I] hCursor : the new hot cursor handle
8714 * Returns the previous hot cursor
8716 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8718 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8720 infoPtr
->hHotCursor
= hCursor
;
8728 * Sets the hot item index.
8731 * [I] infoPtr : valid pointer to the listview structure
8732 * [I] iIndex : index
8735 * SUCCESS : previous hot item index
8736 * FAILURE : -1 (no hot item)
8738 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8740 INT iOldIndex
= infoPtr
->nHotItem
;
8742 infoPtr
->nHotItem
= iIndex
;
8750 * Sets the amount of time the cursor must hover over an item before it is selected.
8753 * [I] infoPtr : valid pointer to the listview structure
8754 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8757 * Returns the previous hover time
8759 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8761 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8763 infoPtr
->dwHoverTime
= dwHoverTime
;
8765 return oldHoverTime
;
8770 * Sets spacing for icons of LVS_ICON style.
8773 * [I] infoPtr : valid pointer to the listview structure
8774 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8775 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8778 * MAKELONG(oldcx, oldcy)
8780 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8782 INT iconWidth
= 0, iconHeight
= 0;
8783 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8785 TRACE("requested=(%d,%d)\n", cx
, cy
);
8787 /* set to defaults, if instructed to */
8788 if (cx
== -1 && cy
== -1)
8790 infoPtr
->autoSpacing
= TRUE
;
8791 if (infoPtr
->himlNormal
)
8792 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8793 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8794 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8797 infoPtr
->autoSpacing
= FALSE
;
8799 /* if 0 then keep width */
8801 infoPtr
->iconSpacing
.cx
= cx
;
8803 /* if 0 then keep height */
8805 infoPtr
->iconSpacing
.cy
= cy
;
8807 TRACE("old=(%d,%d), new=(%ld,%ld), iconSize=(%ld,%ld), ntmH=%d\n",
8808 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8809 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8810 infoPtr
->ntmHeight
);
8812 /* these depend on the iconSpacing */
8813 LISTVIEW_UpdateItemSize(infoPtr
);
8818 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL is_small
)
8822 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8829 size
->cx
= GetSystemMetrics(is_small
? SM_CXSMICON
: SM_CXICON
);
8830 size
->cy
= GetSystemMetrics(is_small
? SM_CYSMICON
: SM_CYICON
);
8839 * [I] infoPtr : valid pointer to the listview structure
8840 * [I] nType : image list type
8841 * [I] himl : image list handle
8844 * SUCCESS : old image list
8847 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8849 INT oldHeight
= infoPtr
->nItemHeight
;
8850 HIMAGELIST himlOld
= 0;
8852 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8857 himlOld
= infoPtr
->himlNormal
;
8858 infoPtr
->himlNormal
= himl
;
8859 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8860 if (infoPtr
->autoSpacing
)
8861 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8865 himlOld
= infoPtr
->himlSmall
;
8866 infoPtr
->himlSmall
= himl
;
8867 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8868 if (infoPtr
->hwndHeader
)
8869 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8873 himlOld
= infoPtr
->himlState
;
8874 infoPtr
->himlState
= himl
;
8875 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8876 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8880 ERR("Unknown icon type=%d\n", nType
);
8884 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8885 if (infoPtr
->nItemHeight
!= oldHeight
)
8886 LISTVIEW_UpdateScroll(infoPtr
);
8893 * Preallocates memory (does *not* set the actual count of items !)
8896 * [I] infoPtr : valid pointer to the listview structure
8897 * [I] nItems : item count (projected number of items to allocate)
8898 * [I] dwFlags : update flags
8904 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8906 TRACE("nItems %d, flags %#lx\n", nItems
, dwFlags
);
8908 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8910 INT nOldCount
= infoPtr
->nItemCount
;
8911 infoPtr
->nItemCount
= nItems
;
8913 if (nItems
< nOldCount
)
8915 RANGE range
= { nItems
, nOldCount
};
8916 ranges_del(infoPtr
->selectionRanges
, range
);
8917 if (infoPtr
->nFocusedItem
>= nItems
)
8919 LISTVIEW_SetItemFocus(infoPtr
, -1);
8920 infoPtr
->nFocusedItem
= -1;
8921 SetRectEmpty(&infoPtr
->rcFocus
);
8925 LISTVIEW_UpdateScroll(infoPtr
);
8927 /* the flags are valid only in ownerdata report and list modes */
8928 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8930 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8931 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8933 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8934 LISTVIEW_InvalidateList(infoPtr
);
8941 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8942 nFrom
= min(nOldCount
, nItems
);
8943 nTo
= max(nOldCount
, nItems
);
8945 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8947 SetRect(&rcErase
, 0, nFrom
* infoPtr
->nItemHeight
, infoPtr
->nItemWidth
,
8948 nTo
* infoPtr
->nItemHeight
);
8949 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8950 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8951 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8953 else /* LV_VIEW_LIST */
8955 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8957 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8958 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8959 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8960 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8961 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8962 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8963 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8965 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8967 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8968 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8969 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8970 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8971 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8977 /* According to MSDN for non-LVS_OWNERDATA this is just
8978 * a performance issue. The control allocates its internal
8979 * data structures for the number of items specified. It
8980 * cuts down on the number of memory allocations. Therefore
8981 * we will just issue a WARN here
8983 WARN("for non-ownerdata performance option not implemented.\n");
8991 * Sets the position of an item.
8994 * [I] infoPtr : valid pointer to the listview structure
8995 * [I] nItem : item index
8996 * [I] pt : coordinate
9002 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
9006 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
9008 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
9009 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
9012 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
9014 /* This point value seems to be an undocumented feature.
9015 * The best guess is that it means either at the origin,
9016 * or at true beginning of the list. I will assume the origin. */
9017 if ((Pt
.x
== -1) && (Pt
.y
== -1))
9020 if (infoPtr
->uView
== LV_VIEW_ICON
)
9022 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
9023 Pt
.y
-= ICON_TOP_PADDING
;
9028 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
9031 /* Make sure to also disable per item notifications via the notification mask. */
9032 static VOID
LISTVIEW_SetOwnerDataState(LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
, const LVITEMW
*item
)
9034 NMLVODSTATECHANGE nmlv
;
9036 if (nFirst
== nLast
) return;
9039 ZeroMemory(&nmlv
, sizeof(nmlv
));
9040 nmlv
.iFrom
= nFirst
;
9043 nmlv
.uNewState
= item
->state
;
9045 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
9050 * Sets the state of one or many items.
9053 * [I] infoPtr : valid pointer to the listview structure
9054 * [I] nItem : item index
9055 * [I] item : item or subitem info
9061 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
9066 if (!item
) return FALSE
;
9068 lvItem
.iItem
= nItem
;
9069 lvItem
.iSubItem
= 0;
9070 lvItem
.mask
= LVIF_STATE
;
9071 lvItem
.state
= item
->state
;
9072 lvItem
.stateMask
= item
->stateMask
;
9073 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
9080 /* special case optimization for recurring attempt to deselect all */
9081 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
9084 /* select all isn't allowed in LVS_SINGLESEL */
9085 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
9088 /* focus all isn't allowed */
9089 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
9091 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
9092 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9094 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
9095 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
9096 oldstate
|= LVIS_SELECTED
;
9097 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
9100 /* apply to all items */
9101 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
9102 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
9104 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9108 infoPtr
->notify_mask
|= old_mask
;
9112 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
9113 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
9114 nmlv
.uChanged
= LVIF_STATE
;
9115 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
9118 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
9122 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9129 * Sets the text of an item or subitem.
9132 * [I] hwnd : window handle
9133 * [I] nItem : item index
9134 * [I] lpLVItem : item or subitem info
9135 * [I] isW : TRUE if input is Unicode
9141 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9145 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9146 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9148 lvItem
.iItem
= nItem
;
9149 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9150 lvItem
.mask
= LVIF_TEXT
;
9151 lvItem
.pszText
= lpLVItem
->pszText
;
9152 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9154 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9156 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9161 * Set item index that marks the start of a multiple selection.
9164 * [I] infoPtr : valid pointer to the listview structure
9165 * [I] nIndex : index
9168 * Index number or -1 if there is no selection mark.
9170 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9172 INT nOldIndex
= infoPtr
->nSelectionMark
;
9174 TRACE("(nIndex=%d)\n", nIndex
);
9176 if (nIndex
>= -1 && nIndex
< infoPtr
->nItemCount
)
9177 infoPtr
->nSelectionMark
= nIndex
;
9184 * Sets the text background color.
9187 * [I] infoPtr : valid pointer to the listview structure
9188 * [I] color : text background color
9194 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9196 TRACE("color %#lx\n", color
);
9198 infoPtr
->clrTextBk
= color
;
9204 * Sets the text foreground color.
9207 * [I] infoPtr : valid pointer to the listview structure
9208 * [I] color : text color
9214 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9216 TRACE("color %#lx\n", color
);
9218 infoPtr
->clrText
= color
;
9224 * Sets new ToolTip window to ListView control.
9227 * [I] infoPtr : valid pointer to the listview structure
9228 * [I] hwndNewToolTip : handle to new ToolTip
9233 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9235 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9236 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9237 return hwndOldToolTip
;
9242 * sets the Unicode character format flag for the control
9244 * [I] infoPtr :valid pointer to the listview structure
9245 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9248 * Old Unicode Format
9250 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9252 SHORT rc
= infoPtr
->notifyFormat
;
9253 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9254 return rc
== NFR_UNICODE
;
9259 * sets the control view mode
9261 * [I] infoPtr :valid pointer to the listview structure
9262 * [I] nView :new view mode value
9268 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9272 if (infoPtr
->uView
== nView
) return 1;
9274 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9275 if (nView
== LV_VIEW_TILE
)
9277 FIXME("View LV_VIEW_TILE unimplemented\n");
9281 infoPtr
->uView
= nView
;
9283 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9284 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9286 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9287 SetRectEmpty(&infoPtr
->rcFocus
);
9289 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9290 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9295 case LV_VIEW_SMALLICON
:
9296 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9298 case LV_VIEW_DETAILS
:
9303 LISTVIEW_CreateHeader( infoPtr
);
9305 hl
.prc
= &infoPtr
->rcList
;
9307 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9308 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9309 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9316 LISTVIEW_UpdateItemSize(infoPtr
);
9317 LISTVIEW_UpdateSize(infoPtr
);
9318 LISTVIEW_UpdateScroll(infoPtr
);
9319 LISTVIEW_InvalidateList(infoPtr
);
9321 TRACE("nView %ld\n", nView
);
9326 /* LISTVIEW_SetWorkAreas */
9328 struct sorting_context
9331 PFNLVCOMPARE compare_func
;
9335 /* DPA_Sort() callback used for LVM_SORTITEMS */
9336 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9338 struct sorting_context
*context
= (struct sorting_context
*)lParam
;
9339 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9340 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9342 return context
->compare_func(lv_first
->lParam
, lv_second
->lParam
, context
->lParam
);
9345 /* DPA_Sort() callback used for LVM_SORTITEMSEX */
9346 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9348 struct sorting_context
*context
= (struct sorting_context
*)lParam
;
9349 INT first_idx
= DPA_GetPtrIndex( context
->items
, first
);
9350 INT second_idx
= DPA_GetPtrIndex( context
->items
, second
);
9352 return context
->compare_func(first_idx
, second_idx
, context
->lParam
);
9357 * Sorts the listview items.
9360 * [I] infoPtr : valid pointer to the listview structure
9361 * [I] pfnCompare : application-defined value
9362 * [I] lParamSort : pointer to comparison callback
9363 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9369 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9370 LPARAM lParamSort
, BOOL IsEx
)
9372 HDPA hdpaSubItems
, hdpaItems
;
9374 LPVOID selectionMarkItem
= NULL
;
9375 LPVOID focusedItem
= NULL
;
9376 struct sorting_context context
;
9379 TRACE("pfnCompare %p, lParamSort %Ix\n", pfnCompare
, lParamSort
);
9381 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9383 if (!pfnCompare
) return FALSE
;
9384 if (!infoPtr
->hdpaItems
) return FALSE
;
9386 /* if there are 0 or 1 items, there is no need to sort */
9387 if (infoPtr
->nItemCount
< 2) return TRUE
;
9388 if (!(hdpaItems
= DPA_Clone(infoPtr
->hdpaItems
, NULL
))) return FALSE
;
9390 /* clear selection */
9391 ranges_clear(infoPtr
->selectionRanges
);
9393 /* save selection mark and focused item */
9394 if (infoPtr
->nSelectionMark
>= 0)
9395 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9396 if (infoPtr
->nFocusedItem
>= 0)
9397 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9399 context
.items
= hdpaItems
;
9400 context
.compare_func
= pfnCompare
;
9401 context
.lParam
= lParamSort
;
9403 DPA_Sort(hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)&context
);
9405 DPA_Sort(hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)&context
);
9406 DPA_Destroy(infoPtr
->hdpaItems
);
9407 infoPtr
->hdpaItems
= hdpaItems
;
9409 /* restore selection ranges */
9410 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9412 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9413 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9415 if (lpItem
->state
& LVIS_SELECTED
)
9416 ranges_additem(infoPtr
->selectionRanges
, i
);
9418 /* restore selection mark and focused item */
9419 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9420 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9422 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9424 /* refresh the display */
9425 LISTVIEW_InvalidateList(infoPtr
);
9431 * Update theme handle after a theme change.
9434 * [I] infoPtr : valid pointer to the listview structure
9438 * FAILURE : something else
9440 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9442 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9443 CloseThemeData(theme
);
9444 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9445 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9451 * Updates an items or rearranges the listview control.
9454 * [I] infoPtr : valid pointer to the listview structure
9455 * [I] nItem : item index
9461 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9463 TRACE("(nItem=%d)\n", nItem
);
9465 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9467 /* rearrange with default alignment style */
9468 if (is_autoarrange(infoPtr
))
9469 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9471 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9478 * Draw the track line at the place defined in the infoPtr structure.
9479 * The line is drawn with a XOR pen so drawing the line for the second time
9480 * in the same place erases the line.
9483 * [I] infoPtr : valid pointer to the listview structure
9489 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9493 if (infoPtr
->xTrackLine
== -1)
9496 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9498 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9499 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9500 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9506 * Called when an edit control should be displayed. This function is called after
9507 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9510 * [I] hwnd : Handle to the listview
9511 * [I] uMsg : WM_TIMER (ignored)
9512 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9513 * [I] dwTimer : The elapsed time (ignored)
9518 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9520 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9521 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9523 KillTimer(hwnd
, idEvent
);
9524 editItem
->fEnabled
= FALSE
;
9525 /* check if the item is still selected */
9526 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9527 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9532 * Creates the listview control - the WM_NCCREATE phase.
9535 * [I] hwnd : window handle
9536 * [I] lpcs : the create parameters
9542 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
9544 LISTVIEW_INFO
*infoPtr
;
9547 TRACE("(lpcs=%p)\n", lpcs
);
9549 /* initialize info pointer */
9550 infoPtr
= Alloc(sizeof(*infoPtr
));
9551 if (!infoPtr
) return FALSE
;
9553 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9555 infoPtr
->hwndSelf
= hwnd
;
9556 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9557 map_style_view(infoPtr
);
9558 /* determine the type of structures to use */
9559 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9560 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9562 /* initialize color information */
9563 infoPtr
->clrBk
= CLR_NONE
;
9564 infoPtr
->clrText
= CLR_DEFAULT
;
9565 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9566 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9568 /* set default values */
9569 infoPtr
->nFocusedItem
= -1;
9570 infoPtr
->nSelectionMark
= -1;
9571 infoPtr
->nHotItem
= -1;
9572 infoPtr
->redraw
= TRUE
;
9573 infoPtr
->bNoItemMetrics
= TRUE
;
9574 infoPtr
->notify_mask
= NOTIFY_MASK_UNMASK_ALL
;
9575 infoPtr
->autoSpacing
= TRUE
;
9576 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9577 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9578 infoPtr
->nEditLabelItem
= -1;
9579 infoPtr
->nLButtonDownItem
= -1;
9580 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9581 infoPtr
->cWheelRemainder
= 0;
9582 infoPtr
->nMeasureItemHeight
= 0;
9583 infoPtr
->xTrackLine
= -1; /* no track line */
9584 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9585 infoPtr
->iVersion
= COMCTL32_VERSION
;
9586 infoPtr
->colRectsDirty
= FALSE
;
9587 infoPtr
->selected_column
= -1;
9589 /* get default font (icon title) */
9590 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9591 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9592 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9593 LISTVIEW_SaveTextMetrics(infoPtr
);
9595 /* allocate memory for the data structure */
9596 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9597 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9598 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9599 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9600 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9601 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9603 return DefWindowProcW(hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
9606 DestroyWindow(infoPtr
->hwndHeader
);
9607 ranges_destroy(infoPtr
->selectionRanges
);
9608 DPA_Destroy(infoPtr
->hdpaItems
);
9609 DPA_Destroy(infoPtr
->hdpaItemIds
);
9610 DPA_Destroy(infoPtr
->hdpaPosX
);
9611 DPA_Destroy(infoPtr
->hdpaPosY
);
9612 DPA_Destroy(infoPtr
->hdpaColumns
);
9619 * Creates the listview control - the WM_CREATE phase. Most of the data is
9620 * already set up in LISTVIEW_NCCreate
9623 * [I] hwnd : window handle
9624 * [I] lpcs : the create parameters
9630 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9632 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9634 TRACE("lpcs %p, style %#lx\n", lpcs
, lpcs
->style
);
9636 infoPtr
->dwStyle
= lpcs
->style
;
9637 map_style_view(infoPtr
);
9639 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9640 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9641 /* on error defaulting to ANSI notifications */
9642 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9643 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9645 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9647 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9650 infoPtr
->hwndHeader
= 0;
9652 /* init item size to avoid division by 0 */
9653 LISTVIEW_UpdateItemSize (infoPtr
);
9654 LISTVIEW_UpdateSize (infoPtr
);
9656 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9658 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9660 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9662 LISTVIEW_UpdateScroll(infoPtr
);
9663 /* send WM_MEASUREITEM notification */
9664 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9667 OpenThemeData(hwnd
, themeClass
);
9669 /* initialize the icon sizes */
9670 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9671 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9677 * Destroys the listview control.
9680 * [I] infoPtr : valid pointer to the listview structure
9686 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9688 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9689 CloseThemeData(theme
);
9691 /* delete all items */
9692 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9699 * Enables the listview control.
9702 * [I] infoPtr : valid pointer to the listview structure
9703 * [I] bEnable : specifies whether to enable or disable the window
9709 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9711 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9712 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9718 * Erases the background of the listview control.
9721 * [I] infoPtr : valid pointer to the listview structure
9722 * [I] hdc : device context handle
9728 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9732 TRACE("(hdc=%p)\n", hdc
);
9734 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9736 if (infoPtr
->clrBk
== CLR_NONE
)
9738 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9739 SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_ERASEBKGND
);
9741 SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9742 LISTVIEW_DrawBackgroundBitmap(infoPtr
, hdc
, &rc
);
9746 /* for double buffered controls we need to do this during refresh */
9747 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9749 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9755 * Helper function for LISTVIEW_[HV]Scroll *only*.
9756 * Performs vertical/horizontal scrolling by a give amount.
9759 * [I] infoPtr : valid pointer to the listview structure
9760 * [I] dx : amount of horizontal scroll
9761 * [I] dy : amount of vertical scroll
9763 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9765 /* now we can scroll the list */
9766 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9767 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9768 /* if we have focus, adjust rect */
9769 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9770 UpdateWindow(infoPtr
->hwndSelf
);
9775 * Performs vertical scrolling.
9778 * [I] infoPtr : valid pointer to the listview structure
9779 * [I] nScrollCode : scroll code
9780 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9781 * [I] hScrollWnd : scrollbar control window handle
9787 * SB_LINEUP/SB_LINEDOWN:
9788 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9789 * for LVS_REPORT is 1 line
9790 * for LVS_LIST cannot occur
9793 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9796 INT nOldScrollPos
, nNewScrollPos
;
9797 SCROLLINFO scrollInfo
;
9800 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9801 debugscrollcode(nScrollCode
), nScrollDiff
);
9803 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9805 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9806 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9808 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9810 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9812 nOldScrollPos
= scrollInfo
.nPos
;
9813 switch (nScrollCode
)
9819 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9823 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9827 nScrollDiff
= -scrollInfo
.nPage
;
9831 nScrollDiff
= scrollInfo
.nPage
;
9834 case SB_THUMBPOSITION
:
9836 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9843 /* quit right away if pos isn't changing */
9844 if (nScrollDiff
== 0) return 0;
9846 /* calculate new position, and handle overflows */
9847 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9848 if (nScrollDiff
> 0) {
9849 if (nNewScrollPos
< nOldScrollPos
||
9850 nNewScrollPos
> scrollInfo
.nMax
)
9851 nNewScrollPos
= scrollInfo
.nMax
;
9853 if (nNewScrollPos
> nOldScrollPos
||
9854 nNewScrollPos
< scrollInfo
.nMin
)
9855 nNewScrollPos
= scrollInfo
.nMin
;
9858 /* set the new position, and reread in case it changed */
9859 scrollInfo
.fMask
= SIF_POS
;
9860 scrollInfo
.nPos
= nNewScrollPos
;
9861 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9863 /* carry on only if it really changed */
9864 if (nNewScrollPos
== nOldScrollPos
) return 0;
9866 /* now adjust to client coordinates */
9867 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9868 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9870 /* and scroll the window */
9871 scroll_list(infoPtr
, 0, nScrollDiff
);
9878 * Performs horizontal scrolling.
9881 * [I] infoPtr : valid pointer to the listview structure
9882 * [I] nScrollCode : scroll code
9883 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9884 * [I] hScrollWnd : scrollbar control window handle
9890 * SB_LINELEFT/SB_LINERIGHT:
9891 * for LVS_ICON, LVS_SMALLICON 1 pixel
9892 * for LVS_REPORT is 1 pixel
9893 * for LVS_LIST is 1 column --> which is a 1 because the
9894 * scroll is based on columns not pixels
9897 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9900 INT nOldScrollPos
, nNewScrollPos
;
9901 SCROLLINFO scrollInfo
;
9904 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9905 debugscrollcode(nScrollCode
), nScrollDiff
);
9907 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9909 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9910 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9912 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9914 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9916 nOldScrollPos
= scrollInfo
.nPos
;
9918 switch (nScrollCode
)
9924 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9928 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9932 nScrollDiff
= -scrollInfo
.nPage
;
9936 nScrollDiff
= scrollInfo
.nPage
;
9939 case SB_THUMBPOSITION
:
9941 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9948 /* quit right away if pos isn't changing */
9949 if (nScrollDiff
== 0) return 0;
9951 /* calculate new position, and handle overflows */
9952 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9953 if (nScrollDiff
> 0) {
9954 if (nNewScrollPos
< nOldScrollPos
||
9955 nNewScrollPos
> scrollInfo
.nMax
)
9956 nNewScrollPos
= scrollInfo
.nMax
;
9958 if (nNewScrollPos
> nOldScrollPos
||
9959 nNewScrollPos
< scrollInfo
.nMin
)
9960 nNewScrollPos
= scrollInfo
.nMin
;
9963 /* set the new position, and reread in case it changed */
9964 scrollInfo
.fMask
= SIF_POS
;
9965 scrollInfo
.nPos
= nNewScrollPos
;
9966 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9968 /* carry on only if it really changed */
9969 if (nNewScrollPos
== nOldScrollPos
) return 0;
9971 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9973 /* now adjust to client coordinates */
9974 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9975 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9977 /* and scroll the window */
9978 scroll_list(infoPtr
, nScrollDiff
, 0);
9983 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9985 INT pulScrollLines
= 3;
9987 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9989 switch(infoPtr
->uView
)
9992 case LV_VIEW_SMALLICON
:
9994 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9995 * should be fixed in the future.
9997 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9998 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
10001 case LV_VIEW_DETAILS
:
10002 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
10004 /* if scrolling changes direction, ignore left overs */
10005 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
10006 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
10007 infoPtr
->cWheelRemainder
+= wheelDelta
;
10009 infoPtr
->cWheelRemainder
= wheelDelta
;
10010 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
10013 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
10014 cLineScroll
= pulScrollLines
* infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
10015 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ pulScrollLines
;
10016 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
10021 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
10032 * [I] infoPtr : valid pointer to the listview structure
10033 * [I] nVirtualKey : virtual key
10034 * [I] lKeyData : key data
10039 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
10041 HWND hwndSelf
= infoPtr
->hwndSelf
;
10043 NMLVKEYDOWN nmKeyDown
;
10045 TRACE("(nVirtualKey=%d, lKeyData=%ld)\n", nVirtualKey
, lKeyData
);
10047 /* send LVN_KEYDOWN notification */
10048 nmKeyDown
.wVKey
= nVirtualKey
;
10049 nmKeyDown
.flags
= 0;
10050 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
10051 if (!IsWindow(hwndSelf
))
10054 switch (nVirtualKey
)
10057 nItem
= infoPtr
->nFocusedItem
;
10058 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
10059 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
10063 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
10065 if (!notify(infoPtr
, NM_RETURN
)) return 0;
10066 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
10071 if (infoPtr
->nItemCount
> 0)
10076 if (infoPtr
->nItemCount
> 0)
10077 nItem
= infoPtr
->nItemCount
- 1;
10081 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
10085 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
10089 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
10093 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
10097 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10099 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10100 if (infoPtr
->nFocusedItem
== topidx
)
10101 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
10106 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
10107 * LISTVIEW_GetCountPerRow(infoPtr
);
10108 if(nItem
< 0) nItem
= 0;
10112 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10114 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10115 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10116 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10117 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10119 nItem
= topidx
+ cnt
- 1;
10122 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10123 * LISTVIEW_GetCountPerRow(infoPtr
);
10124 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10128 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10129 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10139 * [I] infoPtr : valid pointer to the listview structure
10144 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10148 /* drop any left over scroll amount */
10149 infoPtr
->cWheelRemainder
= 0;
10151 /* if we did not have the focus, there's nothing more to do */
10152 if (!infoPtr
->bFocus
) return 0;
10154 /* send NM_KILLFOCUS notification */
10155 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10157 /* if we have a focus rectangle, get rid of it */
10158 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10160 /* if have a marquee selection, stop it */
10161 if (infoPtr
->bMarqueeSelect
)
10163 /* Remove the marquee rectangle and release our mouse capture */
10164 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10167 SetRectEmpty(&infoPtr
->marqueeRect
);
10169 infoPtr
->bMarqueeSelect
= FALSE
;
10170 infoPtr
->bScrolling
= FALSE
;
10171 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10174 /* set window focus flag */
10175 infoPtr
->bFocus
= FALSE
;
10177 /* invalidate the selected items before resetting focus flag */
10178 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10185 * Processes double click messages (left mouse button).
10188 * [I] infoPtr : valid pointer to the listview structure
10189 * [I] wKey : key flag
10190 * [I] x,y : mouse coordinate
10195 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10197 LVHITTESTINFO htInfo
;
10199 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10201 /* Cancel the item edition if any */
10202 if (infoPtr
->itemEdit
.fEnabled
)
10204 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10205 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10208 /* send NM_RELEASEDCAPTURE notification */
10209 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10214 /* send NM_DBLCLK notification */
10215 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10216 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10218 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10219 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10224 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10229 r
.top
= r
.bottom
= pt
.y
;
10230 r
.left
= r
.right
= pt
.x
;
10232 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10234 SetCapture(infoPtr
->hwndSelf
);
10238 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10240 if (msg
.message
== WM_MOUSEMOVE
)
10242 pt
.x
= (short)LOWORD(msg
.lParam
);
10243 pt
.y
= (short)HIWORD(msg
.lParam
);
10244 if (PtInRect(&r
, pt
))
10252 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10253 msg
.message
<= WM_RBUTTONDBLCLK
)
10258 DispatchMessageW(&msg
);
10261 if (GetCapture() != infoPtr
->hwndSelf
)
10272 * Processes mouse down messages (left mouse button).
10275 * infoPtr [I ] valid pointer to the listview structure
10276 * wKey [I ] key flag
10277 * x,y [I ] mouse coordinate
10282 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10284 LVHITTESTINFO lvHitTestInfo
;
10285 static BOOL bGroupSelect
= TRUE
;
10286 POINT pt
= { x
, y
};
10289 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10291 /* send NM_RELEASEDCAPTURE notification */
10292 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10294 /* set left button down flag and record the click position */
10295 infoPtr
->bLButtonDown
= TRUE
;
10296 infoPtr
->ptClickPos
= pt
;
10297 infoPtr
->bDragging
= FALSE
;
10298 infoPtr
->bMarqueeSelect
= FALSE
;
10299 infoPtr
->bScrolling
= FALSE
;
10301 lvHitTestInfo
.pt
.x
= x
;
10302 lvHitTestInfo
.pt
.y
= y
;
10304 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10305 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10306 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10308 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10310 notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
);
10311 toggle_checkbox_state(infoPtr
, nItem
);
10312 infoPtr
->bLButtonDown
= FALSE
;
10316 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10318 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10319 infoPtr
->nEditLabelItem
= nItem
;
10321 LISTVIEW_SetSelection(infoPtr
, nItem
);
10325 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10329 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10330 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10331 infoPtr
->nSelectionMark
= nItem
;
10337 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10338 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10340 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10341 infoPtr
->nSelectionMark
= nItem
;
10344 else if (wKey
& MK_CONTROL
)
10348 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10350 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10351 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10352 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10353 infoPtr
->nSelectionMark
= nItem
;
10355 else if (wKey
& MK_SHIFT
)
10357 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10361 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10363 infoPtr
->nEditLabelItem
= nItem
;
10364 infoPtr
->nLButtonDownItem
= nItem
;
10366 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10369 /* set selection (clears other pre-existing selections) */
10370 LISTVIEW_SetSelection(infoPtr
, nItem
);
10374 if (!infoPtr
->bFocus
)
10375 SetFocus(infoPtr
->hwndSelf
);
10377 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10378 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10382 if (!infoPtr
->bFocus
)
10383 SetFocus(infoPtr
->hwndSelf
);
10385 /* remove all selections */
10386 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10387 LISTVIEW_DeselectAll(infoPtr
);
10396 * Processes mouse up messages (left mouse button).
10399 * infoPtr [I ] valid pointer to the listview structure
10400 * wKey [I ] key flag
10401 * x,y [I ] mouse coordinate
10406 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10408 LVHITTESTINFO lvHitTestInfo
;
10410 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10412 if (!infoPtr
->bLButtonDown
) return 0;
10414 lvHitTestInfo
.pt
.x
= x
;
10415 lvHitTestInfo
.pt
.y
= y
;
10417 /* send NM_CLICK notification */
10418 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10419 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10421 /* set left button flag */
10422 infoPtr
->bLButtonDown
= FALSE
;
10424 /* set a single selection, reset others */
10425 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10426 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10427 infoPtr
->nLButtonDownItem
= -1;
10429 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10431 /* Remove the marquee rectangle and release our mouse capture */
10432 if (infoPtr
->bMarqueeSelect
)
10434 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10438 SetRectEmpty(&infoPtr
->marqueeRect
);
10439 SetRectEmpty(&infoPtr
->marqueeDrawRect
);
10441 infoPtr
->bDragging
= FALSE
;
10442 infoPtr
->bMarqueeSelect
= FALSE
;
10443 infoPtr
->bScrolling
= FALSE
;
10445 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10449 /* if we clicked on a selected item, edit the label */
10450 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10452 /* we want to make sure the user doesn't want to do a double click. So we will
10453 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10455 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10456 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10457 SetTimer(infoPtr
->hwndSelf
,
10458 (UINT_PTR
)&infoPtr
->itemEdit
,
10459 GetDoubleClickTime(),
10460 LISTVIEW_DelayedEditItem
);
10468 * Destroys the listview control (called after WM_DESTROY).
10471 * [I] infoPtr : valid pointer to the listview structure
10476 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10482 /* destroy data structure */
10483 DPA_Destroy(infoPtr
->hdpaItems
);
10484 DPA_Destroy(infoPtr
->hdpaItemIds
);
10485 DPA_Destroy(infoPtr
->hdpaPosX
);
10486 DPA_Destroy(infoPtr
->hdpaPosY
);
10488 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10489 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10490 DPA_Destroy(infoPtr
->hdpaColumns
);
10491 ranges_destroy(infoPtr
->selectionRanges
);
10493 /* destroy image lists */
10494 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10496 ImageList_Destroy(infoPtr
->himlNormal
);
10497 ImageList_Destroy(infoPtr
->himlSmall
);
10498 ImageList_Destroy(infoPtr
->himlState
);
10501 /* destroy font, bkgnd brush */
10502 infoPtr
->hFont
= 0;
10503 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10504 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10505 if (infoPtr
->hBkBitmap
) DeleteObject(infoPtr
->hBkBitmap
);
10507 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10516 * Handles notifications.
10519 * [I] infoPtr : valid pointer to the listview structure
10520 * [I] lpnmhdr : notification information
10525 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10529 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10531 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10533 /* remember: HDN_LAST < HDN_FIRST */
10534 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10535 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10537 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10539 switch (lpnmhdr
->code
)
10544 COLUMN_INFO
*lpColumnInfo
;
10548 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10551 /* remove the old line (if any) */
10552 LISTVIEW_DrawTrackLine(infoPtr
);
10554 /* compute & draw the new line */
10555 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10556 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10557 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10558 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10559 LISTVIEW_DrawTrackLine(infoPtr
);
10560 return notify_forward_header(infoPtr
, lpnmh
);
10563 case HDN_ENDTRACKA
:
10564 case HDN_ENDTRACKW
:
10565 /* remove the track line (if any) */
10566 LISTVIEW_DrawTrackLine(infoPtr
);
10567 infoPtr
->xTrackLine
= -1;
10568 return notify_forward_header(infoPtr
, lpnmh
);
10570 case HDN_BEGINDRAG
:
10571 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10572 return notify_forward_header(infoPtr
, lpnmh
);
10575 infoPtr
->colRectsDirty
= TRUE
;
10576 LISTVIEW_InvalidateList(infoPtr
);
10577 return notify_forward_header(infoPtr
, lpnmh
);
10579 case HDN_ITEMCHANGEDW
:
10580 case HDN_ITEMCHANGEDA
:
10582 COLUMN_INFO
*lpColumnInfo
;
10586 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10588 hdi
.mask
= HDI_WIDTH
;
10589 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10593 cxy
= lpnmh
->pitem
->cxy
;
10595 /* determine how much we change since the last know position */
10596 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10597 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10600 lpColumnInfo
->rcHeader
.right
+= dx
;
10602 hdi
.mask
= HDI_ORDER
;
10603 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10605 /* not the rightmost one */
10606 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10608 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10609 hdi
.iOrder
+ 1, 0);
10610 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10614 /* only needs to update the scrolls */
10615 infoPtr
->nItemWidth
+= dx
;
10616 LISTVIEW_UpdateScroll(infoPtr
);
10618 LISTVIEW_UpdateItemSize(infoPtr
);
10619 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10622 RECT rcCol
= lpColumnInfo
->rcHeader
;
10624 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10625 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10627 rcCol
.top
= infoPtr
->rcList
.top
;
10628 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10630 /* resizing left-aligned columns leaves most of the left side untouched */
10631 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10633 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10636 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10639 /* when shrinking the last column clear the now unused field */
10640 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10646 /* deal with right from rightmost column area */
10647 right
.left
= rcCol
.right
;
10648 right
.top
= rcCol
.top
;
10649 right
.bottom
= rcCol
.bottom
;
10650 right
.right
= infoPtr
->rcList
.right
;
10652 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10655 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10661 case HDN_ITEMCLICKW
:
10662 case HDN_ITEMCLICKA
:
10664 /* Handle sorting by Header Column */
10667 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10669 nmlv
.iSubItem
= lpnmh
->iItem
;
10670 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10671 return notify_forward_header(infoPtr
, lpnmh
);
10674 case HDN_DIVIDERDBLCLICKW
:
10675 case HDN_DIVIDERDBLCLICKA
:
10676 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10677 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10678 split needed for that */
10679 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10680 return notify_forward_header(infoPtr
, lpnmh
);
10687 * Paint non-client area of control.
10690 * [I] infoPtr : valid pointer to the listview structureof the sender
10691 * [I] region : update region
10694 * 0 - frame was painted
10696 static LRESULT
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10698 LONG exstyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
);
10699 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10700 RECT r
, window_rect
;
10703 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10704 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10706 if (!theme
|| !(exstyle
& WS_EX_CLIENTEDGE
))
10707 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10709 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10711 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10712 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10713 if (region
!= (HRGN
)1)
10714 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10716 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
| DCX_INTERSECTRGN
);
10717 if (infoPtr
->hwndHeader
&& LISTVIEW_IsHeaderEnabled(infoPtr
))
10719 GetWindowRect(infoPtr
->hwndHeader
, &window_rect
);
10720 OffsetRect(&window_rect
, -r
.left
, -r
.top
);
10721 ExcludeClipRect(dc
, window_rect
.left
, window_rect
.top
, window_rect
.right
, window_rect
.bottom
);
10724 OffsetRect(&r
, -r
.left
, -r
.top
);
10725 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10726 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10727 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10728 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10730 /* Call default proc to get the scrollbars etc. painted */
10731 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10732 DeleteObject(cliprgn
);
10739 * Determines the type of structure to use.
10742 * [I] infoPtr : valid pointer to the listview structureof the sender
10743 * [I] hwndFrom : listview window handle
10744 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10749 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10751 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10753 if (nCommand
== NF_REQUERY
)
10754 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10756 return infoPtr
->notifyFormat
;
10761 * Paints/Repaints the listview control. Internal use.
10764 * [I] infoPtr : valid pointer to the listview structure
10765 * [I] hdc : device context handle
10770 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10772 TRACE("(hdc=%p)\n", hdc
);
10774 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10776 infoPtr
->bNoItemMetrics
= FALSE
;
10777 LISTVIEW_UpdateItemSize(infoPtr
);
10778 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10779 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10780 LISTVIEW_UpdateScroll(infoPtr
);
10783 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10786 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10791 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10792 if (!hdc
) return 1;
10793 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10794 EndPaint(infoPtr
->hwndSelf
, &ps
);
10802 * Paints/Repaints the listview control, WM_PAINT handler.
10805 * [I] infoPtr : valid pointer to the listview structure
10806 * [I] hdc : device context handle
10811 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10813 TRACE("(hdc=%p)\n", hdc
);
10815 if (!is_redrawing(infoPtr
))
10816 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10818 return LISTVIEW_Paint(infoPtr
, hdc
);
10823 * Paints/Repaints the listview control.
10826 * [I] infoPtr : valid pointer to the listview structure
10827 * [I] hdc : device context handle
10828 * [I] options : drawing options
10833 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10835 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10838 if (options
& ~(PRF_ERASEBKGND
|PRF_CLIENT
))
10839 FIXME("(hdc=%p options %#lx) partial stub\n", hdc
, options
);
10841 if (options
& PRF_ERASEBKGND
)
10842 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10844 if (options
& PRF_CLIENT
)
10845 LISTVIEW_Paint(infoPtr
, hdc
);
10853 * Processes double click messages (right mouse button).
10856 * [I] infoPtr : valid pointer to the listview structure
10857 * [I] wKey : key flag
10858 * [I] x,y : mouse coordinate
10863 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10865 LVHITTESTINFO lvHitTestInfo
;
10867 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10869 /* send NM_RELEASEDCAPTURE notification */
10870 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10872 /* send NM_RDBLCLK notification */
10873 lvHitTestInfo
.pt
.x
= x
;
10874 lvHitTestInfo
.pt
.y
= y
;
10875 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10876 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10883 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10886 * [I] infoPtr : valid pointer to the listview structure
10887 * [I] wKey : key flag
10888 * [I] x, y : mouse coordinate
10893 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10898 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10900 /* send NM_RELEASEDCAPTURE notification */
10901 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10903 /* determine the index of the selected item */
10906 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10908 /* make sure the listview control window has the focus */
10909 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10911 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10913 LISTVIEW_SetItemFocus(infoPtr
, item
);
10914 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10915 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10916 LISTVIEW_SetSelection(infoPtr
, item
);
10919 LISTVIEW_DeselectAll(infoPtr
);
10921 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10923 if (ht
.iItem
!= -1)
10927 memset(&nmlv
, 0, sizeof(nmlv
));
10928 nmlv
.iItem
= ht
.iItem
;
10929 nmlv
.ptAction
= ht
.pt
;
10931 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10936 SetFocus(infoPtr
->hwndSelf
);
10940 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10942 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10944 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10945 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10946 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10958 * [I] infoPtr : valid pointer to the listview structure
10959 * [I] hwnd : window handle of window containing the cursor
10960 * [I] nHittest : hit-test code
10961 * [I] wMouseMsg : ideintifier of the mouse message
10964 * TRUE if cursor is set
10967 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10969 LVHITTESTINFO lvHitTestInfo
;
10971 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10973 if (!infoPtr
->hHotCursor
) goto forward
;
10975 GetCursorPos(&lvHitTestInfo
.pt
);
10976 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10978 SetCursor(infoPtr
->hHotCursor
);
10984 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10992 * [I] infoPtr : valid pointer to the listview structure
10993 * [I] hwndLoseFocus : handle of previously focused window
10998 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
11000 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
11002 /* if we have the focus already, there's nothing to do */
11003 if (infoPtr
->bFocus
) return 0;
11005 /* send NM_SETFOCUS notification */
11006 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
11008 /* set window focus flag */
11009 infoPtr
->bFocus
= TRUE
;
11011 /* put the focus rect back on */
11012 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
11014 /* redraw all visible selected items */
11015 LISTVIEW_InvalidateSelectedItems(infoPtr
);
11025 * [I] infoPtr : valid pointer to the listview structure
11026 * [I] fRedraw : font handle
11027 * [I] fRedraw : redraw flag
11032 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
11034 HFONT oldFont
= infoPtr
->hFont
;
11035 INT oldHeight
= infoPtr
->nItemHeight
;
11037 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
11039 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
11040 if (infoPtr
->hFont
== oldFont
) return 0;
11042 LISTVIEW_SaveTextMetrics(infoPtr
);
11044 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
11046 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
11048 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
11049 LISTVIEW_UpdateSize(infoPtr
);
11050 LISTVIEW_UpdateScroll(infoPtr
);
11052 else if (infoPtr
->nItemHeight
!= oldHeight
)
11053 LISTVIEW_UpdateScroll(infoPtr
);
11055 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
11062 * Message handling for WM_SETREDRAW.
11063 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
11066 * [I] infoPtr : valid pointer to the listview structure
11067 * [I] redraw: state of redraw flag
11072 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL redraw
)
11074 TRACE("old=%d, new=%d\n", infoPtr
->redraw
, redraw
);
11076 if (infoPtr
->redraw
== !!redraw
)
11079 if (!(infoPtr
->redraw
= !!redraw
))
11082 if (is_autoarrange(infoPtr
))
11083 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11084 LISTVIEW_UpdateScroll(infoPtr
);
11086 /* despite what the WM_SETREDRAW docs says, apps expect us
11087 * to invalidate the listview here... stupid! */
11088 LISTVIEW_InvalidateList(infoPtr
);
11095 * Resizes the listview control. This function processes WM_SIZE
11096 * messages. At this time, the width and height are not used.
11099 * [I] infoPtr : valid pointer to the listview structure
11100 * [I] Width : new width
11101 * [I] Height : new height
11106 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
11108 RECT rcOld
= infoPtr
->rcList
;
11110 TRACE("(width=%d, height=%d)\n", Width
, Height
);
11112 LISTVIEW_UpdateSize(infoPtr
);
11113 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
11115 /* do not bother with display related stuff if we're not redrawing */
11116 if (!is_redrawing(infoPtr
)) return 0;
11118 if (is_autoarrange(infoPtr
))
11119 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11121 LISTVIEW_UpdateScroll(infoPtr
);
11123 /* refresh all only for lists whose height changed significantly */
11124 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11125 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11126 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11127 LISTVIEW_InvalidateList(infoPtr
);
11134 * Sets the size information.
11137 * [I] infoPtr : valid pointer to the listview structure
11142 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11144 TRACE("uView %ld, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11146 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11148 if (infoPtr
->uView
== LV_VIEW_LIST
)
11150 /* Apparently the "LIST" style is supposed to have the same
11151 * number of items in a column even if there is no scroll bar.
11152 * Since if a scroll bar already exists then the bottom is already
11153 * reduced, only reduce if the scroll bar does not currently exist.
11154 * The "2" is there to mimic the native control. I think it may be
11155 * related to either padding or edges. (GLA 7/2002)
11157 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11158 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11159 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11162 /* When ListView control is created invisible, header isn't created right away. */
11163 if (infoPtr
->hwndHeader
)
11170 LISTVIEW_GetOrigin(infoPtr
, &origin
);
11172 rect
= infoPtr
->rcList
;
11173 rect
.left
+= origin
.x
;
11177 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11178 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11180 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11181 wp
.flags
|= SWP_SHOWWINDOW
;
11184 wp
.flags
|= SWP_HIDEWINDOW
;
11188 SetWindowPos(infoPtr
->hwndHeader
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11189 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11191 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11193 /* extra padding for grid */
11194 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11195 infoPtr
->rcList
.top
+= 2;
11197 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11202 * Processes WM_STYLECHANGED messages.
11205 * [I] infoPtr : valid pointer to the listview structure
11206 * [I] wStyleType : window style type (normal or extended)
11207 * [I] lpss : window style information
11212 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11213 const STYLESTRUCT
*lpss
)
11215 UINT uNewView
, uOldView
;
11216 BOOL repaint
= FALSE
;
11219 TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n",
11220 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11222 if (wStyleType
!= GWL_STYLE
|| lpss
->styleNew
== infoPtr
->dwStyle
) return 0;
11224 infoPtr
->dwStyle
= lpss
->styleNew
;
11226 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11227 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11228 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11230 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11231 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11232 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11234 uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11235 uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11237 if (uNewView
!= uOldView
)
11243 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11244 changing style updates current view only when view bits change. */
11245 map_style_view(infoPtr
);
11246 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11247 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11249 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11250 SetRectEmpty(&infoPtr
->rcFocus
);
11252 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11253 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11255 if (uNewView
== LVS_REPORT
)
11260 LISTVIEW_CreateHeader( infoPtr
);
11262 hl
.prc
= &infoPtr
->rcList
;
11264 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11265 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11266 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11267 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11270 LISTVIEW_UpdateItemSize(infoPtr
);
11273 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11275 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11277 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11279 /* Turn off the header control */
11280 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11281 TRACE("Hide header control, was 0x%08x\n", style
);
11282 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11284 /* Turn on the header control */
11285 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11287 TRACE("Show header control, was 0x%08x\n", style
);
11288 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11294 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11295 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11296 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11298 /* update the size of the client area */
11299 LISTVIEW_UpdateSize(infoPtr
);
11301 /* add scrollbars if needed */
11302 LISTVIEW_UpdateScroll(infoPtr
);
11305 LISTVIEW_InvalidateList(infoPtr
);
11312 * Processes WM_STYLECHANGING messages.
11315 * [I] wStyleType : window style type (normal or extended)
11316 * [I0] lpss : window style information
11321 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11324 TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n",
11325 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11327 /* don't forward LVS_OWNERDATA only if not already set to */
11328 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11330 if (lpss
->styleOld
& LVS_OWNERDATA
)
11331 lpss
->styleNew
|= LVS_OWNERDATA
;
11333 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11341 * Processes WM_SHOWWINDOW messages.
11344 * [I] infoPtr : valid pointer to the listview structure
11345 * [I] bShown : window is being shown (FALSE when hidden)
11346 * [I] iStatus : window show status
11351 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11353 /* header delayed creation */
11354 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11356 LISTVIEW_CreateHeader(infoPtr
);
11358 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11359 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11362 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11367 * Processes CCM_GETVERSION messages.
11370 * [I] infoPtr : valid pointer to the listview structure
11375 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11377 return infoPtr
->iVersion
;
11382 * Processes CCM_SETVERSION messages.
11385 * [I] infoPtr : valid pointer to the listview structure
11386 * [I] iVersion : version to be set
11389 * -1 when requested version is greater than DLL version;
11390 * previous version otherwise
11392 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11394 INT iOldVersion
= infoPtr
->iVersion
;
11396 if (iVersion
> COMCTL32_VERSION
)
11399 infoPtr
->iVersion
= iVersion
;
11401 TRACE("new version %ld\n", iVersion
);
11403 return iOldVersion
;
11408 * Window procedure of the listview control.
11411 static LRESULT WINAPI
11412 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11414 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11416 TRACE("hwnd %p, uMsg %x, wParam %Ix, lParam %Ix\n", hwnd
, uMsg
, wParam
, lParam
);
11418 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11419 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11423 case LVM_APPROXIMATEVIEWRECT
:
11424 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11425 LOWORD(lParam
), HIWORD(lParam
));
11427 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11429 case LVM_CANCELEDITLABEL
:
11430 return LISTVIEW_CancelEditLabel(infoPtr
);
11432 case LVM_CREATEDRAGIMAGE
:
11433 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11435 case LVM_DELETEALLITEMS
:
11436 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11438 case LVM_DELETECOLUMN
:
11439 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11441 case LVM_DELETEITEM
:
11442 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11444 case LVM_EDITLABELA
:
11445 case LVM_EDITLABELW
:
11446 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11447 uMsg
== LVM_EDITLABELW
);
11448 /* case LVM_ENABLEGROUPVIEW: */
11450 case LVM_ENSUREVISIBLE
:
11451 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11453 case LVM_FINDITEMW
:
11454 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11456 case LVM_FINDITEMA
:
11457 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11459 case LVM_GETBKCOLOR
:
11460 return infoPtr
->clrBk
;
11462 /* case LVM_GETBKIMAGE: */
11464 case LVM_GETCALLBACKMASK
:
11465 return infoPtr
->uCallbackMask
;
11467 case LVM_GETCOLUMNA
:
11468 case LVM_GETCOLUMNW
:
11469 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11470 uMsg
== LVM_GETCOLUMNW
);
11472 case LVM_GETCOLUMNORDERARRAY
:
11473 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11475 case LVM_GETCOLUMNWIDTH
:
11476 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11478 case LVM_GETCOUNTPERPAGE
:
11479 return LISTVIEW_GetCountPerPage(infoPtr
);
11481 case LVM_GETEDITCONTROL
:
11482 return (LRESULT
)infoPtr
->hwndEdit
;
11484 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11485 return infoPtr
->dwLvExStyle
;
11487 /* case LVM_GETGROUPINFO: */
11489 /* case LVM_GETGROUPMETRICS: */
11491 case LVM_GETHEADER
:
11492 return (LRESULT
)infoPtr
->hwndHeader
;
11494 case LVM_GETHOTCURSOR
:
11495 return (LRESULT
)infoPtr
->hHotCursor
;
11497 case LVM_GETHOTITEM
:
11498 return infoPtr
->nHotItem
;
11500 case LVM_GETHOVERTIME
:
11501 return infoPtr
->dwHoverTime
;
11503 case LVM_GETIMAGELIST
:
11504 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11506 /* case LVM_GETINSERTMARK: */
11508 /* case LVM_GETINSERTMARKCOLOR: */
11510 /* case LVM_GETINSERTMARKRECT: */
11512 case LVM_GETISEARCHSTRINGA
:
11513 case LVM_GETISEARCHSTRINGW
:
11514 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11519 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11521 case LVM_GETITEMCOUNT
:
11522 return infoPtr
->nItemCount
;
11524 case LVM_GETITEMPOSITION
:
11525 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11527 case LVM_GETITEMRECT
:
11528 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11530 case LVM_GETITEMSPACING
:
11531 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11533 case LVM_GETITEMSTATE
:
11534 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11536 case LVM_GETITEMTEXTA
:
11537 case LVM_GETITEMTEXTW
:
11538 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11539 uMsg
== LVM_GETITEMTEXTW
);
11541 case LVM_GETNEXTITEM
:
11542 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11544 case LVM_GETNEXTITEMINDEX
:
11545 return LISTVIEW_GetNextItemIndex(infoPtr
, (LVITEMINDEX
*)wParam
, lParam
);
11547 case LVM_GETNUMBEROFWORKAREAS
:
11548 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11551 case LVM_GETORIGIN
:
11552 if (!lParam
) return FALSE
;
11553 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11554 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11555 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11558 /* case LVM_GETOUTLINECOLOR: */
11560 case LVM_GETSELECTEDCOLUMN
:
11561 return infoPtr
->selected_column
;
11563 case LVM_GETSELECTEDCOUNT
:
11564 return LISTVIEW_GetSelectedCount(infoPtr
);
11566 case LVM_GETSELECTIONMARK
:
11567 return infoPtr
->nSelectionMark
;
11569 case LVM_GETSTRINGWIDTHA
:
11570 case LVM_GETSTRINGWIDTHW
:
11571 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11572 uMsg
== LVM_GETSTRINGWIDTHW
);
11574 case LVM_GETSUBITEMRECT
:
11575 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11577 case LVM_GETTEXTBKCOLOR
:
11578 return infoPtr
->clrTextBk
;
11580 case LVM_GETTEXTCOLOR
:
11581 return infoPtr
->clrText
;
11583 /* case LVM_GETTILEINFO: */
11585 /* case LVM_GETTILEVIEWINFO: */
11587 case LVM_GETTOOLTIPS
:
11588 if( !infoPtr
->hwndToolTip
)
11589 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11590 return (LRESULT
)infoPtr
->hwndToolTip
;
11592 case LVM_GETTOPINDEX
:
11593 return LISTVIEW_GetTopIndex(infoPtr
);
11595 case LVM_GETUNICODEFORMAT
:
11596 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11599 return infoPtr
->uView
;
11601 case LVM_GETVIEWRECT
:
11602 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11604 case LVM_GETWORKAREAS
:
11605 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11608 /* case LVM_HASGROUP: */
11611 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11613 case LVM_INSERTCOLUMNA
:
11614 case LVM_INSERTCOLUMNW
:
11615 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11616 uMsg
== LVM_INSERTCOLUMNW
);
11618 /* case LVM_INSERTGROUP: */
11620 /* case LVM_INSERTGROUPSORTED: */
11622 case LVM_INSERTITEMA
:
11623 case LVM_INSERTITEMW
:
11624 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11626 /* case LVM_INSERTMARKHITTEST: */
11628 /* case LVM_ISGROUPVIEWENABLED: */
11630 case LVM_ISITEMVISIBLE
:
11631 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11633 case LVM_MAPIDTOINDEX
:
11634 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11636 case LVM_MAPINDEXTOID
:
11637 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11639 /* case LVM_MOVEGROUP: */
11641 /* case LVM_MOVEITEMTOGROUP: */
11643 case LVM_REDRAWITEMS
:
11644 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11646 /* case LVM_REMOVEALLGROUPS: */
11648 /* case LVM_REMOVEGROUP: */
11651 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11653 case LVM_SETBKCOLOR
:
11654 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11656 case LVM_SETBKIMAGEA
:
11657 case LVM_SETBKIMAGEW
:
11658 return LISTVIEW_SetBkImage(infoPtr
, (LVBKIMAGEW
*)lParam
, uMsg
== LVM_SETBKIMAGEW
);
11660 case LVM_SETCALLBACKMASK
:
11661 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11664 case LVM_SETCOLUMNA
:
11665 case LVM_SETCOLUMNW
:
11666 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11667 uMsg
== LVM_SETCOLUMNW
);
11669 case LVM_SETCOLUMNORDERARRAY
:
11670 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11672 case LVM_SETCOLUMNWIDTH
:
11673 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11675 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11676 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11678 /* case LVM_SETGROUPINFO: */
11680 /* case LVM_SETGROUPMETRICS: */
11682 case LVM_SETHOTCURSOR
:
11683 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11685 case LVM_SETHOTITEM
:
11686 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11688 case LVM_SETHOVERTIME
:
11689 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11691 case LVM_SETICONSPACING
:
11693 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11694 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11696 case LVM_SETIMAGELIST
:
11697 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11699 /* case LVM_SETINFOTIP: */
11701 /* case LVM_SETINSERTMARK: */
11703 /* case LVM_SETINSERTMARKCOLOR: */
11708 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11709 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11712 case LVM_SETITEMCOUNT
:
11713 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11715 case LVM_SETITEMPOSITION
:
11718 pt
.x
= (short)LOWORD(lParam
);
11719 pt
.y
= (short)HIWORD(lParam
);
11720 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11723 case LVM_SETITEMPOSITION32
:
11724 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11726 case LVM_SETITEMSTATE
:
11727 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11729 case LVM_SETITEMTEXTA
:
11730 case LVM_SETITEMTEXTW
:
11731 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11732 uMsg
== LVM_SETITEMTEXTW
);
11734 /* case LVM_SETOUTLINECOLOR: */
11736 case LVM_SETSELECTEDCOLUMN
:
11737 infoPtr
->selected_column
= (INT
)wParam
;
11740 case LVM_SETSELECTIONMARK
:
11741 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11743 case LVM_SETTEXTBKCOLOR
:
11744 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11746 case LVM_SETTEXTCOLOR
:
11747 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11749 /* case LVM_SETTILEINFO: */
11751 /* case LVM_SETTILEVIEWINFO: */
11753 /* case LVM_SETTILEWIDTH: */
11755 case LVM_SETTOOLTIPS
:
11756 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11758 case LVM_SETUNICODEFORMAT
:
11759 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11762 return LISTVIEW_SetView(infoPtr
, wParam
);
11764 /* case LVM_SETWORKAREAS: */
11766 /* case LVM_SORTGROUPS: */
11768 case LVM_SORTITEMS
:
11769 case LVM_SORTITEMSEX
:
11770 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11771 uMsg
== LVM_SORTITEMSEX
);
11772 case LVM_SUBITEMHITTEST
:
11773 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11776 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11778 case CCM_GETVERSION
:
11779 return LISTVIEW_GetVersion(infoPtr
);
11781 case CCM_SETVERSION
:
11782 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11785 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11788 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11791 return LISTVIEW_NCCreate(hwnd
, wParam
, (LPCREATESTRUCTW
)lParam
);
11794 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11797 return LISTVIEW_Destroy(infoPtr
);
11800 return LISTVIEW_Enable(infoPtr
);
11802 case WM_ERASEBKGND
:
11803 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11805 case WM_GETDLGCODE
:
11806 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11809 return (LRESULT
)infoPtr
->hFont
;
11812 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11815 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11818 return LISTVIEW_KillFocus(infoPtr
);
11820 case WM_LBUTTONDBLCLK
:
11821 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11823 case WM_LBUTTONDOWN
:
11824 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11827 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11830 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11832 case WM_MOUSEHOVER
:
11833 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11836 return LISTVIEW_NCDestroy(infoPtr
);
11839 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11842 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11844 case WM_NOTIFYFORMAT
:
11845 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11847 case WM_PRINTCLIENT
:
11848 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11851 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11853 case WM_RBUTTONDBLCLK
:
11854 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11856 case WM_RBUTTONDOWN
:
11857 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11860 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11863 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11866 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11869 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11871 case WM_SHOWWINDOW
:
11872 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11874 case WM_STYLECHANGED
:
11875 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11877 case WM_STYLECHANGING
:
11878 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11880 case WM_SYSCOLORCHANGE
:
11881 COMCTL32_RefreshSysColors();
11884 /* case WM_TIMER: */
11885 case WM_THEMECHANGED
:
11886 return LISTVIEW_ThemeChanged(infoPtr
);
11889 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11891 case WM_MOUSEWHEEL
:
11892 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11893 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11894 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11896 case WM_WINDOWPOSCHANGED
:
11897 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11899 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11900 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11902 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11904 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11906 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11908 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11910 /* case WM_WININICHANGE: */
11913 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11914 ERR("unknown msg %04x, wp %Ix, lp %Ix\n", uMsg
, wParam
, lParam
);
11916 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11923 * Registers the window class.
11931 void LISTVIEW_Register(void)
11933 WNDCLASSW wndClass
;
11935 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11936 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11937 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11938 wndClass
.cbClsExtra
= 0;
11939 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11940 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11941 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11942 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11943 RegisterClassW(&wndClass
);
11948 * Unregisters the window class.
11956 void LISTVIEW_Unregister(void)
11958 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11963 * Handle any WM_COMMAND messages
11966 * [I] infoPtr : valid pointer to the listview structure
11967 * [I] wParam : the first message parameter
11968 * [I] lParam : the second message parameter
11973 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11976 TRACE("%p, %x, %x, %Ix\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11978 if (!infoPtr
->hwndEdit
) return 0;
11980 switch (HIWORD(wParam
))
11985 * Adjust the edit window size
11987 WCHAR buffer
[1024];
11988 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11989 HFONT hFont
, hOldFont
= 0;
11993 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11994 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, ARRAY_SIZE(buffer
));
11995 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11997 /* Select font to get the right dimension of the string */
11998 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
12001 hOldFont
= SelectObject(hdc
, hFont
);
12004 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
12006 TEXTMETRICW textMetric
;
12008 /* Add Extra spacing for the next character */
12009 GetTextMetricsW(hdc
, &textMetric
);
12010 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
12012 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
12013 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
12016 SelectObject(hdc
, hOldFont
);
12018 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
12024 if (infoPtr
->notify_mask
& NOTIFY_MASK_END_LABEL_EDIT
)
12025 LISTVIEW_CancelEditLabel(infoPtr
);
12030 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);