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"
144 #include "wine/debug.h"
146 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
148 typedef struct tagCOLUMN_INFO
150 RECT rcHeader
; /* tracks the header's rectangle */
151 INT fmt
; /* same as LVCOLUMN.fmt */
155 typedef struct tagITEMHDR
159 } ITEMHDR
, *LPITEMHDR
;
161 typedef struct tagSUBITEM_INFO
167 typedef struct tagITEM_ID ITEM_ID
;
169 typedef struct tagITEM_INFO
180 UINT id
; /* item id */
181 HDPA item
; /* link to item data */
184 typedef struct tagRANGE
190 typedef struct tagRANGES
195 typedef struct tagITERATOR
204 typedef struct tagDELAYED_ITEM_EDIT
210 enum notification_mask
212 NOTIFY_MASK_ITEM_CHANGE
= 0x1,
213 NOTIFY_MASK_END_LABEL_EDIT
= 0x2,
214 NOTIFY_MASK_UNMASK_ALL
= 0xffffffff
217 typedef struct tagLISTVIEW_INFO
221 RECT rcList
; /* This rectangle is really the window
222 * client rectangle possibly reduced by the
223 * horizontal scroll bar and/or header - see
224 * LISTVIEW_UpdateSize. This rectangle offset
225 * by the LISTVIEW_GetOrigin value is in
226 * client coordinates */
228 /* notification window */
238 INT nItemCount
; /* the number of items in the list */
239 HDPA hdpaItems
; /* array ITEM_INFO pointers */
240 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
241 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
242 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
243 RANGES selectionRanges
;
244 INT nSelectionMark
; /* item to start next multiselection from */
248 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
249 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
250 INT selected_column
; /* index for LVM_SETSELECTEDCOLUMN/LVM_GETSELECTEDCOLUMN */
253 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
258 DWORD dwStyle
; /* the cached window GWL_STYLE */
259 DWORD dwLvExStyle
; /* extended listview style */
260 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
266 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
269 HIMAGELIST himlNormal
;
270 HIMAGELIST himlSmall
;
271 HIMAGELIST himlState
;
276 POINT currIconPos
; /* this is the position next icon will be placed */
280 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
282 /* marquee selection */
283 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
285 RECT marqueeRect
; /* absolute coordinates of marquee selection */
286 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
287 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
290 BOOL bFocus
; /* control has focus */
292 RECT rcFocus
; /* focus bounds */
303 INT ntmHeight
; /* Some cached metrics of the font used */
304 INT ntmMaxCharWidth
; /* by the listview to draw items */
307 /* mouse operation */
310 POINT ptClickPos
; /* point where the user clicked */
311 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
316 /* keyboard operation */
317 DWORD lastKeyPressTimestamp
;
319 INT nSearchParamLength
;
320 WCHAR szSearchParam
[ MAX_PATH
];
323 BOOL bIsDrawing
; /* Drawing in progress */
324 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
325 BOOL redraw
; /* WM_SETREDRAW switch */
328 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
334 /* How many we debug buffer to allocate */
335 #define DEBUG_BUFFERS 20
336 /* The size of a single debug buffer */
337 #define DEBUG_BUFFER_SIZE 256
339 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
340 #define SB_INTERNAL -1
342 /* maximum size of a label */
343 #define DISP_TEXT_SIZE 260
345 /* padding for items in list and small icon display modes */
346 #define WIDTH_PADDING 12
348 /* padding for items in list, report and small icon display modes */
349 #define HEIGHT_PADDING 1
351 /* offset of items in report display mode */
352 #define REPORT_MARGINX 2
354 /* padding for icon in large icon display mode
355 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
356 * that HITTEST will see.
357 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
358 * ICON_TOP_PADDING - sum of the two above.
359 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
360 * LABEL_HOR_PADDING - between text and sides of box
361 * LABEL_VERT_PADDING - between bottom of text and end of box
363 * ICON_LR_PADDING - additional width above icon size.
364 * ICON_LR_HALF - half of the above value
366 #define ICON_TOP_PADDING_NOTHITABLE 2
367 #define ICON_TOP_PADDING_HITABLE 2
368 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
369 #define ICON_BOTTOM_PADDING 4
370 #define LABEL_HOR_PADDING 5
371 #define LABEL_VERT_PADDING 7
372 #define ICON_LR_PADDING 16
373 #define ICON_LR_HALF (ICON_LR_PADDING/2)
375 /* default label width for items in list and small icon display modes */
376 #define DEFAULT_LABEL_WIDTH 40
377 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
378 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
380 /* default column width for items in list display mode */
381 #define DEFAULT_COLUMN_WIDTH 128
383 /* Size of "line" scroll for V & H scrolls */
384 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
386 /* Padding between image and label */
387 #define IMAGE_PADDING 2
389 /* Padding behind the label */
390 #define TRAILING_LABEL_PADDING 12
391 #define TRAILING_HEADER_PADDING 11
393 /* Border for the icon caption */
394 #define CAPTION_BORDER 2
396 /* Standard DrawText flags */
397 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
398 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
399 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
401 /* Image index from state */
402 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
404 /* The time in milliseconds to reset the search in the list */
405 #define KEY_DELAY 450
407 /* Dump the LISTVIEW_INFO structure to the debug channel */
408 #define LISTVIEW_DUMP(iP) do { \
409 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
410 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
411 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
412 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
413 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
414 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
415 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
416 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
417 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
418 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
421 static const WCHAR themeClass
[] = L
"ListView";
424 * forward declarations
426 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
427 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
428 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
429 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
430 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
431 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
432 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
433 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
434 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
435 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
436 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
437 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
438 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
439 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
440 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
441 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
442 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
443 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
444 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
445 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
447 /******** Text handling functions *************************************/
449 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
450 * text string. The string may be ANSI or Unicode, in which case
451 * the boolean isW tells us the type of the string.
453 * The name of the function tell what type of strings it expects:
454 * W: Unicode, T: ANSI/Unicode - function of isW
457 static inline BOOL
is_text(LPCWSTR text
)
459 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
462 static inline int textlenT(LPCWSTR text
, BOOL isW
)
464 return !is_text(text
) ? 0 :
465 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
468 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
471 if (isSrcW
) lstrcpynW(dest
, src
, max
);
472 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
474 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
475 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
478 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
480 LPWSTR wstr
= (LPWSTR
)text
;
482 if (!isW
&& is_text(text
))
484 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
485 wstr
= Alloc(len
* sizeof(WCHAR
));
486 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
488 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
492 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
494 if (!isW
&& is_text(wstr
)) Free (wstr
);
498 * dest is a pointer to a Unicode string
499 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
501 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
505 if (src
== LPSTR_TEXTCALLBACKW
)
507 if (is_text(*dest
)) Free(*dest
);
508 *dest
= LPSTR_TEXTCALLBACKW
;
512 LPWSTR pszText
= textdupTtoW(src
, isW
);
513 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
514 bResult
= Str_SetPtrW(dest
, pszText
);
515 textfreeT(pszText
, isW
);
521 * compares a Unicode to a Unicode/ANSI text string
523 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
525 if (!aw
) return bt
? -1 : 0;
527 if (aw
== LPSTR_TEXTCALLBACKW
)
528 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
529 if (bt
!= LPSTR_TEXTCALLBACKW
)
531 LPWSTR bw
= textdupTtoW(bt
, isW
);
532 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
540 /******** Debugging functions *****************************************/
542 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
544 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
545 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
548 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
550 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
551 n
= min(textlenT(text
, isW
), n
);
552 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
555 static char* debug_getbuf(void)
557 static int index
= 0;
558 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
559 return buffers
[index
++ % DEBUG_BUFFERS
];
562 static inline const char* debugrange(const RANGE
*lprng
)
564 if (!lprng
) return "(null)";
565 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
568 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
570 char* buf
= debug_getbuf(), *text
= buf
;
571 int len
, size
= DEBUG_BUFFER_SIZE
;
573 if (pScrollInfo
== NULL
) return "(null)";
574 len
= snprintf(buf
, size
, "{cbSize=%u, ", pScrollInfo
->cbSize
);
575 if (len
== -1) goto end
;
576 buf
+= len
; size
-= len
;
577 if (pScrollInfo
->fMask
& SIF_RANGE
)
578 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
580 if (len
== -1) goto end
;
581 buf
+= len
; size
-= len
;
582 if (pScrollInfo
->fMask
& SIF_PAGE
)
583 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
585 if (len
== -1) goto end
;
586 buf
+= len
; size
-= len
;
587 if (pScrollInfo
->fMask
& SIF_POS
)
588 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
590 if (len
== -1) goto end
;
591 buf
+= len
; size
-= len
;
592 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
593 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
595 if (len
== -1) goto end
;
599 buf
= text
+ strlen(text
);
601 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
605 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
607 if (!plvnm
) return "(null)";
608 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
609 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
610 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
611 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
614 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
616 char* buf
= debug_getbuf(), *text
= buf
;
617 int len
, size
= DEBUG_BUFFER_SIZE
;
619 if (lpLVItem
== NULL
) return "(null)";
620 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
621 if (len
== -1) goto end
;
622 buf
+= len
; size
-= len
;
623 if (lpLVItem
->mask
& LVIF_STATE
)
624 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
626 if (len
== -1) goto end
;
627 buf
+= len
; size
-= len
;
628 if (lpLVItem
->mask
& LVIF_TEXT
)
629 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
631 if (len
== -1) goto end
;
632 buf
+= len
; size
-= len
;
633 if (lpLVItem
->mask
& LVIF_IMAGE
)
634 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
636 if (len
== -1) goto end
;
637 buf
+= len
; size
-= len
;
638 if (lpLVItem
->mask
& LVIF_PARAM
)
639 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
641 if (len
== -1) goto end
;
642 buf
+= len
; size
-= len
;
643 if (lpLVItem
->mask
& LVIF_INDENT
)
644 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
646 if (len
== -1) goto end
;
650 buf
= text
+ strlen(text
);
652 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
656 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
658 char* buf
= debug_getbuf(), *text
= buf
;
659 int len
, size
= DEBUG_BUFFER_SIZE
;
661 if (lpColumn
== NULL
) return "(null)";
662 len
= snprintf(buf
, size
, "{");
663 if (len
== -1) goto end
;
664 buf
+= len
; size
-= len
;
665 if (lpColumn
->mask
& LVCF_SUBITEM
)
666 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
668 if (len
== -1) goto end
;
669 buf
+= len
; size
-= len
;
670 if (lpColumn
->mask
& LVCF_FMT
)
671 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
673 if (len
== -1) goto end
;
674 buf
+= len
; size
-= len
;
675 if (lpColumn
->mask
& LVCF_WIDTH
)
676 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
678 if (len
== -1) goto end
;
679 buf
+= len
; size
-= len
;
680 if (lpColumn
->mask
& LVCF_TEXT
)
681 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
683 if (len
== -1) goto end
;
684 buf
+= len
; size
-= len
;
685 if (lpColumn
->mask
& LVCF_IMAGE
)
686 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
688 if (len
== -1) goto end
;
689 buf
+= len
; size
-= len
;
690 if (lpColumn
->mask
& LVCF_ORDER
)
691 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
693 if (len
== -1) goto end
;
697 buf
= text
+ strlen(text
);
699 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
703 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
705 if (!lpht
) return "(null)";
707 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
708 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
711 /* Return the corresponding text for a given scroll value */
712 static inline LPCSTR
debugscrollcode(int nScrollCode
)
716 case SB_LINELEFT
: return "SB_LINELEFT";
717 case SB_LINERIGHT
: return "SB_LINERIGHT";
718 case SB_PAGELEFT
: return "SB_PAGELEFT";
719 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
720 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
721 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
722 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
723 case SB_INTERNAL
: return "SB_INTERNAL";
724 default: return "unknown";
729 /******** Notification functions ************************************/
731 static int get_ansi_notification(UINT unicodeNotificationCode
)
733 switch (unicodeNotificationCode
)
735 case LVN_BEGINLABELEDITA
:
736 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
737 case LVN_ENDLABELEDITA
:
738 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
739 case LVN_GETDISPINFOA
:
740 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
741 case LVN_SETDISPINFOA
:
742 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
743 case LVN_ODFINDITEMA
:
744 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
745 case LVN_GETINFOTIPA
:
746 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
747 /* header forwards */
749 case HDN_TRACKW
: return HDN_TRACKA
;
751 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
752 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
753 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
754 case HDN_ITEMCHANGINGA
:
755 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
756 case HDN_ITEMCHANGEDA
:
757 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
759 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
760 case HDN_DIVIDERDBLCLICKA
:
761 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
764 FIXME("unknown notification %x\n", unicodeNotificationCode
);
765 return unicodeNotificationCode
;
768 /* forwards header notifications to listview parent */
769 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
771 LPCWSTR text
= NULL
, filter
= NULL
;
773 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
775 /* on unicode format exit earlier */
776 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
777 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
780 /* header always supplies unicode notifications,
781 all we have to do is to convert strings to ANSI */
784 /* convert item text */
785 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
787 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
788 lpnmh
->pitem
->pszText
= NULL
;
789 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
791 /* convert filter text */
792 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
793 lpnmh
->pitem
->pvFilter
)
795 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
796 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= NULL
;
797 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
800 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
802 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
808 Free(lpnmh
->pitem
->pszText
);
809 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
813 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
814 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
820 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
824 TRACE("(code=%d)\n", code
);
826 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
827 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
829 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
831 TRACE(" <= %ld\n", result
);
836 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
839 HWND hwnd
= infoPtr
->hwndSelf
;
840 notify_hdr(infoPtr
, code
, &nmh
);
841 return IsWindow(hwnd
);
844 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
854 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
855 item
.iItem
= htInfo
->iItem
;
857 item
.stateMask
= (UINT
)-1;
858 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
859 nmia
.lParam
= item
.lParam
;
860 nmia
.uOldState
= item
.state
;
861 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
862 nmia
.uChanged
= LVIF_STATE
;
865 nmia
.iItem
= htInfo
->iItem
;
866 nmia
.iSubItem
= htInfo
->iSubItem
;
867 nmia
.ptAction
= htInfo
->pt
;
869 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
870 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
871 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
873 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
876 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
878 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
879 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
882 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
883 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
887 HWND hwnd
= infoPtr
->hwndSelf
;
890 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
891 ZeroMemory(&nmia
, sizeof(nmia
));
892 nmia
.iItem
= lvht
->iItem
;
893 nmia
.iSubItem
= lvht
->iSubItem
;
894 nmia
.ptAction
= lvht
->pt
;
895 item
.mask
= LVIF_PARAM
;
896 item
.iItem
= lvht
->iItem
;
898 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
899 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
900 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
903 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
907 HWND hwnd
= infoPtr
->hwndSelf
;
909 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
911 item
.mask
= LVIF_PARAM
;
914 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
915 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
916 return IsWindow(hwnd
);
920 Send notification. depends on dispinfoW having same
921 structure as dispinfoA.
922 infoPtr : listview struct
923 code : *Unicode* notification code
924 pdi : dispinfo structure (can be unicode or ansi)
925 isW : TRUE if dispinfo is Unicode
927 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
929 INT length
= 0, ret_length
;
930 LPWSTR buffer
= NULL
, ret_text
;
931 BOOL return_ansi
= FALSE
;
932 BOOL return_unicode
= FALSE
;
935 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
937 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
938 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
941 ret_length
= pdi
->item
.cchTextMax
;
942 ret_text
= pdi
->item
.pszText
;
944 if (return_unicode
|| return_ansi
)
946 if (code
!= LVN_GETDISPINFOW
)
948 length
= return_ansi
?
949 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
950 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
954 length
= pdi
->item
.cchTextMax
;
955 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
958 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
959 if (!buffer
) return FALSE
;
962 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
965 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
968 pdi
->item
.pszText
= buffer
;
969 pdi
->item
.cchTextMax
= length
;
972 if (infoPtr
->notifyFormat
== NFR_ANSI
)
973 code
= get_ansi_notification(code
);
975 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
976 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
977 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
979 if (return_ansi
|| return_unicode
)
981 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
983 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
985 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
987 lstrcpyW(ret_text
, pdi
->item
.pszText
);
989 else if (return_ansi
) /* note : pointer can be changed by app ! */
991 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
992 ret_length
, NULL
, NULL
);
995 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
996 ret_text
, ret_length
);
998 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
999 pdi
->item
.cchTextMax
= ret_length
;
1005 /* if dispinfo holder changed notification code then convert */
1006 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1008 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1010 buffer
= Alloc(length
* sizeof(CHAR
));
1011 if (!buffer
) return FALSE
;
1013 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1014 ret_length
, NULL
, NULL
);
1016 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1023 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1024 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1026 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1027 lpnmlvcd
->nmcd
.hdc
= hdc
;
1028 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1029 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1030 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1031 if (!lplvItem
) return;
1032 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1033 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1034 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1035 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1036 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1037 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1040 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1042 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1045 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1046 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1047 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1048 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1049 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1050 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1054 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const NMLVCUSTOMDRAW
*cd
, BOOL SubItem
)
1056 COLORREF backcolor
, textcolor
;
1058 backcolor
= cd
->clrTextBk
;
1059 textcolor
= cd
->clrText
;
1061 /* apparently, for selected items, we have to override the returned values */
1064 if (cd
->nmcd
.uItemState
& CDIS_SELECTED
)
1066 if (infoPtr
->bFocus
)
1068 backcolor
= comctl32_color
.clrHighlight
;
1069 textcolor
= comctl32_color
.clrHighlightText
;
1071 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1073 backcolor
= comctl32_color
.clr3dFace
;
1074 textcolor
= comctl32_color
.clrBtnText
;
1079 if (backcolor
== CLR_DEFAULT
)
1080 backcolor
= comctl32_color
.clrWindow
;
1081 if (textcolor
== CLR_DEFAULT
)
1082 textcolor
= comctl32_color
.clrWindowText
;
1084 /* Set the text attributes */
1085 if (backcolor
!= CLR_NONE
)
1087 SetBkMode(hdc
, OPAQUE
);
1088 SetBkColor(hdc
, backcolor
);
1091 SetBkMode(hdc
, TRANSPARENT
);
1092 SetTextColor(hdc
, textcolor
);
1095 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1097 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1100 /* returns TRUE when repaint needed, FALSE otherwise */
1101 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1103 MEASUREITEMSTRUCT mis
;
1104 mis
.CtlType
= ODT_LISTVIEW
;
1105 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1109 mis
.itemHeight
= infoPtr
->nItemHeight
;
1110 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1111 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1113 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1119 /******** Item iterator functions **********************************/
1121 static RANGES
ranges_create(int count
);
1122 static void ranges_destroy(RANGES ranges
);
1123 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1124 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1125 static void ranges_dump(RANGES ranges
);
1127 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1129 RANGE range
= { nItem
, nItem
+ 1 };
1131 return ranges_add(ranges
, range
);
1134 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1136 RANGE range
= { nItem
, nItem
+ 1 };
1138 return ranges_del(ranges
, range
);
1142 * ITERATOR DOCUMENTATION
1144 * The iterator functions allow for easy, and convenient iteration
1145 * over items of interest in the list. Typically, you create an
1146 * iterator, use it, and destroy it, as such:
1149 * iterator_xxxitems(&i, ...);
1150 * while (iterator_{prev,next}(&i)
1152 * //code which uses i.nItem
1154 * iterator_destroy(&i);
1156 * where xxx is either: framed, or visible.
1157 * Note that it is important that the code destroys the iterator
1158 * after it's done with it, as the creation of the iterator may
1159 * allocate memory, which thus needs to be freed.
1161 * You can iterate both forwards, and backwards through the list,
1162 * by using iterator_next or iterator_prev respectively.
1164 * Lower numbered items are draw on top of higher number items in
1165 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1166 * items may overlap). So, to test items, you should use
1168 * which lists the items top to bottom (in Z-order).
1169 * For drawing items, you should use
1171 * which lists the items bottom to top (in Z-order).
1172 * If you keep iterating over the items after the end-of-items
1173 * marker (-1) is returned, the iterator will start from the
1174 * beginning. Typically, you don't need to test for -1,
1175 * because iterator_{next,prev} will return TRUE if more items
1176 * are to be iterated over, or FALSE otherwise.
1178 * Note: the iterator is defined to be bidirectional. That is,
1179 * any number of prev followed by any number of next, or
1180 * five versa, should leave the iterator at the same item:
1181 * prev * n, next * n = next * n, prev * n
1183 * The iterator has a notion of an out-of-order, special item,
1184 * which sits at the start of the list. This is used in
1185 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1186 * which needs to be first, as it may overlap other items.
1188 * The code is a bit messy because we have:
1189 * - a special item to deal with
1190 * - simple range, or composite range
1192 * If you find bugs, or want to add features, please make sure you
1193 * always check/modify *both* iterator_prev, and iterator_next.
1197 * This function iterates through the items in increasing order,
1198 * but prefixed by the special item, then -1. That is:
1199 * special, 1, 2, 3, ..., n, -1.
1200 * Each item is listed only once.
1202 static inline BOOL
iterator_next(ITERATOR
* i
)
1206 i
->nItem
= i
->nSpecial
;
1207 if (i
->nItem
!= -1) return TRUE
;
1209 if (i
->nItem
== i
->nSpecial
)
1211 if (i
->ranges
) i
->index
= 0;
1217 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1218 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1223 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1224 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1227 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1229 i
->nItem
= i
->range
.lower
;
1230 if (i
->nItem
>= 0) goto testitem
;
1237 * This function iterates through the items in decreasing order,
1238 * followed by the special item, then -1. That is:
1239 * n, n-1, ..., 3, 2, 1, special, -1.
1240 * Each item is listed only once.
1242 static inline BOOL
iterator_prev(ITERATOR
* i
)
1249 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1252 if (i
->nItem
== i
->nSpecial
)
1260 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1261 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1267 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1270 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1272 i
->nItem
= i
->range
.upper
;
1273 if (i
->nItem
> 0) goto testitem
;
1275 return (i
->nItem
= i
->nSpecial
) != -1;
1278 static RANGE
iterator_range(const ITERATOR
*i
)
1282 if (!i
->ranges
) return i
->range
;
1284 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1286 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1287 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1289 else range
.lower
= range
.upper
= 0;
1295 * Releases resources associated with this iterator.
1297 static inline void iterator_destroy(const ITERATOR
*i
)
1299 ranges_destroy(i
->ranges
);
1303 * Create an empty iterator.
1305 static inline void iterator_empty(ITERATOR
* i
)
1307 ZeroMemory(i
, sizeof(*i
));
1308 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1312 * Create an iterator over a range.
1314 static inline void iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1321 * Create an iterator over a bunch of ranges.
1322 * Please note that the iterator will take ownership of the ranges,
1323 * and will free them upon destruction.
1325 static inline void iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1332 * Creates an iterator over the items which intersect frame.
1333 * Uses absolute coordinates rather than compensating for the current offset.
1335 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1337 RECT rcItem
, rcTemp
;
1340 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1342 /* in case we fail, we want to return an empty iterator */
1345 if (infoPtr
->nItemCount
== 0)
1348 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1352 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1354 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1355 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1356 i
->nSpecial
= infoPtr
->nFocusedItem
;
1358 if (!(ranges
= ranges_create(50))) return FALSE
;
1359 iterator_rangesitems(i
, ranges
);
1360 /* to do better here, we need to have PosX, and PosY sorted */
1361 TRACE("building icon ranges:\n");
1362 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1364 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1365 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1366 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1367 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1368 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1369 ranges_additem(i
->ranges
, nItem
);
1373 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1377 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1378 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1380 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1381 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1382 if (range
.upper
<= range
.lower
) return TRUE
;
1383 iterator_rangeitems(i
, range
);
1384 TRACE(" report=%s\n", debugrange(&i
->range
));
1388 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1389 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1390 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1397 if (infoPtr
->nItemWidth
)
1399 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1400 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1404 nFirstCol
= max(frame
->left
, 0);
1405 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1408 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1410 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1411 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1413 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1415 if (!(ranges
= ranges_create(nLastCol
- nFirstCol
+ 1))) return FALSE
;
1416 iterator_rangesitems(i
, ranges
);
1417 TRACE("building list ranges:\n");
1418 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1420 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1421 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1422 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1423 TRACE(" list=%s\n", debugrange(&item_range
));
1424 ranges_add(i
->ranges
, item_range
);
1432 * Creates an iterator over the items which intersect lprc.
1434 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1439 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1441 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1442 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1444 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1448 * Creates an iterator over the items which intersect the visible region of hdc.
1450 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1452 POINT Origin
, Position
;
1453 RECT rcItem
, rcClip
;
1456 rgntype
= GetClipBox(hdc
, &rcClip
);
1457 if (rgntype
== NULLREGION
)
1462 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1463 if (rgntype
== SIMPLEREGION
) return TRUE
;
1465 /* first deal with the special item */
1466 if (i
->nSpecial
!= -1)
1468 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1469 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1472 /* if we can't deal with the region, we'll just go with the simple range */
1473 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1474 TRACE("building visible range:\n");
1475 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1477 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1478 if (!ranges_add(i
->ranges
, i
->range
))
1480 ranges_destroy(i
->ranges
);
1486 /* now delete the invisible items from the list */
1487 while(iterator_next(i
))
1489 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1490 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1491 rcItem
.top
= Position
.y
+ Origin
.y
;
1492 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1493 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1494 if (!RectVisible(hdc
, &rcItem
))
1495 ranges_delitem(i
->ranges
, i
->nItem
);
1497 /* the iterator should restart on the next iterator_next */
1503 /* Remove common elements from two iterators */
1504 /* Passed iterators have to point on the first elements */
1505 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1507 if(!iter1
->ranges
|| !iter2
->ranges
) {
1510 if(iter1
->ranges
|| iter2
->ranges
||
1511 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1512 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1513 ERR("result is not a one range iterator\n");
1517 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1520 lower
= iter1
->range
.lower
;
1521 upper
= iter1
->range
.upper
;
1523 if(lower
< iter2
->range
.lower
)
1524 iter1
->range
.upper
= iter2
->range
.lower
;
1525 else if(upper
> iter2
->range
.upper
)
1526 iter1
->range
.lower
= iter2
->range
.upper
;
1528 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1530 if(iter2
->range
.lower
< lower
)
1531 iter2
->range
.upper
= lower
;
1532 else if(iter2
->range
.upper
> upper
)
1533 iter2
->range
.lower
= upper
;
1535 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1540 iterator_next(iter1
);
1541 iterator_next(iter2
);
1544 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1547 if(iter1
->nItem
== iter2
->nItem
) {
1548 int delete = iter1
->nItem
;
1550 iterator_prev(iter1
);
1551 iterator_prev(iter2
);
1552 ranges_delitem(iter1
->ranges
, delete);
1553 ranges_delitem(iter2
->ranges
, delete);
1554 iterator_next(iter1
);
1555 iterator_next(iter2
);
1556 } else if(iter1
->nItem
> iter2
->nItem
)
1557 iterator_next(iter2
);
1559 iterator_next(iter1
);
1562 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1563 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1567 /******** Misc helper functions ************************************/
1569 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1570 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1572 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1573 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1576 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1578 return (infoPtr
->dwStyle
& LVS_AUTOARRANGE
) &&
1579 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1582 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1584 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1585 if(state
== 1 || state
== 2)
1589 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1590 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1591 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1595 /* this should be called after window style got updated,
1596 it used to reset view state to match current window style */
1597 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1599 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1602 infoPtr
->uView
= LV_VIEW_ICON
;
1605 infoPtr
->uView
= LV_VIEW_DETAILS
;
1608 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1611 infoPtr
->uView
= LV_VIEW_LIST
;
1615 /* computes next item id value */
1616 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1618 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1622 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1623 return lpID
->id
+ 1;
1628 /******** Internal API functions ************************************/
1630 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1632 static COLUMN_INFO mainItem
;
1634 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1635 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1637 /* update cached column rectangles */
1638 if (infoPtr
->colRectsDirty
)
1641 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1644 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1645 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1646 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1648 Ptr
->colRectsDirty
= FALSE
;
1651 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1654 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1656 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1659 if (infoPtr
->hwndHeader
) return 0;
1661 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1663 /* setup creation flags */
1664 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1665 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1667 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1670 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1671 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1672 if (!infoPtr
->hwndHeader
) return -1;
1674 /* set header unicode format */
1675 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1677 /* set header font */
1678 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1680 /* set header image list */
1681 if (infoPtr
->himlSmall
)
1682 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1684 LISTVIEW_UpdateSize(infoPtr
);
1689 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1691 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1694 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1696 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1697 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1698 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1701 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1703 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1706 /* used to handle collapse main item column case */
1707 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1709 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1710 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1713 /* Listview invalidation functions: use _only_ these functions to invalidate */
1715 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1717 return infoPtr
->redraw
;
1720 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1722 if(!is_redrawing(infoPtr
)) return;
1723 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1724 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1727 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1731 if (!is_redrawing(infoPtr
) || nItem
< 0 || nItem
>= infoPtr
->nItemCount
)
1734 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1735 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1738 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1740 POINT Origin
, Position
;
1743 if(!is_redrawing(infoPtr
)) return;
1744 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1745 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1746 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1747 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1749 rcBox
.bottom
= infoPtr
->nItemHeight
;
1750 OffsetRect(&rcBox
, Origin
.x
, Origin
.y
+ Position
.y
);
1751 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1754 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1756 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1759 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1763 if(!is_redrawing(infoPtr
)) return;
1764 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1765 rcCol
.top
= infoPtr
->rcList
.top
;
1766 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1767 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1772 * Retrieves the number of items that can fit vertically in the client area.
1775 * [I] infoPtr : valid pointer to the listview structure
1778 * Number of items per row.
1780 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1782 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1784 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1789 * Retrieves the number of items that can fit horizontally in the client
1793 * [I] infoPtr : valid pointer to the listview structure
1796 * Number of items per column.
1798 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1800 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1802 return infoPtr
->nItemHeight
? max(nListHeight
/ infoPtr
->nItemHeight
, 1) : 0;
1806 /*************************************************************************
1807 * LISTVIEW_ProcessLetterKeys
1809 * Processes keyboard messages generated by pressing the letter keys
1811 * What this does is perform a case insensitive search from the
1812 * current position with the following quirks:
1813 * - If two chars or more are pressed in quick succession we search
1814 * for the corresponding string (e.g. 'abc').
1815 * - If there is a delay we wipe away the current search string and
1816 * restart with just that char.
1817 * - If the user keeps pressing the same character, whether slowly or
1818 * fast, so that the search string is entirely composed of this
1819 * character ('aaaaa' for instance), then we search for first item
1820 * that starting with that character.
1821 * - If the user types the above character in quick succession, then
1822 * we must also search for the corresponding string ('aaaaa'), and
1823 * go to that string if there is a match.
1826 * [I] hwnd : handle to the window
1827 * [I] charCode : the character code, the actual character
1828 * [I] keyData : key data
1836 * - The current implementation has a list of characters it will
1837 * accept and it ignores everything else. In particular it will
1838 * ignore accentuated characters which seems to match what
1839 * Windows does. But I'm not sure it makes sense to follow
1841 * - We don't sound a beep when the search fails.
1845 * TREEVIEW_ProcessLetterKeys
1847 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1849 WCHAR buffer
[MAX_PATH
];
1856 /* simple parameter checking */
1857 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1859 /* only allow the valid WM_CHARs through */
1860 if (!iswalnum(charCode
) &&
1861 charCode
!= '.' && charCode
!= '`' && 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
!= '~')
1872 /* update the search parameters */
1873 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1874 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1875 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1877 if (diff
>= 0 && diff
< KEY_DELAY
)
1879 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1880 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1882 if (infoPtr
->charCode
!= charCode
)
1883 infoPtr
->charCode
= charCode
= 0;
1887 infoPtr
->charCode
= charCode
;
1888 infoPtr
->szSearchParam
[0] = charCode
;
1889 infoPtr
->nSearchParamLength
= 1;
1892 /* should start from next after focused item, so next item that matches
1893 will be selected, if there isn't any and focused matches it will be selected
1894 on second search stage from beginning of the list */
1895 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1897 /* with some accumulated search data available start with current focus, otherwise
1898 it's excluded from search */
1899 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1900 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1905 /* let application handle this for virtual listview */
1906 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1910 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1911 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1912 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1913 nmlv
.iStart
= startidx
;
1915 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1917 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1921 int i
= startidx
, endidx
;
1923 /* and search from the current position */
1925 endidx
= infoPtr
->nItemCount
;
1927 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1930 /* start from first item if not found with >= startidx */
1931 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1937 for (i
= startidx
; i
< endidx
; i
++)
1940 item
.mask
= LVIF_TEXT
;
1943 item
.pszText
= buffer
;
1944 item
.cchTextMax
= MAX_PATH
;
1945 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1947 if (!wcsnicmp(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1952 /* this is used to find first char match when search string is not available yet,
1953 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1954 already waiting for user to complete a string */
1955 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !wcsnicmp(item
.pszText
, infoPtr
->szSearchParam
, 1))
1957 /* this would work but we must keep looking for a longer match */
1962 if ( nItem
!= -1 || /* found something */
1963 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1964 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1970 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1975 /*************************************************************************
1976 * LISTVIEW_UpdateHeaderSize [Internal]
1978 * Function to resize the header control
1981 * [I] hwnd : handle to a window
1982 * [I] nNewScrollPos : scroll pos to set
1987 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1992 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1994 if (!infoPtr
->hwndHeader
) return;
1996 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1997 point
[0].x
= winRect
.left
;
1998 point
[0].y
= winRect
.top
;
1999 point
[1].x
= winRect
.right
;
2000 point
[1].y
= winRect
.bottom
;
2002 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
2003 point
[0].x
= -nNewScrollPos
;
2004 point
[1].x
+= nNewScrollPos
;
2006 SetWindowPos(infoPtr
->hwndHeader
,0,
2007 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
2008 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
2009 SWP_NOZORDER
| SWP_NOACTIVATE
);
2012 static INT
LISTVIEW_UpdateHScroll(LISTVIEW_INFO
*infoPtr
)
2014 SCROLLINFO horzInfo
;
2017 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2018 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2019 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2021 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2022 if (infoPtr
->uView
== LV_VIEW_LIST
)
2024 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2025 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2027 /* scroll by at least one column per page */
2028 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2029 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2031 if (infoPtr
->nItemWidth
)
2032 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2034 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2036 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2038 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2042 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2045 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2047 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2052 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2053 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2055 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2056 horzInfo
.nMax
= rcHeader
.right
;
2057 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2061 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2062 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2063 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2064 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2065 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2067 /* Update the Header Control */
2068 if (infoPtr
->hwndHeader
)
2070 horzInfo
.fMask
= SIF_POS
;
2071 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2072 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2075 LISTVIEW_UpdateSize(infoPtr
);
2079 static INT
LISTVIEW_UpdateVScroll(LISTVIEW_INFO
*infoPtr
)
2081 SCROLLINFO vertInfo
;
2084 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2085 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2086 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2088 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2090 vertInfo
.nMax
= infoPtr
->nItemCount
;
2092 /* scroll by at least one page */
2093 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2094 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2096 if (infoPtr
->nItemHeight
> 0)
2097 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2099 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2103 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2106 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2107 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2108 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2109 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2110 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2112 LISTVIEW_UpdateSize(infoPtr
);
2118 * Update the scrollbars. This function should be called whenever
2119 * the content, size or view changes.
2122 * [I] infoPtr : valid pointer to the listview structure
2127 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*infoPtr
)
2131 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2133 /* Setting the horizontal scroll can change the listview size
2134 * (and potentially everything else) so we need to recompute
2135 * everything again for the vertical scroll and vice-versa
2137 for (dx
= 0, dy
= 0, pass
= 0; pass
<= 1; pass
++)
2139 dx
+= LISTVIEW_UpdateHScroll(infoPtr
);
2140 dy
+= LISTVIEW_UpdateVScroll(infoPtr
);
2143 /* Change of the range may have changed the scroll pos. If so move the content */
2144 if (dx
!= 0 || dy
!= 0)
2147 listRect
= infoPtr
->rcList
;
2148 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2149 SW_ERASE
| SW_INVALIDATE
);
2156 * Shows/hides the focus rectangle.
2159 * [I] infoPtr : valid pointer to the listview structure
2160 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2165 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2169 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2171 if (infoPtr
->nFocusedItem
< 0) return;
2173 /* we need some gymnastics in ICON mode to handle large items */
2174 if (infoPtr
->uView
== LV_VIEW_ICON
)
2178 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2179 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2181 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2186 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2188 /* for some reason, owner draw should work only in report mode */
2189 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2194 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2195 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2197 item
.iItem
= infoPtr
->nFocusedItem
;
2199 item
.mask
= LVIF_PARAM
;
2200 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2202 ZeroMemory(&dis
, sizeof(dis
));
2203 dis
.CtlType
= ODT_LISTVIEW
;
2204 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2205 dis
.itemID
= item
.iItem
;
2206 dis
.itemAction
= ODA_FOCUS
;
2207 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2208 dis
.hwndItem
= infoPtr
->hwndSelf
;
2210 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2211 dis
.itemData
= item
.lParam
;
2213 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2215 SelectObject(hdc
, hOldFont
);
2218 LISTVIEW_InvalidateItem(infoPtr
, infoPtr
->nFocusedItem
);
2221 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2225 * Invalidates all visible selected items.
2227 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2231 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2232 while(iterator_next(&i
))
2234 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2235 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2237 iterator_destroy(&i
);
2242 * DESCRIPTION: [INTERNAL]
2243 * Computes an item's (left,top) corner, relative to rcView.
2244 * That is, the position has NOT been made relative to the Origin.
2245 * This is deliberate, to avoid computing the Origin over, and
2246 * over again, when this function is called in a loop. Instead,
2247 * one can factor the computation of the Origin before the loop,
2248 * and offset the value returned by this function, on every iteration.
2251 * [I] infoPtr : valid pointer to the listview structure
2252 * [I] nItem : item number
2253 * [O] lpptOrig : item top, left corner
2258 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2260 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2262 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2264 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2265 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2267 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2269 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2270 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2271 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2273 else /* LV_VIEW_DETAILS */
2275 lpptPosition
->x
= REPORT_MARGINX
;
2276 /* item is always at zero indexed column */
2277 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2278 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2279 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2284 * DESCRIPTION: [INTERNAL]
2285 * Compute the rectangles of an item. This is to localize all
2286 * the computations in one place. If you are not interested in some
2287 * of these values, simply pass in a NULL -- the function is smart
2288 * enough to compute only what's necessary. The function computes
2289 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2290 * one, the BOX rectangle. This rectangle is very cheap to compute,
2291 * and is guaranteed to contain all the other rectangles. Computing
2292 * the ICON rect is also cheap, but all the others are potentially
2293 * expensive. This gives an easy and effective optimization when
2294 * searching (like point inclusion, or rectangle intersection):
2295 * first test against the BOX, and if TRUE, test against the desired
2297 * If the function does not have all the necessary information
2298 * to computed the requested rectangles, will crash with a
2299 * failed assertion. This is done so we catch all programming
2300 * errors, given that the function is called only from our code.
2302 * We have the following 'special' meanings for a few fields:
2303 * * If LVIS_FOCUSED is set, we assume the item has the focus
2304 * This is important in ICON mode, where it might get a larger
2305 * then usual rectangle
2307 * Please note that subitem support works only in REPORT mode.
2310 * [I] infoPtr : valid pointer to the listview structure
2311 * [I] lpLVItem : item to compute the measures for
2312 * [O] lprcBox : ptr to Box rectangle
2313 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2314 * [0] lprcSelectBox : ptr to select box rectangle
2315 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2316 * [O] lprcIcon : ptr to Icon rectangle
2317 * Same as LVM_GETITEMRECT with LVIR_ICON
2318 * [O] lprcStateIcon: ptr to State Icon rectangle
2319 * [O] lprcLabel : ptr to Label rectangle
2320 * Same as LVM_GETITEMRECT with LVIR_LABEL
2325 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2326 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2327 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2329 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2330 RECT Box
, SelectBox
, Icon
, Label
;
2331 COLUMN_INFO
*lpColumnInfo
= NULL
;
2332 SIZE labelSize
= { 0, 0 };
2334 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2336 /* Be smart and try to figure out the minimum we have to do */
2337 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2338 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2340 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2341 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2343 if (lprcSelectBox
) doSelectBox
= TRUE
;
2344 if (lprcLabel
) doLabel
= TRUE
;
2345 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2352 /************************************************************/
2353 /* compute the box rectangle (it should be cheap to do) */
2354 /************************************************************/
2355 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2356 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2358 if (lpLVItem
->iSubItem
)
2360 Box
= lpColumnInfo
->rcHeader
;
2365 Box
.right
= infoPtr
->nItemWidth
;
2368 Box
.bottom
= infoPtr
->nItemHeight
;
2370 /******************************************************************/
2371 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2372 /******************************************************************/
2375 LONG state_width
= 0;
2377 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2378 state_width
= infoPtr
->iconStateSize
.cx
;
2380 if (infoPtr
->uView
== LV_VIEW_ICON
)
2382 Icon
.left
= Box
.left
+ state_width
;
2383 if (infoPtr
->himlNormal
)
2384 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2385 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2386 Icon
.right
= Icon
.left
;
2387 Icon
.bottom
= Icon
.top
;
2388 if (infoPtr
->himlNormal
)
2390 Icon
.right
+= infoPtr
->iconSize
.cx
;
2391 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2394 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2396 Icon
.left
= Box
.left
+ state_width
;
2398 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2400 /* we need the indent in report mode */
2401 assert(lpLVItem
->mask
& LVIF_INDENT
);
2402 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2406 Icon
.right
= Icon
.left
;
2407 if (infoPtr
->himlSmall
&&
2408 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2409 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2410 Icon
.right
+= infoPtr
->iconSize
.cx
;
2411 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2413 if(lprcIcon
) *lprcIcon
= Icon
;
2414 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2416 /* TODO: is this correct? */
2419 lprcStateIcon
->left
= Icon
.left
- state_width
;
2420 lprcStateIcon
->right
= Icon
.left
;
2421 lprcStateIcon
->top
= Icon
.top
;
2422 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2423 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2426 else Icon
.right
= 0;
2428 /************************************************************/
2429 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2430 /************************************************************/
2433 /* calculate how far to the right can the label stretch */
2434 Label
.right
= Box
.right
;
2435 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2437 if (lpLVItem
->iSubItem
== 0)
2439 /* we need a zero based rect here */
2440 Label
= lpColumnInfo
->rcHeader
;
2441 OffsetRect(&Label
, -Label
.left
, 0);
2445 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2447 labelSize
.cx
= infoPtr
->nItemWidth
;
2448 labelSize
.cy
= infoPtr
->nItemHeight
;
2452 /* we need the text in non owner draw mode */
2453 assert(lpLVItem
->mask
& LVIF_TEXT
);
2454 if (is_text(lpLVItem
->pszText
))
2456 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2457 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2458 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2462 /* compute rough rectangle where the label will go */
2463 SetRectEmpty(&rcText
);
2464 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2465 rcText
.bottom
= infoPtr
->nItemHeight
;
2466 if (infoPtr
->uView
== LV_VIEW_ICON
)
2467 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2469 /* now figure out the flags */
2470 if (infoPtr
->uView
== LV_VIEW_ICON
)
2471 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2473 uFormat
= LV_SL_DT_FLAGS
;
2475 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2477 if (rcText
.right
!= rcText
.left
)
2478 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2480 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2482 SelectObject(hdc
, hOldFont
);
2483 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2487 if (infoPtr
->uView
== LV_VIEW_ICON
)
2489 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2490 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2491 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2492 Label
.right
= Label
.left
+ labelSize
.cx
;
2493 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2494 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2496 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2497 labelSize
.cy
/= infoPtr
->ntmHeight
;
2498 labelSize
.cy
= max(labelSize
.cy
, 1);
2499 labelSize
.cy
*= infoPtr
->ntmHeight
;
2501 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2503 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2505 Label
.left
= Icon
.right
;
2506 Label
.top
= Box
.top
;
2507 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2508 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2509 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2511 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2513 Label
.left
= Icon
.right
;
2514 Label
.top
= Box
.top
;
2515 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2516 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2519 if (lprcLabel
) *lprcLabel
= Label
;
2520 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2523 /************************************************************/
2524 /* compute SELECT bounding box */
2525 /************************************************************/
2528 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2530 SelectBox
.left
= Icon
.left
;
2531 SelectBox
.top
= Box
.top
;
2532 SelectBox
.bottom
= Box
.bottom
;
2535 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2537 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2541 UnionRect(&SelectBox
, &Icon
, &Label
);
2543 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2544 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2547 /* Fix the Box if necessary */
2550 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2551 else *lprcBox
= Box
;
2553 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2557 * DESCRIPTION: [INTERNAL]
2560 * [I] infoPtr : valid pointer to the listview structure
2561 * [I] nItem : item number
2562 * [O] lprcBox : ptr to Box rectangle
2567 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2569 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2570 POINT Position
, Origin
;
2573 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2574 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2576 /* Be smart and try to figure out the minimum we have to do */
2578 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2579 lvItem
.mask
|= LVIF_TEXT
;
2580 lvItem
.iItem
= nItem
;
2581 lvItem
.iSubItem
= 0;
2582 lvItem
.pszText
= szDispText
;
2583 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2584 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2585 if (infoPtr
->uView
== LV_VIEW_ICON
)
2587 lvItem
.mask
|= LVIF_STATE
;
2588 lvItem
.stateMask
= LVIS_FOCUSED
;
2589 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2591 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2593 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2594 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2596 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2599 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2602 /* LISTVIEW_MapIdToIndex helper */
2603 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2605 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2606 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2608 if (id1
->id
== id2
->id
) return 0;
2610 return (id1
->id
< id2
->id
) ? -1 : 1;
2615 * Returns the item index for id specified.
2618 * [I] infoPtr : valid pointer to the listview structure
2619 * [I] iID : item id to get index for
2622 * Item index, or -1 on failure.
2624 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2629 TRACE("iID=%d\n", iID
);
2631 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2632 if (infoPtr
->nItemCount
== 0) return -1;
2635 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2639 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2640 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2648 * Returns the item id for index given.
2651 * [I] infoPtr : valid pointer to the listview structure
2652 * [I] iItem : item index to get id for
2657 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2662 TRACE("iItem=%d\n", iItem
);
2664 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2665 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2667 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2668 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2670 return lpItem
->id
->id
;
2675 * Returns the current icon position, and advances it along the top.
2676 * The returned position is not offset by Origin.
2679 * [I] infoPtr : valid pointer to the listview structure
2680 * [O] lpPos : will get the current icon position
2685 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2687 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2689 *lpPos
= infoPtr
->currIconPos
;
2691 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2692 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2694 infoPtr
->currIconPos
.x
= 0;
2695 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2701 * Returns the current icon position, and advances it down the left edge.
2702 * The returned position is not offset by Origin.
2705 * [I] infoPtr : valid pointer to the listview structure
2706 * [O] lpPos : will get the current icon position
2711 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2713 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2715 *lpPos
= infoPtr
->currIconPos
;
2717 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2718 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2720 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2721 infoPtr
->currIconPos
.y
= 0;
2727 * Moves an icon to the specified position.
2728 * It takes care of invalidating the item, etc.
2731 * [I] infoPtr : valid pointer to the listview structure
2732 * [I] nItem : the item to move
2733 * [I] lpPos : the new icon position
2734 * [I] isNew : flags the item as being new
2740 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2746 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2747 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2749 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2750 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2753 /* Allocating a POINTER for every item is too resource intensive,
2754 * so we'll keep the (x,y) in different arrays */
2755 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2756 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2758 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2765 * Arranges listview items in icon display mode.
2768 * [I] infoPtr : valid pointer to the listview structure
2769 * [I] nAlignCode : alignment code
2775 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2777 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2781 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2783 TRACE("nAlignCode=%d\n", nAlignCode
);
2785 if (nAlignCode
== LVA_DEFAULT
)
2787 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2788 else nAlignCode
= LVA_ALIGNTOP
;
2793 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2794 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2795 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2796 default: return FALSE
;
2799 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2800 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2802 next_pos(infoPtr
, &pos
);
2803 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2811 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2812 * For LVS_REPORT always returns empty rectangle.
2815 * [I] infoPtr : valid pointer to the listview structure
2816 * [O] lprcView : bounding rectangle
2822 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2826 SetRectEmpty(lprcView
);
2828 switch (infoPtr
->uView
)
2831 case LV_VIEW_SMALLICON
:
2832 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2834 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2835 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2836 lprcView
->right
= max(lprcView
->right
, x
);
2837 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2839 if (infoPtr
->nItemCount
> 0)
2841 lprcView
->right
+= infoPtr
->nItemWidth
;
2842 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2847 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2848 x
= infoPtr
->nItemCount
/ y
;
2849 if (infoPtr
->nItemCount
% y
) x
++;
2850 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2851 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2858 * Retrieves the bounding rectangle of all the items.
2861 * [I] infoPtr : valid pointer to the listview structure
2862 * [O] lprcView : bounding rectangle
2868 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2872 TRACE("(lprcView=%p)\n", lprcView
);
2874 if (!lprcView
) return FALSE
;
2876 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2878 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2880 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2881 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2884 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2891 * Retrieves the subitem pointer associated with the subitem index.
2894 * [I] hdpaSubItems : DPA handle for a specific item
2895 * [I] nSubItem : index of subitem
2898 * SUCCESS : subitem pointer
2901 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2903 SUBITEM_INFO
*lpSubItem
;
2906 /* we should binary search here if need be */
2907 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2909 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2910 if (lpSubItem
->iSubItem
== nSubItem
)
2920 * Calculates the desired item width.
2923 * [I] infoPtr : valid pointer to the listview structure
2926 * The desired item width.
2928 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2932 TRACE("uView=%d\n", infoPtr
->uView
);
2934 if (infoPtr
->uView
== LV_VIEW_ICON
)
2935 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2936 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2938 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2943 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2944 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2946 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2947 nItemWidth
= rcHeader
.right
;
2950 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2952 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2956 lvItem
.mask
= LVIF_TEXT
;
2957 lvItem
.iSubItem
= 0;
2959 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2962 lvItem
.pszText
= szDispText
;
2963 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2964 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2965 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2969 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2970 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2972 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2980 * Calculates the desired item height.
2983 * [I] infoPtr : valid pointer to the listview structure
2986 * The desired item height.
2988 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2992 TRACE("uView=%d\n", infoPtr
->uView
);
2994 if (infoPtr
->uView
== LV_VIEW_ICON
)
2995 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2998 nItemHeight
= infoPtr
->ntmHeight
;
2999 if (infoPtr
->himlState
)
3000 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
3001 if (infoPtr
->himlSmall
)
3002 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
3003 nItemHeight
+= HEIGHT_PADDING
;
3004 if (infoPtr
->nMeasureItemHeight
> 0)
3005 nItemHeight
= infoPtr
->nMeasureItemHeight
;
3008 return max(nItemHeight
, 1);
3013 * Updates the width, and height of an item.
3016 * [I] infoPtr : valid pointer to the listview structure
3021 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
3023 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
3024 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3030 * Retrieves and saves important text metrics info for the current
3034 * [I] infoPtr : valid pointer to the listview structure
3037 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3039 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3040 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3041 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3045 if (GetTextMetricsW(hdc
, &tm
))
3047 infoPtr
->ntmHeight
= tm
.tmHeight
;
3048 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3051 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3052 infoPtr
->nEllipsisWidth
= sz
.cx
;
3054 SelectObject(hdc
, hOldFont
);
3055 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3057 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3062 * A compare function for ranges
3065 * [I] range1 : pointer to range 1;
3066 * [I] range2 : pointer to range 2;
3070 * > 0 : if range 1 > range 2
3071 * < 0 : if range 2 > range 1
3072 * = 0 : if range intersects range 2
3074 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3078 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3080 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3085 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3090 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3092 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3097 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3099 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3100 ranges_dump(ranges
);
3101 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3103 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3104 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3105 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3107 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3108 assert (prev
->upper
<= curr
->lower
);
3109 assert (curr
->lower
< curr
->upper
);
3113 TRACE("--- Done checking---\n");
3116 static RANGES
ranges_create(int count
)
3118 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3119 if (!ranges
) return NULL
;
3120 ranges
->hdpa
= DPA_Create(count
);
3121 if (ranges
->hdpa
) return ranges
;
3126 static void ranges_clear(RANGES ranges
)
3130 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3131 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3132 DPA_DeleteAllPtrs(ranges
->hdpa
);
3136 static void ranges_destroy(RANGES ranges
)
3138 if (!ranges
) return;
3139 ranges_clear(ranges
);
3140 DPA_Destroy(ranges
->hdpa
);
3144 static RANGES
ranges_clone(RANGES ranges
)
3149 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3151 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3153 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3154 if (!newrng
) goto fail
;
3155 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3156 if (!DPA_SetPtr(clone
->hdpa
, i
, newrng
))
3165 TRACE ("clone failed\n");
3166 ranges_destroy(clone
);
3170 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3174 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3175 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3180 static void ranges_dump(RANGES ranges
)
3184 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3185 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3188 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3190 RANGE srchrng
= { nItem
, nItem
+ 1 };
3192 TRACE("(nItem=%d)\n", nItem
);
3193 ranges_check(ranges
, "before contain");
3194 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3197 static INT
ranges_itemcount(RANGES ranges
)
3201 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3203 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3204 count
+= sel
->upper
- sel
->lower
;
3210 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3212 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3215 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3216 if (index
== -1) return TRUE
;
3218 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3220 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3221 if (chkrng
->lower
>= nItem
)
3222 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3223 if (chkrng
->upper
> nItem
)
3224 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3229 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3234 TRACE("(%s)\n", debugrange(&range
));
3235 ranges_check(ranges
, "before add");
3237 /* try find overlapping regions first */
3238 srchrgn
.lower
= range
.lower
- 1;
3239 srchrgn
.upper
= range
.upper
+ 1;
3240 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3246 TRACE("Adding new range\n");
3248 /* create the brand new range to insert */
3249 newrgn
= Alloc(sizeof(RANGE
));
3250 if(!newrgn
) goto fail
;
3253 /* figure out where to insert it */
3254 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3255 TRACE("index=%d\n", index
);
3256 if (index
== -1) index
= 0;
3258 /* and get it over with */
3259 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3267 RANGE
*chkrgn
, *mrgrgn
;
3268 INT fromindex
, mergeindex
;
3270 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3271 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3273 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3274 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3276 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3278 /* merge now common ranges */
3280 srchrgn
.lower
= chkrgn
->lower
- 1;
3281 srchrgn
.upper
= chkrgn
->upper
+ 1;
3285 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3286 if (mergeindex
== -1) break;
3287 if (mergeindex
== index
)
3289 fromindex
= index
+ 1;
3293 TRACE("Merge with index %i\n", mergeindex
);
3295 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3296 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3297 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3299 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3300 if (mergeindex
< index
) index
--;
3304 ranges_check(ranges
, "after add");
3308 ranges_check(ranges
, "failed add");
3312 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3317 TRACE("(%s)\n", debugrange(&range
));
3318 ranges_check(ranges
, "before del");
3320 /* we don't use DPAS_SORTED here, since we need *
3321 * to find the first overlapping range */
3322 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3325 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3327 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3329 /* case 1: Same range */
3330 if ( (chkrgn
->upper
== range
.upper
) &&
3331 (chkrgn
->lower
== range
.lower
) )
3333 DPA_DeletePtr(ranges
->hdpa
, index
);
3337 /* case 2: engulf */
3338 else if ( (chkrgn
->upper
<= range
.upper
) &&
3339 (chkrgn
->lower
>= range
.lower
) )
3341 DPA_DeletePtr(ranges
->hdpa
, index
);
3344 /* case 3: overlap upper */
3345 else if ( (chkrgn
->upper
<= range
.upper
) &&
3346 (chkrgn
->lower
< range
.lower
) )
3348 chkrgn
->upper
= range
.lower
;
3350 /* case 4: overlap lower */
3351 else if ( (chkrgn
->upper
> range
.upper
) &&
3352 (chkrgn
->lower
>= range
.lower
) )
3354 chkrgn
->lower
= range
.upper
;
3357 /* case 5: fully internal */
3362 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3363 newrgn
->lower
= chkrgn
->lower
;
3364 newrgn
->upper
= range
.lower
;
3365 chkrgn
->lower
= range
.upper
;
3366 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3374 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3377 ranges_check(ranges
, "after del");
3381 ranges_check(ranges
, "failed del");
3387 * Removes all selection ranges
3390 * [I] infoPtr : valid pointer to the listview structure
3391 * [I] toSkip : item range to skip removing the selection
3397 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3406 lvItem
.stateMask
= LVIS_SELECTED
;
3408 /* need to clone the DPA because callbacks can change it */
3409 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3410 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3411 while(iterator_next(&i
))
3412 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3413 /* note that the iterator destructor will free the cloned range */
3414 iterator_destroy(&i
);
3419 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3423 if (!(toSkip
= ranges_create(1))) return FALSE
;
3424 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3425 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3426 ranges_destroy(toSkip
);
3430 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3432 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3437 * Retrieves the number of items that are marked as selected.
3440 * [I] infoPtr : valid pointer to the listview structure
3443 * Number of items selected.
3445 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3447 INT nSelectedCount
= 0;
3449 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3452 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3454 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3459 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3461 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3462 return nSelectedCount
;
3467 * Manages the item focus.
3470 * [I] infoPtr : valid pointer to the listview structure
3471 * [I] nItem : item index
3474 * TRUE : focused item changed
3475 * FALSE : focused item has NOT changed
3477 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3479 INT oldFocus
= infoPtr
->nFocusedItem
;
3482 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3484 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3485 lvItem
.stateMask
= LVIS_FOCUSED
;
3486 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3488 return oldFocus
!= infoPtr
->nFocusedItem
;
3491 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3493 if (nShiftItem
< nItem
) return nShiftItem
;
3495 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3497 if (direction
> 0) return nShiftItem
+ direction
;
3499 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3502 /* This function updates focus index.
3505 focus : current focus index
3506 item : index of item to be added/removed
3507 direction : add/remove flag
3509 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3511 DWORD old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3513 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3514 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3515 if (focus
!= infoPtr
->nFocusedItem
)
3516 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3517 infoPtr
->notify_mask
|= old_mask
;
3522 * Updates the various indices after an item has been inserted or deleted.
3525 * [I] infoPtr : valid pointer to the listview structure
3526 * [I] nItem : item index
3527 * [I] direction : Direction of shift, +1 or -1.
3532 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3534 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3536 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3537 assert(abs(direction
) == 1);
3538 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3540 /* But we are not supposed to modify nHotItem! */
3545 * Adds a block of selections.
3548 * [I] infoPtr : valid pointer to the listview structure
3549 * [I] nItem : item index
3552 * Whether the window is still valid.
3554 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3556 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3557 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3558 HWND hwndSelf
= infoPtr
->hwndSelf
;
3559 NMLVODSTATECHANGE nmlv
;
3564 /* Temporarily disable change notification
3565 * If the control is LVS_OWNERDATA, we need to send
3566 * only one LVN_ODSTATECHANGED notification.
3567 * See MSDN documentation for LVN_ITEMCHANGED.
3569 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3570 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3571 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3573 if (nFirst
== -1) nFirst
= nItem
;
3575 item
.state
= LVIS_SELECTED
;
3576 item
.stateMask
= LVIS_SELECTED
;
3578 for (i
= nFirst
; i
<= nLast
; i
++)
3579 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3581 ZeroMemory(&nmlv
, sizeof(nmlv
));
3582 nmlv
.iFrom
= nFirst
;
3585 nmlv
.uNewState
= item
.state
;
3587 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3588 if (!IsWindow(hwndSelf
))
3590 infoPtr
->notify_mask
|= old_mask
;
3597 * Sets a single group selection.
3600 * [I] infoPtr : valid pointer to the listview structure
3601 * [I] nItem : item index
3606 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3613 if (!(selection
= ranges_create(100))) return;
3615 item
.state
= LVIS_SELECTED
;
3616 item
.stateMask
= LVIS_SELECTED
;
3618 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3620 if (infoPtr
->nSelectionMark
== -1)
3622 infoPtr
->nSelectionMark
= nItem
;
3623 ranges_additem(selection
, nItem
);
3629 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3630 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3631 ranges_add(selection
, sel
);
3636 RECT rcItem
, rcSel
, rcSelMark
;
3639 rcItem
.left
= LVIR_BOUNDS
;
3640 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3641 ranges_destroy (selection
);
3644 rcSelMark
.left
= LVIR_BOUNDS
;
3645 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3646 ranges_destroy (selection
);
3649 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3650 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3651 while(iterator_next(&i
))
3653 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3654 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3656 iterator_destroy(&i
);
3659 /* disable per item notifications on LVS_OWNERDATA style
3660 FIXME: single LVN_ODSTATECHANGED should be used */
3661 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3662 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3663 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3665 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3668 iterator_rangesitems(&i
, selection
);
3669 while(iterator_next(&i
))
3670 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3671 /* this will also destroy the selection */
3672 iterator_destroy(&i
);
3674 infoPtr
->notify_mask
|= old_mask
;
3675 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3680 * Sets a single selection.
3683 * [I] infoPtr : valid pointer to the listview structure
3684 * [I] nItem : item index
3689 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3693 TRACE("nItem=%d\n", nItem
);
3695 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3697 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3698 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3699 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3701 infoPtr
->nSelectionMark
= nItem
;
3706 * Set selection(s) with keyboard.
3709 * [I] infoPtr : valid pointer to the listview structure
3710 * [I] nItem : item index
3711 * [I] space : VK_SPACE code sent
3714 * SUCCESS : TRUE (needs to be repainted)
3715 * FAILURE : FALSE (nothing has changed)
3717 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3719 /* FIXME: pass in the state */
3720 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3721 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3722 BOOL bResult
= FALSE
;
3724 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3725 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3729 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3730 LISTVIEW_SetSelection(infoPtr
, nItem
);
3734 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3738 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3739 lvItem
.stateMask
= LVIS_SELECTED
;
3742 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3743 if (lvItem
.state
& LVIS_SELECTED
)
3744 infoPtr
->nSelectionMark
= nItem
;
3746 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3749 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3752 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3756 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3758 LVHITTESTINFO lvHitTestInfo
;
3760 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3761 lvHitTestInfo
.pt
.x
= pt
.x
;
3762 lvHitTestInfo
.pt
.y
= pt
.y
;
3764 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3766 lpLVItem
->mask
= LVIF_PARAM
;
3767 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3768 lpLVItem
->iSubItem
= 0;
3770 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3773 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3775 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3776 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3777 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3782 * Called when the mouse is being actively tracked and has hovered for a specified
3786 * [I] infoPtr : valid pointer to the listview structure
3787 * [I] fwKeys : key indicator
3788 * [I] x,y : mouse position
3791 * 0 if the message was processed, non-zero if there was an error
3794 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3795 * over the item for a certain period of time.
3798 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3802 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3804 if (LISTVIEW_IsHotTracking(infoPtr
))
3812 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3813 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3815 SetFocus(infoPtr
->hwndSelf
);
3821 #define SCROLL_LEFT 0x1
3822 #define SCROLL_RIGHT 0x2
3823 #define SCROLL_UP 0x4
3824 #define SCROLL_DOWN 0x8
3828 * Utility routine to draw and highlight items within a marquee selection rectangle.
3831 * [I] infoPtr : valid pointer to the listview structure
3832 * [I] coords_orig : original co-ordinates of the cursor
3833 * [I] coords_offs : offsetted coordinates of the cursor
3834 * [I] offset : offset amount
3835 * [I] scroll : Bitmask of which directions we should scroll, if at all
3840 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3843 BOOL controlDown
= FALSE
;
3845 ITERATOR old_elems
, new_elems
;
3847 POINT coords_offs
, offset
;
3849 /* Ensure coordinates are within client bounds */
3850 coords_offs
.x
= max(min(coords_orig
->x
, infoPtr
->rcList
.right
), 0);
3851 coords_offs
.y
= max(min(coords_orig
->y
, infoPtr
->rcList
.bottom
), 0);
3854 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3856 /* Offset coordinates by the appropriate amount */
3857 coords_offs
.x
-= offset
.x
;
3858 coords_offs
.y
-= offset
.y
;
3860 if (coords_offs
.x
> infoPtr
->marqueeOrigin
.x
)
3862 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3863 rect
.right
= coords_offs
.x
;
3867 rect
.left
= coords_offs
.x
;
3868 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3871 if (coords_offs
.y
> infoPtr
->marqueeOrigin
.y
)
3873 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3874 rect
.bottom
= coords_offs
.y
;
3878 rect
.top
= coords_offs
.y
;
3879 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3882 /* Cancel out the old marquee rectangle and draw the new one */
3883 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3885 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3886 the cursor is further away */
3888 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3889 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3891 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3892 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3894 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3895 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3897 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3898 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3900 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3902 infoPtr
->marqueeRect
= rect
;
3903 infoPtr
->marqueeDrawRect
= rect
;
3904 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
.x
, offset
.y
);
3906 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3907 iterator_remove_common_items(&old_elems
, &new_elems
);
3909 /* Iterate over no longer selected items */
3910 while (iterator_next(&old_elems
))
3912 if (old_elems
.nItem
> -1)
3914 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3917 item
.state
= LVIS_SELECTED
;
3919 item
.stateMask
= LVIS_SELECTED
;
3921 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3924 iterator_destroy(&old_elems
);
3927 /* Iterate over newly selected items */
3928 if (GetKeyState(VK_CONTROL
) & 0x8000)
3931 while (iterator_next(&new_elems
))
3933 if (new_elems
.nItem
> -1)
3935 /* If CTRL is pressed, invert. If not, always select the item. */
3936 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3939 item
.state
= LVIS_SELECTED
;
3941 item
.stateMask
= LVIS_SELECTED
;
3943 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3946 iterator_destroy(&new_elems
);
3948 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3953 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3954 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3957 * [I] hwnd : Handle to the listview
3958 * [I] uMsg : WM_TIMER (ignored)
3959 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3960 * [I] dwTimer : The elapsed time (ignored)
3965 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3967 LISTVIEW_INFO
*infoPtr
;
3968 SCROLLINFO scrollInfo
;
3972 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3977 /* Get the current cursor position and convert to client coordinates */
3978 GetCursorPos(&coords
);
3979 ScreenToClient(hWnd
, &coords
);
3981 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3982 scrollInfo
.fMask
= SIF_ALL
;
3984 /* Work out in which directions we can scroll */
3985 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3987 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3988 scroll
|= SCROLL_UP
;
3990 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3991 scroll
|= SCROLL_DOWN
;
3994 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3996 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3997 scroll
|= SCROLL_LEFT
;
3999 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
4000 scroll
|= SCROLL_RIGHT
;
4003 if (((coords
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
4004 ((coords
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
4005 ((coords
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
4006 ((coords
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
4008 LISTVIEW_MarqueeHighlight(infoPtr
, &coords
, scroll
);
4014 * Called whenever WM_MOUSEMOVE is received.
4017 * [I] infoPtr : valid pointer to the listview structure
4018 * [I] fwKeys : key indicator
4019 * [I] x,y : mouse position
4022 * 0 if the message is processed, non-zero if there was an error
4024 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4033 if (!(fwKeys
& MK_LBUTTON
))
4034 infoPtr
->bLButtonDown
= FALSE
;
4036 if (infoPtr
->bLButtonDown
)
4038 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4039 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4041 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4043 if (infoPtr
->bMarqueeSelect
)
4045 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4046 move the mouse again */
4048 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4049 (y
>= infoPtr
->rcList
.bottom
))
4051 if (!infoPtr
->bScrolling
)
4053 infoPtr
->bScrolling
= TRUE
;
4054 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4059 infoPtr
->bScrolling
= FALSE
;
4060 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4063 LISTVIEW_MarqueeHighlight(infoPtr
, &pt
, 0);
4068 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4070 /* reset item marker */
4071 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4072 infoPtr
->nLButtonDownItem
= -1;
4074 if (!PtInRect(&rect
, pt
))
4076 /* this path covers the following:
4077 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4078 2. change focus with keys
4079 3. move mouse over item from step 1 selects it and moves focus on it */
4080 if (infoPtr
->nLButtonDownItem
!= -1 &&
4081 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4085 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4086 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4088 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4089 infoPtr
->nLButtonDownItem
= -1;
4092 if (!infoPtr
->bDragging
)
4094 ht
.pt
= infoPtr
->ptClickPos
;
4095 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4097 /* If the click is outside the range of an item, begin a
4098 highlight. If not, begin an item drag. */
4103 /* If we're allowing multiple selections, send notification.
4104 If return value is non-zero, cancel. */
4105 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4107 /* Store the absolute coordinates of the click */
4109 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4111 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4112 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4114 /* Begin selection and capture mouse */
4115 infoPtr
->bMarqueeSelect
= TRUE
;
4116 SetCapture(infoPtr
->hwndSelf
);
4123 ZeroMemory(&nmlv
, sizeof(nmlv
));
4124 nmlv
.iItem
= ht
.iItem
;
4125 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4127 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4128 infoPtr
->bDragging
= TRUE
;
4136 /* see if we are supposed to be tracking mouse hovering */
4137 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4138 TRACKMOUSEEVENT trackinfo
;
4141 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4142 trackinfo
.dwFlags
= TME_QUERY
;
4144 /* see if we are already tracking this hwnd */
4145 _TrackMouseEvent(&trackinfo
);
4148 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
4151 if((trackinfo
.dwFlags
& flags
) != flags
|| trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4152 trackinfo
.dwFlags
= flags
;
4153 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4154 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4156 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4157 _TrackMouseEvent(&trackinfo
);
4166 * Tests whether the item is assignable to a list with style lStyle
4168 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4170 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4171 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4172 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4180 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4183 * [I] infoPtr : valid pointer to the listview structure
4184 * [I] lpLVItem : valid pointer to new item attributes
4185 * [I] isNew : the item being set is being inserted
4186 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4187 * [O] bChanged : will be set to TRUE if the item really changed
4193 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4199 /* stateMask is ignored for LVM_INSERTITEM */
4200 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4204 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4206 if (lpLVItem
->mask
== 0) return TRUE
;
4208 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4210 /* a virtual listview only stores selection and focus */
4211 if (lpLVItem
->mask
& ~LVIF_STATE
)
4217 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4218 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4222 /* we need to get the lParam and state of the item */
4223 item
.iItem
= lpLVItem
->iItem
;
4224 item
.iSubItem
= lpLVItem
->iSubItem
;
4225 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4226 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4230 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4232 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4233 /* determine what fields will change */
4234 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4235 uChanged
|= LVIF_STATE
;
4237 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4238 uChanged
|= LVIF_IMAGE
;
4240 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4241 uChanged
|= LVIF_PARAM
;
4243 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4244 uChanged
|= LVIF_INDENT
;
4246 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4247 uChanged
|= LVIF_TEXT
;
4249 TRACE("change mask=0x%x\n", uChanged
);
4251 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4252 nmlv
.iItem
= lpLVItem
->iItem
;
4253 if (lpLVItem
->mask
& LVIF_STATE
)
4255 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4256 nmlv
.uOldState
= item
.state
;
4258 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4259 nmlv
.lParam
= item
.lParam
;
4261 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4262 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4263 are enabled. Even nothing really changed we still need to send this,
4264 in this case uChanged mask is just set to passed item mask. */
4265 if (lpItem
&& !isNew
&& (infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
))
4267 HWND hwndSelf
= infoPtr
->hwndSelf
;
4269 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4271 if (!IsWindow(hwndSelf
))
4275 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4276 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4277 /* this means we won't hit a focus change path later */
4278 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4280 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4281 infoPtr
->nFocusedItem
++;
4284 if (!uChanged
) return TRUE
;
4287 /* copy information */
4288 if (lpLVItem
->mask
& LVIF_TEXT
)
4289 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4291 if (lpLVItem
->mask
& LVIF_IMAGE
)
4292 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4294 if (lpLVItem
->mask
& LVIF_PARAM
)
4295 lpItem
->lParam
= lpLVItem
->lParam
;
4297 if (lpLVItem
->mask
& LVIF_INDENT
)
4298 lpItem
->iIndent
= lpLVItem
->iIndent
;
4300 if (uChanged
& LVIF_STATE
)
4302 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4304 lpItem
->state
&= ~stateMask
;
4305 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4307 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4309 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4310 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4312 else if (stateMask
& LVIS_SELECTED
)
4314 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4316 /* If we are asked to change focus, and we manage it, do it.
4317 It's important to have all new item data stored at this point,
4318 because changing existing focus could result in a redrawing operation,
4319 which in turn could ask for disp data, application should see all data
4320 for inserted item when processing LVN_GETDISPINFO.
4322 The way this works application will see nested item change notifications -
4323 changed item notifications interrupted by ones from item losing focus. */
4324 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4326 if (lpLVItem
->state
& LVIS_FOCUSED
)
4328 /* update selection mark */
4329 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4330 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4332 if (infoPtr
->nFocusedItem
!= -1)
4334 /* remove current focus */
4335 item
.mask
= LVIF_STATE
;
4337 item
.stateMask
= LVIS_FOCUSED
;
4339 /* recurse with redrawing an item */
4340 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4343 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4344 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4346 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4348 infoPtr
->nFocusedItem
= -1;
4353 /* if we're inserting the item, we're done */
4354 if (isNew
) return TRUE
;
4356 /* send LVN_ITEMCHANGED notification */
4357 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4358 if (infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
)
4359 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4366 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4369 * [I] infoPtr : valid pointer to the listview structure
4370 * [I] lpLVItem : valid pointer to new subitem attributes
4371 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4372 * [O] bChanged : will be set to TRUE if the item really changed
4378 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4381 SUBITEM_INFO
*lpSubItem
;
4383 /* we do not support subitems for virtual listviews */
4384 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4386 /* set subitem only if column is present */
4387 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4389 /* First do some sanity checks */
4390 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4391 particularly useful. We currently do not actually do anything with
4392 the flag on subitems.
4394 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4395 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4397 /* get the subitem structure, and create it if not there */
4398 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4399 assert (hdpaSubItems
);
4401 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4404 SUBITEM_INFO
*tmpSubItem
;
4407 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4408 if (!lpSubItem
) return FALSE
;
4409 /* we could binary search here, if need be...*/
4410 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4412 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4413 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4415 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4420 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4421 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4425 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4427 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4431 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4433 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4442 * Sets item attributes.
4445 * [I] infoPtr : valid pointer to the listview structure
4446 * [I] lpLVItem : new item attributes
4447 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4453 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4455 HWND hwndSelf
= infoPtr
->hwndSelf
;
4456 LPWSTR pszText
= NULL
;
4457 BOOL bResult
, bChanged
= FALSE
;
4460 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4462 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4465 /* Store old item area */
4466 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4468 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4469 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4471 pszText
= lpLVItem
->pszText
;
4472 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4475 /* actually set the fields */
4476 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4478 if (lpLVItem
->iSubItem
)
4479 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4481 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4482 if (!IsWindow(hwndSelf
))
4485 /* redraw item, if necessary */
4486 if (bChanged
&& !infoPtr
->bIsDrawing
)
4488 /* this little optimization eliminates some nasty flicker */
4489 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4490 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4491 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4492 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4495 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4496 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4502 textfreeT(lpLVItem
->pszText
, isW
);
4503 lpLVItem
->pszText
= pszText
;
4511 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4514 * [I] infoPtr : valid pointer to the listview structure
4519 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4522 SCROLLINFO scrollInfo
;
4524 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4525 scrollInfo
.fMask
= SIF_POS
;
4527 if (infoPtr
->uView
== LV_VIEW_LIST
)
4529 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4530 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4532 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4534 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4535 nItem
= scrollInfo
.nPos
;
4539 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4540 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4543 TRACE("nItem=%d\n", nItem
);
4551 * Erases the background of the given rectangle
4554 * [I] infoPtr : valid pointer to the listview structure
4555 * [I] hdc : device context handle
4556 * [I] lprcBox : clipping rectangle
4562 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4564 if (!infoPtr
->hBkBrush
) return FALSE
;
4566 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4568 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4571 /* Draw main item or subitem */
4572 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4574 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4575 const RECT
*background
;
4580 /* now check if we need to update the focus rectangle */
4581 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4582 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4584 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4585 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4586 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4587 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4588 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4589 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4590 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4591 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4592 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4594 /* FIXME: temporary hack */
4595 rcSelect
.left
= rcLabel
.left
;
4597 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4599 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4600 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4601 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4602 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4603 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4606 /* in icon mode, the label rect is really what we want to draw the
4608 /* in detail mode, we want to paint background for label rect when
4609 * item is not selected or listview has full row select; otherwise paint
4610 * background for text only */
4611 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4612 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4613 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4614 background
= &rcLabel
;
4616 background
= &rcSelect
;
4618 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4619 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4621 if (item
->state
& LVIS_FOCUSED
)
4623 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4625 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4627 /* we have to update left focus bound too if item isn't in leftmost column
4628 and reduce right box bound */
4629 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4633 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4635 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4636 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4637 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4639 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4640 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4643 rcSelect
.right
= rcBox
.right
;
4645 infoPtr
->rcFocus
= rcSelect
;
4648 infoPtr
->rcFocus
= rcLabel
;
4652 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4654 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4657 TRACE("stateimage=%d\n", stateimage
);
4658 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4663 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4664 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4668 TRACE("iImage=%d\n", item
->iImage
);
4670 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4671 style
= ILD_SELECTED
;
4675 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4676 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4677 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4678 style
| (item
->state
& LVIS_OVERLAYMASK
));
4681 /* Don't bother painting item being edited */
4682 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4684 /* figure out the text drawing flags */
4685 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4686 if (infoPtr
->uView
== LV_VIEW_ICON
)
4687 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4688 else if (item
->iSubItem
)
4690 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4692 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4693 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4694 default: format
|= DT_LEFT
;
4697 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4699 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4700 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4702 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4704 /* for GRIDLINES reduce the bottom so the text formats correctly */
4705 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4708 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4716 * [I] infoPtr : valid pointer to the listview structure
4717 * [I] hdc : device context handle
4718 * [I] nItem : item index
4719 * [I] nSubItem : subitem index
4720 * [I] pos : item position in client coordinates
4721 * [I] cdmode : custom draw mode
4727 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4729 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4730 static WCHAR callbackW
[] = L
"(callback)";
4731 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4733 NMLVCUSTOMDRAW nmlvcd
;
4736 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4738 /* get information needed for drawing the item */
4739 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4740 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4741 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4742 lvItem
.iItem
= nItem
;
4743 lvItem
.iSubItem
= 0;
4746 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4747 lvItem
.pszText
= szDispText
;
4748 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4749 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4750 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4752 /* now check if we need to update the focus rectangle */
4753 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4754 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4756 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4757 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4759 /* Full custom draw stage sequence looks like this:
4764 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4765 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item itself
4766 - CDDS_ITEMPOSTPAINT
4771 - CDDS_ITEMPOSTPAINT
4774 /* fill in the custom draw structure */
4775 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4776 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4777 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4778 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4782 while (iterator_next(subitems
))
4784 DWORD subitemstage
= CDRF_DODEFAULT
;
4786 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4787 if (subitems
->nItem
)
4789 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4790 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4791 lvItem
.iItem
= nItem
;
4792 lvItem
.iSubItem
= subitems
->nItem
;
4795 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4796 lvItem
.pszText
= szDispText
;
4797 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4798 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4799 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4800 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4801 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4803 /* update custom draw data */
4804 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4805 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4806 nmlvcd
.iSubItem
= subitems
->nItem
;
4809 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4810 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4812 if (subitems
->nItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4813 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4814 else if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4815 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4817 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4818 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4820 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4821 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4826 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4827 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4831 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4833 nmlvcd
.iSubItem
= 0;
4834 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4842 * Draws listview items when in owner draw mode.
4845 * [I] infoPtr : valid pointer to the listview structure
4846 * [I] hdc : device context handle
4851 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4853 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4854 DWORD cditemmode
= CDRF_DODEFAULT
;
4855 NMLVCUSTOMDRAW nmlvcd
;
4856 POINT Origin
, Position
;
4862 ZeroMemory(&dis
, sizeof(dis
));
4864 /* Get scroll info once before loop */
4865 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4867 /* iterate through the invalidated rows */
4868 while(iterator_next(i
))
4870 item
.iItem
= i
->nItem
;
4872 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4873 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4874 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4876 dis
.CtlType
= ODT_LISTVIEW
;
4878 dis
.itemID
= item
.iItem
;
4879 dis
.itemAction
= ODA_DRAWENTIRE
;
4881 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4882 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4883 dis
.hwndItem
= infoPtr
->hwndSelf
;
4885 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4886 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4887 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4888 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4889 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4890 dis
.itemData
= item
.lParam
;
4892 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4895 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4896 * structure for the rest. of the paint cycle
4898 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4899 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4900 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4902 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4904 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4905 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4908 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4909 notify_postpaint(infoPtr
, &nmlvcd
);
4915 * Draws listview items when in report display mode.
4918 * [I] infoPtr : valid pointer to the listview structure
4919 * [I] hdc : device context handle
4920 * [I] cdmode : custom draw mode
4925 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4928 RECT rcClip
, rcItem
;
4936 /* figure out what to draw */
4937 rgntype
= GetClipBox(hdc
, &rcClip
);
4938 if (rgntype
== NULLREGION
) return;
4940 /* Get scroll info once before loop */
4941 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4943 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4945 /* narrow down the columns we need to paint */
4946 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4948 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4950 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4951 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4952 ranges_additem(colRanges
, index
);
4954 iterator_rangesitems(&j
, colRanges
);
4956 /* in full row select, we _have_ to draw the main item */
4957 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4960 /* iterate through the invalidated rows */
4961 while(iterator_next(i
))
4967 SelectObject(hdc
, infoPtr
->hFont
);
4968 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4969 Position
.x
= Origin
.x
;
4970 Position
.y
+= Origin
.y
;
4972 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4974 /* iterate through the invalidated columns */
4975 while(iterator_next(&j
))
4977 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4979 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4982 rcItem
.bottom
= infoPtr
->nItemHeight
;
4983 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4984 if (!RectVisible(hdc
, &rcItem
)) continue;
4987 ranges_additem(subitems
, j
.nItem
);
4990 iterator_rangesitems(&k
, subitems
);
4991 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
4992 iterator_destroy(&k
);
4994 iterator_destroy(&j
);
4999 * Draws the gridlines if necessary when in report display mode.
5002 * [I] infoPtr : valid pointer to the listview structure
5003 * [I] hdc : device context handle
5008 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
5014 RECT rcClip
, rcItem
= {0};
5022 /* figure out what to draw */
5023 rgntype
= GetClipBox(hdc
, &rcClip
);
5024 if (rgntype
== NULLREGION
) return;
5026 /* Get scroll info once before loop */
5027 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5029 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5031 /* narrow down the columns we need to paint */
5032 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5034 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5036 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5037 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5038 ranges_additem(colRanges
, index
);
5041 /* is right most vertical line visible? */
5042 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5044 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5045 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5046 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5049 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5051 hOldPen
= SelectObject ( hdc
, hPen
);
5053 /* draw the vertical lines for the columns */
5054 iterator_rangesitems(&j
, colRanges
);
5055 while(iterator_next(&j
))
5057 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5058 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5059 rcItem
.left
+= Origin
.x
;
5060 rcItem
.right
+= Origin
.x
;
5061 rcItem
.top
= infoPtr
->rcList
.top
;
5062 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5063 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5064 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5065 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5067 iterator_destroy(&j
);
5068 /* draw rightmost grid line if visible */
5071 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5072 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5073 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5075 rcItem
.right
+= Origin
.x
;
5077 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5078 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5081 /* draw the horizontal lines for the rows */
5082 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5083 rcItem
.left
= infoPtr
->rcList
.left
;
5084 rcItem
.right
= infoPtr
->rcList
.right
;
5085 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5087 rcItem
.bottom
= rcItem
.top
= y
;
5088 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5089 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5090 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5093 SelectObject( hdc
, hOldPen
);
5094 DeleteObject( hPen
);
5097 ranges_destroy(colRanges
);
5102 * Draws listview items when in list display mode.
5105 * [I] infoPtr : valid pointer to the listview structure
5106 * [I] hdc : device context handle
5107 * [I] cdmode : custom draw mode
5112 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5114 POINT Origin
, Position
;
5116 /* Get scroll info once before loop */
5117 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5119 while(iterator_prev(i
))
5121 SelectObject(hdc
, infoPtr
->hFont
);
5122 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5123 Position
.x
+= Origin
.x
;
5124 Position
.y
+= Origin
.y
;
5126 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5133 * Draws listview items.
5136 * [I] infoPtr : valid pointer to the listview structure
5137 * [I] hdc : device context handle
5138 * [I] prcErase : rect to be erased before refresh (may be NULL)
5143 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5145 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5146 NMLVCUSTOMDRAW nmlvcd
;
5153 HBITMAP hbmp
= NULL
;
5156 LISTVIEW_DUMP(infoPtr
);
5158 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5159 TRACE("double buffering\n");
5161 hdc
= CreateCompatibleDC(hdcOrig
);
5163 ERR("Failed to create DC for backbuffer\n");
5166 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5167 infoPtr
->rcList
.bottom
);
5169 ERR("Failed to create bitmap for backbuffer\n");
5174 SelectObject(hdc
, hbmp
);
5175 SelectObject(hdc
, infoPtr
->hFont
);
5177 if(GetClipBox(hdcOrig
, &rcClient
))
5178 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5180 /* Save dc values we're gonna trash while drawing
5181 * FIXME: Should be done in LISTVIEW_DrawItem() */
5182 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5183 oldBkMode
= GetBkMode(hdc
);
5184 oldBkColor
= GetBkColor(hdc
);
5185 oldTextColor
= GetTextColor(hdc
);
5188 infoPtr
->bIsDrawing
= TRUE
;
5191 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5192 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5193 /* If no erasing was done (usually because RedrawWindow was called
5194 * with RDW_INVALIDATE only) we need to copy the old contents into
5195 * the backbuffer before continuing. */
5196 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5197 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5198 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5199 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5202 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5203 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5204 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5205 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5207 /* nothing to draw */
5208 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5210 /* figure out what we need to draw */
5211 iterator_visibleitems(&i
, infoPtr
, hdc
);
5212 range
= iterator_range(&i
);
5214 /* send cache hint notification */
5215 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5219 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5220 nmlv
.iFrom
= range
.lower
;
5221 nmlv
.iTo
= range
.upper
- 1;
5222 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5225 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5226 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5229 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5230 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5231 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5232 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5234 /* if we have a focus rect and it's visible, draw it */
5235 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5236 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5237 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5239 iterator_destroy(&i
);
5242 /* For LVS_EX_GRIDLINES go and draw lines */
5243 /* This includes the case where there were *no* items */
5244 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5245 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5247 /* Draw marquee rectangle if appropriate */
5248 if (infoPtr
->bMarqueeSelect
)
5249 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5251 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5252 notify_postpaint(infoPtr
, &nmlvcd
);
5255 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5256 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5257 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5258 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5263 SelectObject(hdc
, hOldFont
);
5264 SetBkMode(hdc
, oldBkMode
);
5265 SetBkColor(hdc
, oldBkColor
);
5266 SetTextColor(hdc
, oldTextColor
);
5269 infoPtr
->bIsDrawing
= FALSE
;
5275 * Calculates the approximate width and height of a given number of items.
5278 * [I] infoPtr : valid pointer to the listview structure
5279 * [I] nItemCount : number of items
5280 * [I] wWidth : width
5281 * [I] wHeight : height
5284 * Returns a DWORD. The width in the low word and the height in high word.
5286 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5287 WORD wWidth
, WORD wHeight
)
5289 DWORD dwViewRect
= 0;
5291 if (nItemCount
== -1)
5292 nItemCount
= infoPtr
->nItemCount
;
5294 if (infoPtr
->uView
== LV_VIEW_LIST
)
5296 INT nItemCountPerColumn
= 1;
5297 INT nColumnCount
= 0;
5299 if (wHeight
== 0xFFFF)
5301 /* use current height */
5302 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5305 if (wHeight
< infoPtr
->nItemHeight
)
5306 wHeight
= infoPtr
->nItemHeight
;
5310 if (infoPtr
->nItemHeight
> 0)
5312 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5313 if (nItemCountPerColumn
== 0)
5314 nItemCountPerColumn
= 1;
5316 if (nItemCount
% nItemCountPerColumn
!= 0)
5317 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5319 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5323 /* Microsoft padding magic */
5324 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5325 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5327 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5329 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5333 if (infoPtr
->nItemCount
> 0)
5335 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5336 wWidth
= rcBox
.right
- rcBox
.left
;
5337 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5341 /* use current height and width */
5342 if (wHeight
== 0xffff)
5343 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5344 if (wWidth
== 0xffff)
5345 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5348 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5350 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5356 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5357 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5359 if (wWidth
== 0xffff)
5360 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5362 if (wWidth
< nItemWidth
)
5363 wWidth
= nItemWidth
;
5365 cols
= wWidth
/ nItemWidth
;
5366 if (cols
> nItemCount
)
5373 rows
= nItemCount
/ cols
;
5374 if (nItemCount
% cols
)
5380 wHeight
= (nItemHeight
* rows
)+2;
5381 wWidth
= (nItemWidth
* cols
)+2;
5383 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5385 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5386 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5393 * Cancel edit label with saving item text.
5396 * [I] infoPtr : valid pointer to the listview structure
5399 * Always returns TRUE.
5401 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5403 if (infoPtr
->hwndEdit
)
5405 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5406 HWND edit
= infoPtr
->hwndEdit
;
5408 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5409 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5417 * Create a drag image list for the specified item.
5420 * [I] infoPtr : valid pointer to the listview structure
5421 * [I] iItem : index of item
5422 * [O] lppt : Upper-left corner of the image
5425 * Returns a handle to the image list if successful, NULL otherwise.
5427 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5433 HBITMAP hbmp
, hOldbmp
;
5435 HIMAGELIST dragList
= 0;
5436 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5438 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5441 rcItem
.left
= LVIR_BOUNDS
;
5442 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5445 lppt
->x
= rcItem
.left
;
5446 lppt
->y
= rcItem
.top
;
5448 size
.cx
= rcItem
.right
- rcItem
.left
;
5449 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5451 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5452 hdc
= CreateCompatibleDC(hdcOrig
);
5453 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5454 hOldbmp
= SelectObject(hdc
, hbmp
);
5455 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5457 SetRect(&rcItem
, 0, 0, size
.cx
, size
.cy
);
5458 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5461 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5463 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5464 SelectObject(hdc
, hOldbmp
);
5465 ImageList_Add(dragList
, hbmp
, 0);
5468 SelectObject(hdc
, hOldbmp
);
5470 SelectObject(hdc
, hOldFont
);
5473 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5475 TRACE("ret=%p\n", dragList
);
5483 * Removes all listview items and subitems.
5486 * [I] infoPtr : valid pointer to the listview structure
5492 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5494 HDPA hdpaSubItems
= NULL
;
5495 BOOL suppress
= FALSE
;
5503 /* we do it directly, to avoid notifications */
5504 ranges_clear(infoPtr
->selectionRanges
);
5505 infoPtr
->nSelectionMark
= -1;
5506 infoPtr
->nFocusedItem
= -1;
5507 SetRectEmpty(&infoPtr
->rcFocus
);
5508 /* But we are supposed to leave nHotItem as is! */
5510 /* send LVN_DELETEALLITEMS notification */
5511 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5515 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5517 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5520 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5522 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5524 /* send LVN_DELETEITEM notification, if not suppressed
5525 and if it is not a virtual listview */
5526 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5527 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5528 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5529 /* free id struct */
5530 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5531 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5532 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5534 /* both item and subitem start with ITEMHDR header */
5535 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5537 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5538 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5541 DPA_Destroy(hdpaSubItems
);
5542 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5544 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5545 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5546 infoPtr
->nItemCount
--;
5551 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5552 LISTVIEW_UpdateScroll(infoPtr
);
5554 LISTVIEW_InvalidateList(infoPtr
);
5561 * Scrolls, and updates the columns, when a column is changing width.
5564 * [I] infoPtr : valid pointer to the listview structure
5565 * [I] nColumn : column to scroll
5566 * [I] dx : amount of scroll, in pixels
5571 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5573 COLUMN_INFO
*lpColumnInfo
;
5579 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5580 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5581 rcCol
= lpColumnInfo
->rcHeader
;
5582 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5583 rcCol
.left
= rcCol
.right
;
5585 /* adjust the other columns */
5586 hdi
.mask
= HDI_ORDER
;
5587 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5589 INT nOrder
= hdi
.iOrder
;
5590 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5592 hdi
.mask
= HDI_ORDER
;
5593 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5594 if (hdi
.iOrder
>= nOrder
) {
5595 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5596 lpColumnInfo
->rcHeader
.left
+= dx
;
5597 lpColumnInfo
->rcHeader
.right
+= dx
;
5602 /* do not update screen if not in report mode */
5603 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5605 /* Need to reset the item width when inserting a new column */
5606 infoPtr
->nItemWidth
+= dx
;
5608 LISTVIEW_UpdateScroll(infoPtr
);
5609 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5611 /* scroll to cover the deleted column, and invalidate for redraw */
5612 rcOld
= infoPtr
->rcList
;
5613 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5614 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5619 * Removes a column from the listview control.
5622 * [I] infoPtr : valid pointer to the listview structure
5623 * [I] nColumn : column index
5629 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5633 TRACE("nColumn=%d\n", nColumn
);
5635 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5638 /* While the MSDN specifically says that column zero should not be deleted,
5639 what actually happens is that the column itself is deleted but no items or subitems
5643 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5645 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5648 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5649 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5651 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5653 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5655 INT nItem
, nSubItem
, i
;
5657 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5659 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5662 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5664 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5665 if (lpSubItem
->iSubItem
== nColumn
)
5668 lpDelItem
= lpSubItem
;
5670 else if (lpSubItem
->iSubItem
> nColumn
)
5672 lpSubItem
->iSubItem
--;
5676 /* if we found our subitem, zap it */
5680 if (is_text(lpDelItem
->hdr
.pszText
))
5681 Free(lpDelItem
->hdr
.pszText
);
5686 /* free dpa memory */
5687 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5692 /* update the other column info */
5693 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5694 LISTVIEW_InvalidateList(infoPtr
);
5696 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5697 LISTVIEW_UpdateItemSize(infoPtr
);
5704 * Invalidates the listview after an item's insertion or deletion.
5707 * [I] infoPtr : valid pointer to the listview structure
5708 * [I] nItem : item index
5709 * [I] dir : -1 if deleting, 1 if inserting
5714 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5716 INT nPerCol
, nItemCol
, nItemRow
;
5720 /* if we don't refresh, what's the point of scrolling? */
5721 if (!is_redrawing(infoPtr
)) return;
5723 assert (abs(dir
) == 1);
5725 /* arrange icons if autoarrange is on */
5726 if (is_autoarrange(infoPtr
))
5728 BOOL arrange
= TRUE
;
5729 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5730 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5731 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5734 /* scrollbars need updating */
5735 LISTVIEW_UpdateScroll(infoPtr
);
5737 /* figure out the item's position */
5738 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5739 nPerCol
= infoPtr
->nItemCount
+ 1;
5740 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5741 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5742 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5745 nItemCol
= nItem
/ nPerCol
;
5746 nItemRow
= nItem
% nPerCol
;
5747 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5749 /* move the items below up a slot */
5750 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5751 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5752 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5753 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5754 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5755 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5756 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5758 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5759 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5762 /* report has only that column, so we're done */
5763 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5765 /* now for LISTs, we have to deal with the columns to the right */
5766 SetRect(&rcScroll
, (nItemCol
+ 1) * infoPtr
->nItemWidth
, 0,
5767 (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
,
5768 nPerCol
* infoPtr
->nItemHeight
);
5769 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5770 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5771 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5776 * Removes an item from the listview control.
5779 * [I] infoPtr : valid pointer to the listview structure
5780 * [I] nItem : item index
5786 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5789 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5790 INT focus
= infoPtr
->nFocusedItem
;
5792 TRACE("(nItem=%d)\n", nItem
);
5794 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5796 /* remove selection, and focus */
5798 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5799 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5801 /* send LVN_DELETEITEM notification. */
5802 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5804 /* we need to do this here, because we'll be deleting stuff */
5806 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5808 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5816 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5817 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5819 /* free id struct */
5820 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5821 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5822 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5824 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5826 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5827 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5830 DPA_Destroy(hdpaSubItems
);
5835 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5836 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5839 infoPtr
->nItemCount
--;
5840 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5841 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5843 /* now is the invalidation fun */
5845 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5852 * Callback implementation for editlabel control
5855 * [I] infoPtr : valid pointer to the listview structure
5856 * [I] storeText : store edit box text as item text
5857 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5863 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5865 HWND hwndSelf
= infoPtr
->hwndSelf
;
5866 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5867 NMLVDISPINFOW dispInfo
;
5868 INT editedItem
= infoPtr
->nEditLabelItem
;
5870 WCHAR
*pszText
= NULL
;
5875 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5879 if (!(pszText
= Alloc(len
* (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5883 GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
);
5885 GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
);
5889 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5891 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5892 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5893 dispInfo
.item
.iItem
= editedItem
;
5894 dispInfo
.item
.iSubItem
= 0;
5895 dispInfo
.item
.stateMask
= ~0;
5896 dispInfo
.item
.pszText
= szDispText
;
5897 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5898 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5905 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5908 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5909 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5910 textfreeT(tmp
, FALSE
);
5913 /* add the text from the edit in */
5914 dispInfo
.item
.mask
|= LVIF_TEXT
;
5915 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5916 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5918 infoPtr
->notify_mask
&= ~NOTIFY_MASK_END_LABEL_EDIT
;
5920 /* Do we need to update the Item Text */
5921 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5923 infoPtr
->notify_mask
|= NOTIFY_MASK_END_LABEL_EDIT
;
5925 infoPtr
->nEditLabelItem
= -1;
5926 infoPtr
->hwndEdit
= 0;
5928 if (!res
) goto cleanup
;
5930 if (!IsWindow(hwndSelf
))
5935 if (!pszText
) return TRUE
;
5942 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5944 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5945 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5946 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5948 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5954 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5955 dispInfo
.item
.mask
= LVIF_TEXT
;
5956 dispInfo
.item
.iItem
= editedItem
;
5957 dispInfo
.item
.iSubItem
= 0;
5958 dispInfo
.item
.pszText
= pszText
;
5959 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5960 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5970 * Subclassed edit control windproc function
5973 * [I] hwnd : the edit window handle
5974 * [I] uMsg : the message that is to be processed
5975 * [I] wParam : first message parameter
5976 * [I] lParam : second message parameter
5977 * [I] isW : TRUE if input is Unicode
5982 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5984 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5987 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5988 hwnd
, uMsg
, wParam
, lParam
, isW
);
5993 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5997 WNDPROC editProc
= infoPtr
->EditWndProc
;
5998 infoPtr
->EditWndProc
= 0;
5999 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
6000 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6004 if (VK_ESCAPE
== (INT
)wParam
)
6009 else if (VK_RETURN
== (INT
)wParam
)
6013 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6017 if (infoPtr
->hwndEdit
)
6018 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
6020 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6026 * Subclassed edit control Unicode windproc function
6029 * [I] hwnd : the edit window handle
6030 * [I] uMsg : the message that is to be processed
6031 * [I] wParam : first message parameter
6032 * [I] lParam : second message parameter
6036 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6038 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6043 * Subclassed edit control ANSI windproc function
6046 * [I] hwnd : the edit window handle
6047 * [I] uMsg : the message that is to be processed
6048 * [I] wParam : first message parameter
6049 * [I] lParam : second message parameter
6053 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6055 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6060 * Creates a subclassed edit control
6063 * [I] infoPtr : valid pointer to the listview structure
6064 * [I] text : initial text for the edit
6065 * [I] style : the window style
6066 * [I] isW : TRUE if input is Unicode
6070 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6072 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6073 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6076 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6078 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6080 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6082 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6084 if (!hedit
) return 0;
6086 infoPtr
->EditWndProc
= (WNDPROC
)
6087 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6088 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6090 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6091 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6098 * Begin in place editing of specified list view item
6101 * [I] infoPtr : valid pointer to the listview structure
6102 * [I] nItem : item index
6103 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6109 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6111 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6112 HWND hwndSelf
= infoPtr
->hwndSelf
;
6113 NMLVDISPINFOW dispInfo
;
6114 HFONT hOldFont
= NULL
;
6120 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6122 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6124 /* remove existing edit box */
6125 if (infoPtr
->hwndEdit
)
6127 SetFocus(infoPtr
->hwndSelf
);
6128 infoPtr
->hwndEdit
= 0;
6131 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6133 infoPtr
->nEditLabelItem
= nItem
;
6135 LISTVIEW_SetSelection(infoPtr
, nItem
);
6136 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6137 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6139 rect
.left
= LVIR_LABEL
;
6140 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6142 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6143 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6144 dispInfo
.item
.iItem
= nItem
;
6145 dispInfo
.item
.iSubItem
= 0;
6146 dispInfo
.item
.stateMask
= ~0;
6147 dispInfo
.item
.pszText
= disptextW
;
6148 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6149 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6151 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6152 if (!infoPtr
->hwndEdit
) return 0;
6154 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6156 if (!IsWindow(hwndSelf
))
6158 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6159 infoPtr
->hwndEdit
= 0;
6163 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6165 /* position and display edit box */
6166 hdc
= GetDC(infoPtr
->hwndSelf
);
6168 /* select the font to get appropriate metric dimensions */
6170 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6172 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6173 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6174 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6176 /* get string length in pixels */
6177 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6179 /* add extra spacing for the next character */
6180 GetTextMetricsW(hdc
, &tm
);
6181 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6184 SelectObject(hdc
, hOldFont
);
6186 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6188 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6191 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6192 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6193 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6194 SetFocus(infoPtr
->hwndEdit
);
6195 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6196 return infoPtr
->hwndEdit
;
6202 * Ensures the specified item is visible, scrolling into view if necessary.
6205 * [I] infoPtr : valid pointer to the listview structure
6206 * [I] nItem : item index
6207 * [I] bPartial : partially or entirely visible
6213 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6215 INT nScrollPosHeight
= 0;
6216 INT nScrollPosWidth
= 0;
6217 INT nHorzAdjust
= 0;
6218 INT nVertAdjust
= 0;
6221 RECT rcItem
, rcTemp
;
6223 rcItem
.left
= LVIR_BOUNDS
;
6224 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6226 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6228 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6230 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6231 if (infoPtr
->uView
== LV_VIEW_LIST
)
6232 nScrollPosWidth
= infoPtr
->nItemWidth
;
6233 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6234 nScrollPosWidth
= 1;
6236 if (rcItem
.left
< infoPtr
->rcList
.left
)
6239 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6244 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6248 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6250 /* scroll up/down, but not in LVS_LIST mode */
6251 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6252 nScrollPosHeight
= infoPtr
->nItemHeight
;
6253 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6254 nScrollPosHeight
= 1;
6256 if (rcItem
.top
< infoPtr
->rcList
.top
)
6259 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6264 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6268 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6270 if (nScrollPosWidth
)
6272 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6273 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6274 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6277 if (nScrollPosHeight
)
6279 INT diff
= nVertDiff
/ nScrollPosHeight
;
6280 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6281 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6289 * Searches for an item with specific characteristics.
6292 * [I] hwnd : window handle
6293 * [I] nStart : base item index
6294 * [I] lpFindInfo : item information to look for
6297 * SUCCESS : index of item
6300 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6301 const LVFINDINFOW
*lpFindInfo
)
6303 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6304 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6305 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6306 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6307 POINT Position
, Destination
;
6311 /* Search in virtual listviews should be done by application, not by
6312 listview control, so we just send LVN_ODFINDITEMW and return the result */
6313 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6317 nmlv
.iStart
= nStart
;
6318 nmlv
.lvfi
= *lpFindInfo
;
6319 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6322 if (!lpFindInfo
|| nItem
< 0) return -1;
6325 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6327 lvItem
.mask
|= LVIF_TEXT
;
6328 lvItem
.pszText
= szDispText
;
6329 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6332 if (lpFindInfo
->flags
& LVFI_WRAP
)
6335 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6336 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6341 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6342 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6343 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6344 switch(lpFindInfo
->vkDirection
)
6346 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6347 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6348 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6349 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6350 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6351 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6352 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6354 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6355 Destination
.x
= rcArea
.right
;
6356 Destination
.y
= rcArea
.bottom
;
6358 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6362 else Destination
.x
= Destination
.y
= 0;
6364 /* if LVFI_PARAM is specified, all other flags are ignored */
6365 if (lpFindInfo
->flags
& LVFI_PARAM
)
6367 lvItem
.mask
|= LVIF_PARAM
;
6369 lvItem
.mask
&= ~LVIF_TEXT
;
6372 nItem
= bNearest
? -1 : nStart
+ 1;
6374 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6375 search_len
= lstrlenW(lpFindInfo
->psz
);
6378 for (; nItem
< nLast
; nItem
++)
6380 lvItem
.iItem
= nItem
;
6381 lvItem
.iSubItem
= 0;
6382 lvItem
.pszText
= szDispText
;
6383 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6385 if (lvItem
.mask
& LVIF_PARAM
)
6387 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6393 if (lvItem
.mask
& LVIF_TEXT
)
6395 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6397 if (StrCmpNIW(lvItem
.pszText
, lpFindInfo
->psz
, search_len
)) continue;
6401 if (StrCmpIW(lvItem
.pszText
, lpFindInfo
->psz
)) continue;
6405 if (!bNearest
) return nItem
;
6407 /* This is very inefficient. To do a good job here,
6408 * we need a sorted array of (x,y) item positions */
6409 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6411 /* compute the distance^2 to the destination */
6412 xdist
= Destination
.x
- Position
.x
;
6413 ydist
= Destination
.y
- Position
.y
;
6414 dist
= xdist
* xdist
+ ydist
* ydist
;
6416 /* remember the distance, and item if it's closer */
6420 nNearestItem
= nItem
;
6427 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6432 return nNearestItem
;
6437 * Searches for an item with specific characteristics.
6440 * [I] hwnd : window handle
6441 * [I] nStart : base item index
6442 * [I] lpFindInfo : item information to look for
6445 * SUCCESS : index of item
6448 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6449 const LVFINDINFOA
*lpFindInfo
)
6455 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6456 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6457 fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6458 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6459 textfreeT(strW
, FALSE
);
6465 * Retrieves column attributes.
6468 * [I] infoPtr : valid pointer to the listview structure
6469 * [I] nColumn : column index
6470 * [IO] lpColumn : column information
6471 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6472 * otherwise it is in fact a LPLVCOLUMNA
6478 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6480 COLUMN_INFO
*lpColumnInfo
;
6483 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6484 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6486 /* initialize memory */
6487 ZeroMemory(&hdi
, sizeof(hdi
));
6489 if (lpColumn
->mask
& LVCF_TEXT
)
6491 hdi
.mask
|= HDI_TEXT
;
6492 hdi
.pszText
= lpColumn
->pszText
;
6493 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6496 if (lpColumn
->mask
& LVCF_IMAGE
)
6497 hdi
.mask
|= HDI_IMAGE
;
6499 if (lpColumn
->mask
& LVCF_ORDER
)
6500 hdi
.mask
|= HDI_ORDER
;
6502 if (lpColumn
->mask
& LVCF_SUBITEM
)
6503 hdi
.mask
|= HDI_LPARAM
;
6505 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6507 if (lpColumn
->mask
& LVCF_FMT
)
6508 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6510 if (lpColumn
->mask
& LVCF_WIDTH
)
6511 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6513 if (lpColumn
->mask
& LVCF_IMAGE
)
6514 lpColumn
->iImage
= hdi
.iImage
;
6516 if (lpColumn
->mask
& LVCF_ORDER
)
6517 lpColumn
->iOrder
= hdi
.iOrder
;
6519 if (lpColumn
->mask
& LVCF_SUBITEM
)
6520 lpColumn
->iSubItem
= hdi
.lParam
;
6522 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6523 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6528 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6530 if (!infoPtr
->hwndHeader
) return FALSE
;
6531 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6536 * Retrieves the column width.
6539 * [I] infoPtr : valid pointer to the listview structure
6540 * [I] int : column index
6543 * SUCCESS : column width
6546 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6548 INT nColumnWidth
= 0;
6551 TRACE("nColumn=%d\n", nColumn
);
6553 /* we have a 'column' in LIST and REPORT mode only */
6554 switch(infoPtr
->uView
)
6557 nColumnWidth
= infoPtr
->nItemWidth
;
6559 case LV_VIEW_DETAILS
:
6560 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6561 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6562 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6564 hdItem
.mask
= HDI_WIDTH
;
6565 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6567 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6570 nColumnWidth
= hdItem
.cxy
;
6574 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6575 return nColumnWidth
;
6580 * In list or report display mode, retrieves the number of items that can fit
6581 * vertically in the visible area. In icon or small icon display mode,
6582 * retrieves the total number of visible items.
6585 * [I] infoPtr : valid pointer to the listview structure
6588 * Number of fully visible items.
6590 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6592 switch (infoPtr
->uView
)
6595 case LV_VIEW_SMALLICON
:
6596 return infoPtr
->nItemCount
;
6597 case LV_VIEW_DETAILS
:
6598 return LISTVIEW_GetCountPerColumn(infoPtr
);
6600 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6608 * Retrieves an image list handle.
6611 * [I] infoPtr : valid pointer to the listview structure
6612 * [I] nImageList : image list identifier
6615 * SUCCESS : image list handle
6618 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6622 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6623 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6624 case LVSIL_STATE
: return infoPtr
->himlState
;
6625 case LVSIL_GROUPHEADER
:
6626 FIXME("LVSIL_GROUPHEADER not supported\n");
6629 WARN("got unknown imagelist index - %d\n", nImageList
);
6634 /* LISTVIEW_GetISearchString */
6638 * Retrieves item attributes.
6641 * [I] hwnd : window handle
6642 * [IO] lpLVItem : item info
6643 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6644 * if FALSE, then lpLVItem is a LPLVITEMA.
6647 * This is the internal 'GetItem' interface -- it tries to
6648 * be smart and avoid text copies, if possible, by modifying
6649 * lpLVItem->pszText to point to the text string. Please note
6650 * that this is not always possible (e.g. OWNERDATA), so on
6651 * entry you *must* supply valid values for pszText, and cchTextMax.
6652 * The only difference to the documented interface is that upon
6653 * return, you should use *only* the lpLVItem->pszText, rather than
6654 * the buffer pointer you provided on input. Most code already does
6655 * that, so it's not a problem.
6656 * For the two cases when the text must be copied (that is,
6657 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6663 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6665 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6666 BOOL is_subitem_invalid
= FALSE
;
6667 NMLVDISPINFOW dispInfo
;
6672 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6674 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6677 if (lpLVItem
->mask
== 0) return TRUE
;
6678 TRACE("mask=%x\n", lpLVItem
->mask
);
6680 if (lpLVItem
->iSubItem
&& (lpLVItem
->mask
& LVIF_STATE
))
6681 lpLVItem
->state
= 0;
6683 /* a quick optimization if all we're asked is the focus state
6684 * these queries are worth optimising since they are common,
6685 * and can be answered in constant time, without the heavy accesses */
6686 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6687 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6689 lpLVItem
->state
= 0;
6690 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
&& !lpLVItem
->iSubItem
)
6691 lpLVItem
->state
|= LVIS_FOCUSED
;
6695 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6697 /* if the app stores all the data, handle it separately */
6698 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6700 dispInfo
.item
.state
= 0;
6702 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6703 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6704 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6706 UINT mask
= lpLVItem
->mask
;
6708 /* NOTE: copy only fields which we _know_ are initialized, some apps
6709 * depend on the uninitialized fields being 0 */
6710 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6711 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6712 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
6713 if (lpLVItem
->mask
& LVIF_TEXT
)
6715 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6717 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6720 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6721 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6724 if (lpLVItem
->mask
& LVIF_STATE
)
6725 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6726 /* could be zeroed on LVIF_NORECOMPUTE case */
6727 if (dispInfo
.item
.mask
)
6729 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6730 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6731 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6733 /* full size structure expected - _WIN32IE >= 0x560 */
6734 *lpLVItem
= dispInfo
.item
;
6736 else if (lpLVItem
->mask
& LVIF_INDENT
)
6738 /* indent member expected - _WIN32IE >= 0x300 */
6739 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6743 /* minimal structure expected */
6744 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6746 lpLVItem
->mask
= mask
;
6747 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6751 /* make sure lParam is zeroed out */
6752 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6754 /* callback marked pointer required here */
6755 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6756 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6758 /* we store only a little state, so if we're not asked, we're done */
6759 if (!(lpLVItem
->mask
& LVIF_STATE
) || lpLVItem
->iSubItem
) return TRUE
;
6761 /* if focus is handled by us, report it */
6762 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6764 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6765 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6766 lpLVItem
->state
|= LVIS_FOCUSED
;
6769 /* and do the same for selection, if we handle it */
6770 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6772 lpLVItem
->state
&= ~LVIS_SELECTED
;
6773 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6774 lpLVItem
->state
|= LVIS_SELECTED
;
6780 /* find the item and subitem structures before we proceed */
6781 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6782 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6785 if (lpLVItem
->iSubItem
)
6787 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
6789 pItemHdr
= &lpSubItem
->hdr
;
6792 pItemHdr
= &callbackHdr
;
6793 is_subitem_invalid
= TRUE
;
6797 pItemHdr
= &lpItem
->hdr
;
6799 /* Do we need to query the state from the app? */
6800 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& (!lpLVItem
->iSubItem
|| is_subitem_invalid
))
6802 dispInfo
.item
.mask
|= LVIF_STATE
;
6803 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6806 /* Do we need to enquire about the image? */
6807 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6808 (!lpLVItem
->iSubItem
|| (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6810 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6811 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6814 /* Only items support indentation */
6815 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&& !lpLVItem
->iSubItem
)
6817 dispInfo
.item
.mask
|= LVIF_INDENT
;
6818 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6821 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6822 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6823 !is_text(pItemHdr
->pszText
))
6825 dispInfo
.item
.mask
|= LVIF_TEXT
;
6826 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6827 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6828 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6829 *dispInfo
.item
.pszText
= '\0';
6832 /* If we don't have all the requested info, query the application */
6833 if (dispInfo
.item
.mask
)
6835 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6836 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
;
6837 dispInfo
.item
.lParam
= lpItem
->lParam
;
6838 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6839 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6842 /* we should not store values for subitems */
6843 if (lpLVItem
->iSubItem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6845 /* Now, handle the iImage field */
6846 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6848 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6849 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6850 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6852 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6854 if (!lpLVItem
->iSubItem
|| (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6855 lpLVItem
->iImage
= pItemHdr
->iImage
;
6857 lpLVItem
->iImage
= 0;
6860 /* The pszText field */
6861 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6863 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6864 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6866 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6868 else if (lpLVItem
->mask
& LVIF_TEXT
)
6870 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6871 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6872 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6875 /* Next is the lParam field */
6876 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6878 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6879 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6880 lpItem
->lParam
= dispInfo
.item
.lParam
;
6882 else if (lpLVItem
->mask
& LVIF_PARAM
)
6883 lpLVItem
->lParam
= lpItem
->lParam
;
6885 /* if this is a subitem, we're done */
6886 if (lpLVItem
->iSubItem
) return TRUE
;
6888 /* ... the state field (this one is different due to uCallbackmask) */
6889 if (lpLVItem
->mask
& LVIF_STATE
)
6891 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6892 if (dispInfo
.item
.mask
& LVIF_STATE
)
6894 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6895 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6897 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6899 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6900 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6901 lpLVItem
->state
|= LVIS_FOCUSED
;
6903 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6905 lpLVItem
->state
&= ~LVIS_SELECTED
;
6906 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6907 lpLVItem
->state
|= LVIS_SELECTED
;
6911 /* and last, but not least, the indent field */
6912 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6914 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6915 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6916 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6918 else if (lpLVItem
->mask
& LVIF_INDENT
)
6920 lpLVItem
->iIndent
= lpItem
->iIndent
;
6928 * Retrieves item attributes.
6931 * [I] hwnd : window handle
6932 * [IO] lpLVItem : item info
6933 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6934 * if FALSE, then lpLVItem is a LPLVITEMA.
6937 * This is the external 'GetItem' interface -- it properly copies
6938 * the text in the provided buffer.
6944 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6949 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6952 pszText
= lpLVItem
->pszText
;
6953 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6954 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6956 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6957 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6959 pszText
= LPSTR_TEXTCALLBACKW
;
6961 lpLVItem
->pszText
= pszText
;
6969 * Retrieves the position (upper-left) of the listview control item.
6970 * Note that for LVS_ICON style, the upper-left is that of the icon
6971 * and not the bounding box.
6974 * [I] infoPtr : valid pointer to the listview structure
6975 * [I] nItem : item index
6976 * [O] lpptPosition : coordinate information
6982 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6986 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6988 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6990 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6991 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6993 if (infoPtr
->uView
== LV_VIEW_ICON
)
6995 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6996 lpptPosition
->y
+= ICON_TOP_PADDING
;
6998 lpptPosition
->x
+= Origin
.x
;
6999 lpptPosition
->y
+= Origin
.y
;
7001 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
7008 * Retrieves the bounding rectangle for a listview control item.
7011 * [I] infoPtr : valid pointer to the listview structure
7012 * [I] nItem : item index
7013 * [IO] lprc : bounding rectangle coordinates
7014 * lprc->left specifies the portion of the item for which the bounding
7015 * rectangle will be retrieved.
7017 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
7018 * including the icon and label.
7021 * * Experiment shows that native control returns:
7022 * * width = min (48, length of text line)
7023 * * .left = position.x - (width - iconsize.cx)/2
7024 * * .right = .left + width
7025 * * height = #lines of text * ntmHeight + icon height + 8
7026 * * .top = position.y - 2
7027 * * .bottom = .top + height
7028 * * separation between items .y = itemSpacing.cy - height
7029 * * .x = itemSpacing.cx - width
7030 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7033 * * Experiment shows that native control returns:
7034 * * width = iconSize.cx + 16
7035 * * .left = position.x - (width - iconsize.cx)/2
7036 * * .right = .left + width
7037 * * height = iconSize.cy + 4
7038 * * .top = position.y - 2
7039 * * .bottom = .top + height
7040 * * separation between items .y = itemSpacing.cy - height
7041 * * .x = itemSpacing.cx - width
7042 * LVIR_LABEL Returns the bounding rectangle of the item text.
7045 * * Experiment shows that native control returns:
7046 * * width = text length
7047 * * .left = position.x - width/2
7048 * * .right = .left + width
7049 * * height = ntmH * linecount + 2
7050 * * .top = position.y + iconSize.cy + 6
7051 * * .bottom = .top + height
7052 * * separation between items .y = itemSpacing.cy - height
7053 * * .x = itemSpacing.cx - width
7054 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7055 * rectangles, but excludes columns in report view.
7062 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7063 * upon whether the window has the focus currently and on whether the item
7064 * is the one with the focus. Ensure that the control's record of which
7065 * item has the focus agrees with the items' records.
7067 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7069 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7070 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7071 POINT Position
, Origin
;
7075 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7077 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7079 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7080 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7082 /* Be smart and try to figure out the minimum we have to do */
7083 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7084 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7085 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7086 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7087 oversizedBox
= TRUE
;
7089 /* get what we need from the item before hand, so we make
7090 * only one request. This can speed up things, if data
7091 * is stored on the app side */
7093 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7094 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7095 lvItem
.iItem
= nItem
;
7096 lvItem
.iSubItem
= 0;
7097 lvItem
.pszText
= szDispText
;
7098 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7099 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7100 /* we got the state already up, simulate it here, to avoid a reget */
7101 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7103 lvItem
.mask
|= LVIF_STATE
;
7104 lvItem
.stateMask
= LVIS_FOCUSED
;
7105 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7108 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7109 lprc
->left
= LVIR_BOUNDS
;
7115 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7119 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7123 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7126 case LVIR_SELECTBOUNDS
:
7127 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7131 WARN("Unknown value: %d\n", lprc
->left
);
7135 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7137 if (mode
!= LVIR_BOUNDS
)
7138 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7139 Position
.y
+ Origin
.y
);
7141 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7144 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7146 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7153 * Retrieves the spacing between listview control items.
7156 * [I] infoPtr : valid pointer to the listview structure
7157 * [IO] lprc : rectangle to receive the output
7158 * on input, lprc->top = nSubItem
7159 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7161 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7162 * not only those of the first column.
7168 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7170 RECT rect
= { 0, 0, 0, 0 };
7174 if (!lprc
) return FALSE
;
7176 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7177 /* Subitem of '0' means item itself, and this works for all control view modes */
7179 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7181 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7183 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7184 /* this works for any item index, no matter if it exists or not */
7185 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7187 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7190 rect
.bottom
= infoPtr
->nItemHeight
;
7194 /* Native implementation is broken for this case and garbage is left for left and right fields,
7195 we zero them to get predictable output */
7196 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7197 lprc
->bottom
= infoPtr
->nItemHeight
;
7198 OffsetRect(lprc
, origin
.x
, y
);
7199 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7207 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7208 if (infoPtr
->himlSmall
)
7209 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7211 rect
.right
= rect
.left
;
7213 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7221 ERR("Unknown bounds=%d\n", lprc
->left
);
7225 OffsetRect(&rect
, origin
.x
, y
);
7227 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7234 * Retrieves the spacing between listview control items.
7237 * [I] infoPtr : valid pointer to the listview structure
7238 * [I] bSmall : flag for small or large icon
7241 * Horizontal + vertical spacing
7243 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7249 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7253 if (infoPtr
->uView
== LV_VIEW_ICON
)
7254 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7256 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7263 * Retrieves the state of a listview control item.
7266 * [I] infoPtr : valid pointer to the listview structure
7267 * [I] nItem : item index
7268 * [I] uMask : state mask
7271 * State specified by the mask.
7273 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7277 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7279 lvItem
.iItem
= nItem
;
7280 lvItem
.iSubItem
= 0;
7281 lvItem
.mask
= LVIF_STATE
;
7282 lvItem
.stateMask
= uMask
;
7283 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7285 return lvItem
.state
& uMask
;
7290 * Retrieves the text of a listview control item or subitem.
7293 * [I] hwnd : window handle
7294 * [I] nItem : item index
7295 * [IO] lpLVItem : item information
7296 * [I] isW : TRUE if lpLVItem is Unicode
7299 * SUCCESS : string length
7302 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7304 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7306 lpLVItem
->mask
= LVIF_TEXT
;
7307 lpLVItem
->iItem
= nItem
;
7308 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7310 return textlenT(lpLVItem
->pszText
, isW
);
7315 * Searches for an item based on properties + relationships.
7318 * [I] infoPtr : valid pointer to the listview structure
7319 * [I] nItem : item index
7320 * [I] uFlags : relationship flag
7323 * SUCCESS : item index
7326 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7329 LVFINDINFOW lvFindInfo
;
7330 INT nCountPerColumn
;
7334 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7335 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7337 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7339 if (uFlags
& LVNI_CUT
)
7342 if (uFlags
& LVNI_DROPHILITED
)
7343 uMask
|= LVIS_DROPHILITED
;
7345 if (uFlags
& LVNI_FOCUSED
)
7346 uMask
|= LVIS_FOCUSED
;
7348 if (uFlags
& LVNI_SELECTED
)
7349 uMask
|= LVIS_SELECTED
;
7351 /* if we're asked for the focused item, that's only one,
7352 * so it's worth optimizing */
7353 if (uFlags
& LVNI_FOCUSED
)
7355 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7356 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7359 if (uFlags
& LVNI_ABOVE
)
7361 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7366 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7372 /* Special case for autoarrange - move 'til the top of a list */
7373 if (is_autoarrange(infoPtr
))
7375 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7376 while (nItem
- nCountPerRow
>= 0)
7378 nItem
-= nCountPerRow
;
7379 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7384 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7385 lvFindInfo
.vkDirection
= VK_UP
;
7386 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7387 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7389 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7394 else if (uFlags
& LVNI_BELOW
)
7396 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7398 while (nItem
< infoPtr
->nItemCount
)
7401 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7407 /* Special case for autoarrange - move 'til the bottom of a list */
7408 if (is_autoarrange(infoPtr
))
7410 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7411 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7413 nItem
+= nCountPerRow
;
7414 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7419 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7420 lvFindInfo
.vkDirection
= VK_DOWN
;
7421 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7422 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7424 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7429 else if (uFlags
& LVNI_TOLEFT
)
7431 if (infoPtr
->uView
== LV_VIEW_LIST
)
7433 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7434 while (nItem
- nCountPerColumn
>= 0)
7436 nItem
-= nCountPerColumn
;
7437 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7441 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7443 /* Special case for autoarrange - move 'til the beginning of a row */
7444 if (is_autoarrange(infoPtr
))
7446 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7447 while (nItem
% nCountPerRow
> 0)
7450 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7455 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7456 lvFindInfo
.vkDirection
= VK_LEFT
;
7457 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7458 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7460 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7465 else if (uFlags
& LVNI_TORIGHT
)
7467 if (infoPtr
->uView
== LV_VIEW_LIST
)
7469 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7470 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7472 nItem
+= nCountPerColumn
;
7473 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7477 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7479 /* Special case for autoarrange - move 'til the end of a row */
7480 if (is_autoarrange(infoPtr
))
7482 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7483 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7486 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7491 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7492 lvFindInfo
.vkDirection
= VK_RIGHT
;
7493 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7494 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7496 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7505 /* search by index */
7506 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7508 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7516 /* LISTVIEW_GetNumberOfWorkAreas */
7520 * Retrieves the origin coordinates when in icon or small icon display mode.
7523 * [I] infoPtr : valid pointer to the listview structure
7524 * [O] lpptOrigin : coordinate information
7529 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7531 INT nHorzPos
= 0, nVertPos
= 0;
7532 SCROLLINFO scrollInfo
;
7534 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7535 scrollInfo
.fMask
= SIF_POS
;
7537 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7538 nHorzPos
= scrollInfo
.nPos
;
7539 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7540 nVertPos
= scrollInfo
.nPos
;
7542 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7544 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7545 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7546 if (infoPtr
->uView
== LV_VIEW_LIST
)
7547 nHorzPos
*= infoPtr
->nItemWidth
;
7548 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7549 nVertPos
*= infoPtr
->nItemHeight
;
7551 lpptOrigin
->x
-= nHorzPos
;
7552 lpptOrigin
->y
-= nVertPos
;
7554 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7559 * Retrieves the width of a string.
7562 * [I] hwnd : window handle
7563 * [I] lpszText : text string to process
7564 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7567 * SUCCESS : string width (in pixels)
7570 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7575 if (is_text(lpszText
))
7577 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7578 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7579 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7582 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7584 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7585 SelectObject(hdc
, hOldFont
);
7586 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7588 return stringSize
.cx
;
7593 * Determines which listview item is located at the specified position.
7596 * [I] infoPtr : valid pointer to the listview structure
7597 * [IO] lpht : hit test information
7598 * [I] subitem : fill out iSubItem.
7599 * [I] select : return the index only if the hit selects the item
7602 * (mm 20001022): We must not allow iSubItem to be touched, for
7603 * an app might pass only a structure with space up to iItem!
7604 * (MS Office 97 does that for instance in the file open dialog)
7607 * SUCCESS : item index
7610 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7612 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7613 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7614 POINT Origin
, Position
, opt
;
7620 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7624 if (subitem
) lpht
->iSubItem
= 0;
7626 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7628 /* set whole list relation flags */
7629 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7631 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7632 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7633 lpht
->flags
|= LVHT_TOLEFT
;
7635 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7636 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7640 if (infoPtr
->rcList
.bottom
< opt
.y
)
7641 lpht
->flags
|= LVHT_BELOW
;
7645 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7646 lpht
->flags
|= LVHT_TOLEFT
;
7647 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7648 lpht
->flags
|= LVHT_TORIGHT
;
7650 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7651 lpht
->flags
|= LVHT_ABOVE
;
7652 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7653 lpht
->flags
|= LVHT_BELOW
;
7656 /* even if item is invalid try to find subitem */
7657 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7662 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7664 lpht
->iSubItem
= -1;
7665 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7667 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7669 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7675 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7677 /* if we're outside horizontal columns bounds there's nothing to test further */
7678 if (lpht
->iSubItem
== -1)
7681 lpht
->flags
= LVHT_NOWHERE
;
7686 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7687 if (lpht
->flags
) return -1;
7689 lpht
->flags
|= LVHT_NOWHERE
;
7691 /* first deal with the large items */
7692 rcSearch
.left
= lpht
->pt
.x
;
7693 rcSearch
.top
= lpht
->pt
.y
;
7694 rcSearch
.right
= rcSearch
.left
+ 1;
7695 rcSearch
.bottom
= rcSearch
.top
+ 1;
7697 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7698 iterator_next(&i
); /* go to first item in the sequence */
7700 iterator_destroy(&i
);
7702 TRACE("lpht->iItem=%d\n", iItem
);
7703 if (iItem
== -1) return -1;
7705 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7706 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7707 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7708 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7709 lvItem
.iItem
= iItem
;
7710 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7711 lvItem
.pszText
= szDispText
;
7712 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7713 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7714 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7716 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7717 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7718 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7720 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7721 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7723 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7725 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7728 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7729 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7733 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7734 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7736 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7737 if (!PtInRect(&rcBounds
, opt
)) return -1;
7739 /* That's a special case - row rectangle is used as item rectangle and
7740 returned flags contain all item parts. */
7741 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7743 if (PtInRect(&rcIcon
, opt
))
7744 lpht
->flags
|= LVHT_ONITEMICON
;
7745 else if (PtInRect(&rcLabel
, opt
))
7746 lpht
->flags
|= LVHT_ONITEMLABEL
;
7747 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7748 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7749 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7751 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7753 if (lpht
->flags
& LVHT_ONITEM
)
7754 lpht
->flags
&= ~LVHT_NOWHERE
;
7755 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7757 if (select
&& !is_fullrow
)
7759 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7761 /* get main item bounds */
7762 lvItem
.iSubItem
= 0;
7763 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7764 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7765 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7767 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7769 return lpht
->iItem
= iItem
;
7774 * Inserts a new item in the listview control.
7777 * [I] infoPtr : valid pointer to the listview structure
7778 * [I] lpLVItem : item information
7779 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7782 * SUCCESS : new item index
7785 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7792 BOOL is_sorted
, has_changed
;
7794 HWND hwndSelf
= infoPtr
->hwndSelf
;
7796 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7798 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7800 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7801 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7803 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7805 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7807 /* insert item in listview control data structure */
7808 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7809 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7811 /* link with id struct */
7812 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7814 lpID
->item
= hdpaSubItems
;
7815 lpID
->id
= get_next_itemid(infoPtr
);
7816 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7818 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7819 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7821 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7823 /* calculate new item index */
7831 textW
= textdupTtoW(lpLVItem
->pszText
, isW
);
7833 while (i
< infoPtr
->nItemCount
)
7835 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7836 item_s
= DPA_GetPtr(hItem
, 0);
7838 cmpv
= textcmpWT(item_s
->hdr
.pszText
, textW
, TRUE
);
7839 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7841 if (cmpv
>= 0) break;
7845 textfreeT(textW
, isW
);
7850 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7852 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7853 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7854 if (nItem
== -1) goto fail
;
7855 infoPtr
->nItemCount
++;
7857 /* shift indices first so they don't get tangled */
7858 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7860 /* set the item attributes */
7861 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7863 /* full size structure expected - _WIN32IE >= 0x560 */
7866 else if (lpLVItem
->mask
& LVIF_INDENT
)
7868 /* indent member expected - _WIN32IE >= 0x300 */
7869 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7873 /* minimal structure expected */
7874 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7877 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7879 if (item
.mask
& LVIF_STATE
)
7881 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7882 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7883 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7887 item
.mask
|= LVIF_STATE
;
7888 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7889 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7893 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7895 /* make room for the position, if we are in the right mode */
7896 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7898 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7900 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7902 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7907 /* send LVN_INSERTITEM notification */
7908 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7910 nmlv
.lParam
= lpItem
->lParam
;
7911 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7912 if (!IsWindow(hwndSelf
))
7915 /* align items (set position of each item) */
7916 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7920 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7921 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7923 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7925 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7928 /* now is the invalidation fun */
7929 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7933 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7934 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7935 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7936 infoPtr
->nItemCount
--;
7938 DPA_DeletePtr(hdpaSubItems
, 0);
7939 DPA_Destroy (hdpaSubItems
);
7946 * Checks item visibility.
7949 * [I] infoPtr : valid pointer to the listview structure
7950 * [I] nFirst : item index to check for
7953 * Item visible : TRUE
7954 * Item invisible or failure : FALSE
7956 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7958 POINT Origin
, Position
;
7963 TRACE("nItem=%d\n", nItem
);
7965 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7967 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7968 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7969 rcItem
.left
= Position
.x
+ Origin
.x
;
7970 rcItem
.top
= Position
.y
+ Origin
.y
;
7971 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7972 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7974 hdc
= GetDC(infoPtr
->hwndSelf
);
7975 if (!hdc
) return FALSE
;
7976 ret
= RectVisible(hdc
, &rcItem
);
7977 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7984 * Redraws a range of items.
7987 * [I] infoPtr : valid pointer to the listview structure
7988 * [I] nFirst : first item
7989 * [I] nLast : last item
7995 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7999 for (i
= max(nFirst
, 0); i
<= min(nLast
, infoPtr
->nItemCount
- 1); i
++)
8000 LISTVIEW_InvalidateItem(infoPtr
, i
);
8007 * Scroll the content of a listview.
8010 * [I] infoPtr : valid pointer to the listview structure
8011 * [I] dx : horizontal scroll amount in pixels
8012 * [I] dy : vertical scroll amount in pixels
8019 * If the control is in report view (LV_VIEW_DETAILS) the control can
8020 * be scrolled only in line increments. "dy" will be rounded to the
8021 * nearest number of pixels that are a whole line. Ex: if line height
8022 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
8023 * is passed, then the scroll will be 0. (per MSDN 7/2002)
8025 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8027 switch(infoPtr
->uView
) {
8028 case LV_VIEW_DETAILS
:
8029 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
8030 dy
/= infoPtr
->nItemHeight
;
8033 if (dy
!= 0) return FALSE
;
8039 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8040 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8047 * Sets the background color.
8050 * [I] infoPtr : valid pointer to the listview structure
8051 * [I] color : background color
8057 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8059 TRACE("(color=%x)\n", color
);
8061 if(infoPtr
->clrBk
!= color
) {
8062 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8063 infoPtr
->clrBk
= color
;
8064 if (color
== CLR_NONE
)
8065 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8068 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8069 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8076 /* LISTVIEW_SetBkImage */
8078 /*** Helper for {Insert,Set}ColumnT *only* */
8079 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8080 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8082 if (lpColumn
->mask
& LVCF_FMT
)
8084 /* format member is valid */
8085 lphdi
->mask
|= HDI_FORMAT
;
8087 /* set text alignment (leftmost column must be left-aligned) */
8088 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8089 lphdi
->fmt
|= HDF_LEFT
;
8090 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8091 lphdi
->fmt
|= HDF_RIGHT
;
8092 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8093 lphdi
->fmt
|= HDF_CENTER
;
8095 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8096 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8098 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8100 lphdi
->fmt
|= HDF_IMAGE
;
8101 lphdi
->iImage
= I_IMAGECALLBACK
;
8104 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8105 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8108 if (lpColumn
->mask
& LVCF_WIDTH
)
8110 lphdi
->mask
|= HDI_WIDTH
;
8111 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8113 /* make it fill the remainder of the controls width */
8117 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8119 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8120 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8123 /* retrieve the layout of the header */
8124 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8125 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8127 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8130 lphdi
->cxy
= lpColumn
->cx
;
8133 if (lpColumn
->mask
& LVCF_TEXT
)
8135 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8136 lphdi
->fmt
|= HDF_STRING
;
8137 lphdi
->pszText
= lpColumn
->pszText
;
8138 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8141 if (lpColumn
->mask
& LVCF_IMAGE
)
8143 lphdi
->mask
|= HDI_IMAGE
;
8144 lphdi
->iImage
= lpColumn
->iImage
;
8147 if (lpColumn
->mask
& LVCF_ORDER
)
8149 lphdi
->mask
|= HDI_ORDER
;
8150 lphdi
->iOrder
= lpColumn
->iOrder
;
8157 * Inserts a new column.
8160 * [I] infoPtr : valid pointer to the listview structure
8161 * [I] nColumn : column index
8162 * [I] lpColumn : column information
8163 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8166 * SUCCESS : new column index
8169 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8170 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8172 COLUMN_INFO
*lpColumnInfo
;
8176 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8178 if (!lpColumn
|| nColumn
< 0) return -1;
8179 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8181 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8182 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8185 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8186 * (can be seen in SPY) otherwise column never gets added.
8188 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8189 hdi
.mask
|= HDI_WIDTH
;
8194 * when the iSubItem is available Windows copies it to the header lParam. It seems
8195 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8197 if (lpColumn
->mask
& LVCF_SUBITEM
)
8199 hdi
.mask
|= HDI_LPARAM
;
8200 hdi
.lParam
= lpColumn
->iSubItem
;
8203 /* create header if not present */
8204 LISTVIEW_CreateHeader(infoPtr
);
8205 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8206 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8208 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8211 /* insert item in header control */
8212 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8213 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8214 nColumn
, (LPARAM
)&hdi
);
8215 if (nNewColumn
== -1) return -1;
8216 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8218 /* create our own column info */
8219 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8220 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8222 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8223 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8224 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8227 /* now we have to actually adjust the data */
8228 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8230 SUBITEM_INFO
*lpSubItem
;
8236 item
.iSubItem
= nNewColumn
;
8237 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8238 item
.iImage
= I_IMAGECALLBACK
;
8239 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8241 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8243 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8244 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8246 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8247 if (lpSubItem
->iSubItem
>= nNewColumn
)
8248 lpSubItem
->iSubItem
++;
8251 /* add new subitem for each item */
8253 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8257 /* make space for the new column */
8258 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8259 LISTVIEW_UpdateItemSize(infoPtr
);
8264 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8267 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8275 * Sets the attributes of a header item.
8278 * [I] infoPtr : valid pointer to the listview structure
8279 * [I] nColumn : column index
8280 * [I] lpColumn : column attributes
8281 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8287 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8288 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8290 HDITEMW hdi
, hdiget
;
8293 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8295 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8297 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8298 if (lpColumn
->mask
& LVCF_FMT
)
8300 hdi
.mask
|= HDI_FORMAT
;
8301 hdiget
.mask
= HDI_FORMAT
;
8302 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8303 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8305 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8307 /* set header item attributes */
8308 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8309 if (!bResult
) return FALSE
;
8311 if (lpColumn
->mask
& LVCF_FMT
)
8313 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8314 INT oldFmt
= lpColumnInfo
->fmt
;
8316 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8317 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8319 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8323 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8324 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8331 * Sets the column order array
8334 * [I] infoPtr : valid pointer to the listview structure
8335 * [I] iCount : number of elements in column order array
8336 * [I] lpiArray : pointer to column order array
8342 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8344 if (!infoPtr
->hwndHeader
) return FALSE
;
8345 infoPtr
->colRectsDirty
= TRUE
;
8346 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8351 * Sets the width of a column
8354 * [I] infoPtr : valid pointer to the listview structure
8355 * [I] nColumn : column index
8356 * [I] cx : column width
8362 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8364 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8368 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8370 /* set column width only if in report or list mode */
8371 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8373 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8374 with _USEHEADER being the lowest */
8375 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8376 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8378 /* resize all columns if in LV_VIEW_LIST mode */
8379 if(infoPtr
->uView
== LV_VIEW_LIST
)
8381 infoPtr
->nItemWidth
= cx
;
8382 LISTVIEW_InvalidateList(infoPtr
);
8386 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8388 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8393 lvItem
.mask
= LVIF_TEXT
;
8395 lvItem
.iSubItem
= nColumn
;
8396 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8397 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8399 lvItem
.pszText
= szDispText
;
8400 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8401 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8402 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8404 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8405 max_cx
+= infoPtr
->iconSize
.cx
;
8406 max_cx
+= TRAILING_LABEL_PADDING
;
8407 if (nColumn
== 0 && (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
))
8408 max_cx
+= GetSystemMetrics(SM_CXSMICON
);
8411 /* autosize based on listview items width */
8412 if(cx
== LVSCW_AUTOSIZE
)
8414 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8416 /* if iCol is the last column make it fill the remainder of the controls width */
8417 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8422 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8423 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8425 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8429 /* Despite what the MS docs say, if this is not the last
8430 column, then MS resizes the column to the width of the
8431 largest text string in the column, including headers
8432 and items. This is different from LVSCW_AUTOSIZE in that
8433 LVSCW_AUTOSIZE ignores the header string length. */
8436 /* retrieve header text */
8437 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8438 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8439 hdi
.pszText
= szDispText
;
8440 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8442 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8443 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8444 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8445 INT bitmap_margin
= 0;
8448 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8449 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8451 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8452 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8454 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8456 INT icon_cx
, icon_cy
;
8458 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8459 cx
+= icon_cx
+ 2*bitmap_margin
;
8461 else if (hdi
.fmt
& HDF_BITMAP
)
8465 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8466 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8469 SelectObject(hdc
, old_font
);
8470 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8472 cx
= max (cx
, max_cx
);
8476 if (cx
< 0) return FALSE
;
8478 /* call header to update the column change */
8479 hdi
.mask
= HDI_WIDTH
;
8480 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8481 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8482 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8486 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8489 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8492 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8494 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8495 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8498 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8499 ILC_COLOR
| ILC_MASK
, 2, 2);
8500 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8501 hdc
= CreateCompatibleDC(hdc_wnd
);
8502 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8503 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8504 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8506 SetRect(&rc
, 0, 0, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8507 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8508 FillRect(hdc
, &rc
, hbr_white
);
8509 InflateRect(&rc
, -2, -2);
8510 FillRect(hdc
, &rc
, hbr_black
);
8512 SelectObject(hdc
, hbm_im
);
8513 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8514 SelectObject(hdc
, hbm_orig
);
8515 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8517 SelectObject(hdc
, hbm_im
);
8518 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8519 SelectObject(hdc
, hbm_orig
);
8520 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8522 DeleteObject(hbm_mask
);
8523 DeleteObject(hbm_im
);
8531 * Sets the extended listview style.
8534 * [I] infoPtr : valid pointer to the listview structure
8536 * [I] dwStyle : style
8539 * SUCCESS : previous style
8542 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8544 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8546 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8550 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8552 infoPtr
->dwLvExStyle
= ex_style
;
8554 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8556 HIMAGELIST himl
= 0;
8557 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8560 item
.mask
= LVIF_STATE
;
8561 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8562 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8563 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8565 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8566 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8567 ImageList_Destroy(infoPtr
->himlState
);
8569 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8570 /* checkbox list replaces previous custom list or... */
8571 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8572 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8573 /* ...previous was checkbox list */
8574 (old_ex_style
& LVS_EX_CHECKBOXES
))
8575 ImageList_Destroy(himl
);
8578 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8582 /* if not already created */
8583 LISTVIEW_CreateHeader(infoPtr
);
8585 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8586 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8587 style
|= HDS_DRAGDROP
;
8589 style
&= ~HDS_DRAGDROP
;
8590 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8593 /* GRIDLINES adds decoration at top so changes sizes */
8594 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8596 LISTVIEW_CreateHeader(infoPtr
);
8597 LISTVIEW_UpdateSize(infoPtr
);
8600 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8602 LISTVIEW_CreateHeader(infoPtr
);
8605 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8607 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8608 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8611 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8613 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8614 LISTVIEW_CreateHeader(infoPtr
);
8616 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8617 LISTVIEW_UpdateSize(infoPtr
);
8618 LISTVIEW_UpdateScroll(infoPtr
);
8621 LISTVIEW_InvalidateList(infoPtr
);
8622 return old_ex_style
;
8627 * Sets the new hot cursor used during hot tracking and hover selection.
8630 * [I] infoPtr : valid pointer to the listview structure
8631 * [I] hCursor : the new hot cursor handle
8634 * Returns the previous hot cursor
8636 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8638 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8640 infoPtr
->hHotCursor
= hCursor
;
8648 * Sets the hot item index.
8651 * [I] infoPtr : valid pointer to the listview structure
8652 * [I] iIndex : index
8655 * SUCCESS : previous hot item index
8656 * FAILURE : -1 (no hot item)
8658 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8660 INT iOldIndex
= infoPtr
->nHotItem
;
8662 infoPtr
->nHotItem
= iIndex
;
8670 * Sets the amount of time the cursor must hover over an item before it is selected.
8673 * [I] infoPtr : valid pointer to the listview structure
8674 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8677 * Returns the previous hover time
8679 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8681 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8683 infoPtr
->dwHoverTime
= dwHoverTime
;
8685 return oldHoverTime
;
8690 * Sets spacing for icons of LVS_ICON style.
8693 * [I] infoPtr : valid pointer to the listview structure
8694 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8695 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8698 * MAKELONG(oldcx, oldcy)
8700 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8702 INT iconWidth
= 0, iconHeight
= 0;
8703 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8705 TRACE("requested=(%d,%d)\n", cx
, cy
);
8707 /* set to defaults, if instructed to */
8708 if (cx
== -1 && cy
== -1)
8710 infoPtr
->autoSpacing
= TRUE
;
8711 if (infoPtr
->himlNormal
)
8712 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8713 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8714 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8717 infoPtr
->autoSpacing
= FALSE
;
8719 /* if 0 then keep width */
8721 infoPtr
->iconSpacing
.cx
= cx
;
8723 /* if 0 then keep height */
8725 infoPtr
->iconSpacing
.cy
= cy
;
8727 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8728 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8729 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8730 infoPtr
->ntmHeight
);
8732 /* these depend on the iconSpacing */
8733 LISTVIEW_UpdateItemSize(infoPtr
);
8738 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL is_small
)
8742 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8749 size
->cx
= GetSystemMetrics(is_small
? SM_CXSMICON
: SM_CXICON
);
8750 size
->cy
= GetSystemMetrics(is_small
? SM_CYSMICON
: SM_CYICON
);
8759 * [I] infoPtr : valid pointer to the listview structure
8760 * [I] nType : image list type
8761 * [I] himl : image list handle
8764 * SUCCESS : old image list
8767 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8769 INT oldHeight
= infoPtr
->nItemHeight
;
8770 HIMAGELIST himlOld
= 0;
8772 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8777 himlOld
= infoPtr
->himlNormal
;
8778 infoPtr
->himlNormal
= himl
;
8779 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8780 if (infoPtr
->autoSpacing
)
8781 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8785 himlOld
= infoPtr
->himlSmall
;
8786 infoPtr
->himlSmall
= himl
;
8787 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8788 if (infoPtr
->hwndHeader
)
8789 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8793 himlOld
= infoPtr
->himlState
;
8794 infoPtr
->himlState
= himl
;
8795 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8796 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8800 ERR("Unknown icon type=%d\n", nType
);
8804 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8805 if (infoPtr
->nItemHeight
!= oldHeight
)
8806 LISTVIEW_UpdateScroll(infoPtr
);
8813 * Preallocates memory (does *not* set the actual count of items !)
8816 * [I] infoPtr : valid pointer to the listview structure
8817 * [I] nItems : item count (projected number of items to allocate)
8818 * [I] dwFlags : update flags
8824 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8826 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8828 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8830 INT nOldCount
= infoPtr
->nItemCount
;
8831 infoPtr
->nItemCount
= nItems
;
8833 if (nItems
< nOldCount
)
8835 RANGE range
= { nItems
, nOldCount
};
8836 ranges_del(infoPtr
->selectionRanges
, range
);
8837 if (infoPtr
->nFocusedItem
>= nItems
)
8839 LISTVIEW_SetItemFocus(infoPtr
, -1);
8840 infoPtr
->nFocusedItem
= -1;
8841 SetRectEmpty(&infoPtr
->rcFocus
);
8845 LISTVIEW_UpdateScroll(infoPtr
);
8847 /* the flags are valid only in ownerdata report and list modes */
8848 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8850 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8851 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8853 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8854 LISTVIEW_InvalidateList(infoPtr
);
8861 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8862 nFrom
= min(nOldCount
, nItems
);
8863 nTo
= max(nOldCount
, nItems
);
8865 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8867 SetRect(&rcErase
, 0, nFrom
* infoPtr
->nItemHeight
, infoPtr
->nItemWidth
,
8868 nTo
* infoPtr
->nItemHeight
);
8869 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8870 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8871 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8873 else /* LV_VIEW_LIST */
8875 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8877 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8878 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8879 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8880 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8881 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8882 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8883 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8885 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8887 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8888 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8889 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8890 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8891 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8897 /* According to MSDN for non-LVS_OWNERDATA this is just
8898 * a performance issue. The control allocates its internal
8899 * data structures for the number of items specified. It
8900 * cuts down on the number of memory allocations. Therefore
8901 * we will just issue a WARN here
8903 WARN("for non-ownerdata performance option not implemented.\n");
8911 * Sets the position of an item.
8914 * [I] infoPtr : valid pointer to the listview structure
8915 * [I] nItem : item index
8916 * [I] pt : coordinate
8922 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8926 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8928 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8929 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8932 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8934 /* This point value seems to be an undocumented feature.
8935 * The best guess is that it means either at the origin,
8936 * or at true beginning of the list. I will assume the origin. */
8937 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8940 if (infoPtr
->uView
== LV_VIEW_ICON
)
8942 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8943 Pt
.y
-= ICON_TOP_PADDING
;
8948 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8953 * Sets the state of one or many items.
8956 * [I] infoPtr : valid pointer to the listview structure
8957 * [I] nItem : item index
8958 * [I] item : item or subitem info
8964 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8969 if (!item
) return FALSE
;
8971 lvItem
.iItem
= nItem
;
8972 lvItem
.iSubItem
= 0;
8973 lvItem
.mask
= LVIF_STATE
;
8974 lvItem
.state
= item
->state
;
8975 lvItem
.stateMask
= item
->stateMask
;
8976 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8983 /* special case optimization for recurring attempt to deselect all */
8984 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8987 /* select all isn't allowed in LVS_SINGLESEL */
8988 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8991 /* focus all isn't allowed */
8992 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8994 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
8995 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8997 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
8998 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8999 oldstate
|= LVIS_SELECTED
;
9000 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
9003 /* apply to all items */
9004 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
9005 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
9007 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9011 infoPtr
->notify_mask
|= old_mask
;
9015 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
9016 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
9017 nmlv
.uChanged
= LVIF_STATE
;
9018 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
9021 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
9025 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9032 * Sets the text of an item or subitem.
9035 * [I] hwnd : window handle
9036 * [I] nItem : item index
9037 * [I] lpLVItem : item or subitem info
9038 * [I] isW : TRUE if input is Unicode
9044 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9048 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9049 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9051 lvItem
.iItem
= nItem
;
9052 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9053 lvItem
.mask
= LVIF_TEXT
;
9054 lvItem
.pszText
= lpLVItem
->pszText
;
9055 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9057 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9059 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9064 * Set item index that marks the start of a multiple selection.
9067 * [I] infoPtr : valid pointer to the listview structure
9068 * [I] nIndex : index
9071 * Index number or -1 if there is no selection mark.
9073 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9075 INT nOldIndex
= infoPtr
->nSelectionMark
;
9077 TRACE("(nIndex=%d)\n", nIndex
);
9079 if (nIndex
>= -1 && nIndex
< infoPtr
->nItemCount
)
9080 infoPtr
->nSelectionMark
= nIndex
;
9087 * Sets the text background color.
9090 * [I] infoPtr : valid pointer to the listview structure
9091 * [I] color : text background color
9097 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9099 TRACE("(color=%x)\n", color
);
9101 infoPtr
->clrTextBk
= color
;
9107 * Sets the text foreground color.
9110 * [I] infoPtr : valid pointer to the listview structure
9111 * [I] color : text color
9117 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9119 TRACE("(color=%x)\n", color
);
9121 infoPtr
->clrText
= color
;
9127 * Sets new ToolTip window to ListView control.
9130 * [I] infoPtr : valid pointer to the listview structure
9131 * [I] hwndNewToolTip : handle to new ToolTip
9136 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9138 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9139 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9140 return hwndOldToolTip
;
9145 * sets the Unicode character format flag for the control
9147 * [I] infoPtr :valid pointer to the listview structure
9148 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9151 * Old Unicode Format
9153 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9155 SHORT rc
= infoPtr
->notifyFormat
;
9156 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9157 return rc
== NFR_UNICODE
;
9162 * sets the control view mode
9164 * [I] infoPtr :valid pointer to the listview structure
9165 * [I] nView :new view mode value
9171 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9175 if (infoPtr
->uView
== nView
) return 1;
9177 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9178 if (nView
== LV_VIEW_TILE
)
9180 FIXME("View LV_VIEW_TILE unimplemented\n");
9184 infoPtr
->uView
= nView
;
9186 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9187 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9189 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9190 SetRectEmpty(&infoPtr
->rcFocus
);
9192 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9193 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9198 case LV_VIEW_SMALLICON
:
9199 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9201 case LV_VIEW_DETAILS
:
9206 LISTVIEW_CreateHeader( infoPtr
);
9208 hl
.prc
= &infoPtr
->rcList
;
9210 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9211 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9212 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9219 LISTVIEW_UpdateItemSize(infoPtr
);
9220 LISTVIEW_UpdateSize(infoPtr
);
9221 LISTVIEW_UpdateScroll(infoPtr
);
9222 LISTVIEW_InvalidateList(infoPtr
);
9224 TRACE("nView=%d\n", nView
);
9229 /* LISTVIEW_SetWorkAreas */
9231 struct sorting_context
9234 PFNLVCOMPARE compare_func
;
9238 /* DPA_Sort() callback used for LVM_SORTITEMS */
9239 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9241 struct sorting_context
*context
= (struct sorting_context
*)lParam
;
9242 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9243 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9245 return context
->compare_func(lv_first
->lParam
, lv_second
->lParam
, context
->lParam
);
9248 /* DPA_Sort() callback used for LVM_SORTITEMSEX */
9249 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9251 struct sorting_context
*context
= (struct sorting_context
*)lParam
;
9252 INT first_idx
= DPA_GetPtrIndex( context
->items
, first
);
9253 INT second_idx
= DPA_GetPtrIndex( context
->items
, second
);
9255 return context
->compare_func(first_idx
, second_idx
, context
->lParam
);
9260 * Sorts the listview items.
9263 * [I] infoPtr : valid pointer to the listview structure
9264 * [I] pfnCompare : application-defined value
9265 * [I] lParamSort : pointer to comparison callback
9266 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9272 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9273 LPARAM lParamSort
, BOOL IsEx
)
9275 HDPA hdpaSubItems
, hdpaItems
;
9277 LPVOID selectionMarkItem
= NULL
;
9278 LPVOID focusedItem
= NULL
;
9279 struct sorting_context context
;
9282 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9284 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9286 if (!pfnCompare
) return FALSE
;
9287 if (!infoPtr
->hdpaItems
) return FALSE
;
9289 /* if there are 0 or 1 items, there is no need to sort */
9290 if (infoPtr
->nItemCount
< 2) return TRUE
;
9291 if (!(hdpaItems
= DPA_Clone(infoPtr
->hdpaItems
, NULL
))) return FALSE
;
9293 /* clear selection */
9294 ranges_clear(infoPtr
->selectionRanges
);
9296 /* save selection mark and focused item */
9297 if (infoPtr
->nSelectionMark
>= 0)
9298 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9299 if (infoPtr
->nFocusedItem
>= 0)
9300 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9302 context
.items
= hdpaItems
;
9303 context
.compare_func
= pfnCompare
;
9304 context
.lParam
= lParamSort
;
9306 DPA_Sort(hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)&context
);
9308 DPA_Sort(hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)&context
);
9309 DPA_Destroy(infoPtr
->hdpaItems
);
9310 infoPtr
->hdpaItems
= hdpaItems
;
9312 /* restore selection ranges */
9313 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9315 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9316 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9318 if (lpItem
->state
& LVIS_SELECTED
)
9319 ranges_additem(infoPtr
->selectionRanges
, i
);
9321 /* restore selection mark and focused item */
9322 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9323 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9325 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9327 /* refresh the display */
9328 LISTVIEW_InvalidateList(infoPtr
);
9334 * Update theme handle after a theme change.
9337 * [I] infoPtr : valid pointer to the listview structure
9341 * FAILURE : something else
9343 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9345 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9346 CloseThemeData(theme
);
9347 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9353 * Updates an items or rearranges the listview control.
9356 * [I] infoPtr : valid pointer to the listview structure
9357 * [I] nItem : item index
9363 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9365 TRACE("(nItem=%d)\n", nItem
);
9367 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9369 /* rearrange with default alignment style */
9370 if (is_autoarrange(infoPtr
))
9371 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9373 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9380 * Draw the track line at the place defined in the infoPtr structure.
9381 * The line is drawn with a XOR pen so drawing the line for the second time
9382 * in the same place erases the line.
9385 * [I] infoPtr : valid pointer to the listview structure
9391 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9395 if (infoPtr
->xTrackLine
== -1)
9398 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9400 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9401 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9402 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9408 * Called when an edit control should be displayed. This function is called after
9409 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9412 * [I] hwnd : Handle to the listview
9413 * [I] uMsg : WM_TIMER (ignored)
9414 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9415 * [I] dwTimer : The elapsed time (ignored)
9420 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9422 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9423 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9425 KillTimer(hwnd
, idEvent
);
9426 editItem
->fEnabled
= FALSE
;
9427 /* check if the item is still selected */
9428 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9429 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9434 * Creates the listview control - the WM_NCCREATE phase.
9437 * [I] hwnd : window handle
9438 * [I] lpcs : the create parameters
9444 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
9446 LISTVIEW_INFO
*infoPtr
;
9449 TRACE("(lpcs=%p)\n", lpcs
);
9451 /* initialize info pointer */
9452 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9453 if (!infoPtr
) return FALSE
;
9455 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9457 infoPtr
->hwndSelf
= hwnd
;
9458 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9459 map_style_view(infoPtr
);
9460 /* determine the type of structures to use */
9461 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9462 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9464 /* initialize color information */
9465 infoPtr
->clrBk
= CLR_NONE
;
9466 infoPtr
->clrText
= CLR_DEFAULT
;
9467 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9468 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9470 /* set default values */
9471 infoPtr
->nFocusedItem
= -1;
9472 infoPtr
->nSelectionMark
= -1;
9473 infoPtr
->nHotItem
= -1;
9474 infoPtr
->redraw
= TRUE
;
9475 infoPtr
->bNoItemMetrics
= TRUE
;
9476 infoPtr
->notify_mask
= NOTIFY_MASK_UNMASK_ALL
;
9477 infoPtr
->autoSpacing
= TRUE
;
9478 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9479 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9480 infoPtr
->nEditLabelItem
= -1;
9481 infoPtr
->nLButtonDownItem
= -1;
9482 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9483 infoPtr
->cWheelRemainder
= 0;
9484 infoPtr
->nMeasureItemHeight
= 0;
9485 infoPtr
->xTrackLine
= -1; /* no track line */
9486 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9487 infoPtr
->iVersion
= COMCTL32_VERSION
;
9488 infoPtr
->colRectsDirty
= FALSE
;
9489 infoPtr
->selected_column
= -1;
9491 /* get default font (icon title) */
9492 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9493 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9494 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9495 LISTVIEW_SaveTextMetrics(infoPtr
);
9497 /* allocate memory for the data structure */
9498 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9499 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9500 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9501 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9502 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9503 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9505 return DefWindowProcW(hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
9508 DestroyWindow(infoPtr
->hwndHeader
);
9509 ranges_destroy(infoPtr
->selectionRanges
);
9510 DPA_Destroy(infoPtr
->hdpaItems
);
9511 DPA_Destroy(infoPtr
->hdpaItemIds
);
9512 DPA_Destroy(infoPtr
->hdpaPosX
);
9513 DPA_Destroy(infoPtr
->hdpaPosY
);
9514 DPA_Destroy(infoPtr
->hdpaColumns
);
9521 * Creates the listview control - the WM_CREATE phase. Most of the data is
9522 * already set up in LISTVIEW_NCCreate
9525 * [I] hwnd : window handle
9526 * [I] lpcs : the create parameters
9532 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9534 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9536 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9538 infoPtr
->dwStyle
= lpcs
->style
;
9539 map_style_view(infoPtr
);
9541 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9542 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9543 /* on error defaulting to ANSI notifications */
9544 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9545 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9547 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9549 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9552 infoPtr
->hwndHeader
= 0;
9554 /* init item size to avoid division by 0 */
9555 LISTVIEW_UpdateItemSize (infoPtr
);
9556 LISTVIEW_UpdateSize (infoPtr
);
9558 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9560 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9562 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9564 LISTVIEW_UpdateScroll(infoPtr
);
9565 /* send WM_MEASUREITEM notification */
9566 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9569 OpenThemeData(hwnd
, themeClass
);
9571 /* initialize the icon sizes */
9572 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9573 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9579 * Destroys the listview control.
9582 * [I] infoPtr : valid pointer to the listview structure
9588 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9590 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9591 CloseThemeData(theme
);
9593 /* delete all items */
9594 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9601 * Enables the listview control.
9604 * [I] infoPtr : valid pointer to the listview structure
9605 * [I] bEnable : specifies whether to enable or disable the window
9611 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9613 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9614 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9620 * Erases the background of the listview control.
9623 * [I] infoPtr : valid pointer to the listview structure
9624 * [I] hdc : device context handle
9630 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9634 TRACE("(hdc=%p)\n", hdc
);
9636 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9638 if (infoPtr
->clrBk
== CLR_NONE
)
9640 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9641 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9642 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9644 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9647 /* for double buffered controls we need to do this during refresh */
9648 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9650 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9656 * Helper function for LISTVIEW_[HV]Scroll *only*.
9657 * Performs vertical/horizontal scrolling by a give amount.
9660 * [I] infoPtr : valid pointer to the listview structure
9661 * [I] dx : amount of horizontal scroll
9662 * [I] dy : amount of vertical scroll
9664 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9666 /* now we can scroll the list */
9667 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9668 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9669 /* if we have focus, adjust rect */
9670 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9671 UpdateWindow(infoPtr
->hwndSelf
);
9676 * Performs vertical scrolling.
9679 * [I] infoPtr : valid pointer to the listview structure
9680 * [I] nScrollCode : scroll code
9681 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9682 * [I] hScrollWnd : scrollbar control window handle
9688 * SB_LINEUP/SB_LINEDOWN:
9689 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9690 * for LVS_REPORT is 1 line
9691 * for LVS_LIST cannot occur
9694 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9697 INT nOldScrollPos
, nNewScrollPos
;
9698 SCROLLINFO scrollInfo
;
9701 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9702 debugscrollcode(nScrollCode
), nScrollDiff
);
9704 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9706 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9707 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9709 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9711 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9713 nOldScrollPos
= scrollInfo
.nPos
;
9714 switch (nScrollCode
)
9720 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9724 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9728 nScrollDiff
= -scrollInfo
.nPage
;
9732 nScrollDiff
= scrollInfo
.nPage
;
9735 case SB_THUMBPOSITION
:
9737 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9744 /* quit right away if pos isn't changing */
9745 if (nScrollDiff
== 0) return 0;
9747 /* calculate new position, and handle overflows */
9748 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9749 if (nScrollDiff
> 0) {
9750 if (nNewScrollPos
< nOldScrollPos
||
9751 nNewScrollPos
> scrollInfo
.nMax
)
9752 nNewScrollPos
= scrollInfo
.nMax
;
9754 if (nNewScrollPos
> nOldScrollPos
||
9755 nNewScrollPos
< scrollInfo
.nMin
)
9756 nNewScrollPos
= scrollInfo
.nMin
;
9759 /* set the new position, and reread in case it changed */
9760 scrollInfo
.fMask
= SIF_POS
;
9761 scrollInfo
.nPos
= nNewScrollPos
;
9762 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9764 /* carry on only if it really changed */
9765 if (nNewScrollPos
== nOldScrollPos
) return 0;
9767 /* now adjust to client coordinates */
9768 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9769 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9771 /* and scroll the window */
9772 scroll_list(infoPtr
, 0, nScrollDiff
);
9779 * Performs horizontal scrolling.
9782 * [I] infoPtr : valid pointer to the listview structure
9783 * [I] nScrollCode : scroll code
9784 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9785 * [I] hScrollWnd : scrollbar control window handle
9791 * SB_LINELEFT/SB_LINERIGHT:
9792 * for LVS_ICON, LVS_SMALLICON 1 pixel
9793 * for LVS_REPORT is 1 pixel
9794 * for LVS_LIST is 1 column --> which is a 1 because the
9795 * scroll is based on columns not pixels
9798 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9801 INT nOldScrollPos
, nNewScrollPos
;
9802 SCROLLINFO scrollInfo
;
9805 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9806 debugscrollcode(nScrollCode
), nScrollDiff
);
9808 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9810 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9811 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9813 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9815 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9817 nOldScrollPos
= scrollInfo
.nPos
;
9819 switch (nScrollCode
)
9825 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9829 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9833 nScrollDiff
= -scrollInfo
.nPage
;
9837 nScrollDiff
= scrollInfo
.nPage
;
9840 case SB_THUMBPOSITION
:
9842 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9849 /* quit right away if pos isn't changing */
9850 if (nScrollDiff
== 0) return 0;
9852 /* calculate new position, and handle overflows */
9853 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9854 if (nScrollDiff
> 0) {
9855 if (nNewScrollPos
< nOldScrollPos
||
9856 nNewScrollPos
> scrollInfo
.nMax
)
9857 nNewScrollPos
= scrollInfo
.nMax
;
9859 if (nNewScrollPos
> nOldScrollPos
||
9860 nNewScrollPos
< scrollInfo
.nMin
)
9861 nNewScrollPos
= scrollInfo
.nMin
;
9864 /* set the new position, and reread in case it changed */
9865 scrollInfo
.fMask
= SIF_POS
;
9866 scrollInfo
.nPos
= nNewScrollPos
;
9867 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9869 /* carry on only if it really changed */
9870 if (nNewScrollPos
== nOldScrollPos
) return 0;
9872 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9874 /* now adjust to client coordinates */
9875 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9876 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9878 /* and scroll the window */
9879 scroll_list(infoPtr
, nScrollDiff
, 0);
9884 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9886 INT pulScrollLines
= 3;
9888 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9890 switch(infoPtr
->uView
)
9893 case LV_VIEW_SMALLICON
:
9895 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9896 * should be fixed in the future.
9898 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9899 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9902 case LV_VIEW_DETAILS
:
9903 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9905 /* if scrolling changes direction, ignore left overs */
9906 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9907 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9908 infoPtr
->cWheelRemainder
+= wheelDelta
;
9910 infoPtr
->cWheelRemainder
= wheelDelta
;
9911 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9914 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9915 cLineScroll
= pulScrollLines
* infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9916 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ pulScrollLines
;
9917 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9922 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9933 * [I] infoPtr : valid pointer to the listview structure
9934 * [I] nVirtualKey : virtual key
9935 * [I] lKeyData : key data
9940 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9942 HWND hwndSelf
= infoPtr
->hwndSelf
;
9944 NMLVKEYDOWN nmKeyDown
;
9946 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9948 /* send LVN_KEYDOWN notification */
9949 nmKeyDown
.wVKey
= nVirtualKey
;
9950 nmKeyDown
.flags
= 0;
9951 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9952 if (!IsWindow(hwndSelf
))
9955 switch (nVirtualKey
)
9958 nItem
= infoPtr
->nFocusedItem
;
9959 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9960 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9964 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9966 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9967 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9972 if (infoPtr
->nItemCount
> 0)
9977 if (infoPtr
->nItemCount
> 0)
9978 nItem
= infoPtr
->nItemCount
- 1;
9982 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9986 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9990 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9994 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9998 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10000 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10001 if (infoPtr
->nFocusedItem
== topidx
)
10002 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
10007 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
10008 * LISTVIEW_GetCountPerRow(infoPtr
);
10009 if(nItem
< 0) nItem
= 0;
10013 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10015 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10016 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10017 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10018 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10020 nItem
= topidx
+ cnt
- 1;
10023 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10024 * LISTVIEW_GetCountPerRow(infoPtr
);
10025 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10029 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10030 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10040 * [I] infoPtr : valid pointer to the listview structure
10045 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10049 /* drop any left over scroll amount */
10050 infoPtr
->cWheelRemainder
= 0;
10052 /* if we did not have the focus, there's nothing more to do */
10053 if (!infoPtr
->bFocus
) return 0;
10055 /* send NM_KILLFOCUS notification */
10056 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10058 /* if we have a focus rectangle, get rid of it */
10059 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10061 /* if have a marquee selection, stop it */
10062 if (infoPtr
->bMarqueeSelect
)
10064 /* Remove the marquee rectangle and release our mouse capture */
10065 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10068 SetRectEmpty(&infoPtr
->marqueeRect
);
10070 infoPtr
->bMarqueeSelect
= FALSE
;
10071 infoPtr
->bScrolling
= FALSE
;
10072 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10075 /* set window focus flag */
10076 infoPtr
->bFocus
= FALSE
;
10078 /* invalidate the selected items before resetting focus flag */
10079 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10086 * Processes double click messages (left mouse button).
10089 * [I] infoPtr : valid pointer to the listview structure
10090 * [I] wKey : key flag
10091 * [I] x,y : mouse coordinate
10096 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10098 LVHITTESTINFO htInfo
;
10100 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10102 /* Cancel the item edition if any */
10103 if (infoPtr
->itemEdit
.fEnabled
)
10105 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10106 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10109 /* send NM_RELEASEDCAPTURE notification */
10110 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10115 /* send NM_DBLCLK notification */
10116 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10117 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10119 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10120 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10125 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10130 r
.top
= r
.bottom
= pt
.y
;
10131 r
.left
= r
.right
= pt
.x
;
10133 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10135 SetCapture(infoPtr
->hwndSelf
);
10139 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10141 if (msg
.message
== WM_MOUSEMOVE
)
10143 pt
.x
= (short)LOWORD(msg
.lParam
);
10144 pt
.y
= (short)HIWORD(msg
.lParam
);
10145 if (PtInRect(&r
, pt
))
10153 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10154 msg
.message
<= WM_RBUTTONDBLCLK
)
10159 DispatchMessageW(&msg
);
10162 if (GetCapture() != infoPtr
->hwndSelf
)
10173 * Processes mouse down messages (left mouse button).
10176 * infoPtr [I ] valid pointer to the listview structure
10177 * wKey [I ] key flag
10178 * x,y [I ] mouse coordinate
10183 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10185 LVHITTESTINFO lvHitTestInfo
;
10186 static BOOL bGroupSelect
= TRUE
;
10187 POINT pt
= { x
, y
};
10190 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10192 /* send NM_RELEASEDCAPTURE notification */
10193 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10195 /* set left button down flag and record the click position */
10196 infoPtr
->bLButtonDown
= TRUE
;
10197 infoPtr
->ptClickPos
= pt
;
10198 infoPtr
->bDragging
= FALSE
;
10199 infoPtr
->bMarqueeSelect
= FALSE
;
10200 infoPtr
->bScrolling
= FALSE
;
10202 lvHitTestInfo
.pt
.x
= x
;
10203 lvHitTestInfo
.pt
.y
= y
;
10205 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10206 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10207 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10209 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10211 notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
);
10212 toggle_checkbox_state(infoPtr
, nItem
);
10213 infoPtr
->bLButtonDown
= FALSE
;
10217 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10219 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10220 infoPtr
->nEditLabelItem
= nItem
;
10222 LISTVIEW_SetSelection(infoPtr
, nItem
);
10226 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10230 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10231 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10232 infoPtr
->nSelectionMark
= nItem
;
10238 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10239 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10241 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10242 infoPtr
->nSelectionMark
= nItem
;
10245 else if (wKey
& MK_CONTROL
)
10249 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10251 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10252 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10253 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10254 infoPtr
->nSelectionMark
= nItem
;
10256 else if (wKey
& MK_SHIFT
)
10258 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10262 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10264 infoPtr
->nEditLabelItem
= nItem
;
10265 infoPtr
->nLButtonDownItem
= nItem
;
10267 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10270 /* set selection (clears other pre-existing selections) */
10271 LISTVIEW_SetSelection(infoPtr
, nItem
);
10275 if (!infoPtr
->bFocus
)
10276 SetFocus(infoPtr
->hwndSelf
);
10278 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10279 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10283 if (!infoPtr
->bFocus
)
10284 SetFocus(infoPtr
->hwndSelf
);
10286 /* remove all selections */
10287 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10288 LISTVIEW_DeselectAll(infoPtr
);
10297 * Processes mouse up messages (left mouse button).
10300 * infoPtr [I ] valid pointer to the listview structure
10301 * wKey [I ] key flag
10302 * x,y [I ] mouse coordinate
10307 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10309 LVHITTESTINFO lvHitTestInfo
;
10311 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10313 if (!infoPtr
->bLButtonDown
) return 0;
10315 lvHitTestInfo
.pt
.x
= x
;
10316 lvHitTestInfo
.pt
.y
= y
;
10318 /* send NM_CLICK notification */
10319 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10320 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10322 /* set left button flag */
10323 infoPtr
->bLButtonDown
= FALSE
;
10325 /* set a single selection, reset others */
10326 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10327 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10328 infoPtr
->nLButtonDownItem
= -1;
10330 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10332 /* Remove the marquee rectangle and release our mouse capture */
10333 if (infoPtr
->bMarqueeSelect
)
10335 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10339 SetRectEmpty(&infoPtr
->marqueeRect
);
10340 SetRectEmpty(&infoPtr
->marqueeDrawRect
);
10342 infoPtr
->bDragging
= FALSE
;
10343 infoPtr
->bMarqueeSelect
= FALSE
;
10344 infoPtr
->bScrolling
= FALSE
;
10346 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10350 /* if we clicked on a selected item, edit the label */
10351 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10353 /* we want to make sure the user doesn't want to do a double click. So we will
10354 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10356 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10357 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10358 SetTimer(infoPtr
->hwndSelf
,
10359 (UINT_PTR
)&infoPtr
->itemEdit
,
10360 GetDoubleClickTime(),
10361 LISTVIEW_DelayedEditItem
);
10369 * Destroys the listview control (called after WM_DESTROY).
10372 * [I] infoPtr : valid pointer to the listview structure
10377 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10383 /* destroy data structure */
10384 DPA_Destroy(infoPtr
->hdpaItems
);
10385 DPA_Destroy(infoPtr
->hdpaItemIds
);
10386 DPA_Destroy(infoPtr
->hdpaPosX
);
10387 DPA_Destroy(infoPtr
->hdpaPosY
);
10389 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10390 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10391 DPA_Destroy(infoPtr
->hdpaColumns
);
10392 ranges_destroy(infoPtr
->selectionRanges
);
10394 /* destroy image lists */
10395 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10397 ImageList_Destroy(infoPtr
->himlNormal
);
10398 ImageList_Destroy(infoPtr
->himlSmall
);
10399 ImageList_Destroy(infoPtr
->himlState
);
10402 /* destroy font, bkgnd brush */
10403 infoPtr
->hFont
= 0;
10404 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10405 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10407 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10409 /* free listview info pointer*/
10417 * Handles notifications.
10420 * [I] infoPtr : valid pointer to the listview structure
10421 * [I] lpnmhdr : notification information
10426 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10430 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10432 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10434 /* remember: HDN_LAST < HDN_FIRST */
10435 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10436 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10438 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10440 switch (lpnmhdr
->code
)
10445 COLUMN_INFO
*lpColumnInfo
;
10449 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10452 /* remove the old line (if any) */
10453 LISTVIEW_DrawTrackLine(infoPtr
);
10455 /* compute & draw the new line */
10456 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10457 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10458 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10459 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10460 LISTVIEW_DrawTrackLine(infoPtr
);
10461 return notify_forward_header(infoPtr
, lpnmh
);
10464 case HDN_ENDTRACKA
:
10465 case HDN_ENDTRACKW
:
10466 /* remove the track line (if any) */
10467 LISTVIEW_DrawTrackLine(infoPtr
);
10468 infoPtr
->xTrackLine
= -1;
10469 return notify_forward_header(infoPtr
, lpnmh
);
10471 case HDN_BEGINDRAG
:
10472 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10473 return notify_forward_header(infoPtr
, lpnmh
);
10476 infoPtr
->colRectsDirty
= TRUE
;
10477 LISTVIEW_InvalidateList(infoPtr
);
10478 return notify_forward_header(infoPtr
, lpnmh
);
10480 case HDN_ITEMCHANGEDW
:
10481 case HDN_ITEMCHANGEDA
:
10483 COLUMN_INFO
*lpColumnInfo
;
10487 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10489 hdi
.mask
= HDI_WIDTH
;
10490 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10494 cxy
= lpnmh
->pitem
->cxy
;
10496 /* determine how much we change since the last know position */
10497 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10498 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10501 lpColumnInfo
->rcHeader
.right
+= dx
;
10503 hdi
.mask
= HDI_ORDER
;
10504 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10506 /* not the rightmost one */
10507 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10509 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10510 hdi
.iOrder
+ 1, 0);
10511 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10515 /* only needs to update the scrolls */
10516 infoPtr
->nItemWidth
+= dx
;
10517 LISTVIEW_UpdateScroll(infoPtr
);
10519 LISTVIEW_UpdateItemSize(infoPtr
);
10520 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10523 RECT rcCol
= lpColumnInfo
->rcHeader
;
10525 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10526 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10528 rcCol
.top
= infoPtr
->rcList
.top
;
10529 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10531 /* resizing left-aligned columns leaves most of the left side untouched */
10532 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10534 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10537 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10540 /* when shrinking the last column clear the now unused field */
10541 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10547 /* deal with right from rightmost column area */
10548 right
.left
= rcCol
.right
;
10549 right
.top
= rcCol
.top
;
10550 right
.bottom
= rcCol
.bottom
;
10551 right
.right
= infoPtr
->rcList
.right
;
10553 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10556 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10562 case HDN_ITEMCLICKW
:
10563 case HDN_ITEMCLICKA
:
10565 /* Handle sorting by Header Column */
10568 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10570 nmlv
.iSubItem
= lpnmh
->iItem
;
10571 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10572 return notify_forward_header(infoPtr
, lpnmh
);
10575 case HDN_DIVIDERDBLCLICKW
:
10576 case HDN_DIVIDERDBLCLICKA
:
10577 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10578 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10579 split needed for that */
10580 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10581 return notify_forward_header(infoPtr
, lpnmh
);
10588 * Paint non-client area of control.
10591 * [I] infoPtr : valid pointer to the listview structureof the sender
10592 * [I] region : update region
10595 * 0 - frame was painted
10597 static LRESULT
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10599 LONG exstyle
= GetWindowLongW (infoPtr
->hwndSelf
, GWL_EXSTYLE
);
10600 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10604 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10605 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10607 if (!theme
|| !(exstyle
& WS_EX_CLIENTEDGE
))
10608 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10610 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10612 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10613 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10614 if (region
!= (HRGN
)1)
10615 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10616 OffsetRect(&r
, -r
.left
, -r
.top
);
10618 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10620 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10621 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10622 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10623 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10625 /* Call default proc to get the scrollbars etc. painted */
10626 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10627 DeleteObject(cliprgn
);
10634 * Determines the type of structure to use.
10637 * [I] infoPtr : valid pointer to the listview structureof the sender
10638 * [I] hwndFrom : listview window handle
10639 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10644 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10646 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10648 if (nCommand
== NF_REQUERY
)
10649 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10651 return infoPtr
->notifyFormat
;
10656 * Paints/Repaints the listview control. Internal use.
10659 * [I] infoPtr : valid pointer to the listview structure
10660 * [I] hdc : device context handle
10665 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10667 TRACE("(hdc=%p)\n", hdc
);
10669 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10671 infoPtr
->bNoItemMetrics
= FALSE
;
10672 LISTVIEW_UpdateItemSize(infoPtr
);
10673 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10674 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10675 LISTVIEW_UpdateScroll(infoPtr
);
10678 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10681 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10686 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10687 if (!hdc
) return 1;
10688 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10689 EndPaint(infoPtr
->hwndSelf
, &ps
);
10697 * Paints/Repaints the listview control, WM_PAINT handler.
10700 * [I] infoPtr : valid pointer to the listview structure
10701 * [I] hdc : device context handle
10706 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10708 TRACE("(hdc=%p)\n", hdc
);
10710 if (!is_redrawing(infoPtr
))
10711 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10713 return LISTVIEW_Paint(infoPtr
, hdc
);
10718 * Paints/Repaints the listview control.
10721 * [I] infoPtr : valid pointer to the listview structure
10722 * [I] hdc : device context handle
10723 * [I] options : drawing options
10728 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10730 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10733 if (options
& ~(PRF_ERASEBKGND
|PRF_CLIENT
))
10734 FIXME("(hdc=%p options=0x%08x) partial stub\n", hdc
, options
);
10736 if (options
& PRF_ERASEBKGND
)
10737 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10739 if (options
& PRF_CLIENT
)
10740 LISTVIEW_Paint(infoPtr
, hdc
);
10748 * Processes double click messages (right mouse button).
10751 * [I] infoPtr : valid pointer to the listview structure
10752 * [I] wKey : key flag
10753 * [I] x,y : mouse coordinate
10758 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10760 LVHITTESTINFO lvHitTestInfo
;
10762 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10764 /* send NM_RELEASEDCAPTURE notification */
10765 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10767 /* send NM_RDBLCLK notification */
10768 lvHitTestInfo
.pt
.x
= x
;
10769 lvHitTestInfo
.pt
.y
= y
;
10770 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10771 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10778 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10781 * [I] infoPtr : valid pointer to the listview structure
10782 * [I] wKey : key flag
10783 * [I] x, y : mouse coordinate
10788 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10793 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10795 /* send NM_RELEASEDCAPTURE notification */
10796 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10798 /* determine the index of the selected item */
10801 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10803 /* make sure the listview control window has the focus */
10804 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10806 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10808 LISTVIEW_SetItemFocus(infoPtr
, item
);
10809 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10810 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10811 LISTVIEW_SetSelection(infoPtr
, item
);
10814 LISTVIEW_DeselectAll(infoPtr
);
10816 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10818 if (ht
.iItem
!= -1)
10822 memset(&nmlv
, 0, sizeof(nmlv
));
10823 nmlv
.iItem
= ht
.iItem
;
10824 nmlv
.ptAction
= ht
.pt
;
10826 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10831 SetFocus(infoPtr
->hwndSelf
);
10835 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10837 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10839 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10840 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10841 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10853 * [I] infoPtr : valid pointer to the listview structure
10854 * [I] hwnd : window handle of window containing the cursor
10855 * [I] nHittest : hit-test code
10856 * [I] wMouseMsg : ideintifier of the mouse message
10859 * TRUE if cursor is set
10862 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10864 LVHITTESTINFO lvHitTestInfo
;
10866 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10868 if (!infoPtr
->hHotCursor
) goto forward
;
10870 GetCursorPos(&lvHitTestInfo
.pt
);
10871 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10873 SetCursor(infoPtr
->hHotCursor
);
10879 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10887 * [I] infoPtr : valid pointer to the listview structure
10888 * [I] hwndLoseFocus : handle of previously focused window
10893 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10895 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10897 /* if we have the focus already, there's nothing to do */
10898 if (infoPtr
->bFocus
) return 0;
10900 /* send NM_SETFOCUS notification */
10901 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10903 /* set window focus flag */
10904 infoPtr
->bFocus
= TRUE
;
10906 /* put the focus rect back on */
10907 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10909 /* redraw all visible selected items */
10910 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10920 * [I] infoPtr : valid pointer to the listview structure
10921 * [I] fRedraw : font handle
10922 * [I] fRedraw : redraw flag
10927 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10929 HFONT oldFont
= infoPtr
->hFont
;
10930 INT oldHeight
= infoPtr
->nItemHeight
;
10932 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10934 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10935 if (infoPtr
->hFont
== oldFont
) return 0;
10937 LISTVIEW_SaveTextMetrics(infoPtr
);
10939 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10941 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10943 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10944 LISTVIEW_UpdateSize(infoPtr
);
10945 LISTVIEW_UpdateScroll(infoPtr
);
10947 else if (infoPtr
->nItemHeight
!= oldHeight
)
10948 LISTVIEW_UpdateScroll(infoPtr
);
10950 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10957 * Message handling for WM_SETREDRAW.
10958 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10961 * [I] infoPtr : valid pointer to the listview structure
10962 * [I] redraw: state of redraw flag
10967 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL redraw
)
10969 TRACE("old=%d, new=%d\n", infoPtr
->redraw
, redraw
);
10971 if (infoPtr
->redraw
== !!redraw
)
10974 if (!(infoPtr
->redraw
= !!redraw
))
10977 if (is_autoarrange(infoPtr
))
10978 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10979 LISTVIEW_UpdateScroll(infoPtr
);
10981 /* despite what the WM_SETREDRAW docs says, apps expect us
10982 * to invalidate the listview here... stupid! */
10983 LISTVIEW_InvalidateList(infoPtr
);
10990 * Resizes the listview control. This function processes WM_SIZE
10991 * messages. At this time, the width and height are not used.
10994 * [I] infoPtr : valid pointer to the listview structure
10995 * [I] Width : new width
10996 * [I] Height : new height
11001 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
11003 RECT rcOld
= infoPtr
->rcList
;
11005 TRACE("(width=%d, height=%d)\n", Width
, Height
);
11007 LISTVIEW_UpdateSize(infoPtr
);
11008 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
11010 /* do not bother with display related stuff if we're not redrawing */
11011 if (!is_redrawing(infoPtr
)) return 0;
11013 if (is_autoarrange(infoPtr
))
11014 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11016 LISTVIEW_UpdateScroll(infoPtr
);
11018 /* refresh all only for lists whose height changed significantly */
11019 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11020 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11021 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11022 LISTVIEW_InvalidateList(infoPtr
);
11029 * Sets the size information.
11032 * [I] infoPtr : valid pointer to the listview structure
11037 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11039 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11041 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11043 if (infoPtr
->uView
== LV_VIEW_LIST
)
11045 /* Apparently the "LIST" style is supposed to have the same
11046 * number of items in a column even if there is no scroll bar.
11047 * Since if a scroll bar already exists then the bottom is already
11048 * reduced, only reduce if the scroll bar does not currently exist.
11049 * The "2" is there to mimic the native control. I think it may be
11050 * related to either padding or edges. (GLA 7/2002)
11052 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11053 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11054 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11057 /* When ListView control is created invisible, header isn't created right away. */
11058 if (infoPtr
->hwndHeader
)
11065 LISTVIEW_GetOrigin(infoPtr
, &origin
);
11067 rect
= infoPtr
->rcList
;
11068 rect
.left
+= origin
.x
;
11072 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11073 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11075 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11076 wp
.flags
|= SWP_SHOWWINDOW
;
11079 wp
.flags
|= SWP_HIDEWINDOW
;
11083 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11084 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11086 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11088 /* extra padding for grid */
11089 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11090 infoPtr
->rcList
.top
+= 2;
11092 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11097 * Processes WM_STYLECHANGED messages.
11100 * [I] infoPtr : valid pointer to the listview structure
11101 * [I] wStyleType : window style type (normal or extended)
11102 * [I] lpss : window style information
11107 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11108 const STYLESTRUCT
*lpss
)
11110 UINT uNewView
, uOldView
;
11113 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11114 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11116 if (wStyleType
!= GWL_STYLE
|| lpss
->styleNew
== infoPtr
->dwStyle
) return 0;
11118 infoPtr
->dwStyle
= lpss
->styleNew
;
11120 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11121 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11122 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11124 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11125 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11126 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11128 uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11129 uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11131 if (uNewView
!= uOldView
)
11135 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11136 changing style updates current view only when view bits change. */
11137 map_style_view(infoPtr
);
11138 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11139 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11141 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11142 SetRectEmpty(&infoPtr
->rcFocus
);
11144 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11145 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11147 if (uNewView
== LVS_REPORT
)
11152 LISTVIEW_CreateHeader( infoPtr
);
11154 hl
.prc
= &infoPtr
->rcList
;
11156 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11157 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11158 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11159 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11162 LISTVIEW_UpdateItemSize(infoPtr
);
11165 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11167 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11169 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11171 /* Turn off the header control */
11172 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11173 TRACE("Hide header control, was 0x%08x\n", style
);
11174 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11176 /* Turn on the header control */
11177 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11179 TRACE("Show header control, was 0x%08x\n", style
);
11180 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11186 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11187 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11188 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11190 /* update the size of the client area */
11191 LISTVIEW_UpdateSize(infoPtr
);
11193 /* add scrollbars if needed */
11194 LISTVIEW_UpdateScroll(infoPtr
);
11196 /* invalidate client area + erase background */
11197 LISTVIEW_InvalidateList(infoPtr
);
11204 * Processes WM_STYLECHANGING messages.
11207 * [I] wStyleType : window style type (normal or extended)
11208 * [I0] lpss : window style information
11213 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11216 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11217 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11219 /* don't forward LVS_OWNERDATA only if not already set to */
11220 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11222 if (lpss
->styleOld
& LVS_OWNERDATA
)
11223 lpss
->styleNew
|= LVS_OWNERDATA
;
11225 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11233 * Processes WM_SHOWWINDOW messages.
11236 * [I] infoPtr : valid pointer to the listview structure
11237 * [I] bShown : window is being shown (FALSE when hidden)
11238 * [I] iStatus : window show status
11243 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11245 /* header delayed creation */
11246 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11248 LISTVIEW_CreateHeader(infoPtr
);
11250 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11251 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11254 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11259 * Processes CCM_GETVERSION messages.
11262 * [I] infoPtr : valid pointer to the listview structure
11267 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11269 return infoPtr
->iVersion
;
11274 * Processes CCM_SETVERSION messages.
11277 * [I] infoPtr : valid pointer to the listview structure
11278 * [I] iVersion : version to be set
11281 * -1 when requested version is greater than DLL version;
11282 * previous version otherwise
11284 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11286 INT iOldVersion
= infoPtr
->iVersion
;
11288 if (iVersion
> COMCTL32_VERSION
)
11291 infoPtr
->iVersion
= iVersion
;
11293 TRACE("new version %d\n", iVersion
);
11295 return iOldVersion
;
11300 * Window procedure of the listview control.
11303 static LRESULT WINAPI
11304 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11306 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11308 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11310 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11311 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11315 case LVM_APPROXIMATEVIEWRECT
:
11316 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11317 LOWORD(lParam
), HIWORD(lParam
));
11319 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11321 case LVM_CANCELEDITLABEL
:
11322 return LISTVIEW_CancelEditLabel(infoPtr
);
11324 case LVM_CREATEDRAGIMAGE
:
11325 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11327 case LVM_DELETEALLITEMS
:
11328 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11330 case LVM_DELETECOLUMN
:
11331 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11333 case LVM_DELETEITEM
:
11334 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11336 case LVM_EDITLABELA
:
11337 case LVM_EDITLABELW
:
11338 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11339 uMsg
== LVM_EDITLABELW
);
11340 /* case LVM_ENABLEGROUPVIEW: */
11342 case LVM_ENSUREVISIBLE
:
11343 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11345 case LVM_FINDITEMW
:
11346 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11348 case LVM_FINDITEMA
:
11349 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11351 case LVM_GETBKCOLOR
:
11352 return infoPtr
->clrBk
;
11354 /* case LVM_GETBKIMAGE: */
11356 case LVM_GETCALLBACKMASK
:
11357 return infoPtr
->uCallbackMask
;
11359 case LVM_GETCOLUMNA
:
11360 case LVM_GETCOLUMNW
:
11361 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11362 uMsg
== LVM_GETCOLUMNW
);
11364 case LVM_GETCOLUMNORDERARRAY
:
11365 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11367 case LVM_GETCOLUMNWIDTH
:
11368 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11370 case LVM_GETCOUNTPERPAGE
:
11371 return LISTVIEW_GetCountPerPage(infoPtr
);
11373 case LVM_GETEDITCONTROL
:
11374 return (LRESULT
)infoPtr
->hwndEdit
;
11376 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11377 return infoPtr
->dwLvExStyle
;
11379 /* case LVM_GETGROUPINFO: */
11381 /* case LVM_GETGROUPMETRICS: */
11383 case LVM_GETHEADER
:
11384 return (LRESULT
)infoPtr
->hwndHeader
;
11386 case LVM_GETHOTCURSOR
:
11387 return (LRESULT
)infoPtr
->hHotCursor
;
11389 case LVM_GETHOTITEM
:
11390 return infoPtr
->nHotItem
;
11392 case LVM_GETHOVERTIME
:
11393 return infoPtr
->dwHoverTime
;
11395 case LVM_GETIMAGELIST
:
11396 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11398 /* case LVM_GETINSERTMARK: */
11400 /* case LVM_GETINSERTMARKCOLOR: */
11402 /* case LVM_GETINSERTMARKRECT: */
11404 case LVM_GETISEARCHSTRINGA
:
11405 case LVM_GETISEARCHSTRINGW
:
11406 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11411 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11413 case LVM_GETITEMCOUNT
:
11414 return infoPtr
->nItemCount
;
11416 case LVM_GETITEMPOSITION
:
11417 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11419 case LVM_GETITEMRECT
:
11420 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11422 case LVM_GETITEMSPACING
:
11423 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11425 case LVM_GETITEMSTATE
:
11426 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11428 case LVM_GETITEMTEXTA
:
11429 case LVM_GETITEMTEXTW
:
11430 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11431 uMsg
== LVM_GETITEMTEXTW
);
11433 case LVM_GETNEXTITEM
:
11434 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11436 case LVM_GETNUMBEROFWORKAREAS
:
11437 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11440 case LVM_GETORIGIN
:
11441 if (!lParam
) return FALSE
;
11442 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11443 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11444 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11447 /* case LVM_GETOUTLINECOLOR: */
11449 case LVM_GETSELECTEDCOLUMN
:
11450 return infoPtr
->selected_column
;
11452 case LVM_GETSELECTEDCOUNT
:
11453 return LISTVIEW_GetSelectedCount(infoPtr
);
11455 case LVM_GETSELECTIONMARK
:
11456 return infoPtr
->nSelectionMark
;
11458 case LVM_GETSTRINGWIDTHA
:
11459 case LVM_GETSTRINGWIDTHW
:
11460 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11461 uMsg
== LVM_GETSTRINGWIDTHW
);
11463 case LVM_GETSUBITEMRECT
:
11464 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11466 case LVM_GETTEXTBKCOLOR
:
11467 return infoPtr
->clrTextBk
;
11469 case LVM_GETTEXTCOLOR
:
11470 return infoPtr
->clrText
;
11472 /* case LVM_GETTILEINFO: */
11474 /* case LVM_GETTILEVIEWINFO: */
11476 case LVM_GETTOOLTIPS
:
11477 if( !infoPtr
->hwndToolTip
)
11478 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11479 return (LRESULT
)infoPtr
->hwndToolTip
;
11481 case LVM_GETTOPINDEX
:
11482 return LISTVIEW_GetTopIndex(infoPtr
);
11484 case LVM_GETUNICODEFORMAT
:
11485 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11488 return infoPtr
->uView
;
11490 case LVM_GETVIEWRECT
:
11491 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11493 case LVM_GETWORKAREAS
:
11494 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11497 /* case LVM_HASGROUP: */
11500 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11502 case LVM_INSERTCOLUMNA
:
11503 case LVM_INSERTCOLUMNW
:
11504 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11505 uMsg
== LVM_INSERTCOLUMNW
);
11507 /* case LVM_INSERTGROUP: */
11509 /* case LVM_INSERTGROUPSORTED: */
11511 case LVM_INSERTITEMA
:
11512 case LVM_INSERTITEMW
:
11513 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11515 /* case LVM_INSERTMARKHITTEST: */
11517 /* case LVM_ISGROUPVIEWENABLED: */
11519 case LVM_ISITEMVISIBLE
:
11520 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11522 case LVM_MAPIDTOINDEX
:
11523 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11525 case LVM_MAPINDEXTOID
:
11526 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11528 /* case LVM_MOVEGROUP: */
11530 /* case LVM_MOVEITEMTOGROUP: */
11532 case LVM_REDRAWITEMS
:
11533 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11535 /* case LVM_REMOVEALLGROUPS: */
11537 /* case LVM_REMOVEGROUP: */
11540 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11542 case LVM_SETBKCOLOR
:
11543 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11545 /* case LVM_SETBKIMAGE: */
11547 case LVM_SETCALLBACKMASK
:
11548 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11551 case LVM_SETCOLUMNA
:
11552 case LVM_SETCOLUMNW
:
11553 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11554 uMsg
== LVM_SETCOLUMNW
);
11556 case LVM_SETCOLUMNORDERARRAY
:
11557 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11559 case LVM_SETCOLUMNWIDTH
:
11560 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11562 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11563 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11565 /* case LVM_SETGROUPINFO: */
11567 /* case LVM_SETGROUPMETRICS: */
11569 case LVM_SETHOTCURSOR
:
11570 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11572 case LVM_SETHOTITEM
:
11573 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11575 case LVM_SETHOVERTIME
:
11576 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11578 case LVM_SETICONSPACING
:
11580 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11581 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11583 case LVM_SETIMAGELIST
:
11584 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11586 /* case LVM_SETINFOTIP: */
11588 /* case LVM_SETINSERTMARK: */
11590 /* case LVM_SETINSERTMARKCOLOR: */
11595 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11596 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11599 case LVM_SETITEMCOUNT
:
11600 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11602 case LVM_SETITEMPOSITION
:
11605 pt
.x
= (short)LOWORD(lParam
);
11606 pt
.y
= (short)HIWORD(lParam
);
11607 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11610 case LVM_SETITEMPOSITION32
:
11611 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11613 case LVM_SETITEMSTATE
:
11614 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11616 case LVM_SETITEMTEXTA
:
11617 case LVM_SETITEMTEXTW
:
11618 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11619 uMsg
== LVM_SETITEMTEXTW
);
11621 /* case LVM_SETOUTLINECOLOR: */
11623 case LVM_SETSELECTEDCOLUMN
:
11624 infoPtr
->selected_column
= (INT
)wParam
;
11627 case LVM_SETSELECTIONMARK
:
11628 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11630 case LVM_SETTEXTBKCOLOR
:
11631 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11633 case LVM_SETTEXTCOLOR
:
11634 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11636 /* case LVM_SETTILEINFO: */
11638 /* case LVM_SETTILEVIEWINFO: */
11640 /* case LVM_SETTILEWIDTH: */
11642 case LVM_SETTOOLTIPS
:
11643 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11645 case LVM_SETUNICODEFORMAT
:
11646 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11649 return LISTVIEW_SetView(infoPtr
, wParam
);
11651 /* case LVM_SETWORKAREAS: */
11653 /* case LVM_SORTGROUPS: */
11655 case LVM_SORTITEMS
:
11656 case LVM_SORTITEMSEX
:
11657 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11658 uMsg
== LVM_SORTITEMSEX
);
11659 case LVM_SUBITEMHITTEST
:
11660 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11663 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11665 case CCM_GETVERSION
:
11666 return LISTVIEW_GetVersion(infoPtr
);
11668 case CCM_SETVERSION
:
11669 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11672 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11675 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11678 return LISTVIEW_NCCreate(hwnd
, wParam
, (LPCREATESTRUCTW
)lParam
);
11681 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11684 return LISTVIEW_Destroy(infoPtr
);
11687 return LISTVIEW_Enable(infoPtr
);
11689 case WM_ERASEBKGND
:
11690 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11692 case WM_GETDLGCODE
:
11693 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11696 return (LRESULT
)infoPtr
->hFont
;
11699 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11702 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11705 return LISTVIEW_KillFocus(infoPtr
);
11707 case WM_LBUTTONDBLCLK
:
11708 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11710 case WM_LBUTTONDOWN
:
11711 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11714 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11717 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11719 case WM_MOUSEHOVER
:
11720 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11723 return LISTVIEW_NCDestroy(infoPtr
);
11726 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11729 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11731 case WM_NOTIFYFORMAT
:
11732 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11734 case WM_PRINTCLIENT
:
11735 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11738 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11740 case WM_RBUTTONDBLCLK
:
11741 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11743 case WM_RBUTTONDOWN
:
11744 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11747 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11750 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11753 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11756 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11758 case WM_SHOWWINDOW
:
11759 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11761 case WM_STYLECHANGED
:
11762 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11764 case WM_STYLECHANGING
:
11765 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11767 case WM_SYSCOLORCHANGE
:
11768 COMCTL32_RefreshSysColors();
11771 /* case WM_TIMER: */
11772 case WM_THEMECHANGED
:
11773 return LISTVIEW_ThemeChanged(infoPtr
);
11776 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11778 case WM_MOUSEWHEEL
:
11779 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11780 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11781 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11783 case WM_WINDOWPOSCHANGED
:
11784 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11786 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11787 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11789 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11791 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11793 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11795 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11797 /* case WM_WININICHANGE: */
11800 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11801 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11803 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11810 * Registers the window class.
11818 void LISTVIEW_Register(void)
11820 WNDCLASSW wndClass
;
11822 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11823 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11824 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11825 wndClass
.cbClsExtra
= 0;
11826 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11827 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11828 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11829 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11830 RegisterClassW(&wndClass
);
11835 * Unregisters the window class.
11843 void LISTVIEW_Unregister(void)
11845 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11850 * Handle any WM_COMMAND messages
11853 * [I] infoPtr : valid pointer to the listview structure
11854 * [I] wParam : the first message parameter
11855 * [I] lParam : the second message parameter
11860 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11863 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11865 if (!infoPtr
->hwndEdit
) return 0;
11867 switch (HIWORD(wParam
))
11872 * Adjust the edit window size
11874 WCHAR buffer
[1024];
11875 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11876 HFONT hFont
, hOldFont
= 0;
11880 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11881 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, ARRAY_SIZE(buffer
));
11882 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11884 /* Select font to get the right dimension of the string */
11885 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11888 hOldFont
= SelectObject(hdc
, hFont
);
11891 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11893 TEXTMETRICW textMetric
;
11895 /* Add Extra spacing for the next character */
11896 GetTextMetricsW(hdc
, &textMetric
);
11897 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11899 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11900 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11903 SelectObject(hdc
, hOldFont
);
11905 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11911 if (infoPtr
->notify_mask
& NOTIFY_MASK_END_LABEL_EDIT
)
11912 LISTVIEW_CancelEditLabel(infoPtr
);
11917 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);