4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1999 Luc Tourangeau
6 * Copyright 2000 Jason Mawdsley
7 * Copyright 2001 CodeWeavers Inc.
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009-2015 Nikolay Sivov
10 * Copyright 2009 Owen Rudge for CodeWeavers
11 * Copyright 2012-2013 Daniel Jelinski
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 * Default Message Processing
30 * -- WM_CREATE: create the icon and small icon image lists at this point only if
31 * the LVS_SHAREIMAGELISTS style is not specified.
32 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
33 * or small icon and the LVS_AUTOARRANGE style is specified.
38 * -- Hot item handling, mouse hovering
39 * -- Workareas support
44 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
45 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
46 * -- LVA_SNAPTOGRID not implemented
47 * -- LISTVIEW_ApproximateViewRect partially implemented
48 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
51 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
52 * linear in the number of items in the list, and this is
53 * unacceptable for large lists.
54 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
55 * binary search to calculate item index (e.g. DPA_Search()).
56 * This requires sorted state to be reliably tracked in item modifiers.
57 * -- we should keep an ordered array of coordinates in iconic mode.
58 * This would allow framing items (iterator_frameditems),
59 * and finding the nearest item (LVFI_NEARESTXY) a lot more efficiently.
66 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
71 * -- LVS_NOSCROLL (see Q137520)
75 * -- LVS_EX_BORDERSELECT
79 * -- LVS_EX_MULTIWORKAREAS
81 * -- LVS_EX_SIMPLESELECT
82 * -- LVS_EX_TWOCLICKACTIVATE
83 * -- LVS_EX_UNDERLINECOLD
84 * -- LVS_EX_UNDERLINEHOT
87 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
93 * -- LVM_ENABLEGROUPVIEW
94 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
95 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
96 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
97 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
98 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
99 * -- LVM_GETINSERTMARKRECT
100 * -- LVM_GETNUMBEROFWORKAREAS
101 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
102 * -- LVM_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 */
304 INT ntmHeight
; /* Some cached metrics of the font used */
305 INT ntmMaxCharWidth
; /* by the listview to draw items */
308 /* mouse operation */
311 POINT ptClickPos
; /* point where the user clicked */
312 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
317 /* keyboard operation */
318 DWORD lastKeyPressTimestamp
;
320 INT nSearchParamLength
;
321 WCHAR szSearchParam
[ MAX_PATH
];
324 BOOL bIsDrawing
; /* Drawing in progress */
325 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
326 BOOL redraw
; /* WM_SETREDRAW switch */
329 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
335 /* How many we debug buffer to allocate */
336 #define DEBUG_BUFFERS 20
337 /* The size of a single debug buffer */
338 #define DEBUG_BUFFER_SIZE 256
340 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
341 #define SB_INTERNAL -1
343 /* maximum size of a label */
344 #define DISP_TEXT_SIZE 260
346 /* padding for items in list and small icon display modes */
347 #define WIDTH_PADDING 12
349 /* padding for items in list, report and small icon display modes */
350 #define HEIGHT_PADDING 1
352 /* offset of items in report display mode */
353 #define REPORT_MARGINX 2
355 /* padding for icon in large icon display mode
356 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
357 * that HITTEST will see.
358 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
359 * ICON_TOP_PADDING - sum of the two above.
360 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
361 * LABEL_HOR_PADDING - between text and sides of box
362 * LABEL_VERT_PADDING - between bottom of text and end of box
364 * ICON_LR_PADDING - additional width above icon size.
365 * ICON_LR_HALF - half of the above value
367 #define ICON_TOP_PADDING_NOTHITABLE 2
368 #define ICON_TOP_PADDING_HITABLE 2
369 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
370 #define ICON_BOTTOM_PADDING 4
371 #define LABEL_HOR_PADDING 5
372 #define LABEL_VERT_PADDING 7
373 #define ICON_LR_PADDING 16
374 #define ICON_LR_HALF (ICON_LR_PADDING/2)
376 /* default label width for items in list and small icon display modes */
377 #define DEFAULT_LABEL_WIDTH 40
378 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
379 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
381 /* default column width for items in list display mode */
382 #define DEFAULT_COLUMN_WIDTH 128
384 /* Size of "line" scroll for V & H scrolls */
385 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
387 /* Padding between image and label */
388 #define IMAGE_PADDING 2
390 /* Padding behind the label */
391 #define TRAILING_LABEL_PADDING 12
392 #define TRAILING_HEADER_PADDING 11
394 /* Border for the icon caption */
395 #define CAPTION_BORDER 2
397 /* Standard DrawText flags */
398 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
399 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
400 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
402 /* Image index from state */
403 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
405 /* The time in milliseconds to reset the search in the list */
406 #define KEY_DELAY 450
408 /* Dump the LISTVIEW_INFO structure to the debug channel */
409 #define LISTVIEW_DUMP(iP) do { \
410 TRACE("hwndSelf=%p, clrBk=%#lx, clrText=%#lx, clrTextBk=%#lx, ItemHeight=%d, ItemWidth=%d, Style=%#lx\n", \
411 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
412 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
413 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=%#lx, Focus=%d\n", \
414 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
415 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
416 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%ld, icSz.cy=%ld, icSp.cx=%ld, icSp.cy=%ld, notifyFmt=%d\n", \
417 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
418 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
419 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
422 static const WCHAR themeClass
[] = L
"ListView";
425 * forward declarations
427 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
428 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
429 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
430 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
431 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
432 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
433 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
434 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
435 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
436 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
437 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
438 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
439 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
440 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
441 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
442 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
443 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
444 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
445 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
446 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
448 /******** Text handling functions *************************************/
450 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
451 * text string. The string may be ANSI or Unicode, in which case
452 * the boolean isW tells us the type of the string.
454 * The name of the function tell what type of strings it expects:
455 * W: Unicode, T: ANSI/Unicode - function of isW
458 static inline BOOL
is_text(LPCWSTR text
)
460 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
463 static inline int textlenT(LPCWSTR text
, BOOL isW
)
465 return !is_text(text
) ? 0 :
466 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
469 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
472 if (isSrcW
) lstrcpynW(dest
, src
, max
);
473 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
475 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
476 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
479 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
481 LPWSTR wstr
= (LPWSTR
)text
;
483 if (!isW
&& is_text(text
))
485 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
486 wstr
= Alloc(len
* sizeof(WCHAR
));
487 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
489 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
493 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
495 if (!isW
&& is_text(wstr
)) Free (wstr
);
499 * dest is a pointer to a Unicode string
500 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
502 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
506 if (src
== LPSTR_TEXTCALLBACKW
)
508 if (is_text(*dest
)) Free(*dest
);
509 *dest
= LPSTR_TEXTCALLBACKW
;
513 LPWSTR pszText
= textdupTtoW(src
, isW
);
514 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
515 bResult
= Str_SetPtrW(dest
, pszText
);
516 textfreeT(pszText
, isW
);
522 * compares a Unicode to a Unicode/ANSI text string
524 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
526 if (!aw
) return bt
? -1 : 0;
528 if (aw
== LPSTR_TEXTCALLBACKW
)
529 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
530 if (bt
!= LPSTR_TEXTCALLBACKW
)
532 LPWSTR bw
= textdupTtoW(bt
, isW
);
533 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
541 /******** Debugging functions *****************************************/
543 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
545 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
546 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
549 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
551 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
552 n
= min(textlenT(text
, isW
), n
);
553 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
556 static char* debug_getbuf(void)
558 static int index
= 0;
559 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
560 return buffers
[index
++ % DEBUG_BUFFERS
];
563 static inline const char* debugrange(const RANGE
*lprng
)
565 if (!lprng
) return "(null)";
566 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
569 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
571 char* buf
= debug_getbuf(), *text
= buf
;
572 int len
, size
= DEBUG_BUFFER_SIZE
;
574 if (pScrollInfo
== NULL
) return "(null)";
575 len
= snprintf(buf
, size
, "{cbSize=%u, ", pScrollInfo
->cbSize
);
576 if (len
== -1) goto end
;
577 buf
+= len
; size
-= len
;
578 if (pScrollInfo
->fMask
& SIF_RANGE
)
579 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
581 if (len
== -1) goto end
;
582 buf
+= len
; size
-= len
;
583 if (pScrollInfo
->fMask
& SIF_PAGE
)
584 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
586 if (len
== -1) goto end
;
587 buf
+= len
; size
-= len
;
588 if (pScrollInfo
->fMask
& SIF_POS
)
589 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
591 if (len
== -1) goto end
;
592 buf
+= len
; size
-= len
;
593 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
594 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
596 if (len
== -1) goto end
;
600 buf
= text
+ strlen(text
);
602 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
606 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
608 if (!plvnm
) return "(null)";
609 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
610 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%Id",
611 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
612 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
615 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
617 char* buf
= debug_getbuf(), *text
= buf
;
618 int len
, size
= DEBUG_BUFFER_SIZE
;
620 if (lpLVItem
== NULL
) return "(null)";
621 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
622 if (len
== -1) goto end
;
623 buf
+= len
; size
-= len
;
624 if (lpLVItem
->mask
& LVIF_STATE
)
625 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
627 if (len
== -1) goto end
;
628 buf
+= len
; size
-= len
;
629 if (lpLVItem
->mask
& LVIF_TEXT
)
630 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
632 if (len
== -1) goto end
;
633 buf
+= len
; size
-= len
;
634 if (lpLVItem
->mask
& LVIF_IMAGE
)
635 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
637 if (len
== -1) goto end
;
638 buf
+= len
; size
-= len
;
639 if (lpLVItem
->mask
& LVIF_PARAM
)
640 len
= snprintf(buf
, size
, "lParam=%Ix, ", lpLVItem
->lParam
);
642 if (len
== -1) goto end
;
643 buf
+= len
; size
-= len
;
644 if (lpLVItem
->mask
& LVIF_INDENT
)
645 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
647 if (len
== -1) goto end
;
651 buf
= text
+ strlen(text
);
653 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
657 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
659 char* buf
= debug_getbuf(), *text
= buf
;
660 int len
, size
= DEBUG_BUFFER_SIZE
;
662 if (lpColumn
== NULL
) return "(null)";
663 len
= snprintf(buf
, size
, "{");
664 if (len
== -1) goto end
;
665 buf
+= len
; size
-= len
;
666 if (lpColumn
->mask
& LVCF_SUBITEM
)
667 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
669 if (len
== -1) goto end
;
670 buf
+= len
; size
-= len
;
671 if (lpColumn
->mask
& LVCF_FMT
)
672 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
674 if (len
== -1) goto end
;
675 buf
+= len
; size
-= len
;
676 if (lpColumn
->mask
& LVCF_WIDTH
)
677 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
679 if (len
== -1) goto end
;
680 buf
+= len
; size
-= len
;
681 if (lpColumn
->mask
& LVCF_TEXT
)
682 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
684 if (len
== -1) goto end
;
685 buf
+= len
; size
-= len
;
686 if (lpColumn
->mask
& LVCF_IMAGE
)
687 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
689 if (len
== -1) goto end
;
690 buf
+= len
; size
-= len
;
691 if (lpColumn
->mask
& LVCF_ORDER
)
692 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
694 if (len
== -1) goto end
;
698 buf
= text
+ strlen(text
);
700 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
704 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
706 if (!lpht
) return "(null)";
708 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
709 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
712 /* Return the corresponding text for a given scroll value */
713 static inline LPCSTR
debugscrollcode(int nScrollCode
)
717 case SB_LINELEFT
: return "SB_LINELEFT";
718 case SB_LINERIGHT
: return "SB_LINERIGHT";
719 case SB_PAGELEFT
: return "SB_PAGELEFT";
720 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
721 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
722 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
723 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
724 case SB_INTERNAL
: return "SB_INTERNAL";
725 default: return "unknown";
730 /******** Notification functions ************************************/
732 static int get_ansi_notification(UINT unicodeNotificationCode
)
734 switch (unicodeNotificationCode
)
736 case LVN_BEGINLABELEDITA
:
737 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
738 case LVN_ENDLABELEDITA
:
739 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
740 case LVN_GETDISPINFOA
:
741 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
742 case LVN_SETDISPINFOA
:
743 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
744 case LVN_ODFINDITEMA
:
745 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
746 case LVN_GETINFOTIPA
:
747 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
748 /* header forwards */
750 case HDN_TRACKW
: return HDN_TRACKA
;
752 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
753 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
754 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
755 case HDN_ITEMCHANGINGA
:
756 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
757 case HDN_ITEMCHANGEDA
:
758 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
760 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
761 case HDN_DIVIDERDBLCLICKA
:
762 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
765 FIXME("unknown notification %x\n", unicodeNotificationCode
);
766 return unicodeNotificationCode
;
769 /* forwards header notifications to listview parent */
770 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
772 LPCWSTR text
= NULL
, filter
= NULL
;
774 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
776 /* on unicode format exit earlier */
777 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
778 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
781 /* header always supplies unicode notifications,
782 all we have to do is to convert strings to ANSI */
785 /* convert item text */
786 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
788 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
789 lpnmh
->pitem
->pszText
= NULL
;
790 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
792 /* convert filter text */
793 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
794 lpnmh
->pitem
->pvFilter
)
796 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
797 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= NULL
;
798 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
801 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
803 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
809 Free(lpnmh
->pitem
->pszText
);
810 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
814 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
815 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
821 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
825 TRACE("(code=%d)\n", code
);
827 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
828 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
830 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
832 TRACE(" <= %Id\n", result
);
837 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
840 HWND hwnd
= infoPtr
->hwndSelf
;
841 notify_hdr(infoPtr
, code
, &nmh
);
842 return IsWindow(hwnd
);
845 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
855 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
856 item
.iItem
= htInfo
->iItem
;
858 item
.stateMask
= (UINT
)-1;
859 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
860 nmia
.lParam
= item
.lParam
;
861 nmia
.uOldState
= item
.state
;
862 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
863 nmia
.uChanged
= LVIF_STATE
;
866 nmia
.iItem
= htInfo
->iItem
;
867 nmia
.iSubItem
= htInfo
->iSubItem
;
868 nmia
.ptAction
= htInfo
->pt
;
870 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
871 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
872 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
874 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
877 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
879 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
880 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
883 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
884 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
888 HWND hwnd
= infoPtr
->hwndSelf
;
891 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
892 ZeroMemory(&nmia
, sizeof(nmia
));
893 nmia
.iItem
= lvht
->iItem
;
894 nmia
.iSubItem
= lvht
->iSubItem
;
895 nmia
.ptAction
= lvht
->pt
;
896 item
.mask
= LVIF_PARAM
;
897 item
.iItem
= lvht
->iItem
;
899 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
900 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
901 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
904 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
908 HWND hwnd
= infoPtr
->hwndSelf
;
910 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
912 item
.mask
= LVIF_PARAM
;
915 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
916 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
917 return IsWindow(hwnd
);
921 Send notification. depends on dispinfoW having same
922 structure as dispinfoA.
923 infoPtr : listview struct
924 code : *Unicode* notification code
925 pdi : dispinfo structure (can be unicode or ansi)
926 isW : TRUE if dispinfo is Unicode
928 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
930 INT length
= 0, ret_length
;
931 LPWSTR buffer
= NULL
, ret_text
;
932 BOOL return_ansi
= FALSE
;
933 BOOL return_unicode
= FALSE
;
936 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
938 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
939 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
942 ret_length
= pdi
->item
.cchTextMax
;
943 ret_text
= pdi
->item
.pszText
;
945 if (return_unicode
|| return_ansi
)
947 if (code
!= LVN_GETDISPINFOW
)
949 length
= return_ansi
?
950 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
951 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
955 length
= pdi
->item
.cchTextMax
;
956 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
959 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
960 if (!buffer
) return FALSE
;
963 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
966 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
969 pdi
->item
.pszText
= buffer
;
970 pdi
->item
.cchTextMax
= length
;
973 if (infoPtr
->notifyFormat
== NFR_ANSI
)
974 code
= get_ansi_notification(code
);
976 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
977 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
978 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
980 if (return_ansi
|| return_unicode
)
982 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
984 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
986 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
988 lstrcpyW(ret_text
, pdi
->item
.pszText
);
990 else if (return_ansi
) /* note : pointer can be changed by app ! */
992 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
993 ret_length
, NULL
, NULL
);
996 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
997 ret_text
, ret_length
);
999 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
1000 pdi
->item
.cchTextMax
= ret_length
;
1006 /* if dispinfo holder changed notification code then convert */
1007 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1009 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1011 buffer
= Alloc(length
* sizeof(CHAR
));
1012 if (!buffer
) return FALSE
;
1014 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1015 ret_length
, NULL
, NULL
);
1017 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1024 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1025 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1027 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1028 lpnmlvcd
->nmcd
.hdc
= hdc
;
1029 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1030 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1031 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1032 if (!lplvItem
) return;
1033 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1034 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1035 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1036 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1037 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1038 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1041 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1043 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1046 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1047 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1048 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1049 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1050 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1051 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1055 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const NMLVCUSTOMDRAW
*cd
, BOOL SubItem
)
1057 COLORREF backcolor
, textcolor
;
1059 backcolor
= cd
->clrTextBk
;
1060 textcolor
= cd
->clrText
;
1062 /* apparently, for selected items, we have to override the returned values */
1065 if (cd
->nmcd
.uItemState
& CDIS_SELECTED
)
1067 if (infoPtr
->bFocus
)
1069 backcolor
= comctl32_color
.clrHighlight
;
1070 textcolor
= comctl32_color
.clrHighlightText
;
1072 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1074 backcolor
= comctl32_color
.clr3dFace
;
1075 textcolor
= comctl32_color
.clrBtnText
;
1080 if (backcolor
== CLR_DEFAULT
)
1081 backcolor
= comctl32_color
.clrWindow
;
1082 if (textcolor
== CLR_DEFAULT
)
1083 textcolor
= comctl32_color
.clrWindowText
;
1085 /* Set the text attributes */
1086 if (backcolor
!= CLR_NONE
)
1088 SetBkMode(hdc
, OPAQUE
);
1089 SetBkColor(hdc
, backcolor
);
1092 SetBkMode(hdc
, TRANSPARENT
);
1093 SetTextColor(hdc
, textcolor
);
1096 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1098 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1101 /* returns TRUE when repaint needed, FALSE otherwise */
1102 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1104 MEASUREITEMSTRUCT mis
;
1105 mis
.CtlType
= ODT_LISTVIEW
;
1106 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1110 mis
.itemHeight
= infoPtr
->nItemHeight
;
1111 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1112 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1114 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1120 /******** Item iterator functions **********************************/
1122 static RANGES
ranges_create(int count
);
1123 static void ranges_destroy(RANGES ranges
);
1124 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1125 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1126 static void ranges_dump(RANGES ranges
);
1128 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1130 RANGE range
= { nItem
, nItem
+ 1 };
1132 return ranges_add(ranges
, range
);
1135 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1137 RANGE range
= { nItem
, nItem
+ 1 };
1139 return ranges_del(ranges
, range
);
1143 * ITERATOR DOCUMENTATION
1145 * The iterator functions allow for easy, and convenient iteration
1146 * over items of interest in the list. Typically, you create an
1147 * iterator, use it, and destroy it, as such:
1150 * iterator_xxxitems(&i, ...);
1151 * while (iterator_{prev,next}(&i)
1153 * //code which uses i.nItem
1155 * iterator_destroy(&i);
1157 * where xxx is either: framed, or visible.
1158 * Note that it is important that the code destroys the iterator
1159 * after it's done with it, as the creation of the iterator may
1160 * allocate memory, which thus needs to be freed.
1162 * You can iterate both forwards, and backwards through the list,
1163 * by using iterator_next or iterator_prev respectively.
1165 * Lower numbered items are draw on top of higher number items in
1166 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1167 * items may overlap). So, to test items, you should use
1169 * which lists the items top to bottom (in Z-order).
1170 * For drawing items, you should use
1172 * which lists the items bottom to top (in Z-order).
1173 * If you keep iterating over the items after the end-of-items
1174 * marker (-1) is returned, the iterator will start from the
1175 * beginning. Typically, you don't need to test for -1,
1176 * because iterator_{next,prev} will return TRUE if more items
1177 * are to be iterated over, or FALSE otherwise.
1179 * Note: the iterator is defined to be bidirectional. That is,
1180 * any number of prev followed by any number of next, or
1181 * five versa, should leave the iterator at the same item:
1182 * prev * n, next * n = next * n, prev * n
1184 * The iterator has a notion of an out-of-order, special item,
1185 * which sits at the start of the list. This is used in
1186 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1187 * which needs to be first, as it may overlap other items.
1189 * The code is a bit messy because we have:
1190 * - a special item to deal with
1191 * - simple range, or composite range
1193 * If you find bugs, or want to add features, please make sure you
1194 * always check/modify *both* iterator_prev, and iterator_next.
1198 * This function iterates through the items in increasing order,
1199 * but prefixed by the special item, then -1. That is:
1200 * special, 1, 2, 3, ..., n, -1.
1201 * Each item is listed only once.
1203 static inline BOOL
iterator_next(ITERATOR
* i
)
1207 i
->nItem
= i
->nSpecial
;
1208 if (i
->nItem
!= -1) return TRUE
;
1210 if (i
->nItem
== i
->nSpecial
)
1212 if (i
->ranges
) i
->index
= 0;
1218 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1219 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1224 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1225 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1228 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1230 i
->nItem
= i
->range
.lower
;
1231 if (i
->nItem
>= 0) goto testitem
;
1238 * This function iterates through the items in decreasing order,
1239 * followed by the special item, then -1. That is:
1240 * n, n-1, ..., 3, 2, 1, special, -1.
1241 * Each item is listed only once.
1243 static inline BOOL
iterator_prev(ITERATOR
* i
)
1250 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1253 if (i
->nItem
== i
->nSpecial
)
1261 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1262 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1268 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1271 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1273 i
->nItem
= i
->range
.upper
;
1274 if (i
->nItem
> 0) goto testitem
;
1276 return (i
->nItem
= i
->nSpecial
) != -1;
1279 static RANGE
iterator_range(const ITERATOR
*i
)
1283 if (!i
->ranges
) return i
->range
;
1285 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1287 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1288 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1290 else range
.lower
= range
.upper
= 0;
1296 * Releases resources associated with this iterator.
1298 static inline void iterator_destroy(const ITERATOR
*i
)
1300 ranges_destroy(i
->ranges
);
1304 * Create an empty iterator.
1306 static inline void iterator_empty(ITERATOR
* i
)
1308 ZeroMemory(i
, sizeof(*i
));
1309 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1313 * Create an iterator over a range.
1315 static inline void iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1322 * Create an iterator over a bunch of ranges.
1323 * Please note that the iterator will take ownership of the ranges,
1324 * and will free them upon destruction.
1326 static inline void iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1333 * Creates an iterator over the items which intersect frame.
1334 * Uses absolute coordinates rather than compensating for the current offset.
1336 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1338 RECT rcItem
, rcTemp
;
1341 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1343 /* in case we fail, we want to return an empty iterator */
1346 if (infoPtr
->nItemCount
== 0)
1349 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1353 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1355 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1356 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1357 i
->nSpecial
= infoPtr
->nFocusedItem
;
1359 if (!(ranges
= ranges_create(50))) return FALSE
;
1360 iterator_rangesitems(i
, ranges
);
1361 /* to do better here, we need to have PosX, and PosY sorted */
1362 TRACE("building icon ranges:\n");
1363 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1365 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1366 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1367 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1368 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1369 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1370 ranges_additem(i
->ranges
, nItem
);
1374 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1378 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1379 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1381 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1382 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1383 if (range
.upper
<= range
.lower
) return TRUE
;
1384 iterator_rangeitems(i
, range
);
1385 TRACE(" report=%s\n", debugrange(&i
->range
));
1389 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1390 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1391 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1398 if (infoPtr
->nItemWidth
)
1400 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1401 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1405 nFirstCol
= max(frame
->left
, 0);
1406 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1409 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1411 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1412 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1414 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1416 if (!(ranges
= ranges_create(nLastCol
- nFirstCol
+ 1))) return FALSE
;
1417 iterator_rangesitems(i
, ranges
);
1418 TRACE("building list ranges:\n");
1419 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1421 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1422 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1423 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1424 TRACE(" list=%s\n", debugrange(&item_range
));
1425 ranges_add(i
->ranges
, item_range
);
1433 * Creates an iterator over the items which intersect lprc.
1435 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1440 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1442 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1443 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1445 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1449 * Creates an iterator over the items which intersect the visible region of hdc.
1451 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1453 POINT Origin
, Position
;
1454 RECT rcItem
, rcClip
;
1457 rgntype
= GetClipBox(hdc
, &rcClip
);
1458 if (rgntype
== NULLREGION
)
1463 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1464 if (rgntype
== SIMPLEREGION
) return TRUE
;
1466 /* first deal with the special item */
1467 if (i
->nSpecial
!= -1)
1469 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1470 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1473 /* if we can't deal with the region, we'll just go with the simple range */
1474 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1475 TRACE("building visible range:\n");
1476 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1478 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1479 if (!ranges_add(i
->ranges
, i
->range
))
1481 ranges_destroy(i
->ranges
);
1487 /* now delete the invisible items from the list */
1488 while(iterator_next(i
))
1490 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1491 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1492 rcItem
.top
= Position
.y
+ Origin
.y
;
1493 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1494 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1495 if (!RectVisible(hdc
, &rcItem
))
1496 ranges_delitem(i
->ranges
, i
->nItem
);
1498 /* the iterator should restart on the next iterator_next */
1504 /* Remove common elements from two iterators */
1505 /* Passed iterators have to point on the first elements */
1506 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1508 if(!iter1
->ranges
|| !iter2
->ranges
) {
1511 if(iter1
->ranges
|| iter2
->ranges
||
1512 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1513 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1514 ERR("result is not a one range iterator\n");
1518 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1521 lower
= iter1
->range
.lower
;
1522 upper
= iter1
->range
.upper
;
1524 if(lower
< iter2
->range
.lower
)
1525 iter1
->range
.upper
= iter2
->range
.lower
;
1526 else if(upper
> iter2
->range
.upper
)
1527 iter1
->range
.lower
= iter2
->range
.upper
;
1529 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1531 if(iter2
->range
.lower
< lower
)
1532 iter2
->range
.upper
= lower
;
1533 else if(iter2
->range
.upper
> upper
)
1534 iter2
->range
.lower
= upper
;
1536 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1541 iterator_next(iter1
);
1542 iterator_next(iter2
);
1545 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1548 if(iter1
->nItem
== iter2
->nItem
) {
1549 int delete = iter1
->nItem
;
1551 iterator_prev(iter1
);
1552 iterator_prev(iter2
);
1553 ranges_delitem(iter1
->ranges
, delete);
1554 ranges_delitem(iter2
->ranges
, delete);
1555 iterator_next(iter1
);
1556 iterator_next(iter2
);
1557 } else if(iter1
->nItem
> iter2
->nItem
)
1558 iterator_next(iter2
);
1560 iterator_next(iter1
);
1563 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1564 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1568 /******** Misc helper functions ************************************/
1570 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1571 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1573 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1574 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1577 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1579 return (infoPtr
->dwStyle
& LVS_AUTOARRANGE
) &&
1580 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1583 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1585 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1586 if(state
== 1 || state
== 2)
1590 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1591 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1592 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1596 /* this should be called after window style got updated,
1597 it used to reset view state to match current window style */
1598 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1600 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1603 infoPtr
->uView
= LV_VIEW_ICON
;
1606 infoPtr
->uView
= LV_VIEW_DETAILS
;
1609 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1612 infoPtr
->uView
= LV_VIEW_LIST
;
1616 /* computes next item id value */
1617 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1619 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1623 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1624 return lpID
->id
+ 1;
1629 /******** Internal API functions ************************************/
1631 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1633 static COLUMN_INFO mainItem
;
1635 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1636 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1638 /* update cached column rectangles */
1639 if (infoPtr
->colRectsDirty
)
1642 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1645 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1646 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1647 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1649 Ptr
->colRectsDirty
= FALSE
;
1652 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1655 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1657 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1660 if (infoPtr
->hwndHeader
) return 0;
1662 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1664 /* setup creation flags */
1665 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1666 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1668 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1671 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1672 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1673 if (!infoPtr
->hwndHeader
) return -1;
1675 /* set header unicode format */
1676 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1678 /* set header font */
1679 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1681 /* set header image list */
1682 if (infoPtr
->himlSmall
)
1683 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1685 LISTVIEW_UpdateSize(infoPtr
);
1690 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1692 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1695 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1697 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1698 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1699 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1702 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1704 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1707 /* used to handle collapse main item column case */
1708 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1710 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1711 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1714 /* Listview invalidation functions: use _only_ these functions to invalidate */
1716 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1718 return infoPtr
->redraw
;
1721 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1723 if(!is_redrawing(infoPtr
)) return;
1724 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1725 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1728 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1732 if (!is_redrawing(infoPtr
) || nItem
< 0 || nItem
>= infoPtr
->nItemCount
)
1735 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1736 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1739 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1741 POINT Origin
, Position
;
1744 if(!is_redrawing(infoPtr
)) return;
1745 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1746 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1747 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1748 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1750 rcBox
.bottom
= infoPtr
->nItemHeight
;
1751 OffsetRect(&rcBox
, Origin
.x
, Origin
.y
+ Position
.y
);
1752 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1755 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1757 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1760 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1764 if(!is_redrawing(infoPtr
)) return;
1765 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1766 rcCol
.top
= infoPtr
->rcList
.top
;
1767 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1768 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1773 * Retrieves the number of items that can fit vertically in the client area.
1776 * [I] infoPtr : valid pointer to the listview structure
1779 * Number of items per row.
1781 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1783 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1785 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1790 * Retrieves the number of items that can fit horizontally in the client
1794 * [I] infoPtr : valid pointer to the listview structure
1797 * Number of items per column.
1799 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1801 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1803 return infoPtr
->nItemHeight
? max(nListHeight
/ infoPtr
->nItemHeight
, 1) : 0;
1807 /*************************************************************************
1808 * LISTVIEW_ProcessLetterKeys
1810 * Processes keyboard messages generated by pressing the letter keys
1812 * What this does is perform a case insensitive search from the
1813 * current position with the following quirks:
1814 * - If two chars or more are pressed in quick succession we search
1815 * for the corresponding string (e.g. 'abc').
1816 * - If there is a delay we wipe away the current search string and
1817 * restart with just that char.
1818 * - If the user keeps pressing the same character, whether slowly or
1819 * fast, so that the search string is entirely composed of this
1820 * character ('aaaaa' for instance), then we search for first item
1821 * that starting with that character.
1822 * - If the user types the above character in quick succession, then
1823 * we must also search for the corresponding string ('aaaaa'), and
1824 * go to that string if there is a match.
1827 * [I] hwnd : handle to the window
1828 * [I] charCode : the character code, the actual character
1829 * [I] keyData : key data
1837 * - The current implementation has a list of characters it will
1838 * accept and it ignores everything else. In particular it will
1839 * ignore accentuated characters which seems to match what
1840 * Windows does. But I'm not sure it makes sense to follow
1842 * - We don't sound a beep when the search fails.
1846 * TREEVIEW_ProcessLetterKeys
1848 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1850 WCHAR buffer
[MAX_PATH
];
1857 /* simple parameter checking */
1858 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1860 /* only allow the valid WM_CHARs through */
1861 if (!iswalnum(charCode
) &&
1862 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1863 charCode
!= '@' && charCode
!= '#' && 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
!= '~')
1873 /* update the search parameters */
1874 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1875 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1876 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1878 if (diff
>= 0 && diff
< KEY_DELAY
)
1880 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1881 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1883 if (infoPtr
->charCode
!= charCode
)
1884 infoPtr
->charCode
= charCode
= 0;
1888 infoPtr
->charCode
= charCode
;
1889 infoPtr
->szSearchParam
[0] = charCode
;
1890 infoPtr
->nSearchParamLength
= 1;
1893 /* should start from next after focused item, so next item that matches
1894 will be selected, if there isn't any and focused matches it will be selected
1895 on second search stage from beginning of the list */
1896 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1898 /* with some accumulated search data available start with current focus, otherwise
1899 it's excluded from search */
1900 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1901 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1906 /* let application handle this for virtual listview */
1907 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1911 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1912 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1913 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1914 nmlv
.iStart
= startidx
;
1916 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1918 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1922 int i
= startidx
, endidx
;
1924 /* and search from the current position */
1926 endidx
= infoPtr
->nItemCount
;
1928 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1931 /* start from first item if not found with >= startidx */
1932 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1938 for (i
= startidx
; i
< endidx
; i
++)
1941 item
.mask
= LVIF_TEXT
;
1944 item
.pszText
= buffer
;
1945 item
.cchTextMax
= MAX_PATH
;
1946 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1948 if (!wcsnicmp(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1953 /* this is used to find first char match when search string is not available yet,
1954 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1955 already waiting for user to complete a string */
1956 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !wcsnicmp(item
.pszText
, infoPtr
->szSearchParam
, 1))
1958 /* this would work but we must keep looking for a longer match */
1963 if ( nItem
!= -1 || /* found something */
1964 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1965 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1971 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1976 /*************************************************************************
1977 * LISTVIEW_UpdateHeaderSize [Internal]
1979 * Function to resize the header control
1982 * [I] hwnd : handle to a window
1983 * [I] nNewScrollPos : scroll pos to set
1988 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1993 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1995 if (!infoPtr
->hwndHeader
) return;
1997 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1998 point
[0].x
= winRect
.left
;
1999 point
[0].y
= winRect
.top
;
2000 point
[1].x
= winRect
.right
;
2001 point
[1].y
= winRect
.bottom
;
2003 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
2004 point
[0].x
= -nNewScrollPos
;
2005 point
[1].x
+= nNewScrollPos
;
2007 SetWindowPos(infoPtr
->hwndHeader
,0,
2008 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
2009 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
2010 SWP_NOZORDER
| SWP_NOACTIVATE
);
2013 static INT
LISTVIEW_UpdateHScroll(LISTVIEW_INFO
*infoPtr
)
2015 SCROLLINFO horzInfo
;
2018 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2019 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2020 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2022 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2023 if (infoPtr
->uView
== LV_VIEW_LIST
)
2025 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2026 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2028 /* scroll by at least one column per page */
2029 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2030 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2032 if (infoPtr
->nItemWidth
)
2033 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2035 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2037 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2039 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2043 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2046 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2048 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2053 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2054 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2056 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2057 horzInfo
.nMax
= rcHeader
.right
;
2058 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2062 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2063 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2064 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2065 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2066 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2068 /* Update the Header Control */
2069 if (infoPtr
->hwndHeader
)
2071 horzInfo
.fMask
= SIF_POS
;
2072 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2073 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2076 LISTVIEW_UpdateSize(infoPtr
);
2080 static INT
LISTVIEW_UpdateVScroll(LISTVIEW_INFO
*infoPtr
)
2082 SCROLLINFO vertInfo
;
2085 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2086 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2087 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2089 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2091 vertInfo
.nMax
= infoPtr
->nItemCount
;
2093 /* scroll by at least one page */
2094 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2095 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2097 if (infoPtr
->nItemHeight
> 0)
2098 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2100 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2104 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2107 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2108 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2109 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2110 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2111 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2113 LISTVIEW_UpdateSize(infoPtr
);
2119 * Update the scrollbars. This function should be called whenever
2120 * the content, size or view changes.
2123 * [I] infoPtr : valid pointer to the listview structure
2128 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*infoPtr
)
2132 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2134 /* Setting the horizontal scroll can change the listview size
2135 * (and potentially everything else) so we need to recompute
2136 * everything again for the vertical scroll and vice-versa
2138 for (dx
= 0, dy
= 0, pass
= 0; pass
<= 1; pass
++)
2140 dx
+= LISTVIEW_UpdateHScroll(infoPtr
);
2141 dy
+= LISTVIEW_UpdateVScroll(infoPtr
);
2144 /* Change of the range may have changed the scroll pos. If so move the content */
2145 if (dx
!= 0 || dy
!= 0)
2148 listRect
= infoPtr
->rcList
;
2149 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2150 SW_ERASE
| SW_INVALIDATE
);
2157 * Shows/hides the focus rectangle.
2160 * [I] infoPtr : valid pointer to the listview structure
2161 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2166 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2170 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2172 if (infoPtr
->nFocusedItem
< 0) return;
2174 /* we need some gymnastics in ICON mode to handle large items */
2175 if (infoPtr
->uView
== LV_VIEW_ICON
)
2179 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2180 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2182 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2187 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2189 /* for some reason, owner draw should work only in report mode */
2190 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2195 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2196 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2198 item
.iItem
= infoPtr
->nFocusedItem
;
2200 item
.mask
= LVIF_PARAM
;
2201 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2203 ZeroMemory(&dis
, sizeof(dis
));
2204 dis
.CtlType
= ODT_LISTVIEW
;
2205 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2206 dis
.itemID
= item
.iItem
;
2207 dis
.itemAction
= ODA_FOCUS
;
2208 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2209 dis
.hwndItem
= infoPtr
->hwndSelf
;
2211 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2212 dis
.itemData
= item
.lParam
;
2214 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2216 SelectObject(hdc
, hOldFont
);
2219 LISTVIEW_InvalidateItem(infoPtr
, infoPtr
->nFocusedItem
);
2222 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2226 * Invalidates all visible selected items.
2228 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2232 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2233 while(iterator_next(&i
))
2235 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2236 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2238 iterator_destroy(&i
);
2243 * DESCRIPTION: [INTERNAL]
2244 * Computes an item's (left,top) corner, relative to rcView.
2245 * That is, the position has NOT been made relative to the Origin.
2246 * This is deliberate, to avoid computing the Origin over, and
2247 * over again, when this function is called in a loop. Instead,
2248 * one can factor the computation of the Origin before the loop,
2249 * and offset the value returned by this function, on every iteration.
2252 * [I] infoPtr : valid pointer to the listview structure
2253 * [I] nItem : item number
2254 * [O] lpptOrig : item top, left corner
2259 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2261 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2263 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2265 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2266 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2268 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2270 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2271 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2272 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2274 else /* LV_VIEW_DETAILS */
2276 lpptPosition
->x
= REPORT_MARGINX
;
2277 /* item is always at zero indexed column */
2278 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2279 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2280 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2285 * DESCRIPTION: [INTERNAL]
2286 * Compute the rectangles of an item. This is to localize all
2287 * the computations in one place. If you are not interested in some
2288 * of these values, simply pass in a NULL -- the function is smart
2289 * enough to compute only what's necessary. The function computes
2290 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2291 * one, the BOX rectangle. This rectangle is very cheap to compute,
2292 * and is guaranteed to contain all the other rectangles. Computing
2293 * the ICON rect is also cheap, but all the others are potentially
2294 * expensive. This gives an easy and effective optimization when
2295 * searching (like point inclusion, or rectangle intersection):
2296 * first test against the BOX, and if TRUE, test against the desired
2298 * If the function does not have all the necessary information
2299 * to computed the requested rectangles, will crash with a
2300 * failed assertion. This is done so we catch all programming
2301 * errors, given that the function is called only from our code.
2303 * We have the following 'special' meanings for a few fields:
2304 * * If LVIS_FOCUSED is set, we assume the item has the focus
2305 * This is important in ICON mode, where it might get a larger
2306 * then usual rectangle
2308 * Please note that subitem support works only in REPORT mode.
2311 * [I] infoPtr : valid pointer to the listview structure
2312 * [I] lpLVItem : item to compute the measures for
2313 * [O] lprcBox : ptr to Box rectangle
2314 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2315 * [0] lprcSelectBox : ptr to select box rectangle
2316 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2317 * [O] lprcIcon : ptr to Icon rectangle
2318 * Same as LVM_GETITEMRECT with LVIR_ICON
2319 * [O] lprcStateIcon: ptr to State Icon rectangle
2320 * [O] lprcLabel : ptr to Label rectangle
2321 * Same as LVM_GETITEMRECT with LVIR_LABEL
2326 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2327 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2328 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2330 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2331 RECT Box
, SelectBox
, Icon
, Label
;
2332 COLUMN_INFO
*lpColumnInfo
= NULL
;
2333 SIZE labelSize
= { 0, 0 };
2335 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2337 /* Be smart and try to figure out the minimum we have to do */
2338 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2339 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2341 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2342 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2344 if (lprcSelectBox
) doSelectBox
= TRUE
;
2345 if (lprcLabel
) doLabel
= TRUE
;
2346 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2353 /************************************************************/
2354 /* compute the box rectangle (it should be cheap to do) */
2355 /************************************************************/
2356 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2357 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2359 if (lpLVItem
->iSubItem
)
2361 Box
= lpColumnInfo
->rcHeader
;
2366 Box
.right
= infoPtr
->nItemWidth
;
2369 Box
.bottom
= infoPtr
->nItemHeight
;
2371 /******************************************************************/
2372 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2373 /******************************************************************/
2376 LONG state_width
= 0;
2378 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2379 state_width
= infoPtr
->iconStateSize
.cx
;
2381 if (infoPtr
->uView
== LV_VIEW_ICON
)
2383 Icon
.left
= Box
.left
+ state_width
;
2384 if (infoPtr
->himlNormal
)
2385 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2386 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2387 Icon
.right
= Icon
.left
;
2388 Icon
.bottom
= Icon
.top
;
2389 if (infoPtr
->himlNormal
)
2391 Icon
.right
+= infoPtr
->iconSize
.cx
;
2392 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2395 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2397 Icon
.left
= Box
.left
+ state_width
;
2399 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2401 /* we need the indent in report mode */
2402 assert(lpLVItem
->mask
& LVIF_INDENT
);
2403 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2407 Icon
.right
= Icon
.left
;
2408 if (infoPtr
->himlSmall
&&
2409 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2410 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2411 Icon
.right
+= infoPtr
->iconSize
.cx
;
2412 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2414 if(lprcIcon
) *lprcIcon
= Icon
;
2415 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2417 /* TODO: is this correct? */
2420 lprcStateIcon
->left
= Icon
.left
- state_width
;
2421 lprcStateIcon
->right
= Icon
.left
;
2422 lprcStateIcon
->top
= Icon
.top
;
2423 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2424 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2427 else Icon
.right
= 0;
2429 /************************************************************/
2430 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2431 /************************************************************/
2434 /* calculate how far to the right can the label stretch */
2435 Label
.right
= Box
.right
;
2436 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2438 if (lpLVItem
->iSubItem
== 0)
2440 /* we need a zero based rect here */
2441 Label
= lpColumnInfo
->rcHeader
;
2442 OffsetRect(&Label
, -Label
.left
, 0);
2446 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2448 labelSize
.cx
= infoPtr
->nItemWidth
;
2449 labelSize
.cy
= infoPtr
->nItemHeight
;
2453 /* we need the text in non owner draw mode */
2454 assert(lpLVItem
->mask
& LVIF_TEXT
);
2455 if (is_text(lpLVItem
->pszText
))
2457 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2458 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2459 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2463 /* compute rough rectangle where the label will go */
2464 SetRectEmpty(&rcText
);
2465 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2466 rcText
.bottom
= infoPtr
->nItemHeight
;
2467 if (infoPtr
->uView
== LV_VIEW_ICON
)
2468 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2470 /* now figure out the flags */
2471 if (infoPtr
->uView
== LV_VIEW_ICON
)
2472 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2474 uFormat
= LV_SL_DT_FLAGS
;
2476 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2478 if (rcText
.right
!= rcText
.left
)
2479 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2481 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2483 SelectObject(hdc
, hOldFont
);
2484 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2488 if (infoPtr
->uView
== LV_VIEW_ICON
)
2490 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2491 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2492 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2493 Label
.right
= Label
.left
+ labelSize
.cx
;
2494 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2495 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2497 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2498 labelSize
.cy
/= infoPtr
->ntmHeight
;
2499 labelSize
.cy
= max(labelSize
.cy
, 1);
2500 labelSize
.cy
*= infoPtr
->ntmHeight
;
2502 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2504 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2506 Label
.left
= Icon
.right
;
2507 Label
.top
= Box
.top
;
2508 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2509 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2510 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2512 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2514 Label
.left
= Icon
.right
;
2515 Label
.top
= Box
.top
;
2516 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2517 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2520 if (lprcLabel
) *lprcLabel
= Label
;
2521 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2524 /************************************************************/
2525 /* compute SELECT bounding box */
2526 /************************************************************/
2529 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2531 SelectBox
.left
= Icon
.left
;
2532 SelectBox
.top
= Box
.top
;
2533 SelectBox
.bottom
= Box
.bottom
;
2536 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2538 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2542 UnionRect(&SelectBox
, &Icon
, &Label
);
2544 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2545 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2548 /* Fix the Box if necessary */
2551 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2552 else *lprcBox
= Box
;
2554 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2558 * DESCRIPTION: [INTERNAL]
2561 * [I] infoPtr : valid pointer to the listview structure
2562 * [I] nItem : item number
2563 * [O] lprcBox : ptr to Box rectangle
2568 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2570 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2571 POINT Position
, Origin
;
2574 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2575 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2577 /* Be smart and try to figure out the minimum we have to do */
2579 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2580 lvItem
.mask
|= LVIF_TEXT
;
2581 lvItem
.iItem
= nItem
;
2582 lvItem
.iSubItem
= 0;
2583 lvItem
.pszText
= szDispText
;
2584 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2585 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2586 if (infoPtr
->uView
== LV_VIEW_ICON
)
2588 lvItem
.mask
|= LVIF_STATE
;
2589 lvItem
.stateMask
= LVIS_FOCUSED
;
2590 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2592 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2594 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2595 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2597 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2600 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2603 /* LISTVIEW_MapIdToIndex helper */
2604 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2606 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2607 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2609 if (id1
->id
== id2
->id
) return 0;
2611 return (id1
->id
< id2
->id
) ? -1 : 1;
2616 * Returns the item index for id specified.
2619 * [I] infoPtr : valid pointer to the listview structure
2620 * [I] iID : item id to get index for
2623 * Item index, or -1 on failure.
2625 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2630 TRACE("iID=%d\n", iID
);
2632 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2633 if (infoPtr
->nItemCount
== 0) return -1;
2636 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2640 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2641 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2649 * Returns the item id for index given.
2652 * [I] infoPtr : valid pointer to the listview structure
2653 * [I] iItem : item index to get id for
2658 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2663 TRACE("iItem=%d\n", iItem
);
2665 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2666 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2668 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2669 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2671 return lpItem
->id
->id
;
2676 * Returns the current icon position, and advances it along the top.
2677 * The returned position is not offset by Origin.
2680 * [I] infoPtr : valid pointer to the listview structure
2681 * [O] lpPos : will get the current icon position
2686 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2688 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2690 *lpPos
= infoPtr
->currIconPos
;
2692 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2693 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2695 infoPtr
->currIconPos
.x
= 0;
2696 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2702 * Returns the current icon position, and advances it down the left edge.
2703 * The returned position is not offset by Origin.
2706 * [I] infoPtr : valid pointer to the listview structure
2707 * [O] lpPos : will get the current icon position
2712 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2714 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2716 *lpPos
= infoPtr
->currIconPos
;
2718 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2719 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2721 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2722 infoPtr
->currIconPos
.y
= 0;
2728 * Moves an icon to the specified position.
2729 * It takes care of invalidating the item, etc.
2732 * [I] infoPtr : valid pointer to the listview structure
2733 * [I] nItem : the item to move
2734 * [I] lpPos : the new icon position
2735 * [I] isNew : flags the item as being new
2741 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2747 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2748 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2750 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2751 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2754 /* Allocating a POINTER for every item is too resource intensive,
2755 * so we'll keep the (x,y) in different arrays */
2756 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2757 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2759 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2766 * Arranges listview items in icon display mode.
2769 * [I] infoPtr : valid pointer to the listview structure
2770 * [I] nAlignCode : alignment code
2776 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2778 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2782 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2784 TRACE("nAlignCode=%d\n", nAlignCode
);
2786 if (nAlignCode
== LVA_DEFAULT
)
2788 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2789 else nAlignCode
= LVA_ALIGNTOP
;
2794 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2795 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2796 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2797 default: return FALSE
;
2800 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2801 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2803 next_pos(infoPtr
, &pos
);
2804 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2812 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2813 * For LVS_REPORT always returns empty rectangle.
2816 * [I] infoPtr : valid pointer to the listview structure
2817 * [O] lprcView : bounding rectangle
2823 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2827 SetRectEmpty(lprcView
);
2829 switch (infoPtr
->uView
)
2832 case LV_VIEW_SMALLICON
:
2833 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2835 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2836 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2837 lprcView
->right
= max(lprcView
->right
, x
);
2838 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2840 if (infoPtr
->nItemCount
> 0)
2842 lprcView
->right
+= infoPtr
->nItemWidth
;
2843 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2848 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2849 x
= infoPtr
->nItemCount
/ y
;
2850 if (infoPtr
->nItemCount
% y
) x
++;
2851 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2852 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2859 * Retrieves the bounding rectangle of all the items.
2862 * [I] infoPtr : valid pointer to the listview structure
2863 * [O] lprcView : bounding rectangle
2869 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2873 TRACE("(lprcView=%p)\n", lprcView
);
2875 if (!lprcView
) return FALSE
;
2877 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2879 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2881 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2882 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2885 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2892 * Retrieves the subitem pointer associated with the subitem index.
2895 * [I] hdpaSubItems : DPA handle for a specific item
2896 * [I] nSubItem : index of subitem
2899 * SUCCESS : subitem pointer
2902 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2904 SUBITEM_INFO
*lpSubItem
;
2907 /* we should binary search here if need be */
2908 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2910 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2911 if (lpSubItem
->iSubItem
== nSubItem
)
2921 * Calculates the desired item width.
2924 * [I] infoPtr : valid pointer to the listview structure
2927 * The desired item width.
2929 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2933 TRACE("view %ld\n", infoPtr
->uView
);
2935 if (infoPtr
->uView
== LV_VIEW_ICON
)
2936 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2937 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2939 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2944 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2945 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2947 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2948 nItemWidth
= rcHeader
.right
;
2951 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2953 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2957 lvItem
.mask
= LVIF_TEXT
;
2958 lvItem
.iSubItem
= 0;
2960 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2963 lvItem
.pszText
= szDispText
;
2964 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2965 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2966 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2970 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2971 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2973 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2981 * Calculates the desired item height.
2984 * [I] infoPtr : valid pointer to the listview structure
2987 * The desired item height.
2989 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2993 TRACE("view %ld\n", infoPtr
->uView
);
2995 if (infoPtr
->uView
== LV_VIEW_ICON
)
2996 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2999 nItemHeight
= infoPtr
->ntmHeight
;
3000 if (infoPtr
->himlState
)
3001 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
3002 if (infoPtr
->himlSmall
)
3003 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
3004 nItemHeight
+= HEIGHT_PADDING
;
3005 if (infoPtr
->nMeasureItemHeight
> 0)
3006 nItemHeight
= infoPtr
->nMeasureItemHeight
;
3009 return max(nItemHeight
, 1);
3014 * Updates the width, and height of an item.
3017 * [I] infoPtr : valid pointer to the listview structure
3022 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
3024 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
3025 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3031 * Retrieves and saves important text metrics info for the current
3035 * [I] infoPtr : valid pointer to the listview structure
3038 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3040 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3041 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3042 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3046 if (GetTextMetricsW(hdc
, &tm
))
3048 infoPtr
->ntmHeight
= tm
.tmHeight
;
3049 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3052 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3053 infoPtr
->nEllipsisWidth
= sz
.cx
;
3055 SelectObject(hdc
, hOldFont
);
3056 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3058 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3063 * A compare function for ranges
3066 * [I] range1 : pointer to range 1;
3067 * [I] range2 : pointer to range 2;
3071 * > 0 : if range 1 > range 2
3072 * < 0 : if range 2 > range 1
3073 * = 0 : if range intersects range 2
3075 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3079 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3081 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3086 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3091 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3093 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3098 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3100 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3101 ranges_dump(ranges
);
3102 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3104 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3105 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3106 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3108 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3109 assert (prev
->upper
<= curr
->lower
);
3110 assert (curr
->lower
< curr
->upper
);
3114 TRACE("--- Done checking---\n");
3117 static RANGES
ranges_create(int count
)
3119 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3120 if (!ranges
) return NULL
;
3121 ranges
->hdpa
= DPA_Create(count
);
3122 if (ranges
->hdpa
) return ranges
;
3127 static void ranges_clear(RANGES ranges
)
3131 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3132 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3133 DPA_DeleteAllPtrs(ranges
->hdpa
);
3137 static void ranges_destroy(RANGES ranges
)
3139 if (!ranges
) return;
3140 ranges_clear(ranges
);
3141 DPA_Destroy(ranges
->hdpa
);
3145 static RANGES
ranges_clone(RANGES ranges
)
3150 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3152 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3154 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3155 if (!newrng
) goto fail
;
3156 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3157 if (!DPA_SetPtr(clone
->hdpa
, i
, newrng
))
3166 TRACE ("clone failed\n");
3167 ranges_destroy(clone
);
3171 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3175 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3176 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3181 static void ranges_dump(RANGES ranges
)
3185 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3186 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3189 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3191 RANGE srchrng
= { nItem
, nItem
+ 1 };
3193 TRACE("(nItem=%d)\n", nItem
);
3194 ranges_check(ranges
, "before contain");
3195 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3198 static INT
ranges_itemcount(RANGES ranges
)
3202 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3204 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3205 count
+= sel
->upper
- sel
->lower
;
3211 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3213 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3216 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3217 if (index
== -1) return TRUE
;
3219 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3221 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3222 if (chkrng
->lower
>= nItem
)
3223 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3224 if (chkrng
->upper
> nItem
)
3225 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3230 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3235 TRACE("(%s)\n", debugrange(&range
));
3236 ranges_check(ranges
, "before add");
3238 /* try find overlapping regions first */
3239 srchrgn
.lower
= range
.lower
- 1;
3240 srchrgn
.upper
= range
.upper
+ 1;
3241 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3247 TRACE("Adding new range\n");
3249 /* create the brand new range to insert */
3250 newrgn
= Alloc(sizeof(RANGE
));
3251 if(!newrgn
) goto fail
;
3254 /* figure out where to insert it */
3255 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3256 TRACE("index=%d\n", index
);
3257 if (index
== -1) index
= 0;
3259 /* and get it over with */
3260 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3268 RANGE
*chkrgn
, *mrgrgn
;
3269 INT fromindex
, mergeindex
;
3271 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3272 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3274 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3275 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3277 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3279 /* merge now common ranges */
3281 srchrgn
.lower
= chkrgn
->lower
- 1;
3282 srchrgn
.upper
= chkrgn
->upper
+ 1;
3286 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3287 if (mergeindex
== -1) break;
3288 if (mergeindex
== index
)
3290 fromindex
= index
+ 1;
3294 TRACE("Merge with index %i\n", mergeindex
);
3296 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3297 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3298 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3300 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3301 if (mergeindex
< index
) index
--;
3305 ranges_check(ranges
, "after add");
3309 ranges_check(ranges
, "failed add");
3313 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3318 TRACE("(%s)\n", debugrange(&range
));
3319 ranges_check(ranges
, "before del");
3321 /* we don't use DPAS_SORTED here, since we need *
3322 * to find the first overlapping range */
3323 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3326 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3328 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3330 /* case 1: Same range */
3331 if ( (chkrgn
->upper
== range
.upper
) &&
3332 (chkrgn
->lower
== range
.lower
) )
3334 DPA_DeletePtr(ranges
->hdpa
, index
);
3338 /* case 2: engulf */
3339 else if ( (chkrgn
->upper
<= range
.upper
) &&
3340 (chkrgn
->lower
>= range
.lower
) )
3342 DPA_DeletePtr(ranges
->hdpa
, index
);
3345 /* case 3: overlap upper */
3346 else if ( (chkrgn
->upper
<= range
.upper
) &&
3347 (chkrgn
->lower
< range
.lower
) )
3349 chkrgn
->upper
= range
.lower
;
3351 /* case 4: overlap lower */
3352 else if ( (chkrgn
->upper
> range
.upper
) &&
3353 (chkrgn
->lower
>= range
.lower
) )
3355 chkrgn
->lower
= range
.upper
;
3358 /* case 5: fully internal */
3363 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3364 newrgn
->lower
= chkrgn
->lower
;
3365 newrgn
->upper
= range
.lower
;
3366 chkrgn
->lower
= range
.upper
;
3367 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3375 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3378 ranges_check(ranges
, "after del");
3382 ranges_check(ranges
, "failed del");
3388 * Removes all selection ranges
3391 * [I] infoPtr : valid pointer to the listview structure
3392 * [I] toSkip : item range to skip removing the selection
3398 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3407 lvItem
.stateMask
= LVIS_SELECTED
;
3409 /* need to clone the DPA because callbacks can change it */
3410 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3411 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3412 while(iterator_next(&i
))
3413 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3414 /* note that the iterator destructor will free the cloned range */
3415 iterator_destroy(&i
);
3420 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3424 if (!(toSkip
= ranges_create(1))) return FALSE
;
3425 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3426 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3427 ranges_destroy(toSkip
);
3431 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3433 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3438 * Retrieves the number of items that are marked as selected.
3441 * [I] infoPtr : valid pointer to the listview structure
3444 * Number of items selected.
3446 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3448 INT nSelectedCount
= 0;
3450 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3453 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3455 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3460 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3462 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3463 return nSelectedCount
;
3468 * Manages the item focus.
3471 * [I] infoPtr : valid pointer to the listview structure
3472 * [I] nItem : item index
3475 * TRUE : focused item changed
3476 * FALSE : focused item has NOT changed
3478 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3480 INT oldFocus
= infoPtr
->nFocusedItem
;
3483 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3485 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3486 lvItem
.stateMask
= LVIS_FOCUSED
;
3487 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3489 return oldFocus
!= infoPtr
->nFocusedItem
;
3492 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3494 if (nShiftItem
< nItem
) return nShiftItem
;
3496 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3498 if (direction
> 0) return nShiftItem
+ direction
;
3500 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3503 /* This function updates focus index.
3506 focus : current focus index
3507 item : index of item to be added/removed
3508 direction : add/remove flag
3510 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3512 DWORD old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3514 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3515 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3516 if (focus
!= infoPtr
->nFocusedItem
)
3517 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3518 infoPtr
->notify_mask
|= old_mask
;
3523 * Updates the various indices after an item has been inserted or deleted.
3526 * [I] infoPtr : valid pointer to the listview structure
3527 * [I] nItem : item index
3528 * [I] direction : Direction of shift, +1 or -1.
3533 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3535 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3537 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3538 assert(abs(direction
) == 1);
3539 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3541 /* But we are not supposed to modify nHotItem! */
3546 * Adds a block of selections.
3549 * [I] infoPtr : valid pointer to the listview structure
3550 * [I] nItem : item index
3553 * Whether the window is still valid.
3555 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3557 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3558 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3559 HWND hwndSelf
= infoPtr
->hwndSelf
;
3560 NMLVODSTATECHANGE nmlv
;
3565 /* Temporarily disable change notification
3566 * If the control is LVS_OWNERDATA, we need to send
3567 * only one LVN_ODSTATECHANGED notification.
3568 * See MSDN documentation for LVN_ITEMCHANGED.
3570 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3571 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3572 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3574 if (nFirst
== -1) nFirst
= nItem
;
3576 item
.state
= LVIS_SELECTED
;
3577 item
.stateMask
= LVIS_SELECTED
;
3579 for (i
= nFirst
; i
<= nLast
; i
++)
3580 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3582 ZeroMemory(&nmlv
, sizeof(nmlv
));
3583 nmlv
.iFrom
= nFirst
;
3586 nmlv
.uNewState
= item
.state
;
3588 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3589 if (!IsWindow(hwndSelf
))
3591 infoPtr
->notify_mask
|= old_mask
;
3598 * Sets a single group selection.
3601 * [I] infoPtr : valid pointer to the listview structure
3602 * [I] nItem : item index
3607 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3614 if (!(selection
= ranges_create(100))) return;
3616 item
.state
= LVIS_SELECTED
;
3617 item
.stateMask
= LVIS_SELECTED
;
3619 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3621 if (infoPtr
->nSelectionMark
== -1)
3623 infoPtr
->nSelectionMark
= nItem
;
3624 ranges_additem(selection
, nItem
);
3630 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3631 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3632 ranges_add(selection
, sel
);
3637 RECT rcItem
, rcSel
, rcSelMark
;
3640 rcItem
.left
= LVIR_BOUNDS
;
3641 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3642 ranges_destroy (selection
);
3645 rcSelMark
.left
= LVIR_BOUNDS
;
3646 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3647 ranges_destroy (selection
);
3650 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3651 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3652 while(iterator_next(&i
))
3654 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3655 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3657 iterator_destroy(&i
);
3660 /* disable per item notifications on LVS_OWNERDATA style
3661 FIXME: single LVN_ODSTATECHANGED should be used */
3662 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3663 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3664 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3666 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3669 iterator_rangesitems(&i
, selection
);
3670 while(iterator_next(&i
))
3671 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3672 /* this will also destroy the selection */
3673 iterator_destroy(&i
);
3675 infoPtr
->notify_mask
|= old_mask
;
3676 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3681 * Sets a single selection.
3684 * [I] infoPtr : valid pointer to the listview structure
3685 * [I] nItem : item index
3690 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3694 TRACE("nItem=%d\n", nItem
);
3696 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3698 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3699 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3700 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3702 infoPtr
->nSelectionMark
= nItem
;
3707 * Set selection(s) with keyboard.
3710 * [I] infoPtr : valid pointer to the listview structure
3711 * [I] nItem : item index
3712 * [I] space : VK_SPACE code sent
3715 * SUCCESS : TRUE (needs to be repainted)
3716 * FAILURE : FALSE (nothing has changed)
3718 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3720 /* FIXME: pass in the state */
3721 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3722 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3723 BOOL bResult
= FALSE
;
3725 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3726 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3730 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3731 LISTVIEW_SetSelection(infoPtr
, nItem
);
3735 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3739 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3740 lvItem
.stateMask
= LVIS_SELECTED
;
3743 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3744 if (lvItem
.state
& LVIS_SELECTED
)
3745 infoPtr
->nSelectionMark
= nItem
;
3747 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3750 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3753 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3757 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3759 LVHITTESTINFO lvHitTestInfo
;
3761 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3762 lvHitTestInfo
.pt
.x
= pt
.x
;
3763 lvHitTestInfo
.pt
.y
= pt
.y
;
3765 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3767 lpLVItem
->mask
= LVIF_PARAM
;
3768 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3769 lpLVItem
->iSubItem
= 0;
3771 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3774 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3776 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3777 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3778 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3783 * Called when the mouse is being actively tracked and has hovered for a specified
3787 * [I] infoPtr : valid pointer to the listview structure
3788 * [I] fwKeys : key indicator
3789 * [I] x,y : mouse position
3792 * 0 if the message was processed, non-zero if there was an error
3795 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3796 * over the item for a certain period of time.
3799 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3803 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3805 if (LISTVIEW_IsHotTracking(infoPtr
))
3813 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3814 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3816 SetFocus(infoPtr
->hwndSelf
);
3822 #define SCROLL_LEFT 0x1
3823 #define SCROLL_RIGHT 0x2
3824 #define SCROLL_UP 0x4
3825 #define SCROLL_DOWN 0x8
3829 * Utility routine to draw and highlight items within a marquee selection rectangle.
3832 * [I] infoPtr : valid pointer to the listview structure
3833 * [I] coords_orig : original co-ordinates of the cursor
3834 * [I] coords_offs : offsetted coordinates of the cursor
3835 * [I] offset : offset amount
3836 * [I] scroll : Bitmask of which directions we should scroll, if at all
3841 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3844 BOOL controlDown
= FALSE
;
3846 ITERATOR old_elems
, new_elems
;
3848 POINT coords_offs
, offset
;
3850 /* Ensure coordinates are within client bounds */
3851 coords_offs
.x
= max(min(coords_orig
->x
, infoPtr
->rcList
.right
), 0);
3852 coords_offs
.y
= max(min(coords_orig
->y
, infoPtr
->rcList
.bottom
), 0);
3855 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3857 /* Offset coordinates by the appropriate amount */
3858 coords_offs
.x
-= offset
.x
;
3859 coords_offs
.y
-= offset
.y
;
3861 if (coords_offs
.x
> infoPtr
->marqueeOrigin
.x
)
3863 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3864 rect
.right
= coords_offs
.x
;
3868 rect
.left
= coords_offs
.x
;
3869 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3872 if (coords_offs
.y
> infoPtr
->marqueeOrigin
.y
)
3874 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3875 rect
.bottom
= coords_offs
.y
;
3879 rect
.top
= coords_offs
.y
;
3880 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3883 /* Cancel out the old marquee rectangle and draw the new one */
3884 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3886 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3887 the cursor is further away */
3889 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3890 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3892 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3893 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3895 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3896 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3898 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3899 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3901 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3903 infoPtr
->marqueeRect
= rect
;
3904 infoPtr
->marqueeDrawRect
= rect
;
3905 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
.x
, offset
.y
);
3907 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3908 iterator_remove_common_items(&old_elems
, &new_elems
);
3910 /* Iterate over no longer selected items */
3911 while (iterator_next(&old_elems
))
3913 if (old_elems
.nItem
> -1)
3915 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3918 item
.state
= LVIS_SELECTED
;
3920 item
.stateMask
= LVIS_SELECTED
;
3922 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3925 iterator_destroy(&old_elems
);
3928 /* Iterate over newly selected items */
3929 if (GetKeyState(VK_CONTROL
) & 0x8000)
3932 while (iterator_next(&new_elems
))
3934 if (new_elems
.nItem
> -1)
3936 /* If CTRL is pressed, invert. If not, always select the item. */
3937 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3940 item
.state
= LVIS_SELECTED
;
3942 item
.stateMask
= LVIS_SELECTED
;
3944 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3947 iterator_destroy(&new_elems
);
3949 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3954 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3955 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3958 * [I] hwnd : Handle to the listview
3959 * [I] uMsg : WM_TIMER (ignored)
3960 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3961 * [I] dwTimer : The elapsed time (ignored)
3966 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3968 LISTVIEW_INFO
*infoPtr
;
3969 SCROLLINFO scrollInfo
;
3973 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3978 /* Get the current cursor position and convert to client coordinates */
3979 GetCursorPos(&coords
);
3980 ScreenToClient(hWnd
, &coords
);
3982 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3983 scrollInfo
.fMask
= SIF_ALL
;
3985 /* Work out in which directions we can scroll */
3986 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3988 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3989 scroll
|= SCROLL_UP
;
3991 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3992 scroll
|= SCROLL_DOWN
;
3995 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3997 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3998 scroll
|= SCROLL_LEFT
;
4000 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
4001 scroll
|= SCROLL_RIGHT
;
4004 if (((coords
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
4005 ((coords
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
4006 ((coords
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
4007 ((coords
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
4009 LISTVIEW_MarqueeHighlight(infoPtr
, &coords
, scroll
);
4015 * Called whenever WM_MOUSEMOVE is received.
4018 * [I] infoPtr : valid pointer to the listview structure
4019 * [I] fwKeys : key indicator
4020 * [I] x,y : mouse position
4023 * 0 if the message is processed, non-zero if there was an error
4025 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4034 if (!(fwKeys
& MK_LBUTTON
))
4035 infoPtr
->bLButtonDown
= FALSE
;
4037 if (infoPtr
->bLButtonDown
)
4039 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4040 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4042 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4044 if (infoPtr
->bMarqueeSelect
)
4046 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4047 move the mouse again */
4049 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4050 (y
>= infoPtr
->rcList
.bottom
))
4052 if (!infoPtr
->bScrolling
)
4054 infoPtr
->bScrolling
= TRUE
;
4055 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4060 infoPtr
->bScrolling
= FALSE
;
4061 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4064 LISTVIEW_MarqueeHighlight(infoPtr
, &pt
, 0);
4069 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4071 /* reset item marker */
4072 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4073 infoPtr
->nLButtonDownItem
= -1;
4075 if (!PtInRect(&rect
, pt
))
4077 /* this path covers the following:
4078 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4079 2. change focus with keys
4080 3. move mouse over item from step 1 selects it and moves focus on it */
4081 if (infoPtr
->nLButtonDownItem
!= -1 &&
4082 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4086 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4087 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4089 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4090 infoPtr
->nLButtonDownItem
= -1;
4093 if (!infoPtr
->bDragging
)
4095 ht
.pt
= infoPtr
->ptClickPos
;
4096 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4098 /* If the click is outside the range of an item, begin a
4099 highlight. If not, begin an item drag. */
4104 /* If we're allowing multiple selections, send notification.
4105 If return value is non-zero, cancel. */
4106 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4108 /* Store the absolute coordinates of the click */
4110 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4112 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4113 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4115 /* Begin selection and capture mouse */
4116 infoPtr
->bMarqueeSelect
= TRUE
;
4117 infoPtr
->marqueeRect
= rect
;
4118 SetCapture(infoPtr
->hwndSelf
);
4125 ZeroMemory(&nmlv
, sizeof(nmlv
));
4126 nmlv
.iItem
= ht
.iItem
;
4127 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4129 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4130 infoPtr
->bDragging
= TRUE
;
4138 /* see if we are supposed to be tracking mouse hovering */
4139 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4140 TRACKMOUSEEVENT trackinfo
;
4143 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4144 trackinfo
.dwFlags
= TME_QUERY
;
4146 /* see if we are already tracking this hwnd */
4147 _TrackMouseEvent(&trackinfo
);
4150 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
4153 if((trackinfo
.dwFlags
& flags
) != flags
|| trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4154 trackinfo
.dwFlags
= flags
;
4155 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4156 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4158 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4159 _TrackMouseEvent(&trackinfo
);
4168 * Tests whether the item is assignable to a list with style lStyle
4170 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4172 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4173 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4174 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4182 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4185 * [I] infoPtr : valid pointer to the listview structure
4186 * [I] lpLVItem : valid pointer to new item attributes
4187 * [I] isNew : the item being set is being inserted
4188 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4189 * [O] bChanged : will be set to TRUE if the item really changed
4195 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4201 /* stateMask is ignored for LVM_INSERTITEM */
4202 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4203 BOOL send_change_notification
;
4207 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4209 if (lpLVItem
->mask
== 0) return TRUE
;
4211 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4213 /* a virtual listview only stores selection and focus */
4214 if (lpLVItem
->mask
& ~LVIF_STATE
)
4220 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4221 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4225 /* we need to get the lParam and state of the item */
4226 item
.iItem
= lpLVItem
->iItem
;
4227 item
.iSubItem
= lpLVItem
->iSubItem
;
4228 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4229 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4233 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4235 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4236 /* determine what fields will change */
4237 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4238 uChanged
|= LVIF_STATE
;
4240 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4241 uChanged
|= LVIF_IMAGE
;
4243 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4244 uChanged
|= LVIF_PARAM
;
4246 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4247 uChanged
|= LVIF_INDENT
;
4249 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4250 uChanged
|= LVIF_TEXT
;
4252 TRACE("change mask=0x%x\n", uChanged
);
4254 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4255 nmlv
.iItem
= lpLVItem
->iItem
;
4256 if (lpLVItem
->mask
& LVIF_STATE
)
4258 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4259 nmlv
.uOldState
= item
.state
;
4261 nmlv
.uChanged
= isNew
? LVIF_STATE
: (uChanged
? uChanged
: lpLVItem
->mask
);
4262 nmlv
.lParam
= item
.lParam
;
4264 /* Send change notification if the item is not being inserted, or inserted (selected|focused),
4265 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4266 are enabled. Even if nothing really changed we still need to send this,
4267 in this case uChanged mask is just set to passed item mask. */
4269 send_change_notification
= !isNew
;
4270 send_change_notification
|= (uChanged
& LVIF_STATE
) && (lpLVItem
->state
& (LVIS_FOCUSED
| LVIS_SELECTED
));
4271 send_change_notification
&= !!(infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
);
4273 if (lpItem
&& send_change_notification
)
4275 HWND hwndSelf
= infoPtr
->hwndSelf
;
4277 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4279 if (!IsWindow(hwndSelf
))
4283 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4284 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4285 /* this means we won't hit a focus change path later */
4286 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4288 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4289 infoPtr
->nFocusedItem
++;
4292 if (!uChanged
) return TRUE
;
4295 /* copy information */
4296 if (lpLVItem
->mask
& LVIF_TEXT
)
4297 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4299 if (lpLVItem
->mask
& LVIF_IMAGE
)
4300 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4302 if (lpLVItem
->mask
& LVIF_PARAM
)
4303 lpItem
->lParam
= lpLVItem
->lParam
;
4305 if (lpLVItem
->mask
& LVIF_INDENT
)
4306 lpItem
->iIndent
= lpLVItem
->iIndent
;
4308 if (uChanged
& LVIF_STATE
)
4310 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4312 lpItem
->state
&= ~stateMask
;
4313 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4315 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4317 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4318 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4320 else if (stateMask
& LVIS_SELECTED
)
4322 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4324 /* If we are asked to change focus, and we manage it, do it.
4325 It's important to have all new item data stored at this point,
4326 because changing existing focus could result in a redrawing operation,
4327 which in turn could ask for disp data, application should see all data
4328 for inserted item when processing LVN_GETDISPINFO.
4330 The way this works application will see nested item change notifications -
4331 changed item notifications interrupted by ones from item losing focus. */
4332 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4334 if (lpLVItem
->state
& LVIS_FOCUSED
)
4336 /* update selection mark */
4337 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4338 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4340 if (infoPtr
->nFocusedItem
!= -1)
4342 /* remove current focus */
4343 item
.mask
= LVIF_STATE
;
4345 item
.stateMask
= LVIS_FOCUSED
;
4347 /* recurse with redrawing an item */
4348 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4351 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4352 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4354 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4356 infoPtr
->nFocusedItem
= -1;
4361 if (send_change_notification
)
4363 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4364 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4372 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4375 * [I] infoPtr : valid pointer to the listview structure
4376 * [I] lpLVItem : valid pointer to new subitem attributes
4377 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4378 * [O] bChanged : will be set to TRUE if the item really changed
4384 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4387 SUBITEM_INFO
*lpSubItem
;
4389 /* we do not support subitems for virtual listviews */
4390 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4392 /* set subitem only if column is present */
4393 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4395 /* First do some sanity checks */
4396 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4397 particularly useful. We currently do not actually do anything with
4398 the flag on subitems.
4400 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4401 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4403 /* get the subitem structure, and create it if not there */
4404 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4405 assert (hdpaSubItems
);
4407 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4410 SUBITEM_INFO
*tmpSubItem
;
4413 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4414 if (!lpSubItem
) return FALSE
;
4415 /* we could binary search here, if need be...*/
4416 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4418 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4419 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4421 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4426 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4427 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4431 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4433 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4437 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4439 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4448 * Sets item attributes.
4451 * [I] infoPtr : valid pointer to the listview structure
4452 * [I] lpLVItem : new item attributes
4453 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4459 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4461 HWND hwndSelf
= infoPtr
->hwndSelf
;
4462 LPWSTR pszText
= NULL
;
4463 BOOL bResult
, bChanged
= FALSE
;
4466 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4468 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4471 /* Store old item area */
4472 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4474 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4475 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4477 pszText
= lpLVItem
->pszText
;
4478 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4481 /* actually set the fields */
4482 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4484 if (lpLVItem
->iSubItem
)
4485 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4487 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4488 if (!IsWindow(hwndSelf
))
4491 /* redraw item, if necessary */
4492 if (bChanged
&& !infoPtr
->bIsDrawing
)
4494 /* this little optimization eliminates some nasty flicker */
4495 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4496 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4497 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4498 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4501 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4502 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4508 textfreeT(lpLVItem
->pszText
, isW
);
4509 lpLVItem
->pszText
= pszText
;
4517 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4520 * [I] infoPtr : valid pointer to the listview structure
4525 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4528 SCROLLINFO scrollInfo
;
4530 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4531 scrollInfo
.fMask
= SIF_POS
;
4533 if (infoPtr
->uView
== LV_VIEW_LIST
)
4535 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4536 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4538 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4540 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4541 nItem
= scrollInfo
.nPos
;
4545 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4546 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4549 TRACE("nItem=%d\n", nItem
);
4557 * Erases the background of the given rectangle
4560 * [I] infoPtr : valid pointer to the listview structure
4561 * [I] hdc : device context handle
4562 * [I] lprcBox : clipping rectangle
4568 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4570 if (!infoPtr
->hBkBrush
) return FALSE
;
4572 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4574 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4577 /* Draw main item or subitem */
4578 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4580 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4581 const RECT
*background
;
4586 /* now check if we need to update the focus rectangle */
4587 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4588 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4590 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4591 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4592 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4593 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4594 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4595 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4596 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4597 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4598 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4600 /* FIXME: temporary hack */
4601 rcSelect
.left
= rcLabel
.left
;
4603 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4605 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4606 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4607 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4608 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4609 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4612 /* in icon mode, the label rect is really what we want to draw the
4614 /* in detail mode, we want to paint background for label rect when
4615 * item is not selected or listview has full row select; otherwise paint
4616 * background for text only */
4617 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4618 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4619 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4620 background
= &rcLabel
;
4622 background
= &rcSelect
;
4624 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4625 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4627 if (item
->state
& LVIS_FOCUSED
)
4629 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4631 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4633 /* we have to update left focus bound too if item isn't in leftmost column
4634 and reduce right box bound */
4635 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4639 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4641 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4642 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4643 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4645 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4646 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4649 rcSelect
.right
= rcBox
.right
;
4651 infoPtr
->rcFocus
= rcSelect
;
4654 infoPtr
->rcFocus
= rcLabel
;
4658 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4660 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4663 TRACE("stateimage=%d\n", stateimage
);
4664 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4669 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4670 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4674 TRACE("iImage=%d\n", item
->iImage
);
4676 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4677 style
= ILD_SELECTED
;
4681 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4682 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4683 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4684 style
| (item
->state
& LVIS_OVERLAYMASK
));
4687 /* Don't bother painting item being edited */
4688 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4690 /* figure out the text drawing flags */
4691 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4692 if (infoPtr
->uView
== LV_VIEW_ICON
)
4693 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4694 else if (item
->iSubItem
)
4696 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4698 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4699 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4700 default: format
|= DT_LEFT
;
4703 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4705 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4706 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4708 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4710 /* for GRIDLINES reduce the bottom so the text formats correctly */
4711 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4714 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4722 * [I] infoPtr : valid pointer to the listview structure
4723 * [I] hdc : device context handle
4724 * [I] nItem : item index
4725 * [I] nSubItem : subitem index
4726 * [I] pos : item position in client coordinates
4727 * [I] cdmode : custom draw mode
4733 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4735 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4736 static WCHAR callbackW
[] = L
"(callback)";
4737 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4739 NMLVCUSTOMDRAW nmlvcd
;
4742 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4744 /* get information needed for drawing the item */
4745 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4746 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4747 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4748 lvItem
.iItem
= nItem
;
4749 lvItem
.iSubItem
= 0;
4752 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4753 lvItem
.pszText
= szDispText
;
4754 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4755 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4756 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4758 /* now check if we need to update the focus rectangle */
4759 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4760 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4762 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4763 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4765 /* Full custom draw stage sequence looks like this:
4770 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4771 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item itself
4772 - CDDS_ITEMPOSTPAINT
4777 - CDDS_ITEMPOSTPAINT
4780 /* fill in the custom draw structure */
4781 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4782 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4783 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4784 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4788 while (iterator_next(subitems
))
4790 DWORD subitemstage
= CDRF_DODEFAULT
;
4792 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4793 if (subitems
->nItem
)
4795 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4796 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4797 lvItem
.iItem
= nItem
;
4798 lvItem
.iSubItem
= subitems
->nItem
;
4801 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4802 lvItem
.pszText
= szDispText
;
4804 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4805 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4806 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4807 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4808 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4810 /* update custom draw data */
4811 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4812 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4813 nmlvcd
.iSubItem
= subitems
->nItem
;
4816 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4817 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4819 if (subitems
->nItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4820 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4821 else if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4822 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4824 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4825 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4827 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4828 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4833 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4834 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4838 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4840 nmlvcd
.iSubItem
= 0;
4841 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4849 * Draws listview items when in owner draw mode.
4852 * [I] infoPtr : valid pointer to the listview structure
4853 * [I] hdc : device context handle
4858 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4860 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4861 DWORD cditemmode
= CDRF_DODEFAULT
;
4862 NMLVCUSTOMDRAW nmlvcd
;
4863 POINT Origin
, Position
;
4869 ZeroMemory(&dis
, sizeof(dis
));
4871 /* Get scroll info once before loop */
4872 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4874 /* iterate through the invalidated rows */
4875 while(iterator_next(i
))
4877 item
.iItem
= i
->nItem
;
4879 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4880 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4881 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4883 dis
.CtlType
= ODT_LISTVIEW
;
4885 dis
.itemID
= item
.iItem
;
4886 dis
.itemAction
= ODA_DRAWENTIRE
;
4888 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4889 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4890 dis
.hwndItem
= infoPtr
->hwndSelf
;
4892 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4893 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4894 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4895 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4896 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4897 dis
.itemData
= item
.lParam
;
4899 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4902 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4903 * structure for the rest. of the paint cycle
4905 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4906 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4907 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4909 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4911 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4912 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4915 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4916 notify_postpaint(infoPtr
, &nmlvcd
);
4922 * Draws listview items when in report display mode.
4925 * [I] infoPtr : valid pointer to the listview structure
4926 * [I] hdc : device context handle
4927 * [I] cdmode : custom draw mode
4932 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4935 RECT rcClip
, rcItem
;
4943 /* figure out what to draw */
4944 rgntype
= GetClipBox(hdc
, &rcClip
);
4945 if (rgntype
== NULLREGION
) return;
4947 /* Get scroll info once before loop */
4948 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4950 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4952 /* narrow down the columns we need to paint */
4953 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4955 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4957 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4958 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4959 ranges_additem(colRanges
, index
);
4961 iterator_rangesitems(&j
, colRanges
);
4963 /* in full row select, we _have_ to draw the main item */
4964 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4967 /* iterate through the invalidated rows */
4968 while(iterator_next(i
))
4974 SelectObject(hdc
, infoPtr
->hFont
);
4975 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4976 Position
.x
= Origin
.x
;
4977 Position
.y
+= Origin
.y
;
4979 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4981 /* iterate through the invalidated columns */
4982 while(iterator_next(&j
))
4984 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4986 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4989 rcItem
.bottom
= infoPtr
->nItemHeight
;
4990 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4991 if (!RectVisible(hdc
, &rcItem
)) continue;
4994 ranges_additem(subitems
, j
.nItem
);
4997 iterator_rangesitems(&k
, subitems
);
4998 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
4999 iterator_destroy(&k
);
5001 iterator_destroy(&j
);
5006 * Draws the gridlines if necessary when in report display mode.
5009 * [I] infoPtr : valid pointer to the listview structure
5010 * [I] hdc : device context handle
5015 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
5021 RECT rcClip
, rcItem
= {0};
5029 /* figure out what to draw */
5030 rgntype
= GetClipBox(hdc
, &rcClip
);
5031 if (rgntype
== NULLREGION
) return;
5033 /* Get scroll info once before loop */
5034 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5036 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5038 /* narrow down the columns we need to paint */
5039 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5041 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5043 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5044 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5045 ranges_additem(colRanges
, index
);
5048 /* is right most vertical line visible? */
5049 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5051 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5052 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5053 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5056 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5058 hOldPen
= SelectObject ( hdc
, hPen
);
5060 /* draw the vertical lines for the columns */
5061 iterator_rangesitems(&j
, colRanges
);
5062 while(iterator_next(&j
))
5064 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5065 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5066 rcItem
.left
+= Origin
.x
;
5067 rcItem
.right
+= Origin
.x
;
5068 rcItem
.top
= infoPtr
->rcList
.top
;
5069 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5070 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5071 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5072 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5074 iterator_destroy(&j
);
5075 /* draw rightmost grid line if visible */
5078 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5079 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5080 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5082 rcItem
.right
+= Origin
.x
;
5084 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5085 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5088 /* draw the horizontal lines for the rows */
5089 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5090 rcItem
.left
= infoPtr
->rcList
.left
;
5091 rcItem
.right
= infoPtr
->rcList
.right
;
5092 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5094 rcItem
.bottom
= rcItem
.top
= y
;
5095 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5096 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5097 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5100 SelectObject( hdc
, hOldPen
);
5101 DeleteObject( hPen
);
5104 ranges_destroy(colRanges
);
5109 * Draws listview items when in list display mode.
5112 * [I] infoPtr : valid pointer to the listview structure
5113 * [I] hdc : device context handle
5114 * [I] cdmode : custom draw mode
5119 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5121 POINT Origin
, Position
;
5123 /* Get scroll info once before loop */
5124 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5126 while(iterator_prev(i
))
5128 SelectObject(hdc
, infoPtr
->hFont
);
5129 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5130 Position
.x
+= Origin
.x
;
5131 Position
.y
+= Origin
.y
;
5133 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5140 * Draws listview items.
5143 * [I] infoPtr : valid pointer to the listview structure
5144 * [I] hdc : device context handle
5145 * [I] prcErase : rect to be erased before refresh (may be NULL)
5150 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5152 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5153 NMLVCUSTOMDRAW nmlvcd
;
5160 HBITMAP hbmp
= NULL
;
5163 LISTVIEW_DUMP(infoPtr
);
5165 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5166 TRACE("double buffering\n");
5168 hdc
= CreateCompatibleDC(hdcOrig
);
5170 ERR("Failed to create DC for backbuffer\n");
5173 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5174 infoPtr
->rcList
.bottom
);
5176 ERR("Failed to create bitmap for backbuffer\n");
5181 SelectObject(hdc
, hbmp
);
5182 SelectObject(hdc
, infoPtr
->hFont
);
5184 if(GetClipBox(hdcOrig
, &rcClient
))
5185 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5187 /* Save dc values we're gonna trash while drawing
5188 * FIXME: Should be done in LISTVIEW_DrawItem() */
5189 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5190 oldBkMode
= GetBkMode(hdc
);
5191 oldBkColor
= GetBkColor(hdc
);
5192 oldTextColor
= GetTextColor(hdc
);
5195 infoPtr
->bIsDrawing
= TRUE
;
5198 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5199 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5200 /* If no erasing was done (usually because RedrawWindow was called
5201 * with RDW_INVALIDATE only) we need to copy the old contents into
5202 * the backbuffer before continuing. */
5203 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5204 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5205 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5206 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5209 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5210 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5211 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5212 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5214 /* nothing to draw */
5215 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5217 /* figure out what we need to draw */
5218 iterator_visibleitems(&i
, infoPtr
, hdc
);
5219 range
= iterator_range(&i
);
5221 /* send cache hint notification */
5222 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5226 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5227 nmlv
.iFrom
= range
.lower
;
5228 nmlv
.iTo
= range
.upper
- 1;
5229 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5232 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5233 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5236 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5237 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5238 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5239 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5241 /* if we have a focus rect and it's visible, draw it */
5242 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5243 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5244 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5246 iterator_destroy(&i
);
5249 /* For LVS_EX_GRIDLINES go and draw lines */
5250 /* This includes the case where there were *no* items */
5251 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5252 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5254 /* Draw marquee rectangle if appropriate */
5255 if (infoPtr
->bMarqueeSelect
)
5256 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5258 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5259 notify_postpaint(infoPtr
, &nmlvcd
);
5262 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5263 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5264 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5265 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5270 SelectObject(hdc
, hOldFont
);
5271 SetBkMode(hdc
, oldBkMode
);
5272 SetBkColor(hdc
, oldBkColor
);
5273 SetTextColor(hdc
, oldTextColor
);
5276 infoPtr
->bIsDrawing
= FALSE
;
5282 * Calculates the approximate width and height of a given number of items.
5285 * [I] infoPtr : valid pointer to the listview structure
5286 * [I] nItemCount : number of items
5287 * [I] wWidth : width
5288 * [I] wHeight : height
5291 * Returns a DWORD. The width in the low word and the height in high word.
5293 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5294 WORD wWidth
, WORD wHeight
)
5296 DWORD dwViewRect
= 0;
5298 if (nItemCount
== -1)
5299 nItemCount
= infoPtr
->nItemCount
;
5301 if (infoPtr
->uView
== LV_VIEW_LIST
)
5303 INT nItemCountPerColumn
= 1;
5304 INT nColumnCount
= 0;
5306 if (wHeight
== 0xFFFF)
5308 /* use current height */
5309 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5312 if (wHeight
< infoPtr
->nItemHeight
)
5313 wHeight
= infoPtr
->nItemHeight
;
5317 if (infoPtr
->nItemHeight
> 0)
5319 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5320 if (nItemCountPerColumn
== 0)
5321 nItemCountPerColumn
= 1;
5323 if (nItemCount
% nItemCountPerColumn
!= 0)
5324 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5326 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5330 /* Microsoft padding magic */
5331 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5332 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5334 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5336 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5340 if (infoPtr
->nItemCount
> 0)
5342 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5343 wWidth
= rcBox
.right
- rcBox
.left
;
5344 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5348 /* use current height and width */
5349 if (wHeight
== 0xffff)
5350 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5351 if (wWidth
== 0xffff)
5352 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5355 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5357 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5363 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5364 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5366 if (wWidth
== 0xffff)
5367 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5369 if (wWidth
< nItemWidth
)
5370 wWidth
= nItemWidth
;
5372 cols
= wWidth
/ nItemWidth
;
5373 if (cols
> nItemCount
)
5380 rows
= nItemCount
/ cols
;
5381 if (nItemCount
% cols
)
5387 wHeight
= (nItemHeight
* rows
)+2;
5388 wWidth
= (nItemWidth
* cols
)+2;
5390 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5392 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5393 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5400 * Cancel edit label with saving item text.
5403 * [I] infoPtr : valid pointer to the listview structure
5406 * Always returns TRUE.
5408 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5410 if (infoPtr
->hwndEdit
)
5412 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5413 HWND edit
= infoPtr
->hwndEdit
;
5415 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5416 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5424 * Create a drag image list for the specified item.
5427 * [I] infoPtr : valid pointer to the listview structure
5428 * [I] iItem : index of item
5429 * [O] lppt : Upper-left corner of the image
5432 * Returns a handle to the image list if successful, NULL otherwise.
5434 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5440 HBITMAP hbmp
, hOldbmp
;
5442 HIMAGELIST dragList
= 0;
5443 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5445 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5448 rcItem
.left
= LVIR_BOUNDS
;
5449 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5452 lppt
->x
= rcItem
.left
;
5453 lppt
->y
= rcItem
.top
;
5455 size
.cx
= rcItem
.right
- rcItem
.left
;
5456 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5458 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5459 hdc
= CreateCompatibleDC(hdcOrig
);
5460 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5461 hOldbmp
= SelectObject(hdc
, hbmp
);
5462 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5464 SetRect(&rcItem
, 0, 0, size
.cx
, size
.cy
);
5465 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5468 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5470 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5471 SelectObject(hdc
, hOldbmp
);
5472 ImageList_Add(dragList
, hbmp
, 0);
5475 SelectObject(hdc
, hOldbmp
);
5477 SelectObject(hdc
, hOldFont
);
5480 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5482 TRACE("ret=%p\n", dragList
);
5490 * Removes all listview items and subitems.
5493 * [I] infoPtr : valid pointer to the listview structure
5499 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5501 HDPA hdpaSubItems
= NULL
;
5502 BOOL suppress
= FALSE
;
5510 /* we do it directly, to avoid notifications */
5511 ranges_clear(infoPtr
->selectionRanges
);
5512 infoPtr
->nSelectionMark
= -1;
5513 infoPtr
->nFocusedItem
= -1;
5514 SetRectEmpty(&infoPtr
->rcFocus
);
5515 /* But we are supposed to leave nHotItem as is! */
5517 /* send LVN_DELETEALLITEMS notification */
5518 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5522 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5524 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5527 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5529 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5531 /* send LVN_DELETEITEM notification, if not suppressed
5532 and if it is not a virtual listview */
5533 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5534 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5535 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5536 /* free id struct */
5537 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5538 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5539 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5541 /* both item and subitem start with ITEMHDR header */
5542 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5544 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5545 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5548 DPA_Destroy(hdpaSubItems
);
5549 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5551 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5552 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5553 infoPtr
->nItemCount
--;
5558 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5559 LISTVIEW_UpdateScroll(infoPtr
);
5561 LISTVIEW_InvalidateList(infoPtr
);
5568 * Scrolls, and updates the columns, when a column is changing width.
5571 * [I] infoPtr : valid pointer to the listview structure
5572 * [I] nColumn : column to scroll
5573 * [I] dx : amount of scroll, in pixels
5578 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5580 COLUMN_INFO
*lpColumnInfo
;
5586 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5587 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5588 rcCol
= lpColumnInfo
->rcHeader
;
5589 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5590 rcCol
.left
= rcCol
.right
;
5592 /* adjust the other columns */
5593 hdi
.mask
= HDI_ORDER
;
5594 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5596 INT nOrder
= hdi
.iOrder
;
5597 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5599 hdi
.mask
= HDI_ORDER
;
5600 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5601 if (hdi
.iOrder
>= nOrder
) {
5602 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5603 lpColumnInfo
->rcHeader
.left
+= dx
;
5604 lpColumnInfo
->rcHeader
.right
+= dx
;
5609 /* do not update screen if not in report mode */
5610 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5612 /* Need to reset the item width when inserting a new column */
5613 infoPtr
->nItemWidth
+= dx
;
5615 LISTVIEW_UpdateScroll(infoPtr
);
5616 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5618 /* scroll to cover the deleted column, and invalidate for redraw */
5619 rcOld
= infoPtr
->rcList
;
5620 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5621 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5626 * Removes a column from the listview control.
5629 * [I] infoPtr : valid pointer to the listview structure
5630 * [I] nColumn : column index
5636 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5640 TRACE("nColumn=%d\n", nColumn
);
5642 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5645 /* While the MSDN specifically says that column zero should not be deleted,
5646 what actually happens is that the column itself is deleted but no items or subitems
5650 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5652 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5655 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5656 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5658 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5660 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5662 INT nItem
, nSubItem
, i
;
5664 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5666 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5669 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5671 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5672 if (lpSubItem
->iSubItem
== nColumn
)
5675 lpDelItem
= lpSubItem
;
5677 else if (lpSubItem
->iSubItem
> nColumn
)
5679 lpSubItem
->iSubItem
--;
5683 /* if we found our subitem, zap it */
5687 if (is_text(lpDelItem
->hdr
.pszText
))
5688 Free(lpDelItem
->hdr
.pszText
);
5693 /* free dpa memory */
5694 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5699 /* update the other column info */
5700 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5701 LISTVIEW_InvalidateList(infoPtr
);
5703 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5704 LISTVIEW_UpdateItemSize(infoPtr
);
5711 * Invalidates the listview after an item's insertion or deletion.
5714 * [I] infoPtr : valid pointer to the listview structure
5715 * [I] nItem : item index
5716 * [I] dir : -1 if deleting, 1 if inserting
5721 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5723 INT nPerCol
, nItemCol
, nItemRow
;
5727 /* if we don't refresh, what's the point of scrolling? */
5728 if (!is_redrawing(infoPtr
)) return;
5730 assert (abs(dir
) == 1);
5732 /* arrange icons if autoarrange is on */
5733 if (is_autoarrange(infoPtr
))
5735 BOOL arrange
= TRUE
;
5736 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5737 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5738 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5741 /* scrollbars need updating */
5742 LISTVIEW_UpdateScroll(infoPtr
);
5744 /* figure out the item's position */
5745 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5746 nPerCol
= infoPtr
->nItemCount
+ 1;
5747 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5748 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5749 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5752 nItemCol
= nItem
/ nPerCol
;
5753 nItemRow
= nItem
% nPerCol
;
5754 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5756 /* move the items below up a slot */
5757 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5758 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5759 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5760 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5761 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5762 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5763 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5765 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5766 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5769 /* report has only that column, so we're done */
5770 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5772 /* now for LISTs, we have to deal with the columns to the right */
5773 SetRect(&rcScroll
, (nItemCol
+ 1) * infoPtr
->nItemWidth
, 0,
5774 (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
,
5775 nPerCol
* infoPtr
->nItemHeight
);
5776 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5777 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5778 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5783 * Removes an item from the listview control.
5786 * [I] infoPtr : valid pointer to the listview structure
5787 * [I] nItem : item index
5793 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5796 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5797 INT focus
= infoPtr
->nFocusedItem
;
5799 TRACE("(nItem=%d)\n", nItem
);
5801 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5803 /* remove selection, and focus */
5805 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5806 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5808 /* send LVN_DELETEITEM notification. */
5809 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5811 /* we need to do this here, because we'll be deleting stuff */
5813 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5815 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5823 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5824 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5826 /* free id struct */
5827 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5828 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5829 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5831 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5833 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5834 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5837 DPA_Destroy(hdpaSubItems
);
5842 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5843 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5846 infoPtr
->nItemCount
--;
5847 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5848 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5850 /* now is the invalidation fun */
5852 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5859 * Callback implementation for editlabel control
5862 * [I] infoPtr : valid pointer to the listview structure
5863 * [I] storeText : store edit box text as item text
5864 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5870 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5872 HWND hwndSelf
= infoPtr
->hwndSelf
;
5873 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5874 NMLVDISPINFOW dispInfo
;
5875 INT editedItem
= infoPtr
->nEditLabelItem
;
5877 WCHAR
*pszText
= NULL
;
5882 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5886 if (!(pszText
= Alloc(len
* (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5890 GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
);
5892 GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
);
5896 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5898 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5899 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5900 dispInfo
.item
.iItem
= editedItem
;
5901 dispInfo
.item
.iSubItem
= 0;
5902 dispInfo
.item
.stateMask
= ~0;
5903 dispInfo
.item
.pszText
= szDispText
;
5904 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5905 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5912 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5915 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5916 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5917 textfreeT(tmp
, FALSE
);
5920 /* add the text from the edit in */
5921 dispInfo
.item
.mask
|= LVIF_TEXT
;
5922 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5923 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5925 infoPtr
->notify_mask
&= ~NOTIFY_MASK_END_LABEL_EDIT
;
5927 /* Do we need to update the Item Text */
5928 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5930 infoPtr
->notify_mask
|= NOTIFY_MASK_END_LABEL_EDIT
;
5932 infoPtr
->nEditLabelItem
= -1;
5933 infoPtr
->hwndEdit
= 0;
5935 if (!res
) goto cleanup
;
5937 if (!IsWindow(hwndSelf
))
5942 if (!pszText
) return TRUE
;
5949 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5951 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5952 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5953 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5955 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5961 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5962 dispInfo
.item
.mask
= LVIF_TEXT
;
5963 dispInfo
.item
.iItem
= editedItem
;
5964 dispInfo
.item
.iSubItem
= 0;
5965 dispInfo
.item
.pszText
= pszText
;
5966 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5967 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5975 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5977 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5980 TRACE("hwnd %p, uMsg %x, wParam %Ix, lParam %Ix, isW %d\n", hwnd
, uMsg
, wParam
, lParam
, isW
);
5985 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5989 WNDPROC editProc
= infoPtr
->EditWndProc
;
5990 infoPtr
->EditWndProc
= 0;
5991 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5992 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5996 if (VK_ESCAPE
== (INT
)wParam
)
6001 else if (VK_RETURN
== (INT
)wParam
)
6005 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6009 if (infoPtr
->hwndEdit
)
6010 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
6012 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6016 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6018 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6021 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6023 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6026 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6028 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6029 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6032 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6034 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6036 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6038 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6040 if (!hedit
) return 0;
6042 infoPtr
->EditWndProc
= (WNDPROC
)
6043 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6044 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6046 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6047 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6052 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6054 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6055 HWND hwndSelf
= infoPtr
->hwndSelf
;
6056 NMLVDISPINFOW dispInfo
;
6057 HFONT hOldFont
= NULL
;
6063 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6065 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6067 /* remove existing edit box */
6068 if (infoPtr
->hwndEdit
)
6070 SetFocus(infoPtr
->hwndSelf
);
6071 infoPtr
->hwndEdit
= 0;
6074 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6076 infoPtr
->nEditLabelItem
= nItem
;
6078 LISTVIEW_SetSelection(infoPtr
, nItem
);
6079 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6080 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6082 rect
.left
= LVIR_LABEL
;
6083 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6085 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6086 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6087 dispInfo
.item
.iItem
= nItem
;
6088 dispInfo
.item
.iSubItem
= 0;
6089 dispInfo
.item
.stateMask
= ~0;
6090 dispInfo
.item
.pszText
= disptextW
;
6091 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6092 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6094 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6095 if (!infoPtr
->hwndEdit
) return 0;
6097 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6099 if (!IsWindow(hwndSelf
))
6101 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6102 infoPtr
->hwndEdit
= 0;
6106 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6108 /* position and display edit box */
6109 hdc
= GetDC(infoPtr
->hwndSelf
);
6111 /* select the font to get appropriate metric dimensions */
6113 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6115 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6116 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6117 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6119 /* get string length in pixels */
6120 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6122 /* add extra spacing for the next character */
6123 GetTextMetricsW(hdc
, &tm
);
6124 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6127 SelectObject(hdc
, hOldFont
);
6129 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6131 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6134 TRACE("moving edit (%ld,%ld)-(%ld,%ld)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6135 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6136 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6137 SetFocus(infoPtr
->hwndEdit
);
6138 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6139 return infoPtr
->hwndEdit
;
6145 * Ensures the specified item is visible, scrolling into view if necessary.
6148 * [I] infoPtr : valid pointer to the listview structure
6149 * [I] nItem : item index
6150 * [I] bPartial : partially or entirely visible
6156 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6158 INT nScrollPosHeight
= 0;
6159 INT nScrollPosWidth
= 0;
6160 INT nHorzAdjust
= 0;
6161 INT nVertAdjust
= 0;
6164 RECT rcItem
, rcTemp
;
6166 rcItem
.left
= LVIR_BOUNDS
;
6167 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6169 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6171 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6173 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6174 if (infoPtr
->uView
== LV_VIEW_LIST
)
6175 nScrollPosWidth
= infoPtr
->nItemWidth
;
6176 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6177 nScrollPosWidth
= 1;
6179 if (rcItem
.left
< infoPtr
->rcList
.left
)
6182 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6187 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6191 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6193 /* scroll up/down, but not in LVS_LIST mode */
6194 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6195 nScrollPosHeight
= infoPtr
->nItemHeight
;
6196 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6197 nScrollPosHeight
= 1;
6199 if (rcItem
.top
< infoPtr
->rcList
.top
)
6202 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6207 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6211 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6213 if (nScrollPosWidth
)
6215 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6216 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6217 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6220 if (nScrollPosHeight
)
6222 INT diff
= nVertDiff
/ nScrollPosHeight
;
6223 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6224 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6232 * Searches for an item with specific characteristics.
6235 * [I] hwnd : window handle
6236 * [I] nStart : base item index
6237 * [I] lpFindInfo : item information to look for
6240 * SUCCESS : index of item
6243 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6244 const LVFINDINFOW
*lpFindInfo
)
6246 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6247 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6248 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6249 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6250 POINT Position
, Destination
;
6254 /* Search in virtual listviews should be done by application, not by
6255 listview control, so we just send LVN_ODFINDITEMW and return the result */
6256 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6260 nmlv
.iStart
= nStart
;
6261 nmlv
.lvfi
= *lpFindInfo
;
6262 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6265 if (!lpFindInfo
|| nItem
< 0) return -1;
6268 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6270 lvItem
.mask
|= LVIF_TEXT
;
6271 lvItem
.pszText
= szDispText
;
6272 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6275 if (lpFindInfo
->flags
& LVFI_WRAP
)
6278 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6279 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6284 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6285 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6286 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6287 switch(lpFindInfo
->vkDirection
)
6289 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6290 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6291 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6292 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6293 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6294 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6295 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6297 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6298 Destination
.x
= rcArea
.right
;
6299 Destination
.y
= rcArea
.bottom
;
6301 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6305 else Destination
.x
= Destination
.y
= 0;
6307 /* if LVFI_PARAM is specified, all other flags are ignored */
6308 if (lpFindInfo
->flags
& LVFI_PARAM
)
6310 lvItem
.mask
|= LVIF_PARAM
;
6312 lvItem
.mask
&= ~LVIF_TEXT
;
6315 nItem
= bNearest
? -1 : nStart
+ 1;
6317 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6318 search_len
= lstrlenW(lpFindInfo
->psz
);
6321 for (; nItem
< nLast
; nItem
++)
6323 lvItem
.iItem
= nItem
;
6324 lvItem
.iSubItem
= 0;
6325 lvItem
.pszText
= szDispText
;
6326 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6328 if (lvItem
.mask
& LVIF_PARAM
)
6330 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6336 if (lvItem
.mask
& LVIF_TEXT
)
6338 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6340 if (StrCmpNIW(lvItem
.pszText
, lpFindInfo
->psz
, search_len
)) continue;
6344 if (StrCmpIW(lvItem
.pszText
, lpFindInfo
->psz
)) continue;
6348 if (!bNearest
) return nItem
;
6350 /* This is very inefficient. To do a good job here,
6351 * we need a sorted array of (x,y) item positions */
6352 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6354 /* compute the distance^2 to the destination */
6355 xdist
= Destination
.x
- Position
.x
;
6356 ydist
= Destination
.y
- Position
.y
;
6357 dist
= xdist
* xdist
+ ydist
* ydist
;
6359 /* remember the distance, and item if it's closer */
6363 nNearestItem
= nItem
;
6370 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6375 return nNearestItem
;
6380 * Searches for an item with specific characteristics.
6383 * [I] hwnd : window handle
6384 * [I] nStart : base item index
6385 * [I] lpFindInfo : item information to look for
6388 * SUCCESS : index of item
6391 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6392 const LVFINDINFOA
*lpFindInfo
)
6398 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6399 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6400 fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6401 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6402 textfreeT(strW
, FALSE
);
6408 * Retrieves column attributes.
6411 * [I] infoPtr : valid pointer to the listview structure
6412 * [I] nColumn : column index
6413 * [IO] lpColumn : column information
6414 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6415 * otherwise it is in fact a LPLVCOLUMNA
6421 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6423 COLUMN_INFO
*lpColumnInfo
;
6426 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6427 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6429 /* initialize memory */
6430 ZeroMemory(&hdi
, sizeof(hdi
));
6432 if (lpColumn
->mask
& LVCF_TEXT
)
6434 hdi
.mask
|= HDI_TEXT
;
6435 hdi
.pszText
= lpColumn
->pszText
;
6436 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6439 if (lpColumn
->mask
& LVCF_IMAGE
)
6440 hdi
.mask
|= HDI_IMAGE
;
6442 if (lpColumn
->mask
& LVCF_ORDER
)
6443 hdi
.mask
|= HDI_ORDER
;
6445 if (lpColumn
->mask
& LVCF_SUBITEM
)
6446 hdi
.mask
|= HDI_LPARAM
;
6448 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6450 if (lpColumn
->mask
& LVCF_FMT
)
6451 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6453 if (lpColumn
->mask
& LVCF_WIDTH
)
6454 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6456 if (lpColumn
->mask
& LVCF_IMAGE
)
6457 lpColumn
->iImage
= hdi
.iImage
;
6459 if (lpColumn
->mask
& LVCF_ORDER
)
6460 lpColumn
->iOrder
= hdi
.iOrder
;
6462 if (lpColumn
->mask
& LVCF_SUBITEM
)
6463 lpColumn
->iSubItem
= hdi
.lParam
;
6465 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6466 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6471 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6473 if (!infoPtr
->hwndHeader
) return FALSE
;
6474 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6479 * Retrieves the column width.
6482 * [I] infoPtr : valid pointer to the listview structure
6483 * [I] int : column index
6486 * SUCCESS : column width
6489 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6491 INT nColumnWidth
= 0;
6494 TRACE("nColumn=%d\n", nColumn
);
6496 /* we have a 'column' in LIST and REPORT mode only */
6497 switch(infoPtr
->uView
)
6500 nColumnWidth
= infoPtr
->nItemWidth
;
6502 case LV_VIEW_DETAILS
:
6503 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6504 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6505 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6507 hdItem
.mask
= HDI_WIDTH
;
6508 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6510 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6513 nColumnWidth
= hdItem
.cxy
;
6517 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6518 return nColumnWidth
;
6523 * In list or report display mode, retrieves the number of items that can fit
6524 * vertically in the visible area. In icon or small icon display mode,
6525 * retrieves the total number of visible items.
6528 * [I] infoPtr : valid pointer to the listview structure
6531 * Number of fully visible items.
6533 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6535 switch (infoPtr
->uView
)
6538 case LV_VIEW_SMALLICON
:
6539 return infoPtr
->nItemCount
;
6540 case LV_VIEW_DETAILS
:
6541 return LISTVIEW_GetCountPerColumn(infoPtr
);
6543 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6551 * Retrieves an image list handle.
6554 * [I] infoPtr : valid pointer to the listview structure
6555 * [I] nImageList : image list identifier
6558 * SUCCESS : image list handle
6561 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6565 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6566 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6567 case LVSIL_STATE
: return infoPtr
->himlState
;
6568 case LVSIL_GROUPHEADER
:
6569 FIXME("LVSIL_GROUPHEADER not supported\n");
6572 WARN("got unknown imagelist index - %d\n", nImageList
);
6577 /* LISTVIEW_GetISearchString */
6581 * Retrieves item attributes.
6584 * [I] hwnd : window handle
6585 * [IO] lpLVItem : item info
6586 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6587 * if FALSE, then lpLVItem is a LPLVITEMA.
6590 * This is the internal 'GetItem' interface -- it tries to
6591 * be smart and avoid text copies, if possible, by modifying
6592 * lpLVItem->pszText to point to the text string. Please note
6593 * that this is not always possible (e.g. OWNERDATA), so on
6594 * entry you *must* supply valid values for pszText, and cchTextMax.
6595 * The only difference to the documented interface is that upon
6596 * return, you should use *only* the lpLVItem->pszText, rather than
6597 * the buffer pointer you provided on input. Most code already does
6598 * that, so it's not a problem.
6599 * For the two cases when the text must be copied (that is,
6600 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6606 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6608 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6609 BOOL is_subitem_invalid
= FALSE
;
6610 NMLVDISPINFOW dispInfo
;
6615 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6617 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6620 if (lpLVItem
->mask
== 0) return TRUE
;
6621 TRACE("mask=%x\n", lpLVItem
->mask
);
6623 if (lpLVItem
->iSubItem
&& (lpLVItem
->mask
& LVIF_STATE
))
6624 lpLVItem
->state
= 0;
6626 /* a quick optimization if all we're asked is the focus state
6627 * these queries are worth optimising since they are common,
6628 * and can be answered in constant time, without the heavy accesses */
6629 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6630 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6632 lpLVItem
->state
= 0;
6633 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
&& !lpLVItem
->iSubItem
)
6634 lpLVItem
->state
|= LVIS_FOCUSED
;
6638 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6640 /* if the app stores all the data, handle it separately */
6641 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6643 dispInfo
.item
.state
= 0;
6645 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6646 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6647 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6649 UINT mask
= lpLVItem
->mask
;
6651 /* NOTE: copy only fields which we _know_ are initialized, some apps
6652 * depend on the uninitialized fields being 0 */
6653 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6654 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6655 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
6656 if (lpLVItem
->mask
& LVIF_TEXT
)
6658 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6660 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6663 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6664 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6667 if (lpLVItem
->mask
& LVIF_STATE
)
6668 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6669 /* could be zeroed on LVIF_NORECOMPUTE case */
6670 if (dispInfo
.item
.mask
)
6672 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6673 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6674 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6676 /* full size structure expected - _WIN32IE >= 0x560 */
6677 *lpLVItem
= dispInfo
.item
;
6679 else if (lpLVItem
->mask
& LVIF_INDENT
)
6681 /* indent member expected - _WIN32IE >= 0x300 */
6682 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6686 /* minimal structure expected */
6687 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6689 lpLVItem
->mask
= mask
;
6690 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6694 /* make sure lParam is zeroed out */
6695 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6697 /* callback marked pointer required here */
6698 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6699 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6701 /* we store only a little state, so if we're not asked, we're done */
6702 if (!(lpLVItem
->mask
& LVIF_STATE
) || lpLVItem
->iSubItem
) return TRUE
;
6704 /* if focus is handled by us, report it */
6705 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6707 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6708 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6709 lpLVItem
->state
|= LVIS_FOCUSED
;
6712 /* and do the same for selection, if we handle it */
6713 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6715 lpLVItem
->state
&= ~LVIS_SELECTED
;
6716 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6717 lpLVItem
->state
|= LVIS_SELECTED
;
6723 /* find the item and subitem structures before we proceed */
6724 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6725 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6728 if (lpLVItem
->iSubItem
)
6730 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
6732 pItemHdr
= &lpSubItem
->hdr
;
6735 pItemHdr
= &callbackHdr
;
6736 is_subitem_invalid
= TRUE
;
6740 pItemHdr
= &lpItem
->hdr
;
6742 /* Do we need to query the state from the app? */
6743 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& (!lpLVItem
->iSubItem
|| is_subitem_invalid
))
6745 dispInfo
.item
.mask
|= LVIF_STATE
;
6746 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6749 /* Do we need to enquire about the image? */
6750 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6751 (!lpLVItem
->iSubItem
|| (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6753 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6754 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6757 /* Only items support indentation */
6758 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&& !lpLVItem
->iSubItem
)
6760 dispInfo
.item
.mask
|= LVIF_INDENT
;
6761 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6764 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6765 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6766 !is_text(pItemHdr
->pszText
))
6768 dispInfo
.item
.mask
|= LVIF_TEXT
;
6769 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6770 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6771 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6772 *dispInfo
.item
.pszText
= '\0';
6775 /* If we don't have all the requested info, query the application */
6776 if (dispInfo
.item
.mask
)
6778 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6779 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
6780 dispInfo
.item
.lParam
= lpItem
->lParam
;
6781 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6782 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6785 /* we should not store values for subitems */
6786 if (lpLVItem
->iSubItem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6788 /* Now, handle the iImage field */
6789 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6791 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6792 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6793 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6795 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6797 if (!lpLVItem
->iSubItem
|| (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6798 lpLVItem
->iImage
= pItemHdr
->iImage
;
6800 lpLVItem
->iImage
= 0;
6803 /* The pszText field */
6804 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6806 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6807 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6809 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6811 else if (lpLVItem
->mask
& LVIF_TEXT
)
6813 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6814 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6815 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6818 /* Next is the lParam field */
6819 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6821 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6822 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6823 lpItem
->lParam
= dispInfo
.item
.lParam
;
6825 else if (lpLVItem
->mask
& LVIF_PARAM
)
6826 lpLVItem
->lParam
= lpItem
->lParam
;
6828 /* if this is a subitem, we're done */
6829 if (lpLVItem
->iSubItem
) return TRUE
;
6831 /* ... the state field (this one is different due to uCallbackmask) */
6832 if (lpLVItem
->mask
& LVIF_STATE
)
6834 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6835 if (dispInfo
.item
.mask
& LVIF_STATE
)
6837 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6838 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6840 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6842 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6843 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6844 lpLVItem
->state
|= LVIS_FOCUSED
;
6846 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6848 lpLVItem
->state
&= ~LVIS_SELECTED
;
6849 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6850 lpLVItem
->state
|= LVIS_SELECTED
;
6854 /* and last, but not least, the indent field */
6855 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6857 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6858 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6859 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6861 else if (lpLVItem
->mask
& LVIF_INDENT
)
6863 lpLVItem
->iIndent
= lpItem
->iIndent
;
6871 * Retrieves item attributes.
6874 * [I] hwnd : window handle
6875 * [IO] lpLVItem : item info
6876 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6877 * if FALSE, then lpLVItem is a LPLVITEMA.
6880 * This is the external 'GetItem' interface -- it properly copies
6881 * the text in the provided buffer.
6887 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6892 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6895 pszText
= lpLVItem
->pszText
;
6896 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6897 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6899 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6900 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6902 pszText
= LPSTR_TEXTCALLBACKW
;
6904 lpLVItem
->pszText
= pszText
;
6912 * Retrieves the position (upper-left) of the listview control item.
6913 * Note that for LVS_ICON style, the upper-left is that of the icon
6914 * and not the bounding box.
6917 * [I] infoPtr : valid pointer to the listview structure
6918 * [I] nItem : item index
6919 * [O] lpptPosition : coordinate information
6925 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6929 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6931 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6933 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6934 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6936 if (infoPtr
->uView
== LV_VIEW_ICON
)
6938 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6939 lpptPosition
->y
+= ICON_TOP_PADDING
;
6941 lpptPosition
->x
+= Origin
.x
;
6942 lpptPosition
->y
+= Origin
.y
;
6944 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6951 * Retrieves the bounding rectangle for a listview control item.
6954 * [I] infoPtr : valid pointer to the listview structure
6955 * [I] nItem : item index
6956 * [IO] lprc : bounding rectangle coordinates
6957 * lprc->left specifies the portion of the item for which the bounding
6958 * rectangle will be retrieved.
6960 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6961 * including the icon and label.
6964 * * Experiment shows that native control returns:
6965 * * width = min (48, length of text line)
6966 * * .left = position.x - (width - iconsize.cx)/2
6967 * * .right = .left + width
6968 * * height = #lines of text * ntmHeight + icon height + 8
6969 * * .top = position.y - 2
6970 * * .bottom = .top + height
6971 * * separation between items .y = itemSpacing.cy - height
6972 * * .x = itemSpacing.cx - width
6973 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
6976 * * Experiment shows that native control returns:
6977 * * width = iconSize.cx + 16
6978 * * .left = position.x - (width - iconsize.cx)/2
6979 * * .right = .left + width
6980 * * height = iconSize.cy + 4
6981 * * .top = position.y - 2
6982 * * .bottom = .top + height
6983 * * separation between items .y = itemSpacing.cy - height
6984 * * .x = itemSpacing.cx - width
6985 * LVIR_LABEL Returns the bounding rectangle of the item text.
6988 * * Experiment shows that native control returns:
6989 * * width = text length
6990 * * .left = position.x - width/2
6991 * * .right = .left + width
6992 * * height = ntmH * linecount + 2
6993 * * .top = position.y + iconSize.cy + 6
6994 * * .bottom = .top + height
6995 * * separation between items .y = itemSpacing.cy - height
6996 * * .x = itemSpacing.cx - width
6997 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
6998 * rectangles, but excludes columns in report view.
7005 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7006 * upon whether the window has the focus currently and on whether the item
7007 * is the one with the focus. Ensure that the control's record of which
7008 * item has the focus agrees with the items' records.
7010 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7012 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7013 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7014 POINT Position
, Origin
;
7018 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7020 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7022 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7023 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7025 /* Be smart and try to figure out the minimum we have to do */
7026 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7027 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7028 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7029 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7030 oversizedBox
= TRUE
;
7032 /* get what we need from the item before hand, so we make
7033 * only one request. This can speed up things, if data
7034 * is stored on the app side */
7036 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7037 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7038 lvItem
.iItem
= nItem
;
7039 lvItem
.iSubItem
= 0;
7040 lvItem
.pszText
= szDispText
;
7041 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7042 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7043 /* we got the state already up, simulate it here, to avoid a reget */
7044 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7046 lvItem
.mask
|= LVIF_STATE
;
7047 lvItem
.stateMask
= LVIS_FOCUSED
;
7048 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7051 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7052 lprc
->left
= LVIR_BOUNDS
;
7058 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7062 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7066 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7069 case LVIR_SELECTBOUNDS
:
7070 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7074 WARN("Unknown value: %ld\n", lprc
->left
);
7078 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7080 if (mode
!= LVIR_BOUNDS
)
7081 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7082 Position
.y
+ Origin
.y
);
7084 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7087 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7089 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7096 * Retrieves the spacing between listview control items.
7099 * [I] infoPtr : valid pointer to the listview structure
7100 * [IO] lprc : rectangle to receive the output
7101 * on input, lprc->top = nSubItem
7102 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7104 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7105 * not only those of the first column.
7111 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7113 RECT rect
= { 0, 0, 0, 0 };
7117 if (!lprc
) return FALSE
;
7119 TRACE("item %d, subitem %ld, type %ld\n", item
, lprc
->top
, lprc
->left
);
7121 /* Subitem of '0' means item itself, and this works for all control view modes */
7123 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7125 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7127 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7128 /* this works for any item index, no matter if it exists or not */
7129 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7131 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7134 rect
.bottom
= infoPtr
->nItemHeight
;
7138 /* Native implementation is broken for this case and garbage is left for left and right fields,
7139 we zero them to get predictable output */
7140 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7141 lprc
->bottom
= infoPtr
->nItemHeight
;
7142 OffsetRect(lprc
, origin
.x
, y
);
7143 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7151 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7152 if (infoPtr
->himlSmall
)
7153 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7155 rect
.right
= rect
.left
;
7157 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7165 ERR("Unknown bounds %ld\n", lprc
->left
);
7169 OffsetRect(&rect
, origin
.x
, y
);
7171 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7178 * Retrieves the spacing between listview control items.
7181 * [I] infoPtr : valid pointer to the listview structure
7182 * [I] bSmall : flag for small or large icon
7185 * Horizontal + vertical spacing
7187 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7193 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7197 if (infoPtr
->uView
== LV_VIEW_ICON
)
7198 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7200 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7207 * Retrieves the state of a listview control item.
7210 * [I] infoPtr : valid pointer to the listview structure
7211 * [I] nItem : item index
7212 * [I] uMask : state mask
7215 * State specified by the mask.
7217 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7221 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7223 lvItem
.iItem
= nItem
;
7224 lvItem
.iSubItem
= 0;
7225 lvItem
.mask
= LVIF_STATE
;
7226 lvItem
.stateMask
= uMask
;
7227 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7229 return lvItem
.state
& uMask
;
7234 * Retrieves the text of a listview control item or subitem.
7237 * [I] hwnd : window handle
7238 * [I] nItem : item index
7239 * [IO] lpLVItem : item information
7240 * [I] isW : TRUE if lpLVItem is Unicode
7243 * SUCCESS : string length
7246 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7248 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7250 lpLVItem
->mask
= LVIF_TEXT
;
7251 lpLVItem
->iItem
= nItem
;
7252 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7254 return textlenT(lpLVItem
->pszText
, isW
);
7259 * Searches for an item based on properties + relationships.
7262 * [I] infoPtr : valid pointer to the listview structure
7263 * [I] nItem : item index
7264 * [I] uFlags : relationship flag
7267 * SUCCESS : item index
7270 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7273 LVFINDINFOW lvFindInfo
;
7274 INT nCountPerColumn
;
7278 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7279 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7281 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7283 if (uFlags
& LVNI_CUT
)
7286 if (uFlags
& LVNI_DROPHILITED
)
7287 uMask
|= LVIS_DROPHILITED
;
7289 if (uFlags
& LVNI_FOCUSED
)
7290 uMask
|= LVIS_FOCUSED
;
7292 if (uFlags
& LVNI_SELECTED
)
7293 uMask
|= LVIS_SELECTED
;
7295 /* if we're asked for the focused item, that's only one,
7296 * so it's worth optimizing */
7297 if (uFlags
& LVNI_FOCUSED
)
7299 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7300 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7303 if (uFlags
& LVNI_ABOVE
)
7305 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7310 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7316 /* Special case for autoarrange - move 'til the top of a list */
7317 if (is_autoarrange(infoPtr
))
7319 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7320 while (nItem
- nCountPerRow
>= 0)
7322 nItem
-= nCountPerRow
;
7323 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7328 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7329 lvFindInfo
.vkDirection
= VK_UP
;
7330 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7331 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7333 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7338 else if (uFlags
& LVNI_BELOW
)
7340 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7342 while (nItem
< infoPtr
->nItemCount
)
7345 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7351 /* Special case for autoarrange - move 'til the bottom of a list */
7352 if (is_autoarrange(infoPtr
))
7354 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7355 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7357 nItem
+= nCountPerRow
;
7358 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7363 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7364 lvFindInfo
.vkDirection
= VK_DOWN
;
7365 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7366 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7368 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7373 else if (uFlags
& LVNI_TOLEFT
)
7375 if (infoPtr
->uView
== LV_VIEW_LIST
)
7377 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7378 while (nItem
- nCountPerColumn
>= 0)
7380 nItem
-= nCountPerColumn
;
7381 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7385 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7387 /* Special case for autoarrange - move 'til the beginning of a row */
7388 if (is_autoarrange(infoPtr
))
7390 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7391 while (nItem
% nCountPerRow
> 0)
7394 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7399 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7400 lvFindInfo
.vkDirection
= VK_LEFT
;
7401 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7402 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7404 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7409 else if (uFlags
& LVNI_TORIGHT
)
7411 if (infoPtr
->uView
== LV_VIEW_LIST
)
7413 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7414 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7416 nItem
+= nCountPerColumn
;
7417 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7421 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7423 /* Special case for autoarrange - move 'til the end of a row */
7424 if (is_autoarrange(infoPtr
))
7426 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7427 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7430 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7435 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7436 lvFindInfo
.vkDirection
= VK_RIGHT
;
7437 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7438 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7440 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7449 /* search by index */
7450 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7452 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7460 static BOOL
LISTVIEW_GetNextItemIndex(const LISTVIEW_INFO
*infoPtr
, LVITEMINDEX
*index
, UINT flags
)
7462 /* FIXME: specified item group is ignored */
7467 index
->iItem
= LISTVIEW_GetNextItem(infoPtr
, index
->iItem
, flags
);
7468 return index
->iItem
!= -1;
7471 /* LISTVIEW_GetNumberOfWorkAreas */
7475 * Retrieves the origin coordinates when in icon or small icon display mode.
7478 * [I] infoPtr : valid pointer to the listview structure
7479 * [O] lpptOrigin : coordinate information
7484 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7486 INT nHorzPos
= 0, nVertPos
= 0;
7487 SCROLLINFO scrollInfo
;
7489 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7490 scrollInfo
.fMask
= SIF_POS
;
7492 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7493 nHorzPos
= scrollInfo
.nPos
;
7494 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7495 nVertPos
= scrollInfo
.nPos
;
7497 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7499 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7500 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7501 if (infoPtr
->uView
== LV_VIEW_LIST
)
7502 nHorzPos
*= infoPtr
->nItemWidth
;
7503 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7504 nVertPos
*= infoPtr
->nItemHeight
;
7506 lpptOrigin
->x
-= nHorzPos
;
7507 lpptOrigin
->y
-= nVertPos
;
7509 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7514 * Retrieves the width of a string.
7517 * [I] hwnd : window handle
7518 * [I] lpszText : text string to process
7519 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7522 * SUCCESS : string width (in pixels)
7525 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7530 if (is_text(lpszText
))
7532 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7533 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7534 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7537 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7539 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7540 SelectObject(hdc
, hOldFont
);
7541 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7543 return stringSize
.cx
;
7548 * Determines which listview item is located at the specified position.
7551 * [I] infoPtr : valid pointer to the listview structure
7552 * [IO] lpht : hit test information
7553 * [I] subitem : fill out iSubItem.
7554 * [I] select : return the index only if the hit selects the item
7557 * (mm 20001022): We must not allow iSubItem to be touched, for
7558 * an app might pass only a structure with space up to iItem!
7559 * (MS Office 97 does that for instance in the file open dialog)
7562 * SUCCESS : item index
7565 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7567 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7568 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7569 POINT Origin
, Position
, opt
;
7575 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7579 if (subitem
) lpht
->iSubItem
= 0;
7581 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7583 /* set whole list relation flags */
7584 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7586 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7587 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7588 lpht
->flags
|= LVHT_TOLEFT
;
7590 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7591 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7595 if (infoPtr
->rcList
.bottom
< opt
.y
)
7596 lpht
->flags
|= LVHT_BELOW
;
7600 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7601 lpht
->flags
|= LVHT_TOLEFT
;
7602 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7603 lpht
->flags
|= LVHT_TORIGHT
;
7605 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7606 lpht
->flags
|= LVHT_ABOVE
;
7607 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7608 lpht
->flags
|= LVHT_BELOW
;
7611 /* even if item is invalid try to find subitem */
7612 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7617 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7619 lpht
->iSubItem
= -1;
7620 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7622 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7624 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7630 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7632 /* if we're outside horizontal columns bounds there's nothing to test further */
7633 if (lpht
->iSubItem
== -1)
7636 lpht
->flags
= LVHT_NOWHERE
;
7641 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7642 if (lpht
->flags
) return -1;
7644 lpht
->flags
|= LVHT_NOWHERE
;
7646 /* first deal with the large items */
7647 rcSearch
.left
= lpht
->pt
.x
;
7648 rcSearch
.top
= lpht
->pt
.y
;
7649 rcSearch
.right
= rcSearch
.left
+ 1;
7650 rcSearch
.bottom
= rcSearch
.top
+ 1;
7652 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7653 iterator_next(&i
); /* go to first item in the sequence */
7655 iterator_destroy(&i
);
7657 TRACE("lpht->iItem=%d\n", iItem
);
7658 if (iItem
== -1) return -1;
7660 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7661 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7662 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7663 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7664 lvItem
.iItem
= iItem
;
7665 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7666 lvItem
.pszText
= szDispText
;
7667 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7668 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7669 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7671 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7672 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7673 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7675 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7676 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7678 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7680 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7683 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7684 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7688 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7689 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7691 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7692 if (!PtInRect(&rcBounds
, opt
)) return -1;
7694 /* That's a special case - row rectangle is used as item rectangle and
7695 returned flags contain all item parts. */
7696 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7698 if (PtInRect(&rcIcon
, opt
))
7699 lpht
->flags
|= LVHT_ONITEMICON
;
7700 else if (PtInRect(&rcLabel
, opt
))
7701 lpht
->flags
|= LVHT_ONITEMLABEL
;
7702 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7703 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7704 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7706 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7708 if (lpht
->flags
& LVHT_ONITEM
)
7709 lpht
->flags
&= ~LVHT_NOWHERE
;
7710 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7712 if (select
&& !is_fullrow
)
7714 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7716 /* get main item bounds */
7717 lvItem
.iSubItem
= 0;
7718 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7719 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7720 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7722 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7724 return lpht
->iItem
= iItem
;
7729 * Inserts a new item in the listview control.
7732 * [I] infoPtr : valid pointer to the listview structure
7733 * [I] lpLVItem : item information
7734 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7737 * SUCCESS : new item index
7740 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7747 BOOL is_sorted
, has_changed
;
7749 HWND hwndSelf
= infoPtr
->hwndSelf
;
7751 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7753 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7755 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7756 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7758 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7760 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7762 /* insert item in listview control data structure */
7763 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7764 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7766 /* link with id struct */
7767 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7769 lpID
->item
= hdpaSubItems
;
7770 lpID
->id
= get_next_itemid(infoPtr
);
7771 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7773 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7774 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7776 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7778 /* calculate new item index */
7786 textW
= textdupTtoW(lpLVItem
->pszText
, isW
);
7788 while (i
< infoPtr
->nItemCount
)
7790 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7791 item_s
= DPA_GetPtr(hItem
, 0);
7793 cmpv
= textcmpWT(item_s
->hdr
.pszText
, textW
, TRUE
);
7794 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7796 if (cmpv
>= 0) break;
7800 textfreeT(textW
, isW
);
7805 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7807 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7808 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7809 if (nItem
== -1) goto fail
;
7810 infoPtr
->nItemCount
++;
7812 /* shift indices first so they don't get tangled */
7813 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7815 /* set the item attributes */
7816 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7818 /* full size structure expected - _WIN32IE >= 0x560 */
7821 else if (lpLVItem
->mask
& LVIF_INDENT
)
7823 /* indent member expected - _WIN32IE >= 0x300 */
7824 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7828 /* minimal structure expected */
7829 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7832 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7834 if (item
.mask
& LVIF_STATE
)
7836 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7837 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7838 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7842 item
.mask
|= LVIF_STATE
;
7843 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7844 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7848 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7850 /* make room for the position, if we are in the right mode */
7851 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7853 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7855 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7857 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7862 /* send LVN_INSERTITEM notification */
7863 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7865 nmlv
.lParam
= lpItem
->lParam
;
7866 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7867 if (!IsWindow(hwndSelf
))
7870 /* align items (set position of each item) */
7871 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7875 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7876 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7878 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7880 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7883 /* now is the invalidation fun */
7884 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7888 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7889 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7890 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7891 infoPtr
->nItemCount
--;
7893 DPA_DeletePtr(hdpaSubItems
, 0);
7894 DPA_Destroy (hdpaSubItems
);
7901 * Checks item visibility.
7904 * [I] infoPtr : valid pointer to the listview structure
7905 * [I] nFirst : item index to check for
7908 * Item visible : TRUE
7909 * Item invisible or failure : FALSE
7911 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7913 POINT Origin
, Position
;
7918 TRACE("nItem=%d\n", nItem
);
7920 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7922 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7923 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7924 rcItem
.left
= Position
.x
+ Origin
.x
;
7925 rcItem
.top
= Position
.y
+ Origin
.y
;
7926 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7927 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7929 hdc
= GetDC(infoPtr
->hwndSelf
);
7930 if (!hdc
) return FALSE
;
7931 ret
= RectVisible(hdc
, &rcItem
);
7932 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7939 * Redraws a range of items.
7942 * [I] infoPtr : valid pointer to the listview structure
7943 * [I] nFirst : first item
7944 * [I] nLast : last item
7950 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7954 for (i
= max(nFirst
, 0); i
<= min(nLast
, infoPtr
->nItemCount
- 1); i
++)
7955 LISTVIEW_InvalidateItem(infoPtr
, i
);
7962 * Scroll the content of a listview.
7965 * [I] infoPtr : valid pointer to the listview structure
7966 * [I] dx : horizontal scroll amount in pixels
7967 * [I] dy : vertical scroll amount in pixels
7974 * If the control is in report view (LV_VIEW_DETAILS) the control can
7975 * be scrolled only in line increments. "dy" will be rounded to the
7976 * nearest number of pixels that are a whole line. Ex: if line height
7977 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7978 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7980 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7982 switch(infoPtr
->uView
) {
7983 case LV_VIEW_DETAILS
:
7984 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7985 dy
/= infoPtr
->nItemHeight
;
7988 if (dy
!= 0) return FALSE
;
7994 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
7995 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8002 * Sets the background color.
8005 * [I] infoPtr : valid pointer to the listview structure
8006 * [I] color : background color
8012 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8014 TRACE("color %lx\n", color
);
8016 if(infoPtr
->clrBk
!= color
) {
8017 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8018 infoPtr
->clrBk
= color
;
8019 if (color
== CLR_NONE
)
8020 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8023 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8024 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8031 /* LISTVIEW_SetBkImage */
8033 /*** Helper for {Insert,Set}ColumnT *only* */
8034 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8035 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8037 if (lpColumn
->mask
& LVCF_FMT
)
8039 /* format member is valid */
8040 lphdi
->mask
|= HDI_FORMAT
;
8042 /* set text alignment (leftmost column must be left-aligned) */
8043 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8044 lphdi
->fmt
|= HDF_LEFT
;
8045 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8046 lphdi
->fmt
|= HDF_RIGHT
;
8047 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8048 lphdi
->fmt
|= HDF_CENTER
;
8050 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8051 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8053 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8055 lphdi
->fmt
|= HDF_IMAGE
;
8056 lphdi
->iImage
= I_IMAGECALLBACK
;
8059 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8060 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8063 if (lpColumn
->mask
& LVCF_WIDTH
)
8065 lphdi
->mask
|= HDI_WIDTH
;
8066 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8068 /* make it fill the remainder of the controls width */
8072 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8074 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8075 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8078 /* retrieve the layout of the header */
8079 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8080 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8082 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8085 lphdi
->cxy
= lpColumn
->cx
;
8088 if (lpColumn
->mask
& LVCF_TEXT
)
8090 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8091 lphdi
->fmt
|= HDF_STRING
;
8092 lphdi
->pszText
= lpColumn
->pszText
;
8093 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8096 if (lpColumn
->mask
& LVCF_IMAGE
)
8098 lphdi
->mask
|= HDI_IMAGE
;
8099 lphdi
->iImage
= lpColumn
->iImage
;
8102 if (lpColumn
->mask
& LVCF_ORDER
)
8104 lphdi
->mask
|= HDI_ORDER
;
8105 lphdi
->iOrder
= lpColumn
->iOrder
;
8112 * Inserts a new column.
8115 * [I] infoPtr : valid pointer to the listview structure
8116 * [I] nColumn : column index
8117 * [I] lpColumn : column information
8118 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8121 * SUCCESS : new column index
8124 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8125 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8127 COLUMN_INFO
*lpColumnInfo
;
8131 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8133 if (!lpColumn
|| nColumn
< 0) return -1;
8134 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8136 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8137 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8140 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8141 * (can be seen in SPY) otherwise column never gets added.
8143 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8144 hdi
.mask
|= HDI_WIDTH
;
8149 * when the iSubItem is available Windows copies it to the header lParam. It seems
8150 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8152 if (lpColumn
->mask
& LVCF_SUBITEM
)
8154 hdi
.mask
|= HDI_LPARAM
;
8155 hdi
.lParam
= lpColumn
->iSubItem
;
8158 /* create header if not present */
8159 LISTVIEW_CreateHeader(infoPtr
);
8160 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8161 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8163 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8166 /* insert item in header control */
8167 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8168 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8169 nColumn
, (LPARAM
)&hdi
);
8170 if (nNewColumn
== -1) return -1;
8171 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8173 /* create our own column info */
8174 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8175 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8177 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8178 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8179 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8182 /* now we have to actually adjust the data */
8183 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8185 SUBITEM_INFO
*lpSubItem
;
8191 item
.iSubItem
= nNewColumn
;
8192 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8193 item
.iImage
= I_IMAGECALLBACK
;
8194 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8196 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8198 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8199 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8201 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8202 if (lpSubItem
->iSubItem
>= nNewColumn
)
8203 lpSubItem
->iSubItem
++;
8206 /* add new subitem for each item */
8208 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8212 /* make space for the new column */
8213 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8214 LISTVIEW_UpdateItemSize(infoPtr
);
8219 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8222 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8230 * Sets the attributes of a header item.
8233 * [I] infoPtr : valid pointer to the listview structure
8234 * [I] nColumn : column index
8235 * [I] lpColumn : column attributes
8236 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8242 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8243 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8245 HDITEMW hdi
, hdiget
;
8248 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8250 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8252 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8253 if (lpColumn
->mask
& LVCF_FMT
)
8255 hdi
.mask
|= HDI_FORMAT
;
8256 hdiget
.mask
= HDI_FORMAT
;
8257 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8258 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8260 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8262 /* set header item attributes */
8263 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8264 if (!bResult
) return FALSE
;
8266 if (lpColumn
->mask
& LVCF_FMT
)
8268 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8269 INT oldFmt
= lpColumnInfo
->fmt
;
8271 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8272 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8274 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8278 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8279 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8286 * Sets the column order array
8289 * [I] infoPtr : valid pointer to the listview structure
8290 * [I] iCount : number of elements in column order array
8291 * [I] lpiArray : pointer to column order array
8297 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8299 if (!infoPtr
->hwndHeader
) return FALSE
;
8300 infoPtr
->colRectsDirty
= TRUE
;
8301 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8306 * Sets the width of a column
8309 * [I] infoPtr : valid pointer to the listview structure
8310 * [I] nColumn : column index
8311 * [I] cx : column width
8317 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8319 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8323 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8325 /* set column width only if in report or list mode */
8326 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8328 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8329 with _USEHEADER being the lowest */
8330 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8331 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8333 /* resize all columns if in LV_VIEW_LIST mode */
8334 if(infoPtr
->uView
== LV_VIEW_LIST
)
8336 infoPtr
->nItemWidth
= cx
;
8337 LISTVIEW_InvalidateList(infoPtr
);
8341 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8343 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8348 lvItem
.mask
= LVIF_TEXT
;
8350 lvItem
.iSubItem
= nColumn
;
8351 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8352 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8354 lvItem
.pszText
= szDispText
;
8355 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8356 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8357 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8359 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8360 max_cx
+= infoPtr
->iconSize
.cx
;
8361 max_cx
+= TRAILING_LABEL_PADDING
;
8362 if (nColumn
== 0 && (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
))
8363 max_cx
+= GetSystemMetrics(SM_CXSMICON
);
8366 /* autosize based on listview items width */
8367 if(cx
== LVSCW_AUTOSIZE
)
8369 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8371 /* if iCol is the last column make it fill the remainder of the controls width */
8372 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8377 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8378 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8380 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8384 /* Despite what the MS docs say, if this is not the last
8385 column, then MS resizes the column to the width of the
8386 largest text string in the column, including headers
8387 and items. This is different from LVSCW_AUTOSIZE in that
8388 LVSCW_AUTOSIZE ignores the header string length. */
8391 /* retrieve header text */
8392 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8393 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8394 hdi
.pszText
= szDispText
;
8395 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8397 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8398 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8399 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8400 INT bitmap_margin
= 0;
8403 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8404 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8406 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8407 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8409 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8411 INT icon_cx
, icon_cy
;
8413 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8414 cx
+= icon_cx
+ 2*bitmap_margin
;
8416 else if (hdi
.fmt
& HDF_BITMAP
)
8420 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8421 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8424 SelectObject(hdc
, old_font
);
8425 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8427 cx
= max (cx
, max_cx
);
8431 if (cx
< 0) return FALSE
;
8433 /* call header to update the column change */
8434 hdi
.mask
= HDI_WIDTH
;
8435 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8436 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8437 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8441 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8444 static HIMAGELIST
LISTVIEW_CreateThemedCheckBoxImageList(const LISTVIEW_INFO
*info
)
8446 HBITMAP bitmap
, old_bitmap
;
8447 HIMAGELIST image_list
;
8453 if (!GetWindowTheme(info
->hwndSelf
))
8456 theme
= OpenThemeDataForDpi(NULL
, L
"Button", GetDpiForWindow(info
->hwndSelf
));
8460 hdc
= GetDC(info
->hwndSelf
);
8461 GetThemePartSize(theme
, hdc
, BP_CHECKBOX
, 0, NULL
, TS_DRAW
, &size
);
8462 SetRect(&rect
, 0, 0, size
.cx
, size
.cy
);
8463 image_list
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR32
, 2, 2);
8464 mem_hdc
= CreateCompatibleDC(hdc
);
8465 bitmap
= CreateCompatibleBitmap(hdc
, size
.cx
, size
.cy
);
8466 old_bitmap
= SelectObject(mem_hdc
, bitmap
);
8467 ReleaseDC(info
->hwndSelf
, hdc
);
8469 if (IsThemeBackgroundPartiallyTransparent(theme
, BP_CHECKBOX
, CBS_UNCHECKEDNORMAL
))
8470 FillRect(mem_hdc
, &rect
, (HBRUSH
)(COLOR_WINDOW
+ 1));
8471 DrawThemeBackground(theme
, mem_hdc
, BP_CHECKBOX
, CBS_UNCHECKEDNORMAL
, &rect
, NULL
);
8472 ImageList_Add(image_list
, bitmap
, NULL
);
8474 if (IsThemeBackgroundPartiallyTransparent(theme
, BP_CHECKBOX
, CBS_CHECKEDNORMAL
))
8475 FillRect(mem_hdc
, &rect
, (HBRUSH
)(COLOR_WINDOW
+ 1));
8476 DrawThemeBackground(theme
, mem_hdc
, BP_CHECKBOX
, CBS_CHECKEDNORMAL
, &rect
, NULL
);
8477 ImageList_Add(image_list
, bitmap
, NULL
);
8479 SelectObject(mem_hdc
, old_bitmap
);
8480 DeleteObject(bitmap
);
8482 CloseThemeData(theme
);
8486 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8489 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8491 HBRUSH hbr_white
, hbr_black
;
8494 himl
= LISTVIEW_CreateThemedCheckBoxImageList(infoPtr
);
8498 hbr_white
= GetStockObject(WHITE_BRUSH
);
8499 hbr_black
= GetStockObject(BLACK_BRUSH
);
8500 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8501 ILC_COLOR
| ILC_MASK
, 2, 2);
8502 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8503 hdc
= CreateCompatibleDC(hdc_wnd
);
8504 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8505 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8506 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8508 SetRect(&rc
, 0, 0, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8509 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8510 FillRect(hdc
, &rc
, hbr_white
);
8511 InflateRect(&rc
, -2, -2);
8512 FillRect(hdc
, &rc
, hbr_black
);
8514 SelectObject(hdc
, hbm_im
);
8515 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8516 SelectObject(hdc
, hbm_orig
);
8517 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8519 SelectObject(hdc
, hbm_im
);
8520 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8521 SelectObject(hdc
, hbm_orig
);
8522 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8524 DeleteObject(hbm_mask
);
8525 DeleteObject(hbm_im
);
8533 * Sets the extended listview style.
8536 * [I] infoPtr : valid pointer to the listview structure
8538 * [I] dwStyle : style
8541 * SUCCESS : previous style
8544 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8546 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8548 TRACE("mask %#lx, ex_style %#lx\n", mask
, ex_style
);
8552 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8554 infoPtr
->dwLvExStyle
= ex_style
;
8556 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8558 HIMAGELIST himl
= 0;
8559 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8562 item
.mask
= LVIF_STATE
;
8563 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8564 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8565 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8567 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8568 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8569 ImageList_Destroy(infoPtr
->himlState
);
8571 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8572 /* checkbox list replaces previous custom list or... */
8573 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8574 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8575 /* ...previous was checkbox list */
8576 (old_ex_style
& LVS_EX_CHECKBOXES
))
8577 ImageList_Destroy(himl
);
8580 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8584 /* if not already created */
8585 LISTVIEW_CreateHeader(infoPtr
);
8587 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8588 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8589 style
|= HDS_DRAGDROP
;
8591 style
&= ~HDS_DRAGDROP
;
8592 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8595 /* GRIDLINES adds decoration at top so changes sizes */
8596 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8598 LISTVIEW_CreateHeader(infoPtr
);
8599 LISTVIEW_UpdateSize(infoPtr
);
8602 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8604 LISTVIEW_CreateHeader(infoPtr
);
8607 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8609 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8610 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8613 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8615 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8616 LISTVIEW_CreateHeader(infoPtr
);
8618 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8619 LISTVIEW_UpdateSize(infoPtr
);
8620 LISTVIEW_UpdateScroll(infoPtr
);
8623 LISTVIEW_InvalidateList(infoPtr
);
8624 return old_ex_style
;
8629 * Sets the new hot cursor used during hot tracking and hover selection.
8632 * [I] infoPtr : valid pointer to the listview structure
8633 * [I] hCursor : the new hot cursor handle
8636 * Returns the previous hot cursor
8638 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8640 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8642 infoPtr
->hHotCursor
= hCursor
;
8650 * Sets the hot item index.
8653 * [I] infoPtr : valid pointer to the listview structure
8654 * [I] iIndex : index
8657 * SUCCESS : previous hot item index
8658 * FAILURE : -1 (no hot item)
8660 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8662 INT iOldIndex
= infoPtr
->nHotItem
;
8664 infoPtr
->nHotItem
= iIndex
;
8672 * Sets the amount of time the cursor must hover over an item before it is selected.
8675 * [I] infoPtr : valid pointer to the listview structure
8676 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8679 * Returns the previous hover time
8681 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8683 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8685 infoPtr
->dwHoverTime
= dwHoverTime
;
8687 return oldHoverTime
;
8692 * Sets spacing for icons of LVS_ICON style.
8695 * [I] infoPtr : valid pointer to the listview structure
8696 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8697 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8700 * MAKELONG(oldcx, oldcy)
8702 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8704 INT iconWidth
= 0, iconHeight
= 0;
8705 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8707 TRACE("requested=(%d,%d)\n", cx
, cy
);
8709 /* set to defaults, if instructed to */
8710 if (cx
== -1 && cy
== -1)
8712 infoPtr
->autoSpacing
= TRUE
;
8713 if (infoPtr
->himlNormal
)
8714 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8715 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8716 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8719 infoPtr
->autoSpacing
= FALSE
;
8721 /* if 0 then keep width */
8723 infoPtr
->iconSpacing
.cx
= cx
;
8725 /* if 0 then keep height */
8727 infoPtr
->iconSpacing
.cy
= cy
;
8729 TRACE("old=(%d,%d), new=(%ld,%ld), iconSize=(%ld,%ld), ntmH=%d\n",
8730 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8731 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8732 infoPtr
->ntmHeight
);
8734 /* these depend on the iconSpacing */
8735 LISTVIEW_UpdateItemSize(infoPtr
);
8740 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL is_small
)
8744 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8751 size
->cx
= GetSystemMetrics(is_small
? SM_CXSMICON
: SM_CXICON
);
8752 size
->cy
= GetSystemMetrics(is_small
? SM_CYSMICON
: SM_CYICON
);
8761 * [I] infoPtr : valid pointer to the listview structure
8762 * [I] nType : image list type
8763 * [I] himl : image list handle
8766 * SUCCESS : old image list
8769 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8771 INT oldHeight
= infoPtr
->nItemHeight
;
8772 HIMAGELIST himlOld
= 0;
8774 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8779 himlOld
= infoPtr
->himlNormal
;
8780 infoPtr
->himlNormal
= himl
;
8781 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8782 if (infoPtr
->autoSpacing
)
8783 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8787 himlOld
= infoPtr
->himlSmall
;
8788 infoPtr
->himlSmall
= himl
;
8789 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8790 if (infoPtr
->hwndHeader
)
8791 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8795 himlOld
= infoPtr
->himlState
;
8796 infoPtr
->himlState
= himl
;
8797 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8798 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8802 ERR("Unknown icon type=%d\n", nType
);
8806 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8807 if (infoPtr
->nItemHeight
!= oldHeight
)
8808 LISTVIEW_UpdateScroll(infoPtr
);
8815 * Preallocates memory (does *not* set the actual count of items !)
8818 * [I] infoPtr : valid pointer to the listview structure
8819 * [I] nItems : item count (projected number of items to allocate)
8820 * [I] dwFlags : update flags
8826 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8828 TRACE("nItems %d, flags %#lx\n", nItems
, dwFlags
);
8830 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8832 INT nOldCount
= infoPtr
->nItemCount
;
8833 infoPtr
->nItemCount
= nItems
;
8835 if (nItems
< nOldCount
)
8837 RANGE range
= { nItems
, nOldCount
};
8838 ranges_del(infoPtr
->selectionRanges
, range
);
8839 if (infoPtr
->nFocusedItem
>= nItems
)
8841 LISTVIEW_SetItemFocus(infoPtr
, -1);
8842 infoPtr
->nFocusedItem
= -1;
8843 SetRectEmpty(&infoPtr
->rcFocus
);
8847 LISTVIEW_UpdateScroll(infoPtr
);
8849 /* the flags are valid only in ownerdata report and list modes */
8850 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8852 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8853 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8855 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8856 LISTVIEW_InvalidateList(infoPtr
);
8863 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8864 nFrom
= min(nOldCount
, nItems
);
8865 nTo
= max(nOldCount
, nItems
);
8867 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8869 SetRect(&rcErase
, 0, nFrom
* infoPtr
->nItemHeight
, infoPtr
->nItemWidth
,
8870 nTo
* infoPtr
->nItemHeight
);
8871 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8872 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8873 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8875 else /* LV_VIEW_LIST */
8877 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8879 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8880 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8881 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8882 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8883 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8884 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8885 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8887 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8889 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8890 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8891 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8892 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8893 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8899 /* According to MSDN for non-LVS_OWNERDATA this is just
8900 * a performance issue. The control allocates its internal
8901 * data structures for the number of items specified. It
8902 * cuts down on the number of memory allocations. Therefore
8903 * we will just issue a WARN here
8905 WARN("for non-ownerdata performance option not implemented.\n");
8913 * Sets the position of an item.
8916 * [I] infoPtr : valid pointer to the listview structure
8917 * [I] nItem : item index
8918 * [I] pt : coordinate
8924 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8928 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8930 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8931 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8934 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8936 /* This point value seems to be an undocumented feature.
8937 * The best guess is that it means either at the origin,
8938 * or at true beginning of the list. I will assume the origin. */
8939 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8942 if (infoPtr
->uView
== LV_VIEW_ICON
)
8944 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8945 Pt
.y
-= ICON_TOP_PADDING
;
8950 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8955 * Sets the state of one or many items.
8958 * [I] infoPtr : valid pointer to the listview structure
8959 * [I] nItem : item index
8960 * [I] item : item or subitem info
8966 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8971 if (!item
) return FALSE
;
8973 lvItem
.iItem
= nItem
;
8974 lvItem
.iSubItem
= 0;
8975 lvItem
.mask
= LVIF_STATE
;
8976 lvItem
.state
= item
->state
;
8977 lvItem
.stateMask
= item
->stateMask
;
8978 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8985 /* special case optimization for recurring attempt to deselect all */
8986 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8989 /* select all isn't allowed in LVS_SINGLESEL */
8990 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8993 /* focus all isn't allowed */
8994 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8996 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
8997 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8999 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
9000 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
9001 oldstate
|= LVIS_SELECTED
;
9002 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
9005 /* apply to all items */
9006 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
9007 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
9009 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9013 infoPtr
->notify_mask
|= old_mask
;
9017 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
9018 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
9019 nmlv
.uChanged
= LVIF_STATE
;
9020 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
9023 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
9027 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9034 * Sets the text of an item or subitem.
9037 * [I] hwnd : window handle
9038 * [I] nItem : item index
9039 * [I] lpLVItem : item or subitem info
9040 * [I] isW : TRUE if input is Unicode
9046 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9050 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9051 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9053 lvItem
.iItem
= nItem
;
9054 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9055 lvItem
.mask
= LVIF_TEXT
;
9056 lvItem
.pszText
= lpLVItem
->pszText
;
9057 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9059 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9061 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9066 * Set item index that marks the start of a multiple selection.
9069 * [I] infoPtr : valid pointer to the listview structure
9070 * [I] nIndex : index
9073 * Index number or -1 if there is no selection mark.
9075 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9077 INT nOldIndex
= infoPtr
->nSelectionMark
;
9079 TRACE("(nIndex=%d)\n", nIndex
);
9081 if (nIndex
>= -1 && nIndex
< infoPtr
->nItemCount
)
9082 infoPtr
->nSelectionMark
= nIndex
;
9089 * Sets the text background color.
9092 * [I] infoPtr : valid pointer to the listview structure
9093 * [I] color : text background color
9099 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9101 TRACE("color %#lx\n", color
);
9103 infoPtr
->clrTextBk
= color
;
9109 * Sets the text foreground color.
9112 * [I] infoPtr : valid pointer to the listview structure
9113 * [I] color : text color
9119 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9121 TRACE("color %#lx\n", color
);
9123 infoPtr
->clrText
= color
;
9129 * Sets new ToolTip window to ListView control.
9132 * [I] infoPtr : valid pointer to the listview structure
9133 * [I] hwndNewToolTip : handle to new ToolTip
9138 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9140 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9141 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9142 return hwndOldToolTip
;
9147 * sets the Unicode character format flag for the control
9149 * [I] infoPtr :valid pointer to the listview structure
9150 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9153 * Old Unicode Format
9155 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9157 SHORT rc
= infoPtr
->notifyFormat
;
9158 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9159 return rc
== NFR_UNICODE
;
9164 * sets the control view mode
9166 * [I] infoPtr :valid pointer to the listview structure
9167 * [I] nView :new view mode value
9173 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9177 if (infoPtr
->uView
== nView
) return 1;
9179 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9180 if (nView
== LV_VIEW_TILE
)
9182 FIXME("View LV_VIEW_TILE unimplemented\n");
9186 infoPtr
->uView
= nView
;
9188 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9189 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9191 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9192 SetRectEmpty(&infoPtr
->rcFocus
);
9194 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9195 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9200 case LV_VIEW_SMALLICON
:
9201 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9203 case LV_VIEW_DETAILS
:
9208 LISTVIEW_CreateHeader( infoPtr
);
9210 hl
.prc
= &infoPtr
->rcList
;
9212 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9213 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9214 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9221 LISTVIEW_UpdateItemSize(infoPtr
);
9222 LISTVIEW_UpdateSize(infoPtr
);
9223 LISTVIEW_UpdateScroll(infoPtr
);
9224 LISTVIEW_InvalidateList(infoPtr
);
9226 TRACE("nView %ld\n", nView
);
9231 /* LISTVIEW_SetWorkAreas */
9233 struct sorting_context
9236 PFNLVCOMPARE compare_func
;
9240 /* DPA_Sort() callback used for LVM_SORTITEMS */
9241 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9243 struct sorting_context
*context
= (struct sorting_context
*)lParam
;
9244 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9245 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9247 return context
->compare_func(lv_first
->lParam
, lv_second
->lParam
, context
->lParam
);
9250 /* DPA_Sort() callback used for LVM_SORTITEMSEX */
9251 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9253 struct sorting_context
*context
= (struct sorting_context
*)lParam
;
9254 INT first_idx
= DPA_GetPtrIndex( context
->items
, first
);
9255 INT second_idx
= DPA_GetPtrIndex( context
->items
, second
);
9257 return context
->compare_func(first_idx
, second_idx
, context
->lParam
);
9262 * Sorts the listview items.
9265 * [I] infoPtr : valid pointer to the listview structure
9266 * [I] pfnCompare : application-defined value
9267 * [I] lParamSort : pointer to comparison callback
9268 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9274 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9275 LPARAM lParamSort
, BOOL IsEx
)
9277 HDPA hdpaSubItems
, hdpaItems
;
9279 LPVOID selectionMarkItem
= NULL
;
9280 LPVOID focusedItem
= NULL
;
9281 struct sorting_context context
;
9284 TRACE("pfnCompare %p, lParamSort %Ix\n", pfnCompare
, lParamSort
);
9286 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9288 if (!pfnCompare
) return FALSE
;
9289 if (!infoPtr
->hdpaItems
) return FALSE
;
9291 /* if there are 0 or 1 items, there is no need to sort */
9292 if (infoPtr
->nItemCount
< 2) return TRUE
;
9293 if (!(hdpaItems
= DPA_Clone(infoPtr
->hdpaItems
, NULL
))) return FALSE
;
9295 /* clear selection */
9296 ranges_clear(infoPtr
->selectionRanges
);
9298 /* save selection mark and focused item */
9299 if (infoPtr
->nSelectionMark
>= 0)
9300 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9301 if (infoPtr
->nFocusedItem
>= 0)
9302 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9304 context
.items
= hdpaItems
;
9305 context
.compare_func
= pfnCompare
;
9306 context
.lParam
= lParamSort
;
9308 DPA_Sort(hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)&context
);
9310 DPA_Sort(hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)&context
);
9311 DPA_Destroy(infoPtr
->hdpaItems
);
9312 infoPtr
->hdpaItems
= hdpaItems
;
9314 /* restore selection ranges */
9315 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9317 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9318 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9320 if (lpItem
->state
& LVIS_SELECTED
)
9321 ranges_additem(infoPtr
->selectionRanges
, i
);
9323 /* restore selection mark and focused item */
9324 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9325 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9327 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9329 /* refresh the display */
9330 LISTVIEW_InvalidateList(infoPtr
);
9336 * Update theme handle after a theme change.
9339 * [I] infoPtr : valid pointer to the listview structure
9343 * FAILURE : something else
9345 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9347 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9348 CloseThemeData(theme
);
9349 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9350 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9356 * Updates an items or rearranges the listview control.
9359 * [I] infoPtr : valid pointer to the listview structure
9360 * [I] nItem : item index
9366 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9368 TRACE("(nItem=%d)\n", nItem
);
9370 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9372 /* rearrange with default alignment style */
9373 if (is_autoarrange(infoPtr
))
9374 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9376 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9383 * Draw the track line at the place defined in the infoPtr structure.
9384 * The line is drawn with a XOR pen so drawing the line for the second time
9385 * in the same place erases the line.
9388 * [I] infoPtr : valid pointer to the listview structure
9394 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9398 if (infoPtr
->xTrackLine
== -1)
9401 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9403 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9404 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9405 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9411 * Called when an edit control should be displayed. This function is called after
9412 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9415 * [I] hwnd : Handle to the listview
9416 * [I] uMsg : WM_TIMER (ignored)
9417 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9418 * [I] dwTimer : The elapsed time (ignored)
9423 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9425 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9426 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9428 KillTimer(hwnd
, idEvent
);
9429 editItem
->fEnabled
= FALSE
;
9430 /* check if the item is still selected */
9431 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9432 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9437 * Creates the listview control - the WM_NCCREATE phase.
9440 * [I] hwnd : window handle
9441 * [I] lpcs : the create parameters
9447 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
9449 LISTVIEW_INFO
*infoPtr
;
9452 TRACE("(lpcs=%p)\n", lpcs
);
9454 /* initialize info pointer */
9455 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9456 if (!infoPtr
) return FALSE
;
9458 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9460 infoPtr
->hwndSelf
= hwnd
;
9461 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9462 map_style_view(infoPtr
);
9463 /* determine the type of structures to use */
9464 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9465 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9467 /* initialize color information */
9468 infoPtr
->clrBk
= CLR_NONE
;
9469 infoPtr
->clrText
= CLR_DEFAULT
;
9470 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9471 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9473 /* set default values */
9474 infoPtr
->nFocusedItem
= -1;
9475 infoPtr
->nSelectionMark
= -1;
9476 infoPtr
->nHotItem
= -1;
9477 infoPtr
->redraw
= TRUE
;
9478 infoPtr
->bNoItemMetrics
= TRUE
;
9479 infoPtr
->notify_mask
= NOTIFY_MASK_UNMASK_ALL
;
9480 infoPtr
->autoSpacing
= TRUE
;
9481 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9482 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9483 infoPtr
->nEditLabelItem
= -1;
9484 infoPtr
->nLButtonDownItem
= -1;
9485 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9486 infoPtr
->cWheelRemainder
= 0;
9487 infoPtr
->nMeasureItemHeight
= 0;
9488 infoPtr
->xTrackLine
= -1; /* no track line */
9489 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9490 infoPtr
->iVersion
= COMCTL32_VERSION
;
9491 infoPtr
->colRectsDirty
= FALSE
;
9492 infoPtr
->selected_column
= -1;
9494 /* get default font (icon title) */
9495 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9496 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9497 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9498 LISTVIEW_SaveTextMetrics(infoPtr
);
9500 /* allocate memory for the data structure */
9501 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9502 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9503 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9504 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9505 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9506 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9508 return DefWindowProcW(hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
9511 DestroyWindow(infoPtr
->hwndHeader
);
9512 ranges_destroy(infoPtr
->selectionRanges
);
9513 DPA_Destroy(infoPtr
->hdpaItems
);
9514 DPA_Destroy(infoPtr
->hdpaItemIds
);
9515 DPA_Destroy(infoPtr
->hdpaPosX
);
9516 DPA_Destroy(infoPtr
->hdpaPosY
);
9517 DPA_Destroy(infoPtr
->hdpaColumns
);
9524 * Creates the listview control - the WM_CREATE phase. Most of the data is
9525 * already set up in LISTVIEW_NCCreate
9528 * [I] hwnd : window handle
9529 * [I] lpcs : the create parameters
9535 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9537 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9539 TRACE("lpcs %p, style %#lx\n", lpcs
, lpcs
->style
);
9541 infoPtr
->dwStyle
= lpcs
->style
;
9542 map_style_view(infoPtr
);
9544 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9545 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9546 /* on error defaulting to ANSI notifications */
9547 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9548 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9550 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9552 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9555 infoPtr
->hwndHeader
= 0;
9557 /* init item size to avoid division by 0 */
9558 LISTVIEW_UpdateItemSize (infoPtr
);
9559 LISTVIEW_UpdateSize (infoPtr
);
9561 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9563 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9565 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9567 LISTVIEW_UpdateScroll(infoPtr
);
9568 /* send WM_MEASUREITEM notification */
9569 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9572 OpenThemeData(hwnd
, themeClass
);
9574 /* initialize the icon sizes */
9575 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9576 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9582 * Destroys the listview control.
9585 * [I] infoPtr : valid pointer to the listview structure
9591 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9593 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9594 CloseThemeData(theme
);
9596 /* delete all items */
9597 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9604 * Enables the listview control.
9607 * [I] infoPtr : valid pointer to the listview structure
9608 * [I] bEnable : specifies whether to enable or disable the window
9614 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9616 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9617 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9623 * Erases the background of the listview control.
9626 * [I] infoPtr : valid pointer to the listview structure
9627 * [I] hdc : device context handle
9633 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9637 TRACE("(hdc=%p)\n", hdc
);
9639 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9641 if (infoPtr
->clrBk
== CLR_NONE
)
9643 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9644 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9645 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9647 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9650 /* for double buffered controls we need to do this during refresh */
9651 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9653 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9659 * Helper function for LISTVIEW_[HV]Scroll *only*.
9660 * Performs vertical/horizontal scrolling by a give amount.
9663 * [I] infoPtr : valid pointer to the listview structure
9664 * [I] dx : amount of horizontal scroll
9665 * [I] dy : amount of vertical scroll
9667 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9669 /* now we can scroll the list */
9670 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9671 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9672 /* if we have focus, adjust rect */
9673 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9674 UpdateWindow(infoPtr
->hwndSelf
);
9679 * Performs vertical scrolling.
9682 * [I] infoPtr : valid pointer to the listview structure
9683 * [I] nScrollCode : scroll code
9684 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9685 * [I] hScrollWnd : scrollbar control window handle
9691 * SB_LINEUP/SB_LINEDOWN:
9692 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9693 * for LVS_REPORT is 1 line
9694 * for LVS_LIST cannot occur
9697 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9700 INT nOldScrollPos
, nNewScrollPos
;
9701 SCROLLINFO scrollInfo
;
9704 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9705 debugscrollcode(nScrollCode
), nScrollDiff
);
9707 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9709 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9710 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9712 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9714 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9716 nOldScrollPos
= scrollInfo
.nPos
;
9717 switch (nScrollCode
)
9723 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9727 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9731 nScrollDiff
= -scrollInfo
.nPage
;
9735 nScrollDiff
= scrollInfo
.nPage
;
9738 case SB_THUMBPOSITION
:
9740 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9747 /* quit right away if pos isn't changing */
9748 if (nScrollDiff
== 0) return 0;
9750 /* calculate new position, and handle overflows */
9751 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9752 if (nScrollDiff
> 0) {
9753 if (nNewScrollPos
< nOldScrollPos
||
9754 nNewScrollPos
> scrollInfo
.nMax
)
9755 nNewScrollPos
= scrollInfo
.nMax
;
9757 if (nNewScrollPos
> nOldScrollPos
||
9758 nNewScrollPos
< scrollInfo
.nMin
)
9759 nNewScrollPos
= scrollInfo
.nMin
;
9762 /* set the new position, and reread in case it changed */
9763 scrollInfo
.fMask
= SIF_POS
;
9764 scrollInfo
.nPos
= nNewScrollPos
;
9765 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9767 /* carry on only if it really changed */
9768 if (nNewScrollPos
== nOldScrollPos
) return 0;
9770 /* now adjust to client coordinates */
9771 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9772 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9774 /* and scroll the window */
9775 scroll_list(infoPtr
, 0, nScrollDiff
);
9782 * Performs horizontal scrolling.
9785 * [I] infoPtr : valid pointer to the listview structure
9786 * [I] nScrollCode : scroll code
9787 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9788 * [I] hScrollWnd : scrollbar control window handle
9794 * SB_LINELEFT/SB_LINERIGHT:
9795 * for LVS_ICON, LVS_SMALLICON 1 pixel
9796 * for LVS_REPORT is 1 pixel
9797 * for LVS_LIST is 1 column --> which is a 1 because the
9798 * scroll is based on columns not pixels
9801 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9804 INT nOldScrollPos
, nNewScrollPos
;
9805 SCROLLINFO scrollInfo
;
9808 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9809 debugscrollcode(nScrollCode
), nScrollDiff
);
9811 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9813 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9814 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9816 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9818 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9820 nOldScrollPos
= scrollInfo
.nPos
;
9822 switch (nScrollCode
)
9828 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9832 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9836 nScrollDiff
= -scrollInfo
.nPage
;
9840 nScrollDiff
= scrollInfo
.nPage
;
9843 case SB_THUMBPOSITION
:
9845 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9852 /* quit right away if pos isn't changing */
9853 if (nScrollDiff
== 0) return 0;
9855 /* calculate new position, and handle overflows */
9856 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9857 if (nScrollDiff
> 0) {
9858 if (nNewScrollPos
< nOldScrollPos
||
9859 nNewScrollPos
> scrollInfo
.nMax
)
9860 nNewScrollPos
= scrollInfo
.nMax
;
9862 if (nNewScrollPos
> nOldScrollPos
||
9863 nNewScrollPos
< scrollInfo
.nMin
)
9864 nNewScrollPos
= scrollInfo
.nMin
;
9867 /* set the new position, and reread in case it changed */
9868 scrollInfo
.fMask
= SIF_POS
;
9869 scrollInfo
.nPos
= nNewScrollPos
;
9870 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9872 /* carry on only if it really changed */
9873 if (nNewScrollPos
== nOldScrollPos
) return 0;
9875 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9877 /* now adjust to client coordinates */
9878 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9879 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9881 /* and scroll the window */
9882 scroll_list(infoPtr
, nScrollDiff
, 0);
9887 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9889 INT pulScrollLines
= 3;
9891 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9893 switch(infoPtr
->uView
)
9896 case LV_VIEW_SMALLICON
:
9898 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9899 * should be fixed in the future.
9901 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9902 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9905 case LV_VIEW_DETAILS
:
9906 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9908 /* if scrolling changes direction, ignore left overs */
9909 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9910 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9911 infoPtr
->cWheelRemainder
+= wheelDelta
;
9913 infoPtr
->cWheelRemainder
= wheelDelta
;
9914 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9917 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9918 cLineScroll
= pulScrollLines
* infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9919 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ pulScrollLines
;
9920 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9925 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9936 * [I] infoPtr : valid pointer to the listview structure
9937 * [I] nVirtualKey : virtual key
9938 * [I] lKeyData : key data
9943 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9945 HWND hwndSelf
= infoPtr
->hwndSelf
;
9947 NMLVKEYDOWN nmKeyDown
;
9949 TRACE("(nVirtualKey=%d, lKeyData=%ld)\n", nVirtualKey
, lKeyData
);
9951 /* send LVN_KEYDOWN notification */
9952 nmKeyDown
.wVKey
= nVirtualKey
;
9953 nmKeyDown
.flags
= 0;
9954 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9955 if (!IsWindow(hwndSelf
))
9958 switch (nVirtualKey
)
9961 nItem
= infoPtr
->nFocusedItem
;
9962 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9963 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9967 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9969 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9970 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9975 if (infoPtr
->nItemCount
> 0)
9980 if (infoPtr
->nItemCount
> 0)
9981 nItem
= infoPtr
->nItemCount
- 1;
9985 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9989 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9993 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9997 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
10001 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10003 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10004 if (infoPtr
->nFocusedItem
== topidx
)
10005 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
10010 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
10011 * LISTVIEW_GetCountPerRow(infoPtr
);
10012 if(nItem
< 0) nItem
= 0;
10016 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10018 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10019 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10020 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10021 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10023 nItem
= topidx
+ cnt
- 1;
10026 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10027 * LISTVIEW_GetCountPerRow(infoPtr
);
10028 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10032 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10033 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10043 * [I] infoPtr : valid pointer to the listview structure
10048 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10052 /* drop any left over scroll amount */
10053 infoPtr
->cWheelRemainder
= 0;
10055 /* if we did not have the focus, there's nothing more to do */
10056 if (!infoPtr
->bFocus
) return 0;
10058 /* send NM_KILLFOCUS notification */
10059 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10061 /* if we have a focus rectangle, get rid of it */
10062 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10064 /* if have a marquee selection, stop it */
10065 if (infoPtr
->bMarqueeSelect
)
10067 /* Remove the marquee rectangle and release our mouse capture */
10068 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10071 SetRectEmpty(&infoPtr
->marqueeRect
);
10073 infoPtr
->bMarqueeSelect
= FALSE
;
10074 infoPtr
->bScrolling
= FALSE
;
10075 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10078 /* set window focus flag */
10079 infoPtr
->bFocus
= FALSE
;
10081 /* invalidate the selected items before resetting focus flag */
10082 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10089 * Processes double click messages (left mouse button).
10092 * [I] infoPtr : valid pointer to the listview structure
10093 * [I] wKey : key flag
10094 * [I] x,y : mouse coordinate
10099 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10101 LVHITTESTINFO htInfo
;
10103 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10105 /* Cancel the item edition if any */
10106 if (infoPtr
->itemEdit
.fEnabled
)
10108 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10109 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10112 /* send NM_RELEASEDCAPTURE notification */
10113 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10118 /* send NM_DBLCLK notification */
10119 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10120 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10122 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10123 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10128 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10133 r
.top
= r
.bottom
= pt
.y
;
10134 r
.left
= r
.right
= pt
.x
;
10136 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10138 SetCapture(infoPtr
->hwndSelf
);
10142 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10144 if (msg
.message
== WM_MOUSEMOVE
)
10146 pt
.x
= (short)LOWORD(msg
.lParam
);
10147 pt
.y
= (short)HIWORD(msg
.lParam
);
10148 if (PtInRect(&r
, pt
))
10156 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10157 msg
.message
<= WM_RBUTTONDBLCLK
)
10162 DispatchMessageW(&msg
);
10165 if (GetCapture() != infoPtr
->hwndSelf
)
10176 * Processes mouse down messages (left mouse button).
10179 * infoPtr [I ] valid pointer to the listview structure
10180 * wKey [I ] key flag
10181 * x,y [I ] mouse coordinate
10186 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10188 LVHITTESTINFO lvHitTestInfo
;
10189 static BOOL bGroupSelect
= TRUE
;
10190 POINT pt
= { x
, y
};
10193 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10195 /* send NM_RELEASEDCAPTURE notification */
10196 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10198 /* set left button down flag and record the click position */
10199 infoPtr
->bLButtonDown
= TRUE
;
10200 infoPtr
->ptClickPos
= pt
;
10201 infoPtr
->bDragging
= FALSE
;
10202 infoPtr
->bMarqueeSelect
= FALSE
;
10203 infoPtr
->bScrolling
= FALSE
;
10205 lvHitTestInfo
.pt
.x
= x
;
10206 lvHitTestInfo
.pt
.y
= y
;
10208 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10209 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10210 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10212 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10214 notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
);
10215 toggle_checkbox_state(infoPtr
, nItem
);
10216 infoPtr
->bLButtonDown
= FALSE
;
10220 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10222 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10223 infoPtr
->nEditLabelItem
= nItem
;
10225 LISTVIEW_SetSelection(infoPtr
, nItem
);
10229 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10233 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10234 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10235 infoPtr
->nSelectionMark
= nItem
;
10241 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10242 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10244 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10245 infoPtr
->nSelectionMark
= nItem
;
10248 else if (wKey
& MK_CONTROL
)
10252 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10254 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10255 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10256 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10257 infoPtr
->nSelectionMark
= nItem
;
10259 else if (wKey
& MK_SHIFT
)
10261 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10265 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10267 infoPtr
->nEditLabelItem
= nItem
;
10268 infoPtr
->nLButtonDownItem
= nItem
;
10270 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10273 /* set selection (clears other pre-existing selections) */
10274 LISTVIEW_SetSelection(infoPtr
, nItem
);
10278 if (!infoPtr
->bFocus
)
10279 SetFocus(infoPtr
->hwndSelf
);
10281 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10282 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10286 if (!infoPtr
->bFocus
)
10287 SetFocus(infoPtr
->hwndSelf
);
10289 /* remove all selections */
10290 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10291 LISTVIEW_DeselectAll(infoPtr
);
10300 * Processes mouse up messages (left mouse button).
10303 * infoPtr [I ] valid pointer to the listview structure
10304 * wKey [I ] key flag
10305 * x,y [I ] mouse coordinate
10310 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10312 LVHITTESTINFO lvHitTestInfo
;
10314 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10316 if (!infoPtr
->bLButtonDown
) return 0;
10318 lvHitTestInfo
.pt
.x
= x
;
10319 lvHitTestInfo
.pt
.y
= y
;
10321 /* send NM_CLICK notification */
10322 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10323 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10325 /* set left button flag */
10326 infoPtr
->bLButtonDown
= FALSE
;
10328 /* set a single selection, reset others */
10329 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10330 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10331 infoPtr
->nLButtonDownItem
= -1;
10333 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10335 /* Remove the marquee rectangle and release our mouse capture */
10336 if (infoPtr
->bMarqueeSelect
)
10338 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10342 SetRectEmpty(&infoPtr
->marqueeRect
);
10343 SetRectEmpty(&infoPtr
->marqueeDrawRect
);
10345 infoPtr
->bDragging
= FALSE
;
10346 infoPtr
->bMarqueeSelect
= FALSE
;
10347 infoPtr
->bScrolling
= FALSE
;
10349 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10353 /* if we clicked on a selected item, edit the label */
10354 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10356 /* we want to make sure the user doesn't want to do a double click. So we will
10357 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10359 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10360 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10361 SetTimer(infoPtr
->hwndSelf
,
10362 (UINT_PTR
)&infoPtr
->itemEdit
,
10363 GetDoubleClickTime(),
10364 LISTVIEW_DelayedEditItem
);
10372 * Destroys the listview control (called after WM_DESTROY).
10375 * [I] infoPtr : valid pointer to the listview structure
10380 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10386 /* destroy data structure */
10387 DPA_Destroy(infoPtr
->hdpaItems
);
10388 DPA_Destroy(infoPtr
->hdpaItemIds
);
10389 DPA_Destroy(infoPtr
->hdpaPosX
);
10390 DPA_Destroy(infoPtr
->hdpaPosY
);
10392 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10393 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10394 DPA_Destroy(infoPtr
->hdpaColumns
);
10395 ranges_destroy(infoPtr
->selectionRanges
);
10397 /* destroy image lists */
10398 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10400 ImageList_Destroy(infoPtr
->himlNormal
);
10401 ImageList_Destroy(infoPtr
->himlSmall
);
10402 ImageList_Destroy(infoPtr
->himlState
);
10405 /* destroy font, bkgnd brush */
10406 infoPtr
->hFont
= 0;
10407 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10408 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10410 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10412 /* free listview info pointer*/
10420 * Handles notifications.
10423 * [I] infoPtr : valid pointer to the listview structure
10424 * [I] lpnmhdr : notification information
10429 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10433 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10435 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10437 /* remember: HDN_LAST < HDN_FIRST */
10438 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10439 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10441 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10443 switch (lpnmhdr
->code
)
10448 COLUMN_INFO
*lpColumnInfo
;
10452 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10455 /* remove the old line (if any) */
10456 LISTVIEW_DrawTrackLine(infoPtr
);
10458 /* compute & draw the new line */
10459 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10460 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10461 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10462 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10463 LISTVIEW_DrawTrackLine(infoPtr
);
10464 return notify_forward_header(infoPtr
, lpnmh
);
10467 case HDN_ENDTRACKA
:
10468 case HDN_ENDTRACKW
:
10469 /* remove the track line (if any) */
10470 LISTVIEW_DrawTrackLine(infoPtr
);
10471 infoPtr
->xTrackLine
= -1;
10472 return notify_forward_header(infoPtr
, lpnmh
);
10474 case HDN_BEGINDRAG
:
10475 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10476 return notify_forward_header(infoPtr
, lpnmh
);
10479 infoPtr
->colRectsDirty
= TRUE
;
10480 LISTVIEW_InvalidateList(infoPtr
);
10481 return notify_forward_header(infoPtr
, lpnmh
);
10483 case HDN_ITEMCHANGEDW
:
10484 case HDN_ITEMCHANGEDA
:
10486 COLUMN_INFO
*lpColumnInfo
;
10490 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10492 hdi
.mask
= HDI_WIDTH
;
10493 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10497 cxy
= lpnmh
->pitem
->cxy
;
10499 /* determine how much we change since the last know position */
10500 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10501 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10504 lpColumnInfo
->rcHeader
.right
+= dx
;
10506 hdi
.mask
= HDI_ORDER
;
10507 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10509 /* not the rightmost one */
10510 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10512 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10513 hdi
.iOrder
+ 1, 0);
10514 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10518 /* only needs to update the scrolls */
10519 infoPtr
->nItemWidth
+= dx
;
10520 LISTVIEW_UpdateScroll(infoPtr
);
10522 LISTVIEW_UpdateItemSize(infoPtr
);
10523 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10526 RECT rcCol
= lpColumnInfo
->rcHeader
;
10528 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10529 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10531 rcCol
.top
= infoPtr
->rcList
.top
;
10532 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10534 /* resizing left-aligned columns leaves most of the left side untouched */
10535 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10537 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10540 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10543 /* when shrinking the last column clear the now unused field */
10544 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10550 /* deal with right from rightmost column area */
10551 right
.left
= rcCol
.right
;
10552 right
.top
= rcCol
.top
;
10553 right
.bottom
= rcCol
.bottom
;
10554 right
.right
= infoPtr
->rcList
.right
;
10556 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10559 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10565 case HDN_ITEMCLICKW
:
10566 case HDN_ITEMCLICKA
:
10568 /* Handle sorting by Header Column */
10571 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10573 nmlv
.iSubItem
= lpnmh
->iItem
;
10574 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10575 return notify_forward_header(infoPtr
, lpnmh
);
10578 case HDN_DIVIDERDBLCLICKW
:
10579 case HDN_DIVIDERDBLCLICKA
:
10580 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10581 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10582 split needed for that */
10583 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10584 return notify_forward_header(infoPtr
, lpnmh
);
10591 * Paint non-client area of control.
10594 * [I] infoPtr : valid pointer to the listview structureof the sender
10595 * [I] region : update region
10598 * 0 - frame was painted
10600 static LRESULT
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10602 LONG exstyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
);
10603 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10604 RECT r
, window_rect
;
10607 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10608 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10610 if (!theme
|| !(exstyle
& WS_EX_CLIENTEDGE
))
10611 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10613 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10615 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10616 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10617 if (region
!= (HRGN
)1)
10618 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10620 OffsetRect(&r
, -r
.left
, -r
.top
);
10621 if (infoPtr
->hwndHeader
&& LISTVIEW_IsHeaderEnabled(infoPtr
))
10623 GetWindowRect(infoPtr
->hwndHeader
, &window_rect
);
10624 r
.top
= min(r
.bottom
, r
.top
+ window_rect
.bottom
- window_rect
.top
);
10627 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10629 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10630 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10631 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10632 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10634 /* Call default proc to get the scrollbars etc. painted */
10635 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10636 DeleteObject(cliprgn
);
10643 * Determines the type of structure to use.
10646 * [I] infoPtr : valid pointer to the listview structureof the sender
10647 * [I] hwndFrom : listview window handle
10648 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10653 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10655 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10657 if (nCommand
== NF_REQUERY
)
10658 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10660 return infoPtr
->notifyFormat
;
10665 * Paints/Repaints the listview control. Internal use.
10668 * [I] infoPtr : valid pointer to the listview structure
10669 * [I] hdc : device context handle
10674 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10676 TRACE("(hdc=%p)\n", hdc
);
10678 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10680 infoPtr
->bNoItemMetrics
= FALSE
;
10681 LISTVIEW_UpdateItemSize(infoPtr
);
10682 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10683 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10684 LISTVIEW_UpdateScroll(infoPtr
);
10687 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10690 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10695 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10696 if (!hdc
) return 1;
10697 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10698 EndPaint(infoPtr
->hwndSelf
, &ps
);
10706 * Paints/Repaints the listview control, WM_PAINT handler.
10709 * [I] infoPtr : valid pointer to the listview structure
10710 * [I] hdc : device context handle
10715 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10717 TRACE("(hdc=%p)\n", hdc
);
10719 if (!is_redrawing(infoPtr
))
10720 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10722 return LISTVIEW_Paint(infoPtr
, hdc
);
10727 * Paints/Repaints the listview control.
10730 * [I] infoPtr : valid pointer to the listview structure
10731 * [I] hdc : device context handle
10732 * [I] options : drawing options
10737 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10739 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10742 if (options
& ~(PRF_ERASEBKGND
|PRF_CLIENT
))
10743 FIXME("(hdc=%p options %#lx) partial stub\n", hdc
, options
);
10745 if (options
& PRF_ERASEBKGND
)
10746 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10748 if (options
& PRF_CLIENT
)
10749 LISTVIEW_Paint(infoPtr
, hdc
);
10757 * Processes double click messages (right mouse button).
10760 * [I] infoPtr : valid pointer to the listview structure
10761 * [I] wKey : key flag
10762 * [I] x,y : mouse coordinate
10767 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10769 LVHITTESTINFO lvHitTestInfo
;
10771 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10773 /* send NM_RELEASEDCAPTURE notification */
10774 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10776 /* send NM_RDBLCLK notification */
10777 lvHitTestInfo
.pt
.x
= x
;
10778 lvHitTestInfo
.pt
.y
= y
;
10779 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10780 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10787 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10790 * [I] infoPtr : valid pointer to the listview structure
10791 * [I] wKey : key flag
10792 * [I] x, y : mouse coordinate
10797 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10802 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10804 /* send NM_RELEASEDCAPTURE notification */
10805 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10807 /* determine the index of the selected item */
10810 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10812 /* make sure the listview control window has the focus */
10813 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10815 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10817 LISTVIEW_SetItemFocus(infoPtr
, item
);
10818 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10819 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10820 LISTVIEW_SetSelection(infoPtr
, item
);
10823 LISTVIEW_DeselectAll(infoPtr
);
10825 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10827 if (ht
.iItem
!= -1)
10831 memset(&nmlv
, 0, sizeof(nmlv
));
10832 nmlv
.iItem
= ht
.iItem
;
10833 nmlv
.ptAction
= ht
.pt
;
10835 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10840 SetFocus(infoPtr
->hwndSelf
);
10844 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10846 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10848 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10849 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10850 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10862 * [I] infoPtr : valid pointer to the listview structure
10863 * [I] hwnd : window handle of window containing the cursor
10864 * [I] nHittest : hit-test code
10865 * [I] wMouseMsg : ideintifier of the mouse message
10868 * TRUE if cursor is set
10871 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10873 LVHITTESTINFO lvHitTestInfo
;
10875 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10877 if (!infoPtr
->hHotCursor
) goto forward
;
10879 GetCursorPos(&lvHitTestInfo
.pt
);
10880 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10882 SetCursor(infoPtr
->hHotCursor
);
10888 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10896 * [I] infoPtr : valid pointer to the listview structure
10897 * [I] hwndLoseFocus : handle of previously focused window
10902 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10904 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10906 /* if we have the focus already, there's nothing to do */
10907 if (infoPtr
->bFocus
) return 0;
10909 /* send NM_SETFOCUS notification */
10910 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10912 /* set window focus flag */
10913 infoPtr
->bFocus
= TRUE
;
10915 /* put the focus rect back on */
10916 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10918 /* redraw all visible selected items */
10919 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10929 * [I] infoPtr : valid pointer to the listview structure
10930 * [I] fRedraw : font handle
10931 * [I] fRedraw : redraw flag
10936 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10938 HFONT oldFont
= infoPtr
->hFont
;
10939 INT oldHeight
= infoPtr
->nItemHeight
;
10941 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10943 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10944 if (infoPtr
->hFont
== oldFont
) return 0;
10946 LISTVIEW_SaveTextMetrics(infoPtr
);
10948 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10950 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10952 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10953 LISTVIEW_UpdateSize(infoPtr
);
10954 LISTVIEW_UpdateScroll(infoPtr
);
10956 else if (infoPtr
->nItemHeight
!= oldHeight
)
10957 LISTVIEW_UpdateScroll(infoPtr
);
10959 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10966 * Message handling for WM_SETREDRAW.
10967 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10970 * [I] infoPtr : valid pointer to the listview structure
10971 * [I] redraw: state of redraw flag
10976 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL redraw
)
10978 TRACE("old=%d, new=%d\n", infoPtr
->redraw
, redraw
);
10980 if (infoPtr
->redraw
== !!redraw
)
10983 if (!(infoPtr
->redraw
= !!redraw
))
10986 if (is_autoarrange(infoPtr
))
10987 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10988 LISTVIEW_UpdateScroll(infoPtr
);
10990 /* despite what the WM_SETREDRAW docs says, apps expect us
10991 * to invalidate the listview here... stupid! */
10992 LISTVIEW_InvalidateList(infoPtr
);
10999 * Resizes the listview control. This function processes WM_SIZE
11000 * messages. At this time, the width and height are not used.
11003 * [I] infoPtr : valid pointer to the listview structure
11004 * [I] Width : new width
11005 * [I] Height : new height
11010 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
11012 RECT rcOld
= infoPtr
->rcList
;
11014 TRACE("(width=%d, height=%d)\n", Width
, Height
);
11016 LISTVIEW_UpdateSize(infoPtr
);
11017 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
11019 /* do not bother with display related stuff if we're not redrawing */
11020 if (!is_redrawing(infoPtr
)) return 0;
11022 if (is_autoarrange(infoPtr
))
11023 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11025 LISTVIEW_UpdateScroll(infoPtr
);
11027 /* refresh all only for lists whose height changed significantly */
11028 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11029 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11030 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11031 LISTVIEW_InvalidateList(infoPtr
);
11038 * Sets the size information.
11041 * [I] infoPtr : valid pointer to the listview structure
11046 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11048 TRACE("uView %ld, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11050 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11052 if (infoPtr
->uView
== LV_VIEW_LIST
)
11054 /* Apparently the "LIST" style is supposed to have the same
11055 * number of items in a column even if there is no scroll bar.
11056 * Since if a scroll bar already exists then the bottom is already
11057 * reduced, only reduce if the scroll bar does not currently exist.
11058 * The "2" is there to mimic the native control. I think it may be
11059 * related to either padding or edges. (GLA 7/2002)
11061 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11062 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11063 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11066 /* When ListView control is created invisible, header isn't created right away. */
11067 if (infoPtr
->hwndHeader
)
11074 LISTVIEW_GetOrigin(infoPtr
, &origin
);
11076 rect
= infoPtr
->rcList
;
11077 rect
.left
+= origin
.x
;
11081 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11082 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11084 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11085 wp
.flags
|= SWP_SHOWWINDOW
;
11088 wp
.flags
|= SWP_HIDEWINDOW
;
11092 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11093 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11095 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11097 /* extra padding for grid */
11098 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11099 infoPtr
->rcList
.top
+= 2;
11101 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11106 * Processes WM_STYLECHANGED messages.
11109 * [I] infoPtr : valid pointer to the listview structure
11110 * [I] wStyleType : window style type (normal or extended)
11111 * [I] lpss : window style information
11116 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11117 const STYLESTRUCT
*lpss
)
11119 UINT uNewView
, uOldView
;
11122 TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n",
11123 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11125 if (wStyleType
!= GWL_STYLE
|| lpss
->styleNew
== infoPtr
->dwStyle
) return 0;
11127 infoPtr
->dwStyle
= lpss
->styleNew
;
11129 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11130 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11131 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11133 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11134 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11135 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11137 uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11138 uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11140 if (uNewView
!= uOldView
)
11144 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11145 changing style updates current view only when view bits change. */
11146 map_style_view(infoPtr
);
11147 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11148 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11150 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11151 SetRectEmpty(&infoPtr
->rcFocus
);
11153 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11154 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11156 if (uNewView
== LVS_REPORT
)
11161 LISTVIEW_CreateHeader( infoPtr
);
11163 hl
.prc
= &infoPtr
->rcList
;
11165 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11166 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11167 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11168 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11171 LISTVIEW_UpdateItemSize(infoPtr
);
11174 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11176 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11178 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11180 /* Turn off the header control */
11181 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11182 TRACE("Hide header control, was 0x%08x\n", style
);
11183 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11185 /* Turn on the header control */
11186 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11188 TRACE("Show header control, was 0x%08x\n", style
);
11189 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11195 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11196 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11197 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11199 /* update the size of the client area */
11200 LISTVIEW_UpdateSize(infoPtr
);
11202 /* add scrollbars if needed */
11203 LISTVIEW_UpdateScroll(infoPtr
);
11205 /* invalidate client area + erase background */
11206 LISTVIEW_InvalidateList(infoPtr
);
11213 * Processes WM_STYLECHANGING messages.
11216 * [I] wStyleType : window style type (normal or extended)
11217 * [I0] lpss : window style information
11222 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11225 TRACE("styletype %Ix, styleOld %#lx, styleNew %#lx\n",
11226 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11228 /* don't forward LVS_OWNERDATA only if not already set to */
11229 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11231 if (lpss
->styleOld
& LVS_OWNERDATA
)
11232 lpss
->styleNew
|= LVS_OWNERDATA
;
11234 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11242 * Processes WM_SHOWWINDOW messages.
11245 * [I] infoPtr : valid pointer to the listview structure
11246 * [I] bShown : window is being shown (FALSE when hidden)
11247 * [I] iStatus : window show status
11252 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11254 /* header delayed creation */
11255 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11257 LISTVIEW_CreateHeader(infoPtr
);
11259 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11260 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11263 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11268 * Processes CCM_GETVERSION messages.
11271 * [I] infoPtr : valid pointer to the listview structure
11276 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11278 return infoPtr
->iVersion
;
11283 * Processes CCM_SETVERSION messages.
11286 * [I] infoPtr : valid pointer to the listview structure
11287 * [I] iVersion : version to be set
11290 * -1 when requested version is greater than DLL version;
11291 * previous version otherwise
11293 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11295 INT iOldVersion
= infoPtr
->iVersion
;
11297 if (iVersion
> COMCTL32_VERSION
)
11300 infoPtr
->iVersion
= iVersion
;
11302 TRACE("new version %ld\n", iVersion
);
11304 return iOldVersion
;
11309 * Window procedure of the listview control.
11312 static LRESULT WINAPI
11313 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11315 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11317 TRACE("hwnd %p, uMsg %x, wParam %Ix, lParam %Ix\n", hwnd
, uMsg
, wParam
, lParam
);
11319 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11320 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11324 case LVM_APPROXIMATEVIEWRECT
:
11325 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11326 LOWORD(lParam
), HIWORD(lParam
));
11328 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11330 case LVM_CANCELEDITLABEL
:
11331 return LISTVIEW_CancelEditLabel(infoPtr
);
11333 case LVM_CREATEDRAGIMAGE
:
11334 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11336 case LVM_DELETEALLITEMS
:
11337 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11339 case LVM_DELETECOLUMN
:
11340 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11342 case LVM_DELETEITEM
:
11343 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11345 case LVM_EDITLABELA
:
11346 case LVM_EDITLABELW
:
11347 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11348 uMsg
== LVM_EDITLABELW
);
11349 /* case LVM_ENABLEGROUPVIEW: */
11351 case LVM_ENSUREVISIBLE
:
11352 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11354 case LVM_FINDITEMW
:
11355 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11357 case LVM_FINDITEMA
:
11358 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11360 case LVM_GETBKCOLOR
:
11361 return infoPtr
->clrBk
;
11363 /* case LVM_GETBKIMAGE: */
11365 case LVM_GETCALLBACKMASK
:
11366 return infoPtr
->uCallbackMask
;
11368 case LVM_GETCOLUMNA
:
11369 case LVM_GETCOLUMNW
:
11370 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11371 uMsg
== LVM_GETCOLUMNW
);
11373 case LVM_GETCOLUMNORDERARRAY
:
11374 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11376 case LVM_GETCOLUMNWIDTH
:
11377 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11379 case LVM_GETCOUNTPERPAGE
:
11380 return LISTVIEW_GetCountPerPage(infoPtr
);
11382 case LVM_GETEDITCONTROL
:
11383 return (LRESULT
)infoPtr
->hwndEdit
;
11385 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11386 return infoPtr
->dwLvExStyle
;
11388 /* case LVM_GETGROUPINFO: */
11390 /* case LVM_GETGROUPMETRICS: */
11392 case LVM_GETHEADER
:
11393 return (LRESULT
)infoPtr
->hwndHeader
;
11395 case LVM_GETHOTCURSOR
:
11396 return (LRESULT
)infoPtr
->hHotCursor
;
11398 case LVM_GETHOTITEM
:
11399 return infoPtr
->nHotItem
;
11401 case LVM_GETHOVERTIME
:
11402 return infoPtr
->dwHoverTime
;
11404 case LVM_GETIMAGELIST
:
11405 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11407 /* case LVM_GETINSERTMARK: */
11409 /* case LVM_GETINSERTMARKCOLOR: */
11411 /* case LVM_GETINSERTMARKRECT: */
11413 case LVM_GETISEARCHSTRINGA
:
11414 case LVM_GETISEARCHSTRINGW
:
11415 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11420 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11422 case LVM_GETITEMCOUNT
:
11423 return infoPtr
->nItemCount
;
11425 case LVM_GETITEMPOSITION
:
11426 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11428 case LVM_GETITEMRECT
:
11429 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11431 case LVM_GETITEMSPACING
:
11432 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11434 case LVM_GETITEMSTATE
:
11435 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11437 case LVM_GETITEMTEXTA
:
11438 case LVM_GETITEMTEXTW
:
11439 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11440 uMsg
== LVM_GETITEMTEXTW
);
11442 case LVM_GETNEXTITEM
:
11443 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11445 case LVM_GETNEXTITEMINDEX
:
11446 return LISTVIEW_GetNextItemIndex(infoPtr
, (LVITEMINDEX
*)wParam
, lParam
);
11448 case LVM_GETNUMBEROFWORKAREAS
:
11449 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11452 case LVM_GETORIGIN
:
11453 if (!lParam
) return FALSE
;
11454 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11455 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11456 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11459 /* case LVM_GETOUTLINECOLOR: */
11461 case LVM_GETSELECTEDCOLUMN
:
11462 return infoPtr
->selected_column
;
11464 case LVM_GETSELECTEDCOUNT
:
11465 return LISTVIEW_GetSelectedCount(infoPtr
);
11467 case LVM_GETSELECTIONMARK
:
11468 return infoPtr
->nSelectionMark
;
11470 case LVM_GETSTRINGWIDTHA
:
11471 case LVM_GETSTRINGWIDTHW
:
11472 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11473 uMsg
== LVM_GETSTRINGWIDTHW
);
11475 case LVM_GETSUBITEMRECT
:
11476 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11478 case LVM_GETTEXTBKCOLOR
:
11479 return infoPtr
->clrTextBk
;
11481 case LVM_GETTEXTCOLOR
:
11482 return infoPtr
->clrText
;
11484 /* case LVM_GETTILEINFO: */
11486 /* case LVM_GETTILEVIEWINFO: */
11488 case LVM_GETTOOLTIPS
:
11489 if( !infoPtr
->hwndToolTip
)
11490 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11491 return (LRESULT
)infoPtr
->hwndToolTip
;
11493 case LVM_GETTOPINDEX
:
11494 return LISTVIEW_GetTopIndex(infoPtr
);
11496 case LVM_GETUNICODEFORMAT
:
11497 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11500 return infoPtr
->uView
;
11502 case LVM_GETVIEWRECT
:
11503 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11505 case LVM_GETWORKAREAS
:
11506 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11509 /* case LVM_HASGROUP: */
11512 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11514 case LVM_INSERTCOLUMNA
:
11515 case LVM_INSERTCOLUMNW
:
11516 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11517 uMsg
== LVM_INSERTCOLUMNW
);
11519 /* case LVM_INSERTGROUP: */
11521 /* case LVM_INSERTGROUPSORTED: */
11523 case LVM_INSERTITEMA
:
11524 case LVM_INSERTITEMW
:
11525 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11527 /* case LVM_INSERTMARKHITTEST: */
11529 /* case LVM_ISGROUPVIEWENABLED: */
11531 case LVM_ISITEMVISIBLE
:
11532 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11534 case LVM_MAPIDTOINDEX
:
11535 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11537 case LVM_MAPINDEXTOID
:
11538 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11540 /* case LVM_MOVEGROUP: */
11542 /* case LVM_MOVEITEMTOGROUP: */
11544 case LVM_REDRAWITEMS
:
11545 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11547 /* case LVM_REMOVEALLGROUPS: */
11549 /* case LVM_REMOVEGROUP: */
11552 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11554 case LVM_SETBKCOLOR
:
11555 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11557 /* case LVM_SETBKIMAGE: */
11559 case LVM_SETCALLBACKMASK
:
11560 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11563 case LVM_SETCOLUMNA
:
11564 case LVM_SETCOLUMNW
:
11565 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11566 uMsg
== LVM_SETCOLUMNW
);
11568 case LVM_SETCOLUMNORDERARRAY
:
11569 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11571 case LVM_SETCOLUMNWIDTH
:
11572 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11574 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11575 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11577 /* case LVM_SETGROUPINFO: */
11579 /* case LVM_SETGROUPMETRICS: */
11581 case LVM_SETHOTCURSOR
:
11582 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11584 case LVM_SETHOTITEM
:
11585 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11587 case LVM_SETHOVERTIME
:
11588 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11590 case LVM_SETICONSPACING
:
11592 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11593 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11595 case LVM_SETIMAGELIST
:
11596 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11598 /* case LVM_SETINFOTIP: */
11600 /* case LVM_SETINSERTMARK: */
11602 /* case LVM_SETINSERTMARKCOLOR: */
11607 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11608 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11611 case LVM_SETITEMCOUNT
:
11612 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11614 case LVM_SETITEMPOSITION
:
11617 pt
.x
= (short)LOWORD(lParam
);
11618 pt
.y
= (short)HIWORD(lParam
);
11619 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11622 case LVM_SETITEMPOSITION32
:
11623 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11625 case LVM_SETITEMSTATE
:
11626 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11628 case LVM_SETITEMTEXTA
:
11629 case LVM_SETITEMTEXTW
:
11630 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11631 uMsg
== LVM_SETITEMTEXTW
);
11633 /* case LVM_SETOUTLINECOLOR: */
11635 case LVM_SETSELECTEDCOLUMN
:
11636 infoPtr
->selected_column
= (INT
)wParam
;
11639 case LVM_SETSELECTIONMARK
:
11640 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11642 case LVM_SETTEXTBKCOLOR
:
11643 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11645 case LVM_SETTEXTCOLOR
:
11646 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11648 /* case LVM_SETTILEINFO: */
11650 /* case LVM_SETTILEVIEWINFO: */
11652 /* case LVM_SETTILEWIDTH: */
11654 case LVM_SETTOOLTIPS
:
11655 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11657 case LVM_SETUNICODEFORMAT
:
11658 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11661 return LISTVIEW_SetView(infoPtr
, wParam
);
11663 /* case LVM_SETWORKAREAS: */
11665 /* case LVM_SORTGROUPS: */
11667 case LVM_SORTITEMS
:
11668 case LVM_SORTITEMSEX
:
11669 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11670 uMsg
== LVM_SORTITEMSEX
);
11671 case LVM_SUBITEMHITTEST
:
11672 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11675 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11677 case CCM_GETVERSION
:
11678 return LISTVIEW_GetVersion(infoPtr
);
11680 case CCM_SETVERSION
:
11681 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11684 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11687 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11690 return LISTVIEW_NCCreate(hwnd
, wParam
, (LPCREATESTRUCTW
)lParam
);
11693 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11696 return LISTVIEW_Destroy(infoPtr
);
11699 return LISTVIEW_Enable(infoPtr
);
11701 case WM_ERASEBKGND
:
11702 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11704 case WM_GETDLGCODE
:
11705 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11708 return (LRESULT
)infoPtr
->hFont
;
11711 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11714 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11717 return LISTVIEW_KillFocus(infoPtr
);
11719 case WM_LBUTTONDBLCLK
:
11720 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11722 case WM_LBUTTONDOWN
:
11723 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11726 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11729 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11731 case WM_MOUSEHOVER
:
11732 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11735 return LISTVIEW_NCDestroy(infoPtr
);
11738 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11741 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11743 case WM_NOTIFYFORMAT
:
11744 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11746 case WM_PRINTCLIENT
:
11747 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11750 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11752 case WM_RBUTTONDBLCLK
:
11753 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11755 case WM_RBUTTONDOWN
:
11756 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11759 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11762 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11765 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11768 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11770 case WM_SHOWWINDOW
:
11771 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11773 case WM_STYLECHANGED
:
11774 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11776 case WM_STYLECHANGING
:
11777 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11779 case WM_SYSCOLORCHANGE
:
11780 COMCTL32_RefreshSysColors();
11783 /* case WM_TIMER: */
11784 case WM_THEMECHANGED
:
11785 return LISTVIEW_ThemeChanged(infoPtr
);
11788 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11790 case WM_MOUSEWHEEL
:
11791 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11792 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11793 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11795 case WM_WINDOWPOSCHANGED
:
11796 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11798 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11799 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11801 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11803 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11805 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11807 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11809 /* case WM_WININICHANGE: */
11812 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11813 ERR("unknown msg %04x, wp %Ix, lp %Ix\n", uMsg
, wParam
, lParam
);
11815 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11822 * Registers the window class.
11830 void LISTVIEW_Register(void)
11832 WNDCLASSW wndClass
;
11834 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11835 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11836 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11837 wndClass
.cbClsExtra
= 0;
11838 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11839 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11840 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11841 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11842 RegisterClassW(&wndClass
);
11847 * Unregisters the window class.
11855 void LISTVIEW_Unregister(void)
11857 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11862 * Handle any WM_COMMAND messages
11865 * [I] infoPtr : valid pointer to the listview structure
11866 * [I] wParam : the first message parameter
11867 * [I] lParam : the second message parameter
11872 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11875 TRACE("%p, %x, %x, %Ix\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11877 if (!infoPtr
->hwndEdit
) return 0;
11879 switch (HIWORD(wParam
))
11884 * Adjust the edit window size
11886 WCHAR buffer
[1024];
11887 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11888 HFONT hFont
, hOldFont
= 0;
11892 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11893 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, ARRAY_SIZE(buffer
));
11894 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11896 /* Select font to get the right dimension of the string */
11897 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11900 hOldFont
= SelectObject(hdc
, hFont
);
11903 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11905 TEXTMETRICW textMetric
;
11907 /* Add Extra spacing for the next character */
11908 GetTextMetricsW(hdc
, &textMetric
);
11909 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11911 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11912 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11915 SelectObject(hdc
, hOldFont
);
11917 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11923 if (infoPtr
->notify_mask
& NOTIFY_MASK_END_LABEL_EDIT
)
11924 LISTVIEW_CancelEditLabel(infoPtr
);
11929 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);