4 * Copyright 1998, 1999 Eric Kohl
5 * Copyright 1999 Luc Tourangeau
6 * Copyright 2000 Jason Mawdsley
7 * Copyright 2001 CodeWeavers Inc.
8 * Copyright 2002 Dimitrie O. Paun
9 * Copyright 2009-2015 Nikolay Sivov
10 * Copyright 2009 Owen Rudge for CodeWeavers
11 * Copyright 2012-2013 Daniel Jelinski
13 * This library is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU Lesser General Public
15 * License as published by the Free Software Foundation; either
16 * version 2.1 of the License, or (at your option) any later version.
18 * This library is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 * Lesser General Public License for more details.
23 * You should have received a copy of the GNU Lesser General Public
24 * License along with this library; if not, write to the Free Software
25 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
29 * Default Message Processing
30 * -- WM_CREATE: create the icon and small icon image lists at this point only if
31 * the LVS_SHAREIMAGELISTS style is not specified.
32 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
33 * or small icon and the LVS_AUTOARRANGE style is specified.
38 * -- Hot item handling, mouse hovering
39 * -- Workareas support
44 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
45 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
46 * -- LVA_SNAPTOGRID not implemented
47 * -- LISTVIEW_ApproximateViewRect partially implemented
48 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
51 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
52 * linear in the number of items in the list, and this is
53 * unacceptable for large lists.
54 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
55 * binary search to calculate item index (e.g. DPA_Search()).
56 * This requires sorted state to be reliably tracked in item modifiers.
57 * -- we should keep an ordered array of coordinates in iconic mode.
58 * This would allow framing items (iterator_frameditems),
59 * and finding the nearest item (LVFI_NEARESTXY) a lot more efficiently.
66 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
71 * -- LVS_NOSCROLL (see Q137520)
75 * -- LVS_EX_BORDERSELECT
79 * -- LVS_EX_MULTIWORKAREAS
81 * -- LVS_EX_SIMPLESELECT
82 * -- LVS_EX_TWOCLICKACTIVATE
83 * -- LVS_EX_UNDERLINECOLD
84 * -- LVS_EX_UNDERLINEHOT
87 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
93 * -- LVM_ENABLEGROUPVIEW
94 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
95 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
96 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
97 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
98 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
99 * -- LVM_GETINSERTMARKRECT
100 * -- LVM_GETNUMBEROFWORKAREAS
101 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
102 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
103 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
104 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
105 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
106 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
107 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
108 * -- LVM_INSERTGROUPSORTED
109 * -- LVM_INSERTMARKHITTEST
110 * -- LVM_ISGROUPVIEWENABLED
112 * -- LVM_MOVEITEMTOGROUP
114 * -- LVM_SETTILEWIDTH
118 * -- ListView_GetHoverTime, ListView_SetHoverTime
119 * -- ListView_GetISearchString
120 * -- ListView_GetNumberOfWorkAreas
121 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
140 #include "commctrl.h"
141 #include "comctl32.h"
144 #include "wine/debug.h"
146 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
148 typedef struct tagCOLUMN_INFO
150 RECT rcHeader
; /* tracks the header's rectangle */
151 INT fmt
; /* same as LVCOLUMN.fmt */
155 typedef struct tagITEMHDR
159 } ITEMHDR
, *LPITEMHDR
;
161 typedef struct tagSUBITEM_INFO
167 typedef struct tagITEM_ID ITEM_ID
;
169 typedef struct tagITEM_INFO
180 UINT id
; /* item id */
181 HDPA item
; /* link to item data */
184 typedef struct tagRANGE
190 typedef struct tagRANGES
195 typedef struct tagITERATOR
204 typedef struct tagDELAYED_ITEM_EDIT
210 enum notification_mask
212 NOTIFY_MASK_ITEM_CHANGE
= 0x1,
213 NOTIFY_MASK_END_LABEL_EDIT
= 0x2,
214 NOTIFY_MASK_UNMASK_ALL
= 0xffffffff
217 typedef struct tagLISTVIEW_INFO
221 RECT rcList
; /* This rectangle is really the window
222 * client rectangle possibly reduced by the
223 * horizontal scroll bar and/or header - see
224 * LISTVIEW_UpdateSize. This rectangle offset
225 * by the LISTVIEW_GetOrigin value is in
226 * client coordinates */
228 /* notification window */
238 INT nItemCount
; /* the number of items in the list */
239 HDPA hdpaItems
; /* array ITEM_INFO pointers */
240 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
241 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
242 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
243 RANGES selectionRanges
;
244 INT nSelectionMark
; /* item to start next multiselection from */
248 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
249 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
252 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
257 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
261 DWORD dwStyle
; /* the cached window GWL_STYLE */
262 DWORD dwLvExStyle
; /* extended listview style */
263 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
269 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
272 HIMAGELIST himlNormal
;
273 HIMAGELIST himlSmall
;
274 HIMAGELIST himlState
;
279 POINT currIconPos
; /* this is the position next icon will be placed */
283 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
285 /* marquee selection */
286 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
288 RECT marqueeRect
; /* absolute coordinates of marquee selection */
289 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
290 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
293 BOOL bFocus
; /* control has focus */
295 RECT rcFocus
; /* focus bounds */
303 BOOL bDefaultBkColor
;
309 INT ntmHeight
; /* Some cached metrics of the font used */
310 INT ntmMaxCharWidth
; /* by the listview to draw items */
313 /* mouse operation */
316 POINT ptClickPos
; /* point where the user clicked */
317 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
322 /* keyboard operation */
323 DWORD lastKeyPressTimestamp
;
325 INT nSearchParamLength
;
326 WCHAR szSearchParam
[ MAX_PATH
];
329 BOOL bIsDrawing
; /* Drawing in progress */
330 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
331 BOOL redraw
; /* WM_SETREDRAW switch */
334 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
340 /* How many we debug buffer to allocate */
341 #define DEBUG_BUFFERS 20
342 /* The size of a single debug buffer */
343 #define DEBUG_BUFFER_SIZE 256
345 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
346 #define SB_INTERNAL -1
348 /* maximum size of a label */
349 #define DISP_TEXT_SIZE 260
351 /* padding for items in list and small icon display modes */
352 #define WIDTH_PADDING 12
354 /* padding for items in list, report and small icon display modes */
355 #define HEIGHT_PADDING 1
357 /* offset of items in report display mode */
358 #define REPORT_MARGINX 2
360 /* padding for icon in large icon display mode
361 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
362 * that HITTEST will see.
363 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
364 * ICON_TOP_PADDING - sum of the two above.
365 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
366 * LABEL_HOR_PADDING - between text and sides of box
367 * LABEL_VERT_PADDING - between bottom of text and end of box
369 * ICON_LR_PADDING - additional width above icon size.
370 * ICON_LR_HALF - half of the above value
372 #define ICON_TOP_PADDING_NOTHITABLE 2
373 #define ICON_TOP_PADDING_HITABLE 2
374 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
375 #define ICON_BOTTOM_PADDING 4
376 #define LABEL_HOR_PADDING 5
377 #define LABEL_VERT_PADDING 7
378 #define ICON_LR_PADDING 16
379 #define ICON_LR_HALF (ICON_LR_PADDING/2)
381 /* default label width for items in list and small icon display modes */
382 #define DEFAULT_LABEL_WIDTH 40
383 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
384 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
386 /* default column width for items in list display mode */
387 #define DEFAULT_COLUMN_WIDTH 128
389 /* Size of "line" scroll for V & H scrolls */
390 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
392 /* Padding between image and label */
393 #define IMAGE_PADDING 2
395 /* Padding behind the label */
396 #define TRAILING_LABEL_PADDING 12
397 #define TRAILING_HEADER_PADDING 11
399 /* Border for the icon caption */
400 #define CAPTION_BORDER 2
402 /* Standard DrawText flags */
403 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
404 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
405 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
407 /* Image index from state */
408 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
410 /* The time in milliseconds to reset the search in the list */
411 #define KEY_DELAY 450
413 /* Dump the LISTVIEW_INFO structure to the debug channel */
414 #define LISTVIEW_DUMP(iP) do { \
415 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
416 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
417 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
418 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
419 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
420 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
421 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
422 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
423 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
424 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
427 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
430 * forward declarations
432 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
433 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
434 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
435 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
436 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
437 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
438 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
439 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
440 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
441 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
442 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
443 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
444 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
445 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
446 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
447 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
448 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
449 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
450 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
451 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
453 /******** Text handling functions *************************************/
455 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
456 * text string. The string may be ANSI or Unicode, in which case
457 * the boolean isW tells us the type of the string.
459 * The name of the function tell what type of strings it expects:
460 * W: Unicode, T: ANSI/Unicode - function of isW
463 static inline BOOL
is_text(LPCWSTR text
)
465 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
468 static inline int textlenT(LPCWSTR text
, BOOL isW
)
470 return !is_text(text
) ? 0 :
471 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
474 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
477 if (isSrcW
) lstrcpynW(dest
, src
, max
);
478 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
480 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
481 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
484 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
486 LPWSTR wstr
= (LPWSTR
)text
;
488 if (!isW
&& is_text(text
))
490 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
491 wstr
= Alloc(len
* sizeof(WCHAR
));
492 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
494 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
498 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
500 if (!isW
&& is_text(wstr
)) Free (wstr
);
504 * dest is a pointer to a Unicode string
505 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
507 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
511 if (src
== LPSTR_TEXTCALLBACKW
)
513 if (is_text(*dest
)) Free(*dest
);
514 *dest
= LPSTR_TEXTCALLBACKW
;
518 LPWSTR pszText
= textdupTtoW(src
, isW
);
519 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
520 bResult
= Str_SetPtrW(dest
, pszText
);
521 textfreeT(pszText
, isW
);
527 * compares a Unicode to a Unicode/ANSI text string
529 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
531 if (!aw
) return bt
? -1 : 0;
533 if (aw
== LPSTR_TEXTCALLBACKW
)
534 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
535 if (bt
!= LPSTR_TEXTCALLBACKW
)
537 LPWSTR bw
= textdupTtoW(bt
, isW
);
538 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
546 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
548 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
549 return CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
) - CSTR_EQUAL
;
552 /******** Debugging functions *****************************************/
554 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
556 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
557 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
560 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
562 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
563 n
= min(textlenT(text
, isW
), n
);
564 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
567 static char* debug_getbuf(void)
569 static int index
= 0;
570 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
571 return buffers
[index
++ % DEBUG_BUFFERS
];
574 static inline const char* debugrange(const RANGE
*lprng
)
576 if (!lprng
) return "(null)";
577 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
580 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
582 char* buf
= debug_getbuf(), *text
= buf
;
583 int len
, size
= DEBUG_BUFFER_SIZE
;
585 if (pScrollInfo
== NULL
) return "(null)";
586 len
= snprintf(buf
, size
, "{cbSize=%u, ", pScrollInfo
->cbSize
);
587 if (len
== -1) goto end
;
588 buf
+= len
; size
-= len
;
589 if (pScrollInfo
->fMask
& SIF_RANGE
)
590 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
592 if (len
== -1) goto end
;
593 buf
+= len
; size
-= len
;
594 if (pScrollInfo
->fMask
& SIF_PAGE
)
595 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
597 if (len
== -1) goto end
;
598 buf
+= len
; size
-= len
;
599 if (pScrollInfo
->fMask
& SIF_POS
)
600 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
602 if (len
== -1) goto end
;
603 buf
+= len
; size
-= len
;
604 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
605 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
607 if (len
== -1) goto end
;
611 buf
= text
+ strlen(text
);
613 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
617 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
619 if (!plvnm
) return "(null)";
620 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
621 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
622 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
623 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
626 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
628 char* buf
= debug_getbuf(), *text
= buf
;
629 int len
, size
= DEBUG_BUFFER_SIZE
;
631 if (lpLVItem
== NULL
) return "(null)";
632 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
633 if (len
== -1) goto end
;
634 buf
+= len
; size
-= len
;
635 if (lpLVItem
->mask
& LVIF_STATE
)
636 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
638 if (len
== -1) goto end
;
639 buf
+= len
; size
-= len
;
640 if (lpLVItem
->mask
& LVIF_TEXT
)
641 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
643 if (len
== -1) goto end
;
644 buf
+= len
; size
-= len
;
645 if (lpLVItem
->mask
& LVIF_IMAGE
)
646 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
648 if (len
== -1) goto end
;
649 buf
+= len
; size
-= len
;
650 if (lpLVItem
->mask
& LVIF_PARAM
)
651 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
653 if (len
== -1) goto end
;
654 buf
+= len
; size
-= len
;
655 if (lpLVItem
->mask
& LVIF_INDENT
)
656 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
658 if (len
== -1) goto end
;
662 buf
= text
+ strlen(text
);
664 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
668 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
670 char* buf
= debug_getbuf(), *text
= buf
;
671 int len
, size
= DEBUG_BUFFER_SIZE
;
673 if (lpColumn
== NULL
) return "(null)";
674 len
= snprintf(buf
, size
, "{");
675 if (len
== -1) goto end
;
676 buf
+= len
; size
-= len
;
677 if (lpColumn
->mask
& LVCF_SUBITEM
)
678 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
680 if (len
== -1) goto end
;
681 buf
+= len
; size
-= len
;
682 if (lpColumn
->mask
& LVCF_FMT
)
683 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
685 if (len
== -1) goto end
;
686 buf
+= len
; size
-= len
;
687 if (lpColumn
->mask
& LVCF_WIDTH
)
688 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
690 if (len
== -1) goto end
;
691 buf
+= len
; size
-= len
;
692 if (lpColumn
->mask
& LVCF_TEXT
)
693 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
695 if (len
== -1) goto end
;
696 buf
+= len
; size
-= len
;
697 if (lpColumn
->mask
& LVCF_IMAGE
)
698 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
700 if (len
== -1) goto end
;
701 buf
+= len
; size
-= len
;
702 if (lpColumn
->mask
& LVCF_ORDER
)
703 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
705 if (len
== -1) goto end
;
709 buf
= text
+ strlen(text
);
711 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
715 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
717 if (!lpht
) return "(null)";
719 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
720 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
723 /* Return the corresponding text for a given scroll value */
724 static inline LPCSTR
debugscrollcode(int nScrollCode
)
728 case SB_LINELEFT
: return "SB_LINELEFT";
729 case SB_LINERIGHT
: return "SB_LINERIGHT";
730 case SB_PAGELEFT
: return "SB_PAGELEFT";
731 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
732 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
733 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
734 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
735 case SB_INTERNAL
: return "SB_INTERNAL";
736 default: return "unknown";
741 /******** Notification functions ************************************/
743 static int get_ansi_notification(UINT unicodeNotificationCode
)
745 switch (unicodeNotificationCode
)
747 case LVN_BEGINLABELEDITA
:
748 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
749 case LVN_ENDLABELEDITA
:
750 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
751 case LVN_GETDISPINFOA
:
752 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
753 case LVN_SETDISPINFOA
:
754 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
755 case LVN_ODFINDITEMA
:
756 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
757 case LVN_GETINFOTIPA
:
758 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
759 /* header forwards */
761 case HDN_TRACKW
: return HDN_TRACKA
;
763 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
764 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
765 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
766 case HDN_ITEMCHANGINGA
:
767 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
768 case HDN_ITEMCHANGEDA
:
769 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
771 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
772 case HDN_DIVIDERDBLCLICKA
:
773 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
776 FIXME("unknown notification %x\n", unicodeNotificationCode
);
777 return unicodeNotificationCode
;
780 /* forwards header notifications to listview parent */
781 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
783 LPCWSTR text
= NULL
, filter
= NULL
;
785 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
787 /* on unicode format exit earlier */
788 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
789 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
792 /* header always supplies unicode notifications,
793 all we have to do is to convert strings to ANSI */
796 /* convert item text */
797 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
799 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
800 lpnmh
->pitem
->pszText
= NULL
;
801 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
803 /* convert filter text */
804 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
805 lpnmh
->pitem
->pvFilter
)
807 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
808 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= NULL
;
809 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
812 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
814 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
820 Free(lpnmh
->pitem
->pszText
);
821 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
825 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
826 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
832 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
836 TRACE("(code=%d)\n", code
);
838 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
839 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
841 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
843 TRACE(" <= %ld\n", result
);
848 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
851 HWND hwnd
= infoPtr
->hwndSelf
;
852 notify_hdr(infoPtr
, code
, &nmh
);
853 return IsWindow(hwnd
);
856 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
866 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
867 item
.iItem
= htInfo
->iItem
;
869 item
.stateMask
= (UINT
)-1;
870 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
871 nmia
.lParam
= item
.lParam
;
872 nmia
.uOldState
= item
.state
;
873 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
874 nmia
.uChanged
= LVIF_STATE
;
877 nmia
.iItem
= htInfo
->iItem
;
878 nmia
.iSubItem
= htInfo
->iSubItem
;
879 nmia
.ptAction
= htInfo
->pt
;
881 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
882 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
883 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
885 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
888 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
890 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
891 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
894 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
895 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
899 HWND hwnd
= infoPtr
->hwndSelf
;
902 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
903 ZeroMemory(&nmia
, sizeof(nmia
));
904 nmia
.iItem
= lvht
->iItem
;
905 nmia
.iSubItem
= lvht
->iSubItem
;
906 nmia
.ptAction
= lvht
->pt
;
907 item
.mask
= LVIF_PARAM
;
908 item
.iItem
= lvht
->iItem
;
910 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
911 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
912 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
915 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
919 HWND hwnd
= infoPtr
->hwndSelf
;
921 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
923 item
.mask
= LVIF_PARAM
;
926 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
927 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
928 return IsWindow(hwnd
);
932 Send notification. depends on dispinfoW having same
933 structure as dispinfoA.
934 infoPtr : listview struct
935 code : *Unicode* notification code
936 pdi : dispinfo structure (can be unicode or ansi)
937 isW : TRUE if dispinfo is Unicode
939 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
941 INT length
= 0, ret_length
;
942 LPWSTR buffer
= NULL
, ret_text
;
943 BOOL return_ansi
= FALSE
;
944 BOOL return_unicode
= FALSE
;
947 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
949 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
950 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
953 ret_length
= pdi
->item
.cchTextMax
;
954 ret_text
= pdi
->item
.pszText
;
956 if (return_unicode
|| return_ansi
)
958 if (code
!= LVN_GETDISPINFOW
)
960 length
= return_ansi
?
961 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
962 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
966 length
= pdi
->item
.cchTextMax
;
967 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
970 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
971 if (!buffer
) return FALSE
;
974 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
977 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
980 pdi
->item
.pszText
= buffer
;
981 pdi
->item
.cchTextMax
= length
;
984 if (infoPtr
->notifyFormat
== NFR_ANSI
)
985 code
= get_ansi_notification(code
);
987 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
988 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
989 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
991 if (return_ansi
|| return_unicode
)
993 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
995 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
997 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
999 lstrcpyW(ret_text
, pdi
->item
.pszText
);
1001 else if (return_ansi
) /* note : pointer can be changed by app ! */
1003 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
1004 ret_length
, NULL
, NULL
);
1007 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
1008 ret_text
, ret_length
);
1010 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
1011 pdi
->item
.cchTextMax
= ret_length
;
1017 /* if dispinfo holder changed notification code then convert */
1018 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1020 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1022 buffer
= Alloc(length
* sizeof(CHAR
));
1023 if (!buffer
) return FALSE
;
1025 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1026 ret_length
, NULL
, NULL
);
1028 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1035 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1036 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1038 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1039 lpnmlvcd
->nmcd
.hdc
= hdc
;
1040 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1041 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1042 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1043 if (!lplvItem
) return;
1044 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1045 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1046 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1047 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1048 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1049 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1052 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1054 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1057 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1058 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1059 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1060 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1061 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1062 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1066 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1068 COLORREF backcolor
, textcolor
;
1070 /* apparently, for selected items, we have to override the returned values */
1071 if (!SubItem
|| (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
1073 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1075 if (infoPtr
->bFocus
)
1077 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1078 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1080 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1082 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1083 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1088 backcolor
= lpnmlvcd
->clrTextBk
;
1089 textcolor
= lpnmlvcd
->clrText
;
1091 if (backcolor
== CLR_DEFAULT
)
1092 backcolor
= comctl32_color
.clrWindow
;
1093 if (textcolor
== CLR_DEFAULT
)
1094 textcolor
= comctl32_color
.clrWindowText
;
1096 /* Set the text attributes */
1097 if (backcolor
!= CLR_NONE
)
1099 SetBkMode(hdc
, OPAQUE
);
1100 SetBkColor(hdc
, backcolor
);
1103 SetBkMode(hdc
, TRANSPARENT
);
1104 SetTextColor(hdc
, textcolor
);
1107 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1109 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1112 /* returns TRUE when repaint needed, FALSE otherwise */
1113 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1115 MEASUREITEMSTRUCT mis
;
1116 mis
.CtlType
= ODT_LISTVIEW
;
1117 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1121 mis
.itemHeight
= infoPtr
->nItemHeight
;
1122 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1123 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1125 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1131 /******** Item iterator functions **********************************/
1133 static RANGES
ranges_create(int count
);
1134 static void ranges_destroy(RANGES ranges
);
1135 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1136 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1137 static void ranges_dump(RANGES ranges
);
1139 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1141 RANGE range
= { nItem
, nItem
+ 1 };
1143 return ranges_add(ranges
, range
);
1146 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1148 RANGE range
= { nItem
, nItem
+ 1 };
1150 return ranges_del(ranges
, range
);
1154 * ITERATOR DOCUMENTATION
1156 * The iterator functions allow for easy, and convenient iteration
1157 * over items of interest in the list. Typically, you create an
1158 * iterator, use it, and destroy it, as such:
1161 * iterator_xxxitems(&i, ...);
1162 * while (iterator_{prev,next}(&i)
1164 * //code which uses i.nItem
1166 * iterator_destroy(&i);
1168 * where xxx is either: framed, or visible.
1169 * Note that it is important that the code destroys the iterator
1170 * after it's done with it, as the creation of the iterator may
1171 * allocate memory, which thus needs to be freed.
1173 * You can iterate both forwards, and backwards through the list,
1174 * by using iterator_next or iterator_prev respectively.
1176 * Lower numbered items are draw on top of higher number items in
1177 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1178 * items may overlap). So, to test items, you should use
1180 * which lists the items top to bottom (in Z-order).
1181 * For drawing items, you should use
1183 * which lists the items bottom to top (in Z-order).
1184 * If you keep iterating over the items after the end-of-items
1185 * marker (-1) is returned, the iterator will start from the
1186 * beginning. Typically, you don't need to test for -1,
1187 * because iterator_{next,prev} will return TRUE if more items
1188 * are to be iterated over, or FALSE otherwise.
1190 * Note: the iterator is defined to be bidirectional. That is,
1191 * any number of prev followed by any number of next, or
1192 * five versa, should leave the iterator at the same item:
1193 * prev * n, next * n = next * n, prev * n
1195 * The iterator has a notion of an out-of-order, special item,
1196 * which sits at the start of the list. This is used in
1197 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1198 * which needs to be first, as it may overlap other items.
1200 * The code is a bit messy because we have:
1201 * - a special item to deal with
1202 * - simple range, or composite range
1204 * If you find bugs, or want to add features, please make sure you
1205 * always check/modify *both* iterator_prev, and iterator_next.
1209 * This function iterates through the items in increasing order,
1210 * but prefixed by the special item, then -1. That is:
1211 * special, 1, 2, 3, ..., n, -1.
1212 * Each item is listed only once.
1214 static inline BOOL
iterator_next(ITERATOR
* i
)
1218 i
->nItem
= i
->nSpecial
;
1219 if (i
->nItem
!= -1) return TRUE
;
1221 if (i
->nItem
== i
->nSpecial
)
1223 if (i
->ranges
) i
->index
= 0;
1229 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1230 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1235 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1236 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1239 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1241 i
->nItem
= i
->range
.lower
;
1242 if (i
->nItem
>= 0) goto testitem
;
1249 * This function iterates through the items in decreasing order,
1250 * followed by the special item, then -1. That is:
1251 * n, n-1, ..., 3, 2, 1, special, -1.
1252 * Each item is listed only once.
1254 static inline BOOL
iterator_prev(ITERATOR
* i
)
1261 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1264 if (i
->nItem
== i
->nSpecial
)
1272 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1273 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1279 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1282 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1284 i
->nItem
= i
->range
.upper
;
1285 if (i
->nItem
> 0) goto testitem
;
1287 return (i
->nItem
= i
->nSpecial
) != -1;
1290 static RANGE
iterator_range(const ITERATOR
*i
)
1294 if (!i
->ranges
) return i
->range
;
1296 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1298 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1299 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1301 else range
.lower
= range
.upper
= 0;
1307 * Releases resources associated with this iterator.
1309 static inline void iterator_destroy(const ITERATOR
*i
)
1311 ranges_destroy(i
->ranges
);
1315 * Create an empty iterator.
1317 static inline void iterator_empty(ITERATOR
* i
)
1319 ZeroMemory(i
, sizeof(*i
));
1320 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1324 * Create an iterator over a range.
1326 static inline void iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1333 * Create an iterator over a bunch of ranges.
1334 * Please note that the iterator will take ownership of the ranges,
1335 * and will free them upon destruction.
1337 static inline void iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1344 * Creates an iterator over the items which intersect frame.
1345 * Uses absolute coordinates rather than compensating for the current offset.
1347 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1349 RECT rcItem
, rcTemp
;
1352 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1354 /* in case we fail, we want to return an empty iterator */
1357 if (infoPtr
->nItemCount
== 0)
1360 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1364 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1366 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1367 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1368 i
->nSpecial
= infoPtr
->nFocusedItem
;
1370 if (!(ranges
= ranges_create(50))) return FALSE
;
1371 iterator_rangesitems(i
, ranges
);
1372 /* to do better here, we need to have PosX, and PosY sorted */
1373 TRACE("building icon ranges:\n");
1374 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1376 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1377 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1378 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1379 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1380 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1381 ranges_additem(i
->ranges
, nItem
);
1385 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1389 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1390 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1392 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1393 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1394 if (range
.upper
<= range
.lower
) return TRUE
;
1395 iterator_rangeitems(i
, range
);
1396 TRACE(" report=%s\n", debugrange(&i
->range
));
1400 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1401 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1402 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1409 if (infoPtr
->nItemWidth
)
1411 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1412 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1416 nFirstCol
= max(frame
->left
, 0);
1417 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1420 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1422 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1423 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1425 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1427 if (!(ranges
= ranges_create(nLastCol
- nFirstCol
+ 1))) return FALSE
;
1428 iterator_rangesitems(i
, ranges
);
1429 TRACE("building list ranges:\n");
1430 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1432 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1433 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1434 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1435 TRACE(" list=%s\n", debugrange(&item_range
));
1436 ranges_add(i
->ranges
, item_range
);
1444 * Creates an iterator over the items which intersect lprc.
1446 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1451 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1453 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1454 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1456 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1460 * Creates an iterator over the items which intersect the visible region of hdc.
1462 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1464 POINT Origin
, Position
;
1465 RECT rcItem
, rcClip
;
1468 rgntype
= GetClipBox(hdc
, &rcClip
);
1469 if (rgntype
== NULLREGION
)
1474 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1475 if (rgntype
== SIMPLEREGION
) return TRUE
;
1477 /* first deal with the special item */
1478 if (i
->nSpecial
!= -1)
1480 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1481 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1484 /* if we can't deal with the region, we'll just go with the simple range */
1485 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1486 TRACE("building visible range:\n");
1487 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1489 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1490 if (!ranges_add(i
->ranges
, i
->range
))
1492 ranges_destroy(i
->ranges
);
1498 /* now delete the invisible items from the list */
1499 while(iterator_next(i
))
1501 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1502 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1503 rcItem
.top
= Position
.y
+ Origin
.y
;
1504 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1505 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1506 if (!RectVisible(hdc
, &rcItem
))
1507 ranges_delitem(i
->ranges
, i
->nItem
);
1509 /* the iterator should restart on the next iterator_next */
1515 /* Remove common elements from two iterators */
1516 /* Passed iterators have to point on the first elements */
1517 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1519 if(!iter1
->ranges
|| !iter2
->ranges
) {
1522 if(iter1
->ranges
|| iter2
->ranges
||
1523 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1524 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1525 ERR("result is not a one range iterator\n");
1529 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1532 lower
= iter1
->range
.lower
;
1533 upper
= iter1
->range
.upper
;
1535 if(lower
< iter2
->range
.lower
)
1536 iter1
->range
.upper
= iter2
->range
.lower
;
1537 else if(upper
> iter2
->range
.upper
)
1538 iter1
->range
.lower
= iter2
->range
.upper
;
1540 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1542 if(iter2
->range
.lower
< lower
)
1543 iter2
->range
.upper
= lower
;
1544 else if(iter2
->range
.upper
> upper
)
1545 iter2
->range
.lower
= upper
;
1547 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1552 iterator_next(iter1
);
1553 iterator_next(iter2
);
1556 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1559 if(iter1
->nItem
== iter2
->nItem
) {
1560 int delete = iter1
->nItem
;
1562 iterator_prev(iter1
);
1563 iterator_prev(iter2
);
1564 ranges_delitem(iter1
->ranges
, delete);
1565 ranges_delitem(iter2
->ranges
, delete);
1566 iterator_next(iter1
);
1567 iterator_next(iter2
);
1568 } else if(iter1
->nItem
> iter2
->nItem
)
1569 iterator_next(iter2
);
1571 iterator_next(iter1
);
1574 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1575 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1579 /******** Misc helper functions ************************************/
1581 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1582 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1584 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1585 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1588 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1590 return (infoPtr
->dwStyle
& LVS_AUTOARRANGE
) &&
1591 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1594 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1596 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1597 if(state
== 1 || state
== 2)
1601 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1602 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1603 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1607 /* this should be called after window style got updated,
1608 it used to reset view state to match current window style */
1609 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1611 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1614 infoPtr
->uView
= LV_VIEW_ICON
;
1617 infoPtr
->uView
= LV_VIEW_DETAILS
;
1620 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1623 infoPtr
->uView
= LV_VIEW_LIST
;
1627 /* computes next item id value */
1628 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1630 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1634 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1635 return lpID
->id
+ 1;
1640 /******** Internal API functions ************************************/
1642 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1644 static COLUMN_INFO mainItem
;
1646 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1647 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1649 /* update cached column rectangles */
1650 if (infoPtr
->colRectsDirty
)
1653 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1656 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1657 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1658 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1660 Ptr
->colRectsDirty
= FALSE
;
1663 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1666 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1668 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1671 if (infoPtr
->hwndHeader
) return 0;
1673 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1675 /* setup creation flags */
1676 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1677 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1679 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1682 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1683 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1684 if (!infoPtr
->hwndHeader
) return -1;
1686 /* set header unicode format */
1687 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1689 /* set header font */
1690 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1692 /* set header image list */
1693 if (infoPtr
->himlSmall
)
1694 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1696 LISTVIEW_UpdateSize(infoPtr
);
1701 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1703 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1706 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1708 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1709 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1710 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1713 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1715 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1718 /* used to handle collapse main item column case */
1719 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1724 if (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
)
1726 DWORD dwOldBkColor
, dwOldTextColor
;
1728 dwOldBkColor
= SetBkColor(hdc
, RGB(255, 255, 255));
1729 dwOldTextColor
= SetBkColor(hdc
, RGB(0, 0, 0));
1730 Ret
= DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1731 SetBkColor(hdc
, dwOldBkColor
);
1732 SetBkColor(hdc
, dwOldTextColor
);
1736 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1737 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1741 /* Listview invalidation functions: use _only_ these functions to invalidate */
1743 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1745 return infoPtr
->redraw
;
1748 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1750 if(!is_redrawing(infoPtr
)) return;
1751 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1752 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1755 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1759 if (!is_redrawing(infoPtr
) || nItem
< 0 || nItem
>= infoPtr
->nItemCount
)
1762 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1763 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1766 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1768 POINT Origin
, Position
;
1771 if(!is_redrawing(infoPtr
)) return;
1772 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1773 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1774 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1775 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1777 rcBox
.bottom
= infoPtr
->nItemHeight
;
1778 OffsetRect(&rcBox
, Origin
.x
, Origin
.y
+ Position
.y
);
1779 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1782 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1784 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1787 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1791 if(!is_redrawing(infoPtr
)) return;
1792 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1793 rcCol
.top
= infoPtr
->rcList
.top
;
1794 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1795 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1800 * Retrieves the number of items that can fit vertically in the client area.
1803 * [I] infoPtr : valid pointer to the listview structure
1806 * Number of items per row.
1808 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1810 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1812 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1817 * Retrieves the number of items that can fit horizontally in the client
1821 * [I] infoPtr : valid pointer to the listview structure
1824 * Number of items per column.
1826 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1828 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1830 return infoPtr
->nItemHeight
? max(nListHeight
/ infoPtr
->nItemHeight
, 1) : 0;
1834 /*************************************************************************
1835 * LISTVIEW_ProcessLetterKeys
1837 * Processes keyboard messages generated by pressing the letter keys
1839 * What this does is perform a case insensitive search from the
1840 * current position with the following quirks:
1841 * - If two chars or more are pressed in quick succession we search
1842 * for the corresponding string (e.g. 'abc').
1843 * - If there is a delay we wipe away the current search string and
1844 * restart with just that char.
1845 * - If the user keeps pressing the same character, whether slowly or
1846 * fast, so that the search string is entirely composed of this
1847 * character ('aaaaa' for instance), then we search for first item
1848 * that starting with that character.
1849 * - If the user types the above character in quick succession, then
1850 * we must also search for the corresponding string ('aaaaa'), and
1851 * go to that string if there is a match.
1854 * [I] hwnd : handle to the window
1855 * [I] charCode : the character code, the actual character
1856 * [I] keyData : key data
1864 * - The current implementation has a list of characters it will
1865 * accept and it ignores everything else. In particular it will
1866 * ignore accentuated characters which seems to match what
1867 * Windows does. But I'm not sure it makes sense to follow
1869 * - We don't sound a beep when the search fails.
1873 * TREEVIEW_ProcessLetterKeys
1875 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1877 WCHAR buffer
[MAX_PATH
];
1884 /* simple parameter checking */
1885 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1887 /* only allow the valid WM_CHARs through */
1888 if (!iswalnum(charCode
) &&
1889 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1890 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1891 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1892 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1893 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1894 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1895 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1896 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1897 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1900 /* update the search parameters */
1901 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1902 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1903 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1905 if (diff
>= 0 && diff
< KEY_DELAY
)
1907 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1908 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1910 if (infoPtr
->charCode
!= charCode
)
1911 infoPtr
->charCode
= charCode
= 0;
1915 infoPtr
->charCode
= charCode
;
1916 infoPtr
->szSearchParam
[0] = charCode
;
1917 infoPtr
->nSearchParamLength
= 1;
1920 /* should start from next after focused item, so next item that matches
1921 will be selected, if there isn't any and focused matches it will be selected
1922 on second search stage from beginning of the list */
1923 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1925 /* with some accumulated search data available start with current focus, otherwise
1926 it's excluded from search */
1927 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1928 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1933 /* let application handle this for virtual listview */
1934 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1938 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1939 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1940 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1941 nmlv
.iStart
= startidx
;
1943 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1945 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1949 int i
= startidx
, endidx
;
1951 /* and search from the current position */
1953 endidx
= infoPtr
->nItemCount
;
1955 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1958 /* start from first item if not found with >= startidx */
1959 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1965 for (i
= startidx
; i
< endidx
; i
++)
1968 item
.mask
= LVIF_TEXT
;
1971 item
.pszText
= buffer
;
1972 item
.cchTextMax
= MAX_PATH
;
1973 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1975 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1980 /* this is used to find first char match when search string is not available yet,
1981 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1982 already waiting for user to complete a string */
1983 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1985 /* this would work but we must keep looking for a longer match */
1990 if ( nItem
!= -1 || /* found something */
1991 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1992 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1998 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
2003 /*************************************************************************
2004 * LISTVIEW_UpdateHeaderSize [Internal]
2006 * Function to resize the header control
2009 * [I] hwnd : handle to a window
2010 * [I] nNewScrollPos : scroll pos to set
2015 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
2020 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
2022 if (!infoPtr
->hwndHeader
) return;
2024 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
2025 point
[0].x
= winRect
.left
;
2026 point
[0].y
= winRect
.top
;
2027 point
[1].x
= winRect
.right
;
2028 point
[1].y
= winRect
.bottom
;
2030 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
2031 point
[0].x
= -nNewScrollPos
;
2032 point
[1].x
+= nNewScrollPos
;
2034 SetWindowPos(infoPtr
->hwndHeader
,0,
2035 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
2036 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
2037 SWP_NOZORDER
| SWP_NOACTIVATE
);
2040 static INT
LISTVIEW_UpdateHScroll(LISTVIEW_INFO
*infoPtr
)
2042 SCROLLINFO horzInfo
;
2045 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2046 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2047 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2049 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2050 if (infoPtr
->uView
== LV_VIEW_LIST
)
2052 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2053 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2055 /* scroll by at least one column per page */
2056 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2057 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2059 if (infoPtr
->nItemWidth
)
2060 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2062 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2064 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2066 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2070 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2073 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2075 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2080 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2081 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2083 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2084 horzInfo
.nMax
= rcHeader
.right
;
2085 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2089 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2090 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2091 #ifdef __REACTOS__ /* CORE-16466 part 1 of 4 */
2092 horzInfo
.nMax
= (horzInfo
.nPage
== 0 ? 0 : horzInfo
.nMax
);
2094 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2095 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2096 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2098 /* Update the Header Control */
2099 if (infoPtr
->hwndHeader
)
2101 horzInfo
.fMask
= SIF_POS
;
2102 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2103 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2106 LISTVIEW_UpdateSize(infoPtr
);
2110 static INT
LISTVIEW_UpdateVScroll(LISTVIEW_INFO
*infoPtr
)
2112 SCROLLINFO vertInfo
;
2115 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2116 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2117 #ifdef __REACTOS__ /* CORE-16466 part 2 of 4 */
2118 vertInfo
.nPage
= max(0, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
);
2120 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2123 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2125 #ifdef __REACTOS__ /* CORE-16466 part 3a of 4 */
2126 if (vertInfo
.nPage
!= 0)
2129 vertInfo
.nMax
= infoPtr
->nItemCount
;
2131 /* scroll by at least one page */
2132 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2133 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2135 if (infoPtr
->nItemHeight
> 0)
2136 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2137 #ifdef __REACTOS__ /* CORE-16466 part 3b of 4 */
2141 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2145 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2148 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2149 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2150 #ifdef __REACTOS__ /* CORE-16466 part 4 of 4 */
2151 vertInfo
.nMax
= (vertInfo
.nPage
== 0 ? 0 : vertInfo
.nMax
);
2153 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2154 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2155 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2157 LISTVIEW_UpdateSize(infoPtr
);
2163 * Update the scrollbars. This function should be called whenever
2164 * the content, size or view changes.
2167 * [I] infoPtr : valid pointer to the listview structure
2172 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*infoPtr
)
2176 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2178 /* Setting the horizontal scroll can change the listview size
2179 * (and potentially everything else) so we need to recompute
2180 * everything again for the vertical scroll and vice-versa
2182 for (dx
= 0, dy
= 0, pass
= 0; pass
<= 1; pass
++)
2184 dx
+= LISTVIEW_UpdateHScroll(infoPtr
);
2185 dy
+= LISTVIEW_UpdateVScroll(infoPtr
);
2188 /* Change of the range may have changed the scroll pos. If so move the content */
2189 if (dx
!= 0 || dy
!= 0)
2192 listRect
= infoPtr
->rcList
;
2193 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2194 SW_ERASE
| SW_INVALIDATE
);
2201 * Shows/hides the focus rectangle.
2204 * [I] infoPtr : valid pointer to the listview structure
2205 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2210 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2214 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2216 if (infoPtr
->nFocusedItem
< 0) return;
2218 /* we need some gymnastics in ICON mode to handle large items */
2219 if (infoPtr
->uView
== LV_VIEW_ICON
)
2223 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2224 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2226 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2231 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2233 /* for some reason, owner draw should work only in report mode */
2234 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2239 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2240 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2242 item
.iItem
= infoPtr
->nFocusedItem
;
2244 item
.mask
= LVIF_PARAM
;
2245 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2247 ZeroMemory(&dis
, sizeof(dis
));
2248 dis
.CtlType
= ODT_LISTVIEW
;
2249 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2250 dis
.itemID
= item
.iItem
;
2251 dis
.itemAction
= ODA_FOCUS
;
2252 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2253 dis
.hwndItem
= infoPtr
->hwndSelf
;
2255 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2256 dis
.itemData
= item
.lParam
;
2258 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2260 SelectObject(hdc
, hOldFont
);
2263 LISTVIEW_InvalidateItem(infoPtr
, infoPtr
->nFocusedItem
);
2266 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2270 * Invalidates all visible selected items.
2272 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2276 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2277 while(iterator_next(&i
))
2279 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2280 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2282 iterator_destroy(&i
);
2287 * DESCRIPTION: [INTERNAL]
2288 * Computes an item's (left,top) corner, relative to rcView.
2289 * That is, the position has NOT been made relative to the Origin.
2290 * This is deliberate, to avoid computing the Origin over, and
2291 * over again, when this function is called in a loop. Instead,
2292 * one can factor the computation of the Origin before the loop,
2293 * and offset the value returned by this function, on every iteration.
2296 * [I] infoPtr : valid pointer to the listview structure
2297 * [I] nItem : item number
2298 * [O] lpptOrig : item top, left corner
2303 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2305 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2307 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2309 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2310 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2312 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2314 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2315 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2316 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2318 else /* LV_VIEW_DETAILS */
2320 lpptPosition
->x
= REPORT_MARGINX
;
2321 /* item is always at zero indexed column */
2322 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2323 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2324 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2329 * DESCRIPTION: [INTERNAL]
2330 * Compute the rectangles of an item. This is to localize all
2331 * the computations in one place. If you are not interested in some
2332 * of these values, simply pass in a NULL -- the function is smart
2333 * enough to compute only what's necessary. The function computes
2334 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2335 * one, the BOX rectangle. This rectangle is very cheap to compute,
2336 * and is guaranteed to contain all the other rectangles. Computing
2337 * the ICON rect is also cheap, but all the others are potentially
2338 * expensive. This gives an easy and effective optimization when
2339 * searching (like point inclusion, or rectangle intersection):
2340 * first test against the BOX, and if TRUE, test against the desired
2342 * If the function does not have all the necessary information
2343 * to computed the requested rectangles, will crash with a
2344 * failed assertion. This is done so we catch all programming
2345 * errors, given that the function is called only from our code.
2347 * We have the following 'special' meanings for a few fields:
2348 * * If LVIS_FOCUSED is set, we assume the item has the focus
2349 * This is important in ICON mode, where it might get a larger
2350 * then usual rectangle
2352 * Please note that subitem support works only in REPORT mode.
2355 * [I] infoPtr : valid pointer to the listview structure
2356 * [I] lpLVItem : item to compute the measures for
2357 * [O] lprcBox : ptr to Box rectangle
2358 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2359 * [0] lprcSelectBox : ptr to select box rectangle
2360 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2361 * [O] lprcIcon : ptr to Icon rectangle
2362 * Same as LVM_GETITEMRECT with LVIR_ICON
2363 * [O] lprcStateIcon: ptr to State Icon rectangle
2364 * [O] lprcLabel : ptr to Label rectangle
2365 * Same as LVM_GETITEMRECT with LVIR_LABEL
2370 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2371 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2372 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2374 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2375 RECT Box
, SelectBox
, Icon
, Label
;
2376 COLUMN_INFO
*lpColumnInfo
= NULL
;
2377 SIZE labelSize
= { 0, 0 };
2379 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2381 /* Be smart and try to figure out the minimum we have to do */
2382 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2383 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2385 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2386 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2388 if (lprcSelectBox
) doSelectBox
= TRUE
;
2389 if (lprcLabel
) doLabel
= TRUE
;
2390 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2397 /************************************************************/
2398 /* compute the box rectangle (it should be cheap to do) */
2399 /************************************************************/
2400 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2401 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2403 if (lpLVItem
->iSubItem
)
2405 Box
= lpColumnInfo
->rcHeader
;
2410 Box
.right
= infoPtr
->nItemWidth
;
2413 Box
.bottom
= infoPtr
->nItemHeight
;
2415 /******************************************************************/
2416 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2417 /******************************************************************/
2420 LONG state_width
= 0;
2422 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2423 state_width
= infoPtr
->iconStateSize
.cx
;
2425 if (infoPtr
->uView
== LV_VIEW_ICON
)
2427 Icon
.left
= Box
.left
+ state_width
;
2428 if (infoPtr
->himlNormal
)
2429 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2430 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2431 Icon
.right
= Icon
.left
;
2432 Icon
.bottom
= Icon
.top
;
2433 if (infoPtr
->himlNormal
)
2435 Icon
.right
+= infoPtr
->iconSize
.cx
;
2436 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2439 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2441 Icon
.left
= Box
.left
+ state_width
;
2443 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2445 /* we need the indent in report mode */
2446 assert(lpLVItem
->mask
& LVIF_INDENT
);
2447 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2451 Icon
.right
= Icon
.left
;
2452 if (infoPtr
->himlSmall
&&
2453 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2454 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2455 Icon
.right
+= infoPtr
->iconSize
.cx
;
2456 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2458 if(lprcIcon
) *lprcIcon
= Icon
;
2459 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2461 /* TODO: is this correct? */
2464 lprcStateIcon
->left
= Icon
.left
- state_width
;
2465 lprcStateIcon
->right
= Icon
.left
;
2466 lprcStateIcon
->top
= Icon
.top
;
2467 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2468 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2471 else Icon
.right
= 0;
2473 /************************************************************/
2474 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2475 /************************************************************/
2478 /* calculate how far to the right can the label stretch */
2479 Label
.right
= Box
.right
;
2480 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2482 if (lpLVItem
->iSubItem
== 0)
2484 /* we need a zero based rect here */
2485 Label
= lpColumnInfo
->rcHeader
;
2486 OffsetRect(&Label
, -Label
.left
, 0);
2490 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2492 labelSize
.cx
= infoPtr
->nItemWidth
;
2493 labelSize
.cy
= infoPtr
->nItemHeight
;
2497 /* we need the text in non owner draw mode */
2498 assert(lpLVItem
->mask
& LVIF_TEXT
);
2499 if (is_text(lpLVItem
->pszText
))
2501 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2502 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2503 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2507 /* compute rough rectangle where the label will go */
2508 SetRectEmpty(&rcText
);
2509 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2510 rcText
.bottom
= infoPtr
->nItemHeight
;
2511 if (infoPtr
->uView
== LV_VIEW_ICON
)
2512 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2514 /* now figure out the flags */
2515 if (infoPtr
->uView
== LV_VIEW_ICON
)
2516 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2518 uFormat
= LV_SL_DT_FLAGS
;
2520 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2522 if (rcText
.right
!= rcText
.left
)
2523 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2525 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2527 SelectObject(hdc
, hOldFont
);
2528 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2532 if (infoPtr
->uView
== LV_VIEW_ICON
)
2534 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2535 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2536 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2537 Label
.right
= Label
.left
+ labelSize
.cx
;
2538 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2539 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2541 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2542 labelSize
.cy
/= infoPtr
->ntmHeight
;
2543 labelSize
.cy
= max(labelSize
.cy
, 1);
2544 labelSize
.cy
*= infoPtr
->ntmHeight
;
2546 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2548 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2550 Label
.left
= Icon
.right
;
2551 Label
.top
= Box
.top
;
2552 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2553 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2554 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2556 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2558 Label
.left
= Icon
.right
;
2559 Label
.top
= Box
.top
;
2560 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2561 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2564 if (lprcLabel
) *lprcLabel
= Label
;
2565 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2568 /************************************************************/
2569 /* compute SELECT bounding box */
2570 /************************************************************/
2573 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2575 SelectBox
.left
= Icon
.left
;
2576 SelectBox
.top
= Box
.top
;
2577 SelectBox
.bottom
= Box
.bottom
;
2580 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2582 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2586 UnionRect(&SelectBox
, &Icon
, &Label
);
2588 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2589 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2592 /* Fix the Box if necessary */
2595 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2596 else *lprcBox
= Box
;
2598 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2602 * DESCRIPTION: [INTERNAL]
2605 * [I] infoPtr : valid pointer to the listview structure
2606 * [I] nItem : item number
2607 * [O] lprcBox : ptr to Box rectangle
2612 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2614 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2615 POINT Position
, Origin
;
2618 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2619 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2621 /* Be smart and try to figure out the minimum we have to do */
2623 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2624 lvItem
.mask
|= LVIF_TEXT
;
2625 lvItem
.iItem
= nItem
;
2626 lvItem
.iSubItem
= 0;
2627 lvItem
.pszText
= szDispText
;
2628 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2629 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2630 if (infoPtr
->uView
== LV_VIEW_ICON
)
2632 lvItem
.mask
|= LVIF_STATE
;
2633 lvItem
.stateMask
= LVIS_FOCUSED
;
2634 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2636 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2638 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2639 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2641 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2644 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2647 /* LISTVIEW_MapIdToIndex helper */
2648 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2650 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2651 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2653 if (id1
->id
== id2
->id
) return 0;
2655 return (id1
->id
< id2
->id
) ? -1 : 1;
2660 * Returns the item index for id specified.
2663 * [I] infoPtr : valid pointer to the listview structure
2664 * [I] iID : item id to get index for
2667 * Item index, or -1 on failure.
2669 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2674 TRACE("iID=%d\n", iID
);
2676 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2677 if (infoPtr
->nItemCount
== 0) return -1;
2680 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2684 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2685 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2693 * Returns the item id for index given.
2696 * [I] infoPtr : valid pointer to the listview structure
2697 * [I] iItem : item index to get id for
2702 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2707 TRACE("iItem=%d\n", iItem
);
2709 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2710 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2712 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2713 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2715 return lpItem
->id
->id
;
2720 * Returns the current icon position, and advances it along the top.
2721 * The returned position is not offset by Origin.
2724 * [I] infoPtr : valid pointer to the listview structure
2725 * [O] lpPos : will get the current icon position
2730 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2732 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2734 *lpPos
= infoPtr
->currIconPos
;
2736 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2737 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2739 infoPtr
->currIconPos
.x
= 0;
2740 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2746 * Returns the current icon position, and advances it down the left edge.
2747 * The returned position is not offset by Origin.
2750 * [I] infoPtr : valid pointer to the listview structure
2751 * [O] lpPos : will get the current icon position
2756 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2758 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2760 *lpPos
= infoPtr
->currIconPos
;
2762 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2763 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2765 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2766 infoPtr
->currIconPos
.y
= 0;
2772 * Moves an icon to the specified position.
2773 * It takes care of invalidating the item, etc.
2776 * [I] infoPtr : valid pointer to the listview structure
2777 * [I] nItem : the item to move
2778 * [I] lpPos : the new icon position
2779 * [I] isNew : flags the item as being new
2785 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2791 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2792 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2794 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2795 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2798 /* Allocating a POINTER for every item is too resource intensive,
2799 * so we'll keep the (x,y) in different arrays */
2800 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2801 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2803 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2810 * Arranges listview items in icon display mode.
2813 * [I] infoPtr : valid pointer to the listview structure
2814 * [I] nAlignCode : alignment code
2820 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2822 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2826 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2828 TRACE("nAlignCode=%d\n", nAlignCode
);
2830 if (nAlignCode
== LVA_DEFAULT
)
2832 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2833 else nAlignCode
= LVA_ALIGNTOP
;
2838 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2839 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2840 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2841 default: return FALSE
;
2844 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2845 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2847 next_pos(infoPtr
, &pos
);
2848 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2856 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2857 * For LVS_REPORT always returns empty rectangle.
2860 * [I] infoPtr : valid pointer to the listview structure
2861 * [O] lprcView : bounding rectangle
2867 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2871 SetRectEmpty(lprcView
);
2873 switch (infoPtr
->uView
)
2876 case LV_VIEW_SMALLICON
:
2877 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2879 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2880 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2881 lprcView
->right
= max(lprcView
->right
, x
);
2882 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2884 if (infoPtr
->nItemCount
> 0)
2886 lprcView
->right
+= infoPtr
->nItemWidth
;
2887 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2892 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2893 x
= infoPtr
->nItemCount
/ y
;
2894 if (infoPtr
->nItemCount
% y
) x
++;
2895 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2896 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2903 * Retrieves the bounding rectangle of all the items.
2906 * [I] infoPtr : valid pointer to the listview structure
2907 * [O] lprcView : bounding rectangle
2913 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2917 TRACE("(lprcView=%p)\n", lprcView
);
2919 if (!lprcView
) return FALSE
;
2921 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2923 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2925 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2926 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2929 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2936 * Retrieves the subitem pointer associated with the subitem index.
2939 * [I] hdpaSubItems : DPA handle for a specific item
2940 * [I] nSubItem : index of subitem
2943 * SUCCESS : subitem pointer
2946 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2948 SUBITEM_INFO
*lpSubItem
;
2951 /* we should binary search here if need be */
2952 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2954 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2955 if (lpSubItem
->iSubItem
== nSubItem
)
2965 * Calculates the desired item width.
2968 * [I] infoPtr : valid pointer to the listview structure
2971 * The desired item width.
2973 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2977 TRACE("uView=%d\n", infoPtr
->uView
);
2979 if (infoPtr
->uView
== LV_VIEW_ICON
)
2980 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2981 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2983 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2988 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2989 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2991 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2992 nItemWidth
= rcHeader
.right
;
2995 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2997 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
3001 lvItem
.mask
= LVIF_TEXT
;
3002 lvItem
.iSubItem
= 0;
3004 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3007 lvItem
.pszText
= szDispText
;
3008 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
3009 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
3010 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
3014 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
3015 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
3017 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
3025 * Calculates the desired item height.
3028 * [I] infoPtr : valid pointer to the listview structure
3031 * The desired item height.
3033 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
3037 TRACE("uView=%d\n", infoPtr
->uView
);
3039 if (infoPtr
->uView
== LV_VIEW_ICON
)
3040 nItemHeight
= infoPtr
->iconSpacing
.cy
;
3043 nItemHeight
= infoPtr
->ntmHeight
;
3044 if (infoPtr
->himlState
)
3045 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
3046 if (infoPtr
->himlSmall
)
3047 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
3048 nItemHeight
+= HEIGHT_PADDING
;
3049 if (infoPtr
->nMeasureItemHeight
> 0)
3050 nItemHeight
= infoPtr
->nMeasureItemHeight
;
3053 return max(nItemHeight
, 1);
3058 * Updates the width, and height of an item.
3061 * [I] infoPtr : valid pointer to the listview structure
3066 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
3068 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
3069 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3075 * Retrieves and saves important text metrics info for the current
3079 * [I] infoPtr : valid pointer to the listview structure
3082 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3084 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3085 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3086 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3090 if (GetTextMetricsW(hdc
, &tm
))
3092 infoPtr
->ntmHeight
= tm
.tmHeight
;
3093 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3096 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3097 infoPtr
->nEllipsisWidth
= sz
.cx
;
3099 SelectObject(hdc
, hOldFont
);
3100 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3102 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3107 * A compare function for ranges
3110 * [I] range1 : pointer to range 1;
3111 * [I] range2 : pointer to range 2;
3115 * > 0 : if range 1 > range 2
3116 * < 0 : if range 2 > range 1
3117 * = 0 : if range intersects range 2
3119 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3123 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3125 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3130 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3135 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3137 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3142 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3144 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3145 ranges_dump(ranges
);
3146 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3148 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3149 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3150 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3152 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3153 assert (prev
->upper
<= curr
->lower
);
3154 assert (curr
->lower
< curr
->upper
);
3158 TRACE("--- Done checking---\n");
3161 static RANGES
ranges_create(int count
)
3163 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3164 if (!ranges
) return NULL
;
3165 ranges
->hdpa
= DPA_Create(count
);
3166 if (ranges
->hdpa
) return ranges
;
3171 static void ranges_clear(RANGES ranges
)
3175 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3176 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3177 DPA_DeleteAllPtrs(ranges
->hdpa
);
3181 static void ranges_destroy(RANGES ranges
)
3183 if (!ranges
) return;
3184 ranges_clear(ranges
);
3185 DPA_Destroy(ranges
->hdpa
);
3189 static RANGES
ranges_clone(RANGES ranges
)
3194 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3196 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3198 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3199 if (!newrng
) goto fail
;
3200 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3201 if (!DPA_SetPtr(clone
->hdpa
, i
, newrng
))
3210 TRACE ("clone failed\n");
3211 ranges_destroy(clone
);
3215 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3219 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3220 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3225 static void ranges_dump(RANGES ranges
)
3229 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3230 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3233 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3235 RANGE srchrng
= { nItem
, nItem
+ 1 };
3237 TRACE("(nItem=%d)\n", nItem
);
3238 ranges_check(ranges
, "before contain");
3239 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3242 static INT
ranges_itemcount(RANGES ranges
)
3246 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3248 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3249 count
+= sel
->upper
- sel
->lower
;
3255 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3257 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3260 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3261 if (index
== -1) return TRUE
;
3263 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3265 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3266 if (chkrng
->lower
>= nItem
)
3267 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3268 if (chkrng
->upper
> nItem
)
3269 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3274 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3279 TRACE("(%s)\n", debugrange(&range
));
3280 ranges_check(ranges
, "before add");
3282 /* try find overlapping regions first */
3283 srchrgn
.lower
= range
.lower
- 1;
3284 srchrgn
.upper
= range
.upper
+ 1;
3285 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3291 TRACE("Adding new range\n");
3293 /* create the brand new range to insert */
3294 newrgn
= Alloc(sizeof(RANGE
));
3295 if(!newrgn
) goto fail
;
3298 /* figure out where to insert it */
3299 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3300 TRACE("index=%d\n", index
);
3301 if (index
== -1) index
= 0;
3303 /* and get it over with */
3304 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3312 RANGE
*chkrgn
, *mrgrgn
;
3313 INT fromindex
, mergeindex
;
3315 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3316 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3318 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3319 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3321 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3323 /* merge now common ranges */
3325 srchrgn
.lower
= chkrgn
->lower
- 1;
3326 srchrgn
.upper
= chkrgn
->upper
+ 1;
3330 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3331 if (mergeindex
== -1) break;
3332 if (mergeindex
== index
)
3334 fromindex
= index
+ 1;
3338 TRACE("Merge with index %i\n", mergeindex
);
3340 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3341 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3342 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3344 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3345 if (mergeindex
< index
) index
--;
3349 ranges_check(ranges
, "after add");
3353 ranges_check(ranges
, "failed add");
3357 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3362 TRACE("(%s)\n", debugrange(&range
));
3363 ranges_check(ranges
, "before del");
3365 /* we don't use DPAS_SORTED here, since we need *
3366 * to find the first overlapping range */
3367 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3370 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3372 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3374 /* case 1: Same range */
3375 if ( (chkrgn
->upper
== range
.upper
) &&
3376 (chkrgn
->lower
== range
.lower
) )
3378 DPA_DeletePtr(ranges
->hdpa
, index
);
3382 /* case 2: engulf */
3383 else if ( (chkrgn
->upper
<= range
.upper
) &&
3384 (chkrgn
->lower
>= range
.lower
) )
3386 DPA_DeletePtr(ranges
->hdpa
, index
);
3389 /* case 3: overlap upper */
3390 else if ( (chkrgn
->upper
<= range
.upper
) &&
3391 (chkrgn
->lower
< range
.lower
) )
3393 chkrgn
->upper
= range
.lower
;
3395 /* case 4: overlap lower */
3396 else if ( (chkrgn
->upper
> range
.upper
) &&
3397 (chkrgn
->lower
>= range
.lower
) )
3399 chkrgn
->lower
= range
.upper
;
3402 /* case 5: fully internal */
3407 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3408 newrgn
->lower
= chkrgn
->lower
;
3409 newrgn
->upper
= range
.lower
;
3410 chkrgn
->lower
= range
.upper
;
3411 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3419 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3422 ranges_check(ranges
, "after del");
3426 ranges_check(ranges
, "failed del");
3432 * Removes all selection ranges
3435 * [I] infoPtr : valid pointer to the listview structure
3436 * [I] toSkip : item range to skip removing the selection
3442 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3451 lvItem
.stateMask
= LVIS_SELECTED
;
3453 /* need to clone the DPA because callbacks can change it */
3454 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3455 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3456 while(iterator_next(&i
))
3457 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3458 /* note that the iterator destructor will free the cloned range */
3459 iterator_destroy(&i
);
3464 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3468 if (!(toSkip
= ranges_create(1))) return FALSE
;
3469 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3470 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3471 ranges_destroy(toSkip
);
3475 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3477 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3482 * Retrieves the number of items that are marked as selected.
3485 * [I] infoPtr : valid pointer to the listview structure
3488 * Number of items selected.
3490 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3492 INT nSelectedCount
= 0;
3494 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3497 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3499 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3504 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3506 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3507 return nSelectedCount
;
3512 * Manages the item focus.
3515 * [I] infoPtr : valid pointer to the listview structure
3516 * [I] nItem : item index
3519 * TRUE : focused item changed
3520 * FALSE : focused item has NOT changed
3522 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3524 INT oldFocus
= infoPtr
->nFocusedItem
;
3527 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3529 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3530 lvItem
.stateMask
= LVIS_FOCUSED
;
3531 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3533 return oldFocus
!= infoPtr
->nFocusedItem
;
3536 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3538 if (nShiftItem
< nItem
) return nShiftItem
;
3540 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3542 if (direction
> 0) return nShiftItem
+ direction
;
3544 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3547 /* This function updates focus index.
3550 focus : current focus index
3551 item : index of item to be added/removed
3552 direction : add/remove flag
3554 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3556 DWORD old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3558 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3559 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3560 if (focus
!= infoPtr
->nFocusedItem
)
3561 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3562 infoPtr
->notify_mask
|= old_mask
;
3567 * Updates the various indices after an item has been inserted or deleted.
3570 * [I] infoPtr : valid pointer to the listview structure
3571 * [I] nItem : item index
3572 * [I] direction : Direction of shift, +1 or -1.
3577 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3579 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3581 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3582 assert(abs(direction
) == 1);
3583 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3585 /* But we are not supposed to modify nHotItem! */
3590 * Adds a block of selections.
3593 * [I] infoPtr : valid pointer to the listview structure
3594 * [I] nItem : item index
3597 * Whether the window is still valid.
3599 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3601 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3602 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3603 HWND hwndSelf
= infoPtr
->hwndSelf
;
3604 NMLVODSTATECHANGE nmlv
;
3609 /* Temporarily disable change notification
3610 * If the control is LVS_OWNERDATA, we need to send
3611 * only one LVN_ODSTATECHANGED notification.
3612 * See MSDN documentation for LVN_ITEMCHANGED.
3614 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3615 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3616 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3618 if (nFirst
== -1) nFirst
= nItem
;
3620 item
.state
= LVIS_SELECTED
;
3621 item
.stateMask
= LVIS_SELECTED
;
3623 for (i
= nFirst
; i
<= nLast
; i
++)
3624 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3626 ZeroMemory(&nmlv
, sizeof(nmlv
));
3627 nmlv
.iFrom
= nFirst
;
3630 nmlv
.uNewState
= item
.state
;
3632 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3633 if (!IsWindow(hwndSelf
))
3635 infoPtr
->notify_mask
|= old_mask
;
3642 * Sets a single group selection.
3645 * [I] infoPtr : valid pointer to the listview structure
3646 * [I] nItem : item index
3651 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3658 if (!(selection
= ranges_create(100))) return;
3660 item
.state
= LVIS_SELECTED
;
3661 item
.stateMask
= LVIS_SELECTED
;
3663 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3665 if (infoPtr
->nSelectionMark
== -1)
3667 infoPtr
->nSelectionMark
= nItem
;
3668 ranges_additem(selection
, nItem
);
3674 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3675 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3676 ranges_add(selection
, sel
);
3681 RECT rcItem
, rcSel
, rcSelMark
;
3684 rcItem
.left
= LVIR_BOUNDS
;
3685 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3686 ranges_destroy (selection
);
3689 rcSelMark
.left
= LVIR_BOUNDS
;
3690 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3691 ranges_destroy (selection
);
3694 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3695 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3696 while(iterator_next(&i
))
3698 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3699 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3701 iterator_destroy(&i
);
3704 /* disable per item notifications on LVS_OWNERDATA style
3705 FIXME: single LVN_ODSTATECHANGED should be used */
3706 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3707 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3708 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3710 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3713 iterator_rangesitems(&i
, selection
);
3714 while(iterator_next(&i
))
3715 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3716 /* this will also destroy the selection */
3717 iterator_destroy(&i
);
3719 infoPtr
->notify_mask
|= old_mask
;
3720 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3725 * Sets a single selection.
3728 * [I] infoPtr : valid pointer to the listview structure
3729 * [I] nItem : item index
3734 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3738 TRACE("nItem=%d\n", nItem
);
3740 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3742 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3743 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3744 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3746 infoPtr
->nSelectionMark
= nItem
;
3751 * Set selection(s) with keyboard.
3754 * [I] infoPtr : valid pointer to the listview structure
3755 * [I] nItem : item index
3756 * [I] space : VK_SPACE code sent
3759 * SUCCESS : TRUE (needs to be repainted)
3760 * FAILURE : FALSE (nothing has changed)
3762 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3764 /* FIXME: pass in the state */
3765 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3766 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3767 BOOL bResult
= FALSE
;
3769 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3770 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3774 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3775 LISTVIEW_SetSelection(infoPtr
, nItem
);
3779 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3783 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3784 lvItem
.stateMask
= LVIS_SELECTED
;
3787 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3788 if (lvItem
.state
& LVIS_SELECTED
)
3789 infoPtr
->nSelectionMark
= nItem
;
3791 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3794 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3797 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3801 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3803 LVHITTESTINFO lvHitTestInfo
;
3805 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3806 lvHitTestInfo
.pt
.x
= pt
.x
;
3807 lvHitTestInfo
.pt
.y
= pt
.y
;
3809 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3811 lpLVItem
->mask
= LVIF_PARAM
;
3812 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3813 lpLVItem
->iSubItem
= 0;
3815 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3818 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3820 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3821 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3822 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3827 * Called when the mouse is being actively tracked and has hovered for a specified
3831 * [I] infoPtr : valid pointer to the listview structure
3832 * [I] fwKeys : key indicator
3833 * [I] x,y : mouse position
3836 * 0 if the message was processed, non-zero if there was an error
3839 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3840 * over the item for a certain period of time.
3843 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3847 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3849 if (LISTVIEW_IsHotTracking(infoPtr
))
3857 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3858 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3860 SetFocus(infoPtr
->hwndSelf
);
3866 #define SCROLL_LEFT 0x1
3867 #define SCROLL_RIGHT 0x2
3868 #define SCROLL_UP 0x4
3869 #define SCROLL_DOWN 0x8
3873 * Utility routine to draw and highlight items within a marquee selection rectangle.
3876 * [I] infoPtr : valid pointer to the listview structure
3877 * [I] coords_orig : original co-ordinates of the cursor
3878 * [I] coords_offs : offsetted coordinates of the cursor
3879 * [I] offset : offset amount
3880 * [I] scroll : Bitmask of which directions we should scroll, if at all
3885 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3888 BOOL controlDown
= FALSE
;
3890 ITERATOR old_elems
, new_elems
;
3892 POINT coords_offs
, offset
;
3894 /* Ensure coordinates are within client bounds */
3895 coords_offs
.x
= max(min(coords_orig
->x
, infoPtr
->rcList
.right
), 0);
3896 coords_offs
.y
= max(min(coords_orig
->y
, infoPtr
->rcList
.bottom
), 0);
3899 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3901 /* Offset coordinates by the appropriate amount */
3902 coords_offs
.x
-= offset
.x
;
3903 coords_offs
.y
-= offset
.y
;
3905 if (coords_offs
.x
> infoPtr
->marqueeOrigin
.x
)
3907 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3908 rect
.right
= coords_offs
.x
;
3912 rect
.left
= coords_offs
.x
;
3913 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3916 if (coords_offs
.y
> infoPtr
->marqueeOrigin
.y
)
3918 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3919 rect
.bottom
= coords_offs
.y
;
3923 rect
.top
= coords_offs
.y
;
3924 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3927 /* Cancel out the old marquee rectangle and draw the new one */
3928 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3930 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3931 the cursor is further away */
3933 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3934 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3936 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3937 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3939 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3940 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3942 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3943 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3945 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3947 infoPtr
->marqueeRect
= rect
;
3948 infoPtr
->marqueeDrawRect
= rect
;
3949 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
.x
, offset
.y
);
3951 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3952 iterator_remove_common_items(&old_elems
, &new_elems
);
3954 /* Iterate over no longer selected items */
3955 while (iterator_next(&old_elems
))
3957 if (old_elems
.nItem
> -1)
3959 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3962 item
.state
= LVIS_SELECTED
;
3964 item
.stateMask
= LVIS_SELECTED
;
3966 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3969 iterator_destroy(&old_elems
);
3972 /* Iterate over newly selected items */
3973 if (GetKeyState(VK_CONTROL
) & 0x8000)
3976 while (iterator_next(&new_elems
))
3978 if (new_elems
.nItem
> -1)
3980 /* If CTRL is pressed, invert. If not, always select the item. */
3981 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3984 item
.state
= LVIS_SELECTED
;
3986 item
.stateMask
= LVIS_SELECTED
;
3988 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3991 iterator_destroy(&new_elems
);
3993 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3998 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3999 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
4002 * [I] hwnd : Handle to the listview
4003 * [I] uMsg : WM_TIMER (ignored)
4004 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
4005 * [I] dwTimer : The elapsed time (ignored)
4010 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
4012 LISTVIEW_INFO
*infoPtr
;
4013 SCROLLINFO scrollInfo
;
4017 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
4022 /* Get the current cursor position and convert to client coordinates */
4023 GetCursorPos(&coords
);
4024 ScreenToClient(hWnd
, &coords
);
4026 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4027 scrollInfo
.fMask
= SIF_ALL
;
4029 /* Work out in which directions we can scroll */
4030 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4032 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
4033 scroll
|= SCROLL_UP
;
4035 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
4036 scroll
|= SCROLL_DOWN
;
4039 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4041 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
4042 scroll
|= SCROLL_LEFT
;
4044 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
4045 scroll
|= SCROLL_RIGHT
;
4048 if (((coords
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
4049 ((coords
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
4050 ((coords
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
4051 ((coords
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
4053 LISTVIEW_MarqueeHighlight(infoPtr
, &coords
, scroll
);
4059 * Called whenever WM_MOUSEMOVE is received.
4062 * [I] infoPtr : valid pointer to the listview structure
4063 * [I] fwKeys : key indicator
4064 * [I] x,y : mouse position
4067 * 0 if the message is processed, non-zero if there was an error
4069 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4078 if (!(fwKeys
& MK_LBUTTON
))
4079 infoPtr
->bLButtonDown
= FALSE
;
4081 if (infoPtr
->bLButtonDown
)
4083 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4084 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4086 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4088 if (infoPtr
->bMarqueeSelect
)
4090 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4091 move the mouse again */
4093 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4094 (y
>= infoPtr
->rcList
.bottom
))
4096 if (!infoPtr
->bScrolling
)
4098 infoPtr
->bScrolling
= TRUE
;
4099 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4104 infoPtr
->bScrolling
= FALSE
;
4105 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4108 LISTVIEW_MarqueeHighlight(infoPtr
, &pt
, 0);
4113 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4115 /* reset item marker */
4116 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4117 infoPtr
->nLButtonDownItem
= -1;
4119 if (!PtInRect(&rect
, pt
))
4121 /* this path covers the following:
4122 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4123 2. change focus with keys
4124 3. move mouse over item from step 1 selects it and moves focus on it */
4125 if (infoPtr
->nLButtonDownItem
!= -1 &&
4126 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4130 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4131 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4133 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4134 infoPtr
->nLButtonDownItem
= -1;
4137 if (!infoPtr
->bDragging
)
4139 ht
.pt
= infoPtr
->ptClickPos
;
4140 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4142 /* If the click is outside the range of an item, begin a
4143 highlight. If not, begin an item drag. */
4148 /* If we're allowing multiple selections, send notification.
4149 If return value is non-zero, cancel. */
4150 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4152 /* Store the absolute coordinates of the click */
4154 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4156 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4157 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4159 /* Begin selection and capture mouse */
4160 infoPtr
->bMarqueeSelect
= TRUE
;
4161 SetCapture(infoPtr
->hwndSelf
);
4168 ZeroMemory(&nmlv
, sizeof(nmlv
));
4169 nmlv
.iItem
= ht
.iItem
;
4170 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4172 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4173 infoPtr
->bDragging
= TRUE
;
4181 /* see if we are supposed to be tracking mouse hovering */
4182 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4183 TRACKMOUSEEVENT trackinfo
;
4186 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4187 trackinfo
.dwFlags
= TME_QUERY
;
4189 /* see if we are already tracking this hwnd */
4190 _TrackMouseEvent(&trackinfo
);
4193 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
4196 if((trackinfo
.dwFlags
& flags
) != flags
|| trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4197 trackinfo
.dwFlags
= flags
;
4198 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4199 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4201 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4202 _TrackMouseEvent(&trackinfo
);
4211 * Tests whether the item is assignable to a list with style lStyle
4213 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4215 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4216 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4217 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4225 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4228 * [I] infoPtr : valid pointer to the listview structure
4229 * [I] lpLVItem : valid pointer to new item attributes
4230 * [I] isNew : the item being set is being inserted
4231 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4232 * [O] bChanged : will be set to TRUE if the item really changed
4238 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4244 /* stateMask is ignored for LVM_INSERTITEM */
4245 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4249 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4251 if (lpLVItem
->mask
== 0) return TRUE
;
4253 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4255 /* a virtual listview only stores selection and focus */
4256 if (lpLVItem
->mask
& ~LVIF_STATE
)
4262 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4263 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4267 /* we need to get the lParam and state of the item */
4268 item
.iItem
= lpLVItem
->iItem
;
4269 item
.iSubItem
= lpLVItem
->iSubItem
;
4270 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4271 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4275 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4277 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4278 /* determine what fields will change */
4279 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4280 uChanged
|= LVIF_STATE
;
4282 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4283 uChanged
|= LVIF_IMAGE
;
4285 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4286 uChanged
|= LVIF_PARAM
;
4288 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4289 uChanged
|= LVIF_INDENT
;
4291 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4292 uChanged
|= LVIF_TEXT
;
4294 TRACE("change mask=0x%x\n", uChanged
);
4296 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4297 nmlv
.iItem
= lpLVItem
->iItem
;
4298 if (lpLVItem
->mask
& LVIF_STATE
)
4300 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4301 nmlv
.uOldState
= item
.state
;
4303 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4304 nmlv
.lParam
= item
.lParam
;
4306 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4307 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4308 are enabled. Even nothing really changed we still need to send this,
4309 in this case uChanged mask is just set to passed item mask. */
4310 if (lpItem
&& !isNew
&& (infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
))
4312 HWND hwndSelf
= infoPtr
->hwndSelf
;
4314 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4316 if (!IsWindow(hwndSelf
))
4320 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4321 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4322 /* this means we won't hit a focus change path later */
4323 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4325 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4326 infoPtr
->nFocusedItem
++;
4329 if (!uChanged
) return TRUE
;
4332 /* copy information */
4333 if (lpLVItem
->mask
& LVIF_TEXT
)
4334 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4336 if (lpLVItem
->mask
& LVIF_IMAGE
)
4337 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4339 if (lpLVItem
->mask
& LVIF_PARAM
)
4340 lpItem
->lParam
= lpLVItem
->lParam
;
4342 if (lpLVItem
->mask
& LVIF_INDENT
)
4343 lpItem
->iIndent
= lpLVItem
->iIndent
;
4345 if (uChanged
& LVIF_STATE
)
4347 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4349 lpItem
->state
&= ~stateMask
;
4350 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4352 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4354 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4355 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4357 else if (stateMask
& LVIS_SELECTED
)
4359 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4361 /* If we are asked to change focus, and we manage it, do it.
4362 It's important to have all new item data stored at this point,
4363 because changing existing focus could result in a redrawing operation,
4364 which in turn could ask for disp data, application should see all data
4365 for inserted item when processing LVN_GETDISPINFO.
4367 The way this works application will see nested item change notifications -
4368 changed item notifications interrupted by ones from item losing focus. */
4369 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4371 if (lpLVItem
->state
& LVIS_FOCUSED
)
4373 /* update selection mark */
4374 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4375 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4377 if (infoPtr
->nFocusedItem
!= -1)
4379 /* remove current focus */
4380 item
.mask
= LVIF_STATE
;
4382 item
.stateMask
= LVIS_FOCUSED
;
4384 /* recurse with redrawing an item */
4385 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4388 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4389 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4391 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4393 infoPtr
->nFocusedItem
= -1;
4398 /* if we're inserting the item, we're done */
4399 if (isNew
) return TRUE
;
4401 /* send LVN_ITEMCHANGED notification */
4402 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4403 if (infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
)
4404 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4411 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4414 * [I] infoPtr : valid pointer to the listview structure
4415 * [I] lpLVItem : valid pointer to new subitem attributes
4416 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4417 * [O] bChanged : will be set to TRUE if the item really changed
4423 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4426 SUBITEM_INFO
*lpSubItem
;
4428 /* we do not support subitems for virtual listviews */
4429 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4431 /* set subitem only if column is present */
4432 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4434 /* First do some sanity checks */
4435 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4436 particularly useful. We currently do not actually do anything with
4437 the flag on subitems.
4439 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4440 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4442 /* get the subitem structure, and create it if not there */
4443 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4444 assert (hdpaSubItems
);
4446 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4449 SUBITEM_INFO
*tmpSubItem
;
4452 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4453 if (!lpSubItem
) return FALSE
;
4454 /* we could binary search here, if need be...*/
4455 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4457 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4458 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4460 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4465 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4466 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4470 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4472 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4476 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4478 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4487 * Sets item attributes.
4490 * [I] infoPtr : valid pointer to the listview structure
4491 * [I] lpLVItem : new item attributes
4492 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4498 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4500 HWND hwndSelf
= infoPtr
->hwndSelf
;
4501 LPWSTR pszText
= NULL
;
4502 BOOL bResult
, bChanged
= FALSE
;
4505 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4507 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4510 /* Store old item area */
4511 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4513 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4514 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4516 pszText
= lpLVItem
->pszText
;
4517 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4520 /* actually set the fields */
4521 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4523 if (lpLVItem
->iSubItem
)
4524 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4526 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4527 if (!IsWindow(hwndSelf
))
4530 /* redraw item, if necessary */
4531 if (bChanged
&& !infoPtr
->bIsDrawing
)
4533 /* this little optimization eliminates some nasty flicker */
4534 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4535 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4536 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4537 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4540 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4541 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4547 textfreeT(lpLVItem
->pszText
, isW
);
4548 lpLVItem
->pszText
= pszText
;
4556 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4559 * [I] infoPtr : valid pointer to the listview structure
4564 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4567 SCROLLINFO scrollInfo
;
4569 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4570 scrollInfo
.fMask
= SIF_POS
;
4572 if (infoPtr
->uView
== LV_VIEW_LIST
)
4574 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4575 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4577 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4579 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4580 nItem
= scrollInfo
.nPos
;
4584 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4585 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4588 TRACE("nItem=%d\n", nItem
);
4596 * Erases the background of the given rectangle
4599 * [I] infoPtr : valid pointer to the listview structure
4600 * [I] hdc : device context handle
4601 * [I] lprcBox : clipping rectangle
4607 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4609 if (!infoPtr
->hBkBrush
) return FALSE
;
4611 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4613 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4616 /* Draw main item or subitem */
4617 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4619 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4620 const RECT
*background
;
4625 /* now check if we need to update the focus rectangle */
4626 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4627 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4629 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4630 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4631 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4632 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4633 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4634 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4635 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4636 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4637 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4639 /* FIXME: temporary hack */
4640 rcSelect
.left
= rcLabel
.left
;
4642 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4644 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4645 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4646 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4647 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4648 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4651 /* in icon mode, the label rect is really what we want to draw the
4653 /* in detail mode, we want to paint background for label rect when
4654 * item is not selected or listview has full row select; otherwise paint
4655 * background for text only */
4656 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4657 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4658 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4659 background
= &rcLabel
;
4661 background
= &rcSelect
;
4663 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4664 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4666 if (item
->state
& LVIS_FOCUSED
)
4668 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4670 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4672 /* we have to update left focus bound too if item isn't in leftmost column
4673 and reduce right box bound */
4674 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4678 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4680 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4681 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4682 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4684 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4685 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4688 rcSelect
.right
= rcBox
.right
;
4690 infoPtr
->rcFocus
= rcSelect
;
4693 infoPtr
->rcFocus
= rcLabel
;
4697 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4699 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4702 TRACE("stateimage=%d\n", stateimage
);
4703 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4708 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4709 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4713 TRACE("iImage=%d\n", item
->iImage
);
4715 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4716 style
= ILD_SELECTED
;
4720 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4721 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4722 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4723 style
| (item
->state
& LVIS_OVERLAYMASK
));
4726 /* Don't bother painting item being edited */
4727 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4729 /* figure out the text drawing flags */
4730 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4731 if (infoPtr
->uView
== LV_VIEW_ICON
)
4732 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4733 else if (item
->iSubItem
)
4735 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4737 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4738 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4739 default: format
|= DT_LEFT
;
4742 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4744 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4745 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4747 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4749 /* for GRIDLINES reduce the bottom so the text formats correctly */
4750 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4754 if ((!(item
->state
& LVIS_SELECTED
) || !infoPtr
->bFocus
) && (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTSHADOWTEXT
))
4755 DrawShadowText(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
, RGB(255, 255, 255), RGB(0, 0, 0), 2, 2);
4758 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4766 * [I] infoPtr : valid pointer to the listview structure
4767 * [I] hdc : device context handle
4768 * [I] nItem : item index
4769 * [I] nSubItem : subitem index
4770 * [I] pos : item position in client coordinates
4771 * [I] cdmode : custom draw mode
4777 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4779 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4780 static WCHAR callbackW
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4781 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4783 NMLVCUSTOMDRAW nmlvcd
;
4786 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4788 /* get information needed for drawing the item */
4789 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4790 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4791 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4792 lvItem
.iItem
= nItem
;
4793 lvItem
.iSubItem
= 0;
4796 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4797 lvItem
.pszText
= szDispText
;
4798 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4799 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4800 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4802 /* now check if we need to update the focus rectangle */
4803 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4804 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4806 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4807 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4809 /* Full custom draw stage sequence looks like this:
4814 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4815 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item itself
4816 - CDDS_ITEMPOSTPAINT
4821 - CDDS_ITEMPOSTPAINT
4824 /* fill in the custom draw structure */
4825 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4826 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4827 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4828 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4832 while (iterator_next(subitems
))
4834 DWORD subitemstage
= CDRF_DODEFAULT
;
4835 NMLVCUSTOMDRAW temp_nmlvcd
;
4837 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4838 if (subitems
->nItem
)
4840 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4841 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4842 lvItem
.iItem
= nItem
;
4843 lvItem
.iSubItem
= subitems
->nItem
;
4846 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4847 lvItem
.pszText
= szDispText
;
4848 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4849 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4850 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4851 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4852 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4854 /* update custom draw data */
4855 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4856 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4857 nmlvcd
.iSubItem
= subitems
->nItem
;
4860 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4861 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4864 * A selection should neither affect the colors in the post paint notification nor
4865 * affect the colors of the next drawn subitem. Copy the structure to prevent this.
4867 temp_nmlvcd
= nmlvcd
;
4868 prepaint_setup(infoPtr
, hdc
, &temp_nmlvcd
, subitems
->nItem
);
4870 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4871 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &temp_nmlvcd
, &pos
);
4873 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4874 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4879 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4880 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4884 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4886 nmlvcd
.iSubItem
= 0;
4887 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4895 * Draws listview items when in owner draw mode.
4898 * [I] infoPtr : valid pointer to the listview structure
4899 * [I] hdc : device context handle
4904 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4906 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4907 DWORD cditemmode
= CDRF_DODEFAULT
;
4908 NMLVCUSTOMDRAW nmlvcd
;
4909 POINT Origin
, Position
;
4915 ZeroMemory(&dis
, sizeof(dis
));
4917 /* Get scroll info once before loop */
4918 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4920 /* iterate through the invalidated rows */
4921 while(iterator_next(i
))
4923 item
.iItem
= i
->nItem
;
4925 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4926 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4927 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4929 dis
.CtlType
= ODT_LISTVIEW
;
4931 dis
.itemID
= item
.iItem
;
4932 dis
.itemAction
= ODA_DRAWENTIRE
;
4934 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4935 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4936 dis
.hwndItem
= infoPtr
->hwndSelf
;
4938 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4939 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4940 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4941 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4942 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4943 dis
.itemData
= item
.lParam
;
4945 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4948 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4949 * structure for the rest. of the paint cycle
4951 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4952 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4953 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4955 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4957 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4958 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4961 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4962 notify_postpaint(infoPtr
, &nmlvcd
);
4968 * Draws listview items when in report display mode.
4971 * [I] infoPtr : valid pointer to the listview structure
4972 * [I] hdc : device context handle
4973 * [I] cdmode : custom draw mode
4978 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4981 RECT rcClip
, rcItem
;
4989 /* figure out what to draw */
4990 rgntype
= GetClipBox(hdc
, &rcClip
);
4991 if (rgntype
== NULLREGION
) return;
4993 /* Get scroll info once before loop */
4994 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4996 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4998 /* narrow down the columns we need to paint */
4999 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5001 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5003 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5004 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5005 ranges_additem(colRanges
, index
);
5007 iterator_rangesitems(&j
, colRanges
);
5009 /* in full row select, we _have_ to draw the main item */
5010 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
5013 /* iterate through the invalidated rows */
5014 while(iterator_next(i
))
5020 SelectObject(hdc
, infoPtr
->hFont
);
5021 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5022 Position
.x
= Origin
.x
;
5023 Position
.y
+= Origin
.y
;
5025 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5027 /* iterate through the invalidated columns */
5028 while(iterator_next(&j
))
5030 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5032 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
5035 rcItem
.bottom
= infoPtr
->nItemHeight
;
5036 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
5037 if (!RectVisible(hdc
, &rcItem
)) continue;
5040 ranges_additem(subitems
, j
.nItem
);
5043 iterator_rangesitems(&k
, subitems
);
5044 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
5045 iterator_destroy(&k
);
5047 iterator_destroy(&j
);
5052 * Draws the gridlines if necessary when in report display mode.
5055 * [I] infoPtr : valid pointer to the listview structure
5056 * [I] hdc : device context handle
5061 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
5067 RECT rcClip
, rcItem
= {0};
5075 /* figure out what to draw */
5076 rgntype
= GetClipBox(hdc
, &rcClip
);
5077 if (rgntype
== NULLREGION
) return;
5079 /* Get scroll info once before loop */
5080 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5082 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5084 /* narrow down the columns we need to paint */
5085 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5087 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5089 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5090 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5091 ranges_additem(colRanges
, index
);
5094 /* is right most vertical line visible? */
5095 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5097 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5098 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5099 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5102 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5104 hOldPen
= SelectObject ( hdc
, hPen
);
5106 /* draw the vertical lines for the columns */
5107 iterator_rangesitems(&j
, colRanges
);
5108 while(iterator_next(&j
))
5110 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5111 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5112 rcItem
.left
+= Origin
.x
;
5113 rcItem
.right
+= Origin
.x
;
5114 rcItem
.top
= infoPtr
->rcList
.top
;
5115 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5116 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5117 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5118 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5120 iterator_destroy(&j
);
5121 /* draw rightmost grid line if visible */
5124 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5125 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5126 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5128 rcItem
.right
+= Origin
.x
;
5130 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5131 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5134 /* draw the horizontal lines for the rows */
5135 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5136 rcItem
.left
= infoPtr
->rcList
.left
;
5137 rcItem
.right
= infoPtr
->rcList
.right
;
5138 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5140 rcItem
.bottom
= rcItem
.top
= y
;
5141 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5142 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5143 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5146 SelectObject( hdc
, hOldPen
);
5147 DeleteObject( hPen
);
5150 ranges_destroy(colRanges
);
5155 * Draws listview items when in list display mode.
5158 * [I] infoPtr : valid pointer to the listview structure
5159 * [I] hdc : device context handle
5160 * [I] cdmode : custom draw mode
5165 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5167 POINT Origin
, Position
;
5169 /* Get scroll info once before loop */
5170 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5172 while(iterator_prev(i
))
5174 SelectObject(hdc
, infoPtr
->hFont
);
5175 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5176 Position
.x
+= Origin
.x
;
5177 Position
.y
+= Origin
.y
;
5179 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5186 * Draws listview items.
5189 * [I] infoPtr : valid pointer to the listview structure
5190 * [I] hdc : device context handle
5191 * [I] prcErase : rect to be erased before refresh (may be NULL)
5196 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5198 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5199 NMLVCUSTOMDRAW nmlvcd
;
5206 HBITMAP hbmp
= NULL
;
5209 LISTVIEW_DUMP(infoPtr
);
5211 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5212 TRACE("double buffering\n");
5214 hdc
= CreateCompatibleDC(hdcOrig
);
5216 ERR("Failed to create DC for backbuffer\n");
5219 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5220 infoPtr
->rcList
.bottom
);
5222 ERR("Failed to create bitmap for backbuffer\n");
5227 SelectObject(hdc
, hbmp
);
5228 SelectObject(hdc
, infoPtr
->hFont
);
5230 if(GetClipBox(hdcOrig
, &rcClient
))
5231 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5233 /* Save dc values we're gonna trash while drawing
5234 * FIXME: Should be done in LISTVIEW_DrawItem() */
5235 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5236 oldBkMode
= GetBkMode(hdc
);
5237 oldBkColor
= GetBkColor(hdc
);
5238 oldTextColor
= GetTextColor(hdc
);
5241 infoPtr
->bIsDrawing
= TRUE
;
5244 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5245 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5246 /* If no erasing was done (usually because RedrawWindow was called
5247 * with RDW_INVALIDATE only) we need to copy the old contents into
5248 * the backbuffer before continuing. */
5249 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5250 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5251 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5252 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5255 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5256 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5257 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5258 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5260 /* nothing to draw */
5261 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5263 /* figure out what we need to draw */
5264 iterator_visibleitems(&i
, infoPtr
, hdc
);
5265 range
= iterator_range(&i
);
5267 /* send cache hint notification */
5268 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5272 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5273 nmlv
.iFrom
= range
.lower
;
5274 nmlv
.iTo
= range
.upper
- 1;
5275 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5278 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5279 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5282 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5283 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5284 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5285 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5287 /* if we have a focus rect and it's visible, draw it */
5288 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5289 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5290 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5292 iterator_destroy(&i
);
5295 /* For LVS_EX_GRIDLINES go and draw lines */
5296 /* This includes the case where there were *no* items */
5297 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5298 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5300 /* Draw marquee rectangle if appropriate */
5301 if (infoPtr
->bMarqueeSelect
)
5304 SetBkColor(hdc
, RGB(255, 255, 255));
5305 SetTextColor(hdc
, RGB(0, 0, 0));
5306 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5309 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5312 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5313 notify_postpaint(infoPtr
, &nmlvcd
);
5316 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5317 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5318 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5319 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5324 SelectObject(hdc
, hOldFont
);
5325 SetBkMode(hdc
, oldBkMode
);
5326 SetBkColor(hdc
, oldBkColor
);
5327 SetTextColor(hdc
, oldTextColor
);
5330 infoPtr
->bIsDrawing
= FALSE
;
5336 * Calculates the approximate width and height of a given number of items.
5339 * [I] infoPtr : valid pointer to the listview structure
5340 * [I] nItemCount : number of items
5341 * [I] wWidth : width
5342 * [I] wHeight : height
5345 * Returns a DWORD. The width in the low word and the height in high word.
5347 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5348 WORD wWidth
, WORD wHeight
)
5350 DWORD dwViewRect
= 0;
5352 if (nItemCount
== -1)
5353 nItemCount
= infoPtr
->nItemCount
;
5355 if (infoPtr
->uView
== LV_VIEW_LIST
)
5357 INT nItemCountPerColumn
= 1;
5358 INT nColumnCount
= 0;
5360 if (wHeight
== 0xFFFF)
5362 /* use current height */
5363 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5366 if (wHeight
< infoPtr
->nItemHeight
)
5367 wHeight
= infoPtr
->nItemHeight
;
5371 if (infoPtr
->nItemHeight
> 0)
5373 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5374 if (nItemCountPerColumn
== 0)
5375 nItemCountPerColumn
= 1;
5377 if (nItemCount
% nItemCountPerColumn
!= 0)
5378 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5380 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5384 /* Microsoft padding magic */
5385 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5386 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5388 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5390 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5394 if (infoPtr
->nItemCount
> 0)
5396 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5397 wWidth
= rcBox
.right
- rcBox
.left
;
5398 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5402 /* use current height and width */
5403 if (wHeight
== 0xffff)
5404 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5405 if (wWidth
== 0xffff)
5406 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5409 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5411 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5417 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5418 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5420 if (wWidth
== 0xffff)
5421 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5423 if (wWidth
< nItemWidth
)
5424 wWidth
= nItemWidth
;
5426 cols
= wWidth
/ nItemWidth
;
5427 if (cols
> nItemCount
)
5434 rows
= nItemCount
/ cols
;
5435 if (nItemCount
% cols
)
5441 wHeight
= (nItemHeight
* rows
)+2;
5442 wWidth
= (nItemWidth
* cols
)+2;
5444 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5446 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5447 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5454 * Cancel edit label with saving item text.
5457 * [I] infoPtr : valid pointer to the listview structure
5460 * Always returns TRUE.
5462 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5464 if (infoPtr
->hwndEdit
)
5466 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5467 HWND edit
= infoPtr
->hwndEdit
;
5469 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5470 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5478 * Create a drag image list for the specified item.
5481 * [I] infoPtr : valid pointer to the listview structure
5482 * [I] iItem : index of item
5483 * [O] lppt : Upper-left corner of the image
5486 * Returns a handle to the image list if successful, NULL otherwise.
5488 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5494 HBITMAP hbmp
, hOldbmp
;
5496 HIMAGELIST dragList
= 0;
5497 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5499 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5502 rcItem
.left
= LVIR_BOUNDS
;
5503 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5506 lppt
->x
= rcItem
.left
;
5507 lppt
->y
= rcItem
.top
;
5509 size
.cx
= rcItem
.right
- rcItem
.left
;
5510 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5512 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5513 hdc
= CreateCompatibleDC(hdcOrig
);
5514 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5515 hOldbmp
= SelectObject(hdc
, hbmp
);
5516 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5518 SetRect(&rcItem
, 0, 0, size
.cx
, size
.cy
);
5519 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5522 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5524 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5525 SelectObject(hdc
, hOldbmp
);
5526 ImageList_Add(dragList
, hbmp
, 0);
5529 SelectObject(hdc
, hOldbmp
);
5531 SelectObject(hdc
, hOldFont
);
5534 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5536 TRACE("ret=%p\n", dragList
);
5544 * Removes all listview items and subitems.
5547 * [I] infoPtr : valid pointer to the listview structure
5553 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5555 HDPA hdpaSubItems
= NULL
;
5556 BOOL suppress
= FALSE
;
5564 /* we do it directly, to avoid notifications */
5565 ranges_clear(infoPtr
->selectionRanges
);
5566 infoPtr
->nSelectionMark
= -1;
5567 infoPtr
->nFocusedItem
= -1;
5568 SetRectEmpty(&infoPtr
->rcFocus
);
5569 /* But we are supposed to leave nHotItem as is! */
5571 /* send LVN_DELETEALLITEMS notification */
5572 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5576 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5578 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5581 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5583 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5585 /* send LVN_DELETEITEM notification, if not suppressed
5586 and if it is not a virtual listview */
5587 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5588 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5589 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5590 /* free id struct */
5591 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5592 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5593 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5595 /* both item and subitem start with ITEMHDR header */
5596 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5598 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5599 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5602 DPA_Destroy(hdpaSubItems
);
5603 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5605 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5606 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5607 infoPtr
->nItemCount
--;
5612 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5613 LISTVIEW_UpdateScroll(infoPtr
);
5615 LISTVIEW_InvalidateList(infoPtr
);
5622 * Scrolls, and updates the columns, when a column is changing width.
5625 * [I] infoPtr : valid pointer to the listview structure
5626 * [I] nColumn : column to scroll
5627 * [I] dx : amount of scroll, in pixels
5632 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5634 COLUMN_INFO
*lpColumnInfo
;
5640 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5641 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5642 rcCol
= lpColumnInfo
->rcHeader
;
5643 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5644 rcCol
.left
= rcCol
.right
;
5646 /* adjust the other columns */
5647 hdi
.mask
= HDI_ORDER
;
5648 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5650 INT nOrder
= hdi
.iOrder
;
5651 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5653 hdi
.mask
= HDI_ORDER
;
5654 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5655 if (hdi
.iOrder
>= nOrder
) {
5656 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5657 lpColumnInfo
->rcHeader
.left
+= dx
;
5658 lpColumnInfo
->rcHeader
.right
+= dx
;
5663 /* do not update screen if not in report mode */
5664 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5666 /* Need to reset the item width when inserting a new column */
5667 infoPtr
->nItemWidth
+= dx
;
5669 LISTVIEW_UpdateScroll(infoPtr
);
5670 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5672 /* scroll to cover the deleted column, and invalidate for redraw */
5673 rcOld
= infoPtr
->rcList
;
5674 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5675 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5680 * Removes a column from the listview control.
5683 * [I] infoPtr : valid pointer to the listview structure
5684 * [I] nColumn : column index
5690 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5694 TRACE("nColumn=%d\n", nColumn
);
5696 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5699 /* While the MSDN specifically says that column zero should not be deleted,
5700 what actually happens is that the column itself is deleted but no items or subitems
5704 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5706 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5709 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5710 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5712 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5714 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5716 INT nItem
, nSubItem
, i
;
5718 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5720 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5723 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5725 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5726 if (lpSubItem
->iSubItem
== nColumn
)
5729 lpDelItem
= lpSubItem
;
5731 else if (lpSubItem
->iSubItem
> nColumn
)
5733 lpSubItem
->iSubItem
--;
5737 /* if we found our subitem, zap it */
5741 if (is_text(lpDelItem
->hdr
.pszText
))
5742 Free(lpDelItem
->hdr
.pszText
);
5747 /* free dpa memory */
5748 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5753 /* update the other column info */
5754 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5755 LISTVIEW_InvalidateList(infoPtr
);
5757 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5758 LISTVIEW_UpdateItemSize(infoPtr
);
5765 * Invalidates the listview after an item's insertion or deletion.
5768 * [I] infoPtr : valid pointer to the listview structure
5769 * [I] nItem : item index
5770 * [I] dir : -1 if deleting, 1 if inserting
5775 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5777 INT nPerCol
, nItemCol
, nItemRow
;
5781 /* if we don't refresh, what's the point of scrolling? */
5782 if (!is_redrawing(infoPtr
)) return;
5784 assert (abs(dir
) == 1);
5786 /* arrange icons if autoarrange is on */
5787 if (is_autoarrange(infoPtr
))
5789 BOOL arrange
= TRUE
;
5790 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5791 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5792 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5795 /* scrollbars need updating */
5796 LISTVIEW_UpdateScroll(infoPtr
);
5798 /* figure out the item's position */
5799 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5800 nPerCol
= infoPtr
->nItemCount
+ 1;
5801 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5802 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5803 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5806 nItemCol
= nItem
/ nPerCol
;
5807 nItemRow
= nItem
% nPerCol
;
5808 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5810 /* move the items below up a slot */
5811 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5812 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5813 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5814 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5815 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5816 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5817 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5819 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5820 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5823 /* report has only that column, so we're done */
5824 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5826 /* now for LISTs, we have to deal with the columns to the right */
5827 SetRect(&rcScroll
, (nItemCol
+ 1) * infoPtr
->nItemWidth
, 0,
5828 (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
,
5829 nPerCol
* infoPtr
->nItemHeight
);
5830 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5831 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5832 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5837 * Removes an item from the listview control.
5840 * [I] infoPtr : valid pointer to the listview structure
5841 * [I] nItem : item index
5847 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5850 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5851 INT focus
= infoPtr
->nFocusedItem
;
5853 TRACE("(nItem=%d)\n", nItem
);
5855 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5857 /* remove selection, and focus */
5859 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5860 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5862 /* send LVN_DELETEITEM notification. */
5863 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5865 /* we need to do this here, because we'll be deleting stuff */
5867 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5869 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5877 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5878 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5880 /* free id struct */
5881 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5882 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5883 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5885 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5887 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5888 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5891 DPA_Destroy(hdpaSubItems
);
5896 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5897 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5900 infoPtr
->nItemCount
--;
5901 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5902 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5904 /* now is the invalidation fun */
5906 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5913 * Callback implementation for editlabel control
5916 * [I] infoPtr : valid pointer to the listview structure
5917 * [I] storeText : store edit box text as item text
5918 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5924 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5926 HWND hwndSelf
= infoPtr
->hwndSelf
;
5927 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5928 NMLVDISPINFOW dispInfo
;
5929 INT editedItem
= infoPtr
->nEditLabelItem
;
5931 WCHAR
*pszText
= NULL
;
5936 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5940 if (!(pszText
= Alloc(len
* (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5944 GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
);
5946 GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
);
5950 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5952 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5953 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5954 dispInfo
.item
.iItem
= editedItem
;
5955 dispInfo
.item
.iSubItem
= 0;
5956 dispInfo
.item
.stateMask
= ~0;
5957 dispInfo
.item
.pszText
= szDispText
;
5958 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5959 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5966 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5969 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5970 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5971 textfreeT(tmp
, FALSE
);
5974 /* add the text from the edit in */
5975 dispInfo
.item
.mask
|= LVIF_TEXT
;
5976 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5977 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5979 infoPtr
->notify_mask
&= ~NOTIFY_MASK_END_LABEL_EDIT
;
5981 /* Do we need to update the Item Text */
5982 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5984 infoPtr
->notify_mask
|= NOTIFY_MASK_END_LABEL_EDIT
;
5986 infoPtr
->nEditLabelItem
= -1;
5987 infoPtr
->hwndEdit
= 0;
5989 if (!res
) goto cleanup
;
5991 if (!IsWindow(hwndSelf
))
5996 if (!pszText
) return TRUE
;
6003 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
6005 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
6006 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6007 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
6009 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
6015 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6016 dispInfo
.item
.mask
= LVIF_TEXT
;
6017 dispInfo
.item
.iItem
= editedItem
;
6018 dispInfo
.item
.iSubItem
= 0;
6019 dispInfo
.item
.pszText
= pszText
;
6020 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
6021 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
6031 * Subclassed edit control windproc function
6034 * [I] hwnd : the edit window handle
6035 * [I] uMsg : the message that is to be processed
6036 * [I] wParam : first message parameter
6037 * [I] lParam : second message parameter
6038 * [I] isW : TRUE if input is Unicode
6043 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
6045 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
6048 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
6049 hwnd
, uMsg
, wParam
, lParam
, isW
);
6054 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
6058 WNDPROC editProc
= infoPtr
->EditWndProc
;
6059 infoPtr
->EditWndProc
= 0;
6060 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
6061 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6065 if (VK_ESCAPE
== (INT
)wParam
)
6070 else if (VK_RETURN
== (INT
)wParam
)
6074 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6078 if (infoPtr
->hwndEdit
)
6079 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
6081 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6087 * Subclassed edit control Unicode windproc function
6090 * [I] hwnd : the edit window handle
6091 * [I] uMsg : the message that is to be processed
6092 * [I] wParam : first message parameter
6093 * [I] lParam : second message parameter
6097 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6099 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6104 * Subclassed edit control ANSI windproc function
6107 * [I] hwnd : the edit window handle
6108 * [I] uMsg : the message that is to be processed
6109 * [I] wParam : first message parameter
6110 * [I] lParam : second message parameter
6114 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6116 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6121 * Creates a subclassed edit control
6124 * [I] infoPtr : valid pointer to the listview structure
6125 * [I] text : initial text for the edit
6126 * [I] style : the window style
6127 * [I] isW : TRUE if input is Unicode
6131 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6133 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6134 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6137 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6139 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6141 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6143 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6145 if (!hedit
) return 0;
6147 infoPtr
->EditWndProc
= (WNDPROC
)
6148 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6149 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6151 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6152 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6159 * Begin in place editing of specified list view item
6162 * [I] infoPtr : valid pointer to the listview structure
6163 * [I] nItem : item index
6164 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6170 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6172 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6173 HWND hwndSelf
= infoPtr
->hwndSelf
;
6174 NMLVDISPINFOW dispInfo
;
6175 HFONT hOldFont
= NULL
;
6181 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6183 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6185 /* remove existing edit box */
6186 if (infoPtr
->hwndEdit
)
6188 SetFocus(infoPtr
->hwndSelf
);
6189 infoPtr
->hwndEdit
= 0;
6192 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6194 infoPtr
->nEditLabelItem
= nItem
;
6196 LISTVIEW_SetSelection(infoPtr
, nItem
);
6197 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6198 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6200 rect
.left
= LVIR_LABEL
;
6201 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6203 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6204 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6205 dispInfo
.item
.iItem
= nItem
;
6206 dispInfo
.item
.iSubItem
= 0;
6207 dispInfo
.item
.stateMask
= ~0;
6208 dispInfo
.item
.pszText
= disptextW
;
6209 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6210 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6212 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6213 if (!infoPtr
->hwndEdit
) return 0;
6215 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6217 if (!IsWindow(hwndSelf
))
6219 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6220 infoPtr
->hwndEdit
= 0;
6224 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6226 /* position and display edit box */
6227 hdc
= GetDC(infoPtr
->hwndSelf
);
6229 /* select the font to get appropriate metric dimensions */
6231 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6233 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6234 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6235 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6237 /* get string length in pixels */
6238 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6240 /* add extra spacing for the next character */
6241 GetTextMetricsW(hdc
, &tm
);
6242 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6245 SelectObject(hdc
, hOldFont
);
6247 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6249 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6252 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6253 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6254 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6255 SetFocus(infoPtr
->hwndEdit
);
6256 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6257 return infoPtr
->hwndEdit
;
6263 * Ensures the specified item is visible, scrolling into view if necessary.
6266 * [I] infoPtr : valid pointer to the listview structure
6267 * [I] nItem : item index
6268 * [I] bPartial : partially or entirely visible
6274 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6276 INT nScrollPosHeight
= 0;
6277 INT nScrollPosWidth
= 0;
6278 INT nHorzAdjust
= 0;
6279 INT nVertAdjust
= 0;
6282 RECT rcItem
, rcTemp
;
6284 rcItem
.left
= LVIR_BOUNDS
;
6285 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6287 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6289 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6291 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6292 if (infoPtr
->uView
== LV_VIEW_LIST
)
6293 nScrollPosWidth
= infoPtr
->nItemWidth
;
6294 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6295 nScrollPosWidth
= 1;
6297 if (rcItem
.left
< infoPtr
->rcList
.left
)
6300 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6305 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6309 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6311 /* scroll up/down, but not in LVS_LIST mode */
6312 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6313 nScrollPosHeight
= infoPtr
->nItemHeight
;
6314 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6315 nScrollPosHeight
= 1;
6317 if (rcItem
.top
< infoPtr
->rcList
.top
)
6320 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6325 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6329 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6331 if (nScrollPosWidth
)
6333 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6334 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6335 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6338 if (nScrollPosHeight
)
6340 INT diff
= nVertDiff
/ nScrollPosHeight
;
6341 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6342 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6350 * Searches for an item with specific characteristics.
6353 * [I] hwnd : window handle
6354 * [I] nStart : base item index
6355 * [I] lpFindInfo : item information to look for
6358 * SUCCESS : index of item
6361 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6362 const LVFINDINFOW
*lpFindInfo
)
6364 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6365 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6366 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6367 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6368 POINT Position
, Destination
;
6371 /* Search in virtual listviews should be done by application, not by
6372 listview control, so we just send LVN_ODFINDITEMW and return the result */
6373 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6377 nmlv
.iStart
= nStart
;
6378 nmlv
.lvfi
= *lpFindInfo
;
6379 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6382 if (!lpFindInfo
|| nItem
< 0) return -1;
6385 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6387 lvItem
.mask
|= LVIF_TEXT
;
6388 lvItem
.pszText
= szDispText
;
6389 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6392 if (lpFindInfo
->flags
& LVFI_WRAP
)
6395 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6396 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6401 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6402 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6403 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6404 switch(lpFindInfo
->vkDirection
)
6406 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6407 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6408 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6409 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6410 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6411 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6412 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6414 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6415 Destination
.x
= rcArea
.right
;
6416 Destination
.y
= rcArea
.bottom
;
6418 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6422 else Destination
.x
= Destination
.y
= 0;
6424 /* if LVFI_PARAM is specified, all other flags are ignored */
6425 if (lpFindInfo
->flags
& LVFI_PARAM
)
6427 lvItem
.mask
|= LVIF_PARAM
;
6429 lvItem
.mask
&= ~LVIF_TEXT
;
6432 nItem
= bNearest
? -1 : nStart
+ 1;
6435 for (; nItem
< nLast
; nItem
++)
6437 lvItem
.iItem
= nItem
;
6438 lvItem
.iSubItem
= 0;
6439 lvItem
.pszText
= szDispText
;
6440 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6442 if (lvItem
.mask
& LVIF_PARAM
)
6444 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6450 if (lvItem
.mask
& LVIF_TEXT
)
6452 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6454 WCHAR
*p
= wcsstr(lvItem
.pszText
, lpFindInfo
->psz
);
6455 if (!p
|| p
!= lvItem
.pszText
) continue;
6459 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6463 if (!bNearest
) return nItem
;
6465 /* This is very inefficient. To do a good job here,
6466 * we need a sorted array of (x,y) item positions */
6467 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6469 /* compute the distance^2 to the destination */
6470 xdist
= Destination
.x
- Position
.x
;
6471 ydist
= Destination
.y
- Position
.y
;
6472 dist
= xdist
* xdist
+ ydist
* ydist
;
6474 /* remember the distance, and item if it's closer */
6478 nNearestItem
= nItem
;
6485 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6490 return nNearestItem
;
6495 * Searches for an item with specific characteristics.
6498 * [I] hwnd : window handle
6499 * [I] nStart : base item index
6500 * [I] lpFindInfo : item information to look for
6503 * SUCCESS : index of item
6506 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6507 const LVFINDINFOA
*lpFindInfo
)
6513 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6514 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6515 fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6516 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6517 textfreeT(strW
, FALSE
);
6523 * Retrieves column attributes.
6526 * [I] infoPtr : valid pointer to the listview structure
6527 * [I] nColumn : column index
6528 * [IO] lpColumn : column information
6529 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6530 * otherwise it is in fact a LPLVCOLUMNA
6536 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6538 COLUMN_INFO
*lpColumnInfo
;
6541 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6542 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6544 /* initialize memory */
6545 ZeroMemory(&hdi
, sizeof(hdi
));
6547 if (lpColumn
->mask
& LVCF_TEXT
)
6549 hdi
.mask
|= HDI_TEXT
;
6550 hdi
.pszText
= lpColumn
->pszText
;
6551 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6554 if (lpColumn
->mask
& LVCF_IMAGE
)
6555 hdi
.mask
|= HDI_IMAGE
;
6557 if (lpColumn
->mask
& LVCF_ORDER
)
6558 hdi
.mask
|= HDI_ORDER
;
6560 if (lpColumn
->mask
& LVCF_SUBITEM
)
6561 hdi
.mask
|= HDI_LPARAM
;
6563 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6565 if (lpColumn
->mask
& LVCF_FMT
)
6566 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6568 if (lpColumn
->mask
& LVCF_WIDTH
)
6569 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6571 if (lpColumn
->mask
& LVCF_IMAGE
)
6572 lpColumn
->iImage
= hdi
.iImage
;
6574 if (lpColumn
->mask
& LVCF_ORDER
)
6575 lpColumn
->iOrder
= hdi
.iOrder
;
6577 if (lpColumn
->mask
& LVCF_SUBITEM
)
6578 lpColumn
->iSubItem
= hdi
.lParam
;
6580 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6581 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6586 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6588 if (!infoPtr
->hwndHeader
) return FALSE
;
6589 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6594 * Retrieves the column width.
6597 * [I] infoPtr : valid pointer to the listview structure
6598 * [I] int : column index
6601 * SUCCESS : column width
6604 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6606 INT nColumnWidth
= 0;
6609 TRACE("nColumn=%d\n", nColumn
);
6611 /* we have a 'column' in LIST and REPORT mode only */
6612 switch(infoPtr
->uView
)
6615 nColumnWidth
= infoPtr
->nItemWidth
;
6617 case LV_VIEW_DETAILS
:
6618 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6619 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6620 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6622 hdItem
.mask
= HDI_WIDTH
;
6623 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6625 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6628 nColumnWidth
= hdItem
.cxy
;
6632 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6633 return nColumnWidth
;
6638 * In list or report display mode, retrieves the number of items that can fit
6639 * vertically in the visible area. In icon or small icon display mode,
6640 * retrieves the total number of visible items.
6643 * [I] infoPtr : valid pointer to the listview structure
6646 * Number of fully visible items.
6648 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6650 switch (infoPtr
->uView
)
6653 case LV_VIEW_SMALLICON
:
6654 return infoPtr
->nItemCount
;
6655 case LV_VIEW_DETAILS
:
6656 return LISTVIEW_GetCountPerColumn(infoPtr
);
6658 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6666 * Retrieves an image list handle.
6669 * [I] infoPtr : valid pointer to the listview structure
6670 * [I] nImageList : image list identifier
6673 * SUCCESS : image list handle
6676 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6680 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6681 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6682 case LVSIL_STATE
: return infoPtr
->himlState
;
6683 case LVSIL_GROUPHEADER
:
6684 FIXME("LVSIL_GROUPHEADER not supported\n");
6687 WARN("got unknown imagelist index - %d\n", nImageList
);
6692 /* LISTVIEW_GetISearchString */
6696 * Retrieves item attributes.
6699 * [I] hwnd : window handle
6700 * [IO] lpLVItem : item info
6701 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6702 * if FALSE, then lpLVItem is a LPLVITEMA.
6705 * This is the internal 'GetItem' interface -- it tries to
6706 * be smart and avoid text copies, if possible, by modifying
6707 * lpLVItem->pszText to point to the text string. Please note
6708 * that this is not always possible (e.g. OWNERDATA), so on
6709 * entry you *must* supply valid values for pszText, and cchTextMax.
6710 * The only difference to the documented interface is that upon
6711 * return, you should use *only* the lpLVItem->pszText, rather than
6712 * the buffer pointer you provided on input. Most code already does
6713 * that, so it's not a problem.
6714 * For the two cases when the text must be copied (that is,
6715 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6721 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6723 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6724 NMLVDISPINFOW dispInfo
;
6730 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6732 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6735 if (lpLVItem
->mask
== 0) return TRUE
;
6736 TRACE("mask=%x\n", lpLVItem
->mask
);
6738 /* make a local copy */
6739 isubitem
= lpLVItem
->iSubItem
;
6741 if (isubitem
&& (lpLVItem
->mask
& LVIF_STATE
))
6742 lpLVItem
->state
= 0;
6744 /* a quick optimization if all we're asked is the focus state
6745 * these queries are worth optimising since they are common,
6746 * and can be answered in constant time, without the heavy accesses */
6747 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6748 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6750 lpLVItem
->state
= 0;
6751 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
&& isubitem
== 0)
6752 lpLVItem
->state
|= LVIS_FOCUSED
;
6756 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6758 /* if the app stores all the data, handle it separately */
6759 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6761 dispInfo
.item
.state
= 0;
6763 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6764 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6765 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6767 UINT mask
= lpLVItem
->mask
;
6769 /* NOTE: copy only fields which we _know_ are initialized, some apps
6770 * depend on the uninitialized fields being 0 */
6771 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6772 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6773 dispInfo
.item
.iSubItem
= isubitem
;
6774 if (lpLVItem
->mask
& LVIF_TEXT
)
6776 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6778 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6781 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6782 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6785 if (lpLVItem
->mask
& LVIF_STATE
)
6786 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6787 /* could be zeroed on LVIF_NORECOMPUTE case */
6788 if (dispInfo
.item
.mask
)
6790 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6791 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6792 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6794 /* full size structure expected - _WIN32IE >= 0x560 */
6795 *lpLVItem
= dispInfo
.item
;
6797 else if (lpLVItem
->mask
& LVIF_INDENT
)
6799 /* indent member expected - _WIN32IE >= 0x300 */
6800 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6804 /* minimal structure expected */
6805 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6807 lpLVItem
->mask
= mask
;
6808 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6812 /* make sure lParam is zeroed out */
6813 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6815 /* callback marked pointer required here */
6816 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6817 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6819 /* we store only a little state, so if we're not asked, we're done */
6820 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6822 /* if focus is handled by us, report it */
6823 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6825 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6826 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6827 lpLVItem
->state
|= LVIS_FOCUSED
;
6830 /* and do the same for selection, if we handle it */
6831 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6833 lpLVItem
->state
&= ~LVIS_SELECTED
;
6834 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6835 lpLVItem
->state
|= LVIS_SELECTED
;
6841 /* find the item and subitem structures before we proceed */
6842 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6843 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6848 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6849 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6852 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6857 pItemHdr
= &lpItem
->hdr
;
6859 /* Do we need to query the state from the app? */
6860 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6862 dispInfo
.item
.mask
|= LVIF_STATE
;
6863 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6866 /* Do we need to enquire about the image? */
6867 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6868 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6870 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6871 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6874 /* Only items support indentation */
6875 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6878 dispInfo
.item
.mask
|= LVIF_INDENT
;
6879 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6882 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6883 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6884 !is_text(pItemHdr
->pszText
))
6886 dispInfo
.item
.mask
|= LVIF_TEXT
;
6887 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6888 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6889 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6890 *dispInfo
.item
.pszText
= '\0';
6893 /* If we don't have all the requested info, query the application */
6894 if (dispInfo
.item
.mask
)
6896 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6897 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6898 dispInfo
.item
.lParam
= lpItem
->lParam
;
6899 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6900 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6903 /* we should not store values for subitems */
6904 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6906 /* Now, handle the iImage field */
6907 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6909 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6910 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6911 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6913 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6915 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6916 lpLVItem
->iImage
= pItemHdr
->iImage
;
6918 lpLVItem
->iImage
= 0;
6921 /* The pszText field */
6922 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6924 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6925 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6927 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6929 else if (lpLVItem
->mask
& LVIF_TEXT
)
6931 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6932 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6933 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6936 /* Next is the lParam field */
6937 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6939 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6940 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6941 lpItem
->lParam
= dispInfo
.item
.lParam
;
6943 else if (lpLVItem
->mask
& LVIF_PARAM
)
6944 lpLVItem
->lParam
= lpItem
->lParam
;
6946 /* if this is a subitem, we're done */
6947 if (isubitem
) return TRUE
;
6949 /* ... the state field (this one is different due to uCallbackmask) */
6950 if (lpLVItem
->mask
& LVIF_STATE
)
6952 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6953 if (dispInfo
.item
.mask
& LVIF_STATE
)
6955 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6956 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6958 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6960 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6961 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6962 lpLVItem
->state
|= LVIS_FOCUSED
;
6964 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6966 lpLVItem
->state
&= ~LVIS_SELECTED
;
6967 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6968 lpLVItem
->state
|= LVIS_SELECTED
;
6972 /* and last, but not least, the indent field */
6973 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6975 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6976 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6977 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6979 else if (lpLVItem
->mask
& LVIF_INDENT
)
6981 lpLVItem
->iIndent
= lpItem
->iIndent
;
6989 * Retrieves item attributes.
6992 * [I] hwnd : window handle
6993 * [IO] lpLVItem : item info
6994 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6995 * if FALSE, then lpLVItem is a LPLVITEMA.
6998 * This is the external 'GetItem' interface -- it properly copies
6999 * the text in the provided buffer.
7005 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
7010 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
7013 pszText
= lpLVItem
->pszText
;
7014 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
7015 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
7017 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
7018 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
7020 pszText
= LPSTR_TEXTCALLBACKW
;
7022 lpLVItem
->pszText
= pszText
;
7030 * Retrieves the position (upper-left) of the listview control item.
7031 * Note that for LVS_ICON style, the upper-left is that of the icon
7032 * and not the bounding box.
7035 * [I] infoPtr : valid pointer to the listview structure
7036 * [I] nItem : item index
7037 * [O] lpptPosition : coordinate information
7043 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
7047 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
7049 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7051 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7052 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
7054 if (infoPtr
->uView
== LV_VIEW_ICON
)
7056 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
7057 lpptPosition
->y
+= ICON_TOP_PADDING
;
7059 lpptPosition
->x
+= Origin
.x
;
7060 lpptPosition
->y
+= Origin
.y
;
7062 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
7069 * Retrieves the bounding rectangle for a listview control item.
7072 * [I] infoPtr : valid pointer to the listview structure
7073 * [I] nItem : item index
7074 * [IO] lprc : bounding rectangle coordinates
7075 * lprc->left specifies the portion of the item for which the bounding
7076 * rectangle will be retrieved.
7078 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
7079 * including the icon and label.
7082 * * Experiment shows that native control returns:
7083 * * width = min (48, length of text line)
7084 * * .left = position.x - (width - iconsize.cx)/2
7085 * * .right = .left + width
7086 * * height = #lines of text * ntmHeight + icon height + 8
7087 * * .top = position.y - 2
7088 * * .bottom = .top + height
7089 * * separation between items .y = itemSpacing.cy - height
7090 * * .x = itemSpacing.cx - width
7091 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7094 * * Experiment shows that native control returns:
7095 * * width = iconSize.cx + 16
7096 * * .left = position.x - (width - iconsize.cx)/2
7097 * * .right = .left + width
7098 * * height = iconSize.cy + 4
7099 * * .top = position.y - 2
7100 * * .bottom = .top + height
7101 * * separation between items .y = itemSpacing.cy - height
7102 * * .x = itemSpacing.cx - width
7103 * LVIR_LABEL Returns the bounding rectangle of the item text.
7106 * * Experiment shows that native control returns:
7107 * * width = text length
7108 * * .left = position.x - width/2
7109 * * .right = .left + width
7110 * * height = ntmH * linecount + 2
7111 * * .top = position.y + iconSize.cy + 6
7112 * * .bottom = .top + height
7113 * * separation between items .y = itemSpacing.cy - height
7114 * * .x = itemSpacing.cx - width
7115 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7116 * rectangles, but excludes columns in report view.
7123 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7124 * upon whether the window has the focus currently and on whether the item
7125 * is the one with the focus. Ensure that the control's record of which
7126 * item has the focus agrees with the items' records.
7128 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7130 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7131 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7132 POINT Position
, Origin
;
7136 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7138 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7140 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7141 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7143 /* Be smart and try to figure out the minimum we have to do */
7144 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7145 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7146 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7147 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7148 oversizedBox
= TRUE
;
7150 /* get what we need from the item before hand, so we make
7151 * only one request. This can speed up things, if data
7152 * is stored on the app side */
7154 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7155 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7156 lvItem
.iItem
= nItem
;
7157 lvItem
.iSubItem
= 0;
7158 lvItem
.pszText
= szDispText
;
7159 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7160 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7161 /* we got the state already up, simulate it here, to avoid a reget */
7162 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7164 lvItem
.mask
|= LVIF_STATE
;
7165 lvItem
.stateMask
= LVIS_FOCUSED
;
7166 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7169 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7170 lprc
->left
= LVIR_BOUNDS
;
7176 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7180 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7184 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7187 case LVIR_SELECTBOUNDS
:
7188 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7192 WARN("Unknown value: %d\n", lprc
->left
);
7196 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7198 if (mode
!= LVIR_BOUNDS
)
7199 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7200 Position
.y
+ Origin
.y
);
7202 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7205 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7207 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7214 * Retrieves the spacing between listview control items.
7217 * [I] infoPtr : valid pointer to the listview structure
7218 * [IO] lprc : rectangle to receive the output
7219 * on input, lprc->top = nSubItem
7220 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7222 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7223 * not only those of the first column.
7229 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7231 RECT rect
= { 0, 0, 0, 0 };
7235 if (!lprc
) return FALSE
;
7237 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7238 /* Subitem of '0' means item itself, and this works for all control view modes */
7240 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7242 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7244 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7245 /* this works for any item index, no matter if it exists or not */
7246 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7248 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7251 rect
.bottom
= infoPtr
->nItemHeight
;
7255 /* Native implementation is broken for this case and garbage is left for left and right fields,
7256 we zero them to get predictable output */
7257 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7258 lprc
->bottom
= infoPtr
->nItemHeight
;
7259 OffsetRect(lprc
, origin
.x
, y
);
7260 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7268 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7269 if (infoPtr
->himlSmall
)
7270 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7272 rect
.right
= rect
.left
;
7274 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7282 ERR("Unknown bounds=%d\n", lprc
->left
);
7286 OffsetRect(&rect
, origin
.x
, y
);
7288 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7295 * Retrieves the spacing between listview control items.
7298 * [I] infoPtr : valid pointer to the listview structure
7299 * [I] bSmall : flag for small or large icon
7302 * Horizontal + vertical spacing
7304 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7310 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7314 if (infoPtr
->uView
== LV_VIEW_ICON
)
7315 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7317 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7324 * Retrieves the state of a listview control item.
7327 * [I] infoPtr : valid pointer to the listview structure
7328 * [I] nItem : item index
7329 * [I] uMask : state mask
7332 * State specified by the mask.
7334 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7338 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7340 lvItem
.iItem
= nItem
;
7341 lvItem
.iSubItem
= 0;
7342 lvItem
.mask
= LVIF_STATE
;
7343 lvItem
.stateMask
= uMask
;
7344 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7346 return lvItem
.state
& uMask
;
7351 * Retrieves the text of a listview control item or subitem.
7354 * [I] hwnd : window handle
7355 * [I] nItem : item index
7356 * [IO] lpLVItem : item information
7357 * [I] isW : TRUE if lpLVItem is Unicode
7360 * SUCCESS : string length
7363 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7365 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7367 lpLVItem
->mask
= LVIF_TEXT
;
7368 lpLVItem
->iItem
= nItem
;
7369 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7371 return textlenT(lpLVItem
->pszText
, isW
);
7376 * Searches for an item based on properties + relationships.
7379 * [I] infoPtr : valid pointer to the listview structure
7380 * [I] nItem : item index
7381 * [I] uFlags : relationship flag
7384 * SUCCESS : item index
7387 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7390 LVFINDINFOW lvFindInfo
;
7391 INT nCountPerColumn
;
7395 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7396 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7398 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7400 if (uFlags
& LVNI_CUT
)
7403 if (uFlags
& LVNI_DROPHILITED
)
7404 uMask
|= LVIS_DROPHILITED
;
7406 if (uFlags
& LVNI_FOCUSED
)
7407 uMask
|= LVIS_FOCUSED
;
7409 if (uFlags
& LVNI_SELECTED
)
7410 uMask
|= LVIS_SELECTED
;
7412 /* if we're asked for the focused item, that's only one,
7413 * so it's worth optimizing */
7414 if (uFlags
& LVNI_FOCUSED
)
7416 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7417 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7420 if (uFlags
& LVNI_ABOVE
)
7422 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7427 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7433 /* Special case for autoarrange - move 'til the top of a list */
7434 if (is_autoarrange(infoPtr
))
7436 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7437 while (nItem
- nCountPerRow
>= 0)
7439 nItem
-= nCountPerRow
;
7440 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7445 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7446 lvFindInfo
.vkDirection
= VK_UP
;
7447 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7448 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7450 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7455 else if (uFlags
& LVNI_BELOW
)
7457 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7459 while (nItem
< infoPtr
->nItemCount
)
7462 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7468 /* Special case for autoarrange - move 'til the bottom of a list */
7469 if (is_autoarrange(infoPtr
))
7471 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7472 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7474 nItem
+= nCountPerRow
;
7475 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7480 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7481 lvFindInfo
.vkDirection
= VK_DOWN
;
7482 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7483 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7485 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7490 else if (uFlags
& LVNI_TOLEFT
)
7492 if (infoPtr
->uView
== LV_VIEW_LIST
)
7494 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7495 while (nItem
- nCountPerColumn
>= 0)
7497 nItem
-= nCountPerColumn
;
7498 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7502 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7504 /* Special case for autoarrange - move 'til the beginning of a row */
7505 if (is_autoarrange(infoPtr
))
7507 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7508 while (nItem
% nCountPerRow
> 0)
7511 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7516 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7517 lvFindInfo
.vkDirection
= VK_LEFT
;
7518 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7519 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7521 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7526 else if (uFlags
& LVNI_TORIGHT
)
7528 if (infoPtr
->uView
== LV_VIEW_LIST
)
7530 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7531 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7533 nItem
+= nCountPerColumn
;
7534 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7538 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7540 /* Special case for autoarrange - move 'til the end of a row */
7541 if (is_autoarrange(infoPtr
))
7543 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7544 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7547 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7552 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7553 lvFindInfo
.vkDirection
= VK_RIGHT
;
7554 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7555 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7557 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7566 /* search by index */
7567 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7569 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7577 /* LISTVIEW_GetNumberOfWorkAreas */
7581 * Retrieves the origin coordinates when in icon or small icon display mode.
7584 * [I] infoPtr : valid pointer to the listview structure
7585 * [O] lpptOrigin : coordinate information
7590 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7592 INT nHorzPos
= 0, nVertPos
= 0;
7593 SCROLLINFO scrollInfo
;
7595 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7596 scrollInfo
.fMask
= SIF_POS
;
7598 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7599 nHorzPos
= scrollInfo
.nPos
;
7600 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7601 nVertPos
= scrollInfo
.nPos
;
7603 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7605 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7606 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7607 if (infoPtr
->uView
== LV_VIEW_LIST
)
7608 nHorzPos
*= infoPtr
->nItemWidth
;
7609 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7610 nVertPos
*= infoPtr
->nItemHeight
;
7612 lpptOrigin
->x
-= nHorzPos
;
7613 lpptOrigin
->y
-= nVertPos
;
7615 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7620 * Retrieves the width of a string.
7623 * [I] hwnd : window handle
7624 * [I] lpszText : text string to process
7625 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7628 * SUCCESS : string width (in pixels)
7631 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7636 if (is_text(lpszText
))
7638 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7639 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7640 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7643 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7645 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7646 SelectObject(hdc
, hOldFont
);
7647 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7649 return stringSize
.cx
;
7654 * Determines which listview item is located at the specified position.
7657 * [I] infoPtr : valid pointer to the listview structure
7658 * [IO] lpht : hit test information
7659 * [I] subitem : fill out iSubItem.
7660 * [I] select : return the index only if the hit selects the item
7663 * (mm 20001022): We must not allow iSubItem to be touched, for
7664 * an app might pass only a structure with space up to iItem!
7665 * (MS Office 97 does that for instance in the file open dialog)
7668 * SUCCESS : item index
7671 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7673 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7674 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7675 POINT Origin
, Position
, opt
;
7681 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7685 if (subitem
) lpht
->iSubItem
= 0;
7687 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7689 /* set whole list relation flags */
7690 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7692 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7693 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7694 lpht
->flags
|= LVHT_TOLEFT
;
7696 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7697 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7701 if (infoPtr
->rcList
.bottom
< opt
.y
)
7702 lpht
->flags
|= LVHT_BELOW
;
7706 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7707 lpht
->flags
|= LVHT_TOLEFT
;
7708 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7709 lpht
->flags
|= LVHT_TORIGHT
;
7711 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7712 lpht
->flags
|= LVHT_ABOVE
;
7713 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7714 lpht
->flags
|= LVHT_BELOW
;
7717 /* even if item is invalid try to find subitem */
7718 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7723 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7725 lpht
->iSubItem
= -1;
7726 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7728 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7730 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7736 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7738 /* if we're outside horizontal columns bounds there's nothing to test further */
7739 if (lpht
->iSubItem
== -1)
7742 lpht
->flags
= LVHT_NOWHERE
;
7747 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7748 if (lpht
->flags
) return -1;
7750 lpht
->flags
|= LVHT_NOWHERE
;
7752 /* first deal with the large items */
7753 rcSearch
.left
= lpht
->pt
.x
;
7754 rcSearch
.top
= lpht
->pt
.y
;
7755 rcSearch
.right
= rcSearch
.left
+ 1;
7756 rcSearch
.bottom
= rcSearch
.top
+ 1;
7758 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7759 iterator_next(&i
); /* go to first item in the sequence */
7761 iterator_destroy(&i
);
7763 TRACE("lpht->iItem=%d\n", iItem
);
7764 if (iItem
== -1) return -1;
7766 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7767 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7768 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7769 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7770 lvItem
.iItem
= iItem
;
7771 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7772 lvItem
.pszText
= szDispText
;
7773 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7774 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7775 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7777 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7778 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7779 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7781 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7782 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7784 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7786 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7789 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7790 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7794 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7795 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7797 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7798 if (!PtInRect(&rcBounds
, opt
)) return -1;
7800 /* That's a special case - row rectangle is used as item rectangle and
7801 returned flags contain all item parts. */
7802 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7804 if (PtInRect(&rcIcon
, opt
))
7805 lpht
->flags
|= LVHT_ONITEMICON
;
7806 else if (PtInRect(&rcLabel
, opt
))
7807 lpht
->flags
|= LVHT_ONITEMLABEL
;
7808 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7809 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7810 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7812 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7814 if (lpht
->flags
& LVHT_ONITEM
)
7815 lpht
->flags
&= ~LVHT_NOWHERE
;
7816 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7818 if (select
&& !is_fullrow
)
7820 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7822 /* get main item bounds */
7823 lvItem
.iSubItem
= 0;
7824 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7825 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7826 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7828 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7830 return lpht
->iItem
= iItem
;
7835 * Inserts a new item in the listview control.
7838 * [I] infoPtr : valid pointer to the listview structure
7839 * [I] lpLVItem : item information
7840 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7843 * SUCCESS : new item index
7846 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7853 BOOL is_sorted
, has_changed
;
7855 HWND hwndSelf
= infoPtr
->hwndSelf
;
7857 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7859 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7861 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7862 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7864 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7866 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7868 /* insert item in listview control data structure */
7869 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7870 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7872 /* link with id struct */
7873 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7875 lpID
->item
= hdpaSubItems
;
7876 lpID
->id
= get_next_itemid(infoPtr
);
7877 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7879 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7880 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7882 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7884 /* calculate new item index */
7892 textW
= textdupTtoW(lpLVItem
->pszText
, isW
);
7894 while (i
< infoPtr
->nItemCount
)
7896 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7897 item_s
= DPA_GetPtr(hItem
, 0);
7899 cmpv
= textcmpWT(item_s
->hdr
.pszText
, textW
, TRUE
);
7900 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7902 if (cmpv
>= 0) break;
7906 textfreeT(textW
, isW
);
7911 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7913 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7914 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7915 if (nItem
== -1) goto fail
;
7916 infoPtr
->nItemCount
++;
7918 /* shift indices first so they don't get tangled */
7919 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7921 /* set the item attributes */
7922 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7924 /* full size structure expected - _WIN32IE >= 0x560 */
7927 else if (lpLVItem
->mask
& LVIF_INDENT
)
7929 /* indent member expected - _WIN32IE >= 0x300 */
7930 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7934 /* minimal structure expected */
7935 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7938 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7940 if (item
.mask
& LVIF_STATE
)
7942 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7943 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7944 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7948 item
.mask
|= LVIF_STATE
;
7949 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7950 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7954 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7956 /* make room for the position, if we are in the right mode */
7957 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7959 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7961 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7963 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7968 /* send LVN_INSERTITEM notification */
7969 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7971 nmlv
.lParam
= lpItem
->lParam
;
7972 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7973 if (!IsWindow(hwndSelf
))
7976 /* align items (set position of each item) */
7977 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7981 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7982 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7984 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7986 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7989 /* now is the invalidation fun */
7990 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7994 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7995 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7996 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7997 infoPtr
->nItemCount
--;
7999 DPA_DeletePtr(hdpaSubItems
, 0);
8000 DPA_Destroy (hdpaSubItems
);
8007 * Checks item visibility.
8010 * [I] infoPtr : valid pointer to the listview structure
8011 * [I] nFirst : item index to check for
8014 * Item visible : TRUE
8015 * Item invisible or failure : FALSE
8017 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
8019 POINT Origin
, Position
;
8024 TRACE("nItem=%d\n", nItem
);
8026 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
8028 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8029 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
8030 rcItem
.left
= Position
.x
+ Origin
.x
;
8031 rcItem
.top
= Position
.y
+ Origin
.y
;
8032 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
8033 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
8035 hdc
= GetDC(infoPtr
->hwndSelf
);
8036 if (!hdc
) return FALSE
;
8037 ret
= RectVisible(hdc
, &rcItem
);
8038 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8045 * Redraws a range of items.
8048 * [I] infoPtr : valid pointer to the listview structure
8049 * [I] nFirst : first item
8050 * [I] nLast : last item
8056 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
8060 for (i
= max(nFirst
, 0); i
<= min(nLast
, infoPtr
->nItemCount
- 1); i
++)
8061 LISTVIEW_InvalidateItem(infoPtr
, i
);
8068 * Scroll the content of a listview.
8071 * [I] infoPtr : valid pointer to the listview structure
8072 * [I] dx : horizontal scroll amount in pixels
8073 * [I] dy : vertical scroll amount in pixels
8080 * If the control is in report view (LV_VIEW_DETAILS) the control can
8081 * be scrolled only in line increments. "dy" will be rounded to the
8082 * nearest number of pixels that are a whole line. Ex: if line height
8083 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
8084 * is passed, then the scroll will be 0. (per MSDN 7/2002)
8086 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8088 switch(infoPtr
->uView
) {
8089 case LV_VIEW_DETAILS
:
8090 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
8091 dy
/= infoPtr
->nItemHeight
;
8094 if (dy
!= 0) return FALSE
;
8100 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8101 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8108 * Sets the background color.
8111 * [I] infoPtr : valid pointer to the listview structure
8112 * [I] color : background color
8118 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8120 TRACE("(color=%x)\n", color
);
8123 infoPtr
->bDefaultBkColor
= FALSE
;
8125 if(infoPtr
->clrBk
!= color
) {
8126 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8127 infoPtr
->clrBk
= color
;
8128 if (color
== CLR_NONE
)
8129 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8132 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8133 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8140 /* LISTVIEW_SetBkImage */
8142 /*** Helper for {Insert,Set}ColumnT *only* */
8143 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8144 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8146 if (lpColumn
->mask
& LVCF_FMT
)
8148 /* format member is valid */
8149 lphdi
->mask
|= HDI_FORMAT
;
8151 /* set text alignment (leftmost column must be left-aligned) */
8152 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8153 lphdi
->fmt
|= HDF_LEFT
;
8154 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8155 lphdi
->fmt
|= HDF_RIGHT
;
8156 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8157 lphdi
->fmt
|= HDF_CENTER
;
8159 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8160 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8162 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8164 lphdi
->fmt
|= HDF_IMAGE
;
8165 lphdi
->iImage
= I_IMAGECALLBACK
;
8168 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8169 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8172 if (lpColumn
->mask
& LVCF_WIDTH
)
8174 lphdi
->mask
|= HDI_WIDTH
;
8175 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8177 /* make it fill the remainder of the controls width */
8181 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8183 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8184 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8187 /* retrieve the layout of the header */
8188 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8189 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8191 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8194 lphdi
->cxy
= lpColumn
->cx
;
8197 if (lpColumn
->mask
& LVCF_TEXT
)
8199 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8200 lphdi
->fmt
|= HDF_STRING
;
8201 lphdi
->pszText
= lpColumn
->pszText
;
8202 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8205 if (lpColumn
->mask
& LVCF_IMAGE
)
8207 lphdi
->mask
|= HDI_IMAGE
;
8208 lphdi
->iImage
= lpColumn
->iImage
;
8211 if (lpColumn
->mask
& LVCF_ORDER
)
8213 lphdi
->mask
|= HDI_ORDER
;
8214 lphdi
->iOrder
= lpColumn
->iOrder
;
8221 * Inserts a new column.
8224 * [I] infoPtr : valid pointer to the listview structure
8225 * [I] nColumn : column index
8226 * [I] lpColumn : column information
8227 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8230 * SUCCESS : new column index
8233 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8234 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8236 COLUMN_INFO
*lpColumnInfo
;
8240 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8242 if (!lpColumn
|| nColumn
< 0) return -1;
8243 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8245 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8246 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8249 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8250 * (can be seen in SPY) otherwise column never gets added.
8252 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8253 hdi
.mask
|= HDI_WIDTH
;
8258 * when the iSubItem is available Windows copies it to the header lParam. It seems
8259 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8261 if (lpColumn
->mask
& LVCF_SUBITEM
)
8263 hdi
.mask
|= HDI_LPARAM
;
8264 hdi
.lParam
= lpColumn
->iSubItem
;
8267 /* create header if not present */
8268 LISTVIEW_CreateHeader(infoPtr
);
8269 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8270 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8272 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8275 /* insert item in header control */
8276 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8277 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8278 nColumn
, (LPARAM
)&hdi
);
8279 if (nNewColumn
== -1) return -1;
8280 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8282 /* create our own column info */
8283 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8284 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8286 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8287 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8288 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8291 /* now we have to actually adjust the data */
8292 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8294 SUBITEM_INFO
*lpSubItem
;
8300 item
.iSubItem
= nNewColumn
;
8301 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8302 item
.iImage
= I_IMAGECALLBACK
;
8303 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8305 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8307 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8308 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8310 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8311 if (lpSubItem
->iSubItem
>= nNewColumn
)
8312 lpSubItem
->iSubItem
++;
8315 /* add new subitem for each item */
8317 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8321 /* make space for the new column */
8322 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8323 LISTVIEW_UpdateItemSize(infoPtr
);
8328 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8331 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8339 * Sets the attributes of a header item.
8342 * [I] infoPtr : valid pointer to the listview structure
8343 * [I] nColumn : column index
8344 * [I] lpColumn : column attributes
8345 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8351 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8352 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8354 HDITEMW hdi
, hdiget
;
8357 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8359 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8361 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8362 if (lpColumn
->mask
& LVCF_FMT
)
8364 hdi
.mask
|= HDI_FORMAT
;
8365 hdiget
.mask
= HDI_FORMAT
;
8366 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8367 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8369 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8371 /* set header item attributes */
8372 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8373 if (!bResult
) return FALSE
;
8375 if (lpColumn
->mask
& LVCF_FMT
)
8377 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8378 INT oldFmt
= lpColumnInfo
->fmt
;
8380 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8381 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8383 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8387 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8388 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8395 * Sets the column order array
8398 * [I] infoPtr : valid pointer to the listview structure
8399 * [I] iCount : number of elements in column order array
8400 * [I] lpiArray : pointer to column order array
8406 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8408 if (!infoPtr
->hwndHeader
) return FALSE
;
8409 infoPtr
->colRectsDirty
= TRUE
;
8410 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8415 * Sets the width of a column
8418 * [I] infoPtr : valid pointer to the listview structure
8419 * [I] nColumn : column index
8420 * [I] cx : column width
8426 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8428 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8432 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8434 /* set column width only if in report or list mode */
8435 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8437 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8438 with _USEHEADER being the lowest */
8439 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8440 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8442 /* resize all columns if in LV_VIEW_LIST mode */
8443 if(infoPtr
->uView
== LV_VIEW_LIST
)
8445 infoPtr
->nItemWidth
= cx
;
8446 LISTVIEW_InvalidateList(infoPtr
);
8450 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8452 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8457 lvItem
.mask
= LVIF_TEXT
;
8459 lvItem
.iSubItem
= nColumn
;
8460 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8461 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8463 lvItem
.pszText
= szDispText
;
8464 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8465 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8466 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8468 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8469 max_cx
+= infoPtr
->iconSize
.cx
;
8470 max_cx
+= TRAILING_LABEL_PADDING
;
8471 if (nColumn
== 0 && (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
))
8472 max_cx
+= GetSystemMetrics(SM_CXSMICON
);
8475 /* autosize based on listview items width */
8476 if(cx
== LVSCW_AUTOSIZE
)
8478 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8480 /* if iCol is the last column make it fill the remainder of the controls width */
8481 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8486 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8487 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8489 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8493 /* Despite what the MS docs say, if this is not the last
8494 column, then MS resizes the column to the width of the
8495 largest text string in the column, including headers
8496 and items. This is different from LVSCW_AUTOSIZE in that
8497 LVSCW_AUTOSIZE ignores the header string length. */
8500 /* retrieve header text */
8501 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8502 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8503 hdi
.pszText
= szDispText
;
8504 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8506 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8507 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8508 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8509 INT bitmap_margin
= 0;
8512 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8513 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8515 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8516 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8518 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8520 INT icon_cx
, icon_cy
;
8522 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8523 cx
+= icon_cx
+ 2*bitmap_margin
;
8525 else if (hdi
.fmt
& HDF_BITMAP
)
8529 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8530 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8533 SelectObject(hdc
, old_font
);
8534 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8536 cx
= max (cx
, max_cx
);
8540 if (cx
< 0) return FALSE
;
8542 /* call header to update the column change */
8543 hdi
.mask
= HDI_WIDTH
;
8544 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8545 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8546 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8550 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8553 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8556 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8558 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8559 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8562 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8563 ILC_COLOR
| ILC_MASK
, 2, 2);
8564 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8565 hdc
= CreateCompatibleDC(hdc_wnd
);
8566 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8567 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8568 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8570 SetRect(&rc
, 0, 0, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8571 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8572 FillRect(hdc
, &rc
, hbr_white
);
8573 InflateRect(&rc
, -2, -2);
8574 FillRect(hdc
, &rc
, hbr_black
);
8576 SelectObject(hdc
, hbm_im
);
8577 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8578 SelectObject(hdc
, hbm_orig
);
8579 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8581 SelectObject(hdc
, hbm_im
);
8582 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8583 SelectObject(hdc
, hbm_orig
);
8584 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8586 DeleteObject(hbm_mask
);
8587 DeleteObject(hbm_im
);
8595 * Sets the extended listview style.
8598 * [I] infoPtr : valid pointer to the listview structure
8600 * [I] dwStyle : style
8603 * SUCCESS : previous style
8606 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8608 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8610 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8614 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8616 infoPtr
->dwLvExStyle
= ex_style
;
8618 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8620 HIMAGELIST himl
= 0;
8621 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8624 item
.mask
= LVIF_STATE
;
8625 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8626 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8627 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8629 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8630 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8631 ImageList_Destroy(infoPtr
->himlState
);
8633 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8634 /* checkbox list replaces previous custom list or... */
8635 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8636 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8637 /* ...previous was checkbox list */
8638 (old_ex_style
& LVS_EX_CHECKBOXES
))
8639 ImageList_Destroy(himl
);
8642 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8646 /* if not already created */
8647 LISTVIEW_CreateHeader(infoPtr
);
8649 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8650 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8651 style
|= HDS_DRAGDROP
;
8653 style
&= ~HDS_DRAGDROP
;
8654 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8657 /* GRIDLINES adds decoration at top so changes sizes */
8658 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8660 LISTVIEW_CreateHeader(infoPtr
);
8661 LISTVIEW_UpdateSize(infoPtr
);
8664 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8666 LISTVIEW_CreateHeader(infoPtr
);
8669 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8671 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8672 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8675 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8677 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8678 LISTVIEW_CreateHeader(infoPtr
);
8680 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8681 LISTVIEW_UpdateSize(infoPtr
);
8682 LISTVIEW_UpdateScroll(infoPtr
);
8685 LISTVIEW_InvalidateList(infoPtr
);
8686 return old_ex_style
;
8691 * Sets the new hot cursor used during hot tracking and hover selection.
8694 * [I] infoPtr : valid pointer to the listview structure
8695 * [I] hCursor : the new hot cursor handle
8698 * Returns the previous hot cursor
8700 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8702 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8704 infoPtr
->hHotCursor
= hCursor
;
8712 * Sets the hot item index.
8715 * [I] infoPtr : valid pointer to the listview structure
8716 * [I] iIndex : index
8719 * SUCCESS : previous hot item index
8720 * FAILURE : -1 (no hot item)
8722 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8724 INT iOldIndex
= infoPtr
->nHotItem
;
8726 infoPtr
->nHotItem
= iIndex
;
8734 * Sets the amount of time the cursor must hover over an item before it is selected.
8737 * [I] infoPtr : valid pointer to the listview structure
8738 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8741 * Returns the previous hover time
8743 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8745 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8747 infoPtr
->dwHoverTime
= dwHoverTime
;
8749 return oldHoverTime
;
8754 * Sets spacing for icons of LVS_ICON style.
8757 * [I] infoPtr : valid pointer to the listview structure
8758 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8759 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8762 * MAKELONG(oldcx, oldcy)
8764 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8766 INT iconWidth
= 0, iconHeight
= 0;
8767 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8769 TRACE("requested=(%d,%d)\n", cx
, cy
);
8771 /* set to defaults, if instructed to */
8772 if (cx
== -1 && cy
== -1)
8774 infoPtr
->autoSpacing
= TRUE
;
8775 if (infoPtr
->himlNormal
)
8776 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8777 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8778 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8781 infoPtr
->autoSpacing
= FALSE
;
8783 /* if 0 then keep width */
8785 infoPtr
->iconSpacing
.cx
= cx
;
8787 /* if 0 then keep height */
8789 infoPtr
->iconSpacing
.cy
= cy
;
8791 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8792 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8793 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8794 infoPtr
->ntmHeight
);
8796 /* these depend on the iconSpacing */
8797 LISTVIEW_UpdateItemSize(infoPtr
);
8802 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL is_small
)
8806 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8813 size
->cx
= GetSystemMetrics(is_small
? SM_CXSMICON
: SM_CXICON
);
8814 size
->cy
= GetSystemMetrics(is_small
? SM_CYSMICON
: SM_CYICON
);
8823 * [I] infoPtr : valid pointer to the listview structure
8824 * [I] nType : image list type
8825 * [I] himl : image list handle
8828 * SUCCESS : old image list
8831 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8833 INT oldHeight
= infoPtr
->nItemHeight
;
8834 HIMAGELIST himlOld
= 0;
8836 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8841 himlOld
= infoPtr
->himlNormal
;
8842 infoPtr
->himlNormal
= himl
;
8843 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8844 if (infoPtr
->autoSpacing
)
8845 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8849 himlOld
= infoPtr
->himlSmall
;
8850 infoPtr
->himlSmall
= himl
;
8851 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8852 if (infoPtr
->hwndHeader
)
8853 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8857 himlOld
= infoPtr
->himlState
;
8858 infoPtr
->himlState
= himl
;
8859 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8860 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8864 ERR("Unknown icon type=%d\n", nType
);
8868 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8869 if (infoPtr
->nItemHeight
!= oldHeight
)
8870 LISTVIEW_UpdateScroll(infoPtr
);
8877 * Preallocates memory (does *not* set the actual count of items !)
8880 * [I] infoPtr : valid pointer to the listview structure
8881 * [I] nItems : item count (projected number of items to allocate)
8882 * [I] dwFlags : update flags
8888 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8890 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8892 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8894 INT nOldCount
= infoPtr
->nItemCount
;
8895 infoPtr
->nItemCount
= nItems
;
8897 if (nItems
< nOldCount
)
8899 RANGE range
= { nItems
, nOldCount
};
8900 ranges_del(infoPtr
->selectionRanges
, range
);
8901 if (infoPtr
->nFocusedItem
>= nItems
)
8903 LISTVIEW_SetItemFocus(infoPtr
, -1);
8904 infoPtr
->nFocusedItem
= -1;
8905 SetRectEmpty(&infoPtr
->rcFocus
);
8909 LISTVIEW_UpdateScroll(infoPtr
);
8911 /* the flags are valid only in ownerdata report and list modes */
8912 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8914 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8915 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8917 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8918 LISTVIEW_InvalidateList(infoPtr
);
8925 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8926 nFrom
= min(nOldCount
, nItems
);
8927 nTo
= max(nOldCount
, nItems
);
8929 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8931 SetRect(&rcErase
, 0, nFrom
* infoPtr
->nItemHeight
, infoPtr
->nItemWidth
,
8932 nTo
* infoPtr
->nItemHeight
);
8933 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8934 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8935 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8937 else /* LV_VIEW_LIST */
8939 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8941 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8942 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8943 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8944 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8945 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8946 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8947 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8949 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8951 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8952 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8953 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8954 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8955 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8961 /* According to MSDN for non-LVS_OWNERDATA this is just
8962 * a performance issue. The control allocates its internal
8963 * data structures for the number of items specified. It
8964 * cuts down on the number of memory allocations. Therefore
8965 * we will just issue a WARN here
8967 WARN("for non-ownerdata performance option not implemented.\n");
8975 * Sets the position of an item.
8978 * [I] infoPtr : valid pointer to the listview structure
8979 * [I] nItem : item index
8980 * [I] pt : coordinate
8986 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8990 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8992 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8993 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8996 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8998 /* This point value seems to be an undocumented feature.
8999 * The best guess is that it means either at the origin,
9000 * or at true beginning of the list. I will assume the origin. */
9001 if ((Pt
.x
== -1) && (Pt
.y
== -1))
9004 if (infoPtr
->uView
== LV_VIEW_ICON
)
9006 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
9007 Pt
.y
-= ICON_TOP_PADDING
;
9012 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
9017 * Sets the state of one or many items.
9020 * [I] infoPtr : valid pointer to the listview structure
9021 * [I] nItem : item index
9022 * [I] item : item or subitem info
9028 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
9033 if (!item
) return FALSE
;
9035 lvItem
.iItem
= nItem
;
9036 lvItem
.iSubItem
= 0;
9037 lvItem
.mask
= LVIF_STATE
;
9038 lvItem
.state
= item
->state
;
9039 lvItem
.stateMask
= item
->stateMask
;
9040 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
9047 /* special case optimization for recurring attempt to deselect all */
9048 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
9051 /* select all isn't allowed in LVS_SINGLESEL */
9052 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
9055 /* focus all isn't allowed */
9056 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
9058 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
9059 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9061 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
9062 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
9063 oldstate
|= LVIS_SELECTED
;
9064 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
9067 /* apply to all items */
9068 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
9069 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
9071 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9075 infoPtr
->notify_mask
|= old_mask
;
9079 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
9080 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
9081 nmlv
.uChanged
= LVIF_STATE
;
9082 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
9085 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
9089 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9096 * Sets the text of an item or subitem.
9099 * [I] hwnd : window handle
9100 * [I] nItem : item index
9101 * [I] lpLVItem : item or subitem info
9102 * [I] isW : TRUE if input is Unicode
9108 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9112 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9113 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9115 lvItem
.iItem
= nItem
;
9116 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9117 lvItem
.mask
= LVIF_TEXT
;
9118 lvItem
.pszText
= lpLVItem
->pszText
;
9119 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9121 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9123 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9128 * Set item index that marks the start of a multiple selection.
9131 * [I] infoPtr : valid pointer to the listview structure
9132 * [I] nIndex : index
9135 * Index number or -1 if there is no selection mark.
9137 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9139 INT nOldIndex
= infoPtr
->nSelectionMark
;
9141 TRACE("(nIndex=%d)\n", nIndex
);
9143 if (nIndex
>= -1 && nIndex
< infoPtr
->nItemCount
)
9144 infoPtr
->nSelectionMark
= nIndex
;
9151 * Sets the text background color.
9154 * [I] infoPtr : valid pointer to the listview structure
9155 * [I] color : text background color
9161 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9163 TRACE("(color=%x)\n", color
);
9165 infoPtr
->clrTextBk
= color
;
9171 * Sets the text foreground color.
9174 * [I] infoPtr : valid pointer to the listview structure
9175 * [I] color : text color
9181 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9183 TRACE("(color=%x)\n", color
);
9185 infoPtr
->clrText
= color
;
9191 * Sets new ToolTip window to ListView control.
9194 * [I] infoPtr : valid pointer to the listview structure
9195 * [I] hwndNewToolTip : handle to new ToolTip
9200 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9202 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9203 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9204 return hwndOldToolTip
;
9209 * sets the Unicode character format flag for the control
9211 * [I] infoPtr :valid pointer to the listview structure
9212 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9215 * Old Unicode Format
9217 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9219 SHORT rc
= infoPtr
->notifyFormat
;
9220 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9221 return rc
== NFR_UNICODE
;
9226 * sets the control view mode
9228 * [I] infoPtr :valid pointer to the listview structure
9229 * [I] nView :new view mode value
9235 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9239 if (infoPtr
->uView
== nView
) return 1;
9241 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9242 if (nView
== LV_VIEW_TILE
)
9244 FIXME("View LV_VIEW_TILE unimplemented\n");
9248 infoPtr
->uView
= nView
;
9250 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9251 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9253 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9254 SetRectEmpty(&infoPtr
->rcFocus
);
9256 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9257 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9262 case LV_VIEW_SMALLICON
:
9263 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9265 case LV_VIEW_DETAILS
:
9270 LISTVIEW_CreateHeader( infoPtr
);
9272 hl
.prc
= &infoPtr
->rcList
;
9274 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9275 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9276 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9283 LISTVIEW_UpdateItemSize(infoPtr
);
9284 LISTVIEW_UpdateSize(infoPtr
);
9285 LISTVIEW_UpdateScroll(infoPtr
);
9286 LISTVIEW_InvalidateList(infoPtr
);
9288 TRACE("nView=%d\n", nView
);
9293 /* LISTVIEW_SetWorkAreas */
9297 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9300 * [I] first : pointer to first ITEM_INFO to compare
9301 * [I] second : pointer to second ITEM_INFO to compare
9302 * [I] lParam : HWND of control
9305 * if first comes before second : negative
9306 * if first comes after second : positive
9307 * if first and second are equivalent : zero
9309 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9311 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9312 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9313 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9315 /* Forward the call to the client defined callback */
9316 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9321 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9324 * [I] first : pointer to first ITEM_INFO to compare
9325 * [I] second : pointer to second ITEM_INFO to compare
9326 * [I] lParam : HWND of control
9329 * if first comes before second : negative
9330 * if first comes after second : positive
9331 * if first and second are equivalent : zero
9333 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9335 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9336 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9337 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9339 /* Forward the call to the client defined callback */
9340 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9345 * Sorts the listview items.
9348 * [I] infoPtr : valid pointer to the listview structure
9349 * [I] pfnCompare : application-defined value
9350 * [I] lParamSort : pointer to comparison callback
9351 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9357 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9358 LPARAM lParamSort
, BOOL IsEx
)
9362 LPVOID selectionMarkItem
= NULL
;
9363 LPVOID focusedItem
= NULL
;
9366 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9368 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9370 if (!pfnCompare
) return FALSE
;
9371 if (!infoPtr
->hdpaItems
) return FALSE
;
9373 /* if there are 0 or 1 items, there is no need to sort */
9374 if (infoPtr
->nItemCount
< 2) return TRUE
;
9376 /* clear selection */
9377 ranges_clear(infoPtr
->selectionRanges
);
9379 /* save selection mark and focused item */
9380 if (infoPtr
->nSelectionMark
>= 0)
9381 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9382 if (infoPtr
->nFocusedItem
>= 0)
9383 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9385 infoPtr
->pfnCompare
= pfnCompare
;
9386 infoPtr
->lParamSort
= lParamSort
;
9388 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9390 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9392 /* restore selection ranges */
9393 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9395 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9396 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9398 if (lpItem
->state
& LVIS_SELECTED
)
9399 ranges_additem(infoPtr
->selectionRanges
, i
);
9401 /* restore selection mark and focused item */
9402 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9403 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9405 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9407 /* refresh the display */
9408 LISTVIEW_InvalidateList(infoPtr
);
9414 * Update theme handle after a theme change.
9417 * [I] infoPtr : valid pointer to the listview structure
9421 * FAILURE : something else
9423 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9425 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9426 CloseThemeData(theme
);
9427 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9433 * Updates an items or rearranges the listview control.
9436 * [I] infoPtr : valid pointer to the listview structure
9437 * [I] nItem : item index
9443 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9445 TRACE("(nItem=%d)\n", nItem
);
9447 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9449 /* rearrange with default alignment style */
9450 if (is_autoarrange(infoPtr
))
9451 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9453 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9460 * Draw the track line at the place defined in the infoPtr structure.
9461 * The line is drawn with a XOR pen so drawing the line for the second time
9462 * in the same place erases the line.
9465 * [I] infoPtr : valid pointer to the listview structure
9471 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9475 if (infoPtr
->xTrackLine
== -1)
9478 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9480 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9481 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9482 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9488 * Called when an edit control should be displayed. This function is called after
9489 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9492 * [I] hwnd : Handle to the listview
9493 * [I] uMsg : WM_TIMER (ignored)
9494 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9495 * [I] dwTimer : The elapsed time (ignored)
9500 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9502 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9503 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9505 KillTimer(hwnd
, idEvent
);
9506 editItem
->fEnabled
= FALSE
;
9507 /* check if the item is still selected */
9508 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9509 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9514 * Creates the listview control - the WM_NCCREATE phase.
9517 * [I] hwnd : window handle
9518 * [I] lpcs : the create parameters
9524 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
9526 LISTVIEW_INFO
*infoPtr
;
9529 TRACE("(lpcs=%p)\n", lpcs
);
9531 /* initialize info pointer */
9532 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9533 if (!infoPtr
) return FALSE
;
9535 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9537 infoPtr
->hwndSelf
= hwnd
;
9538 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9539 map_style_view(infoPtr
);
9540 /* determine the type of structures to use */
9541 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9542 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9544 /* initialize color information */
9545 infoPtr
->clrBk
= CLR_NONE
;
9546 infoPtr
->clrText
= CLR_DEFAULT
;
9547 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9548 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9550 infoPtr
->bDefaultBkColor
= TRUE
;
9553 /* set default values */
9554 infoPtr
->nFocusedItem
= -1;
9555 infoPtr
->nSelectionMark
= -1;
9556 infoPtr
->nHotItem
= -1;
9557 infoPtr
->redraw
= TRUE
;
9558 infoPtr
->bNoItemMetrics
= TRUE
;
9559 infoPtr
->notify_mask
= NOTIFY_MASK_UNMASK_ALL
;
9560 infoPtr
->autoSpacing
= TRUE
;
9561 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9562 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9563 infoPtr
->nEditLabelItem
= -1;
9564 infoPtr
->nLButtonDownItem
= -1;
9565 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9566 infoPtr
->cWheelRemainder
= 0;
9567 infoPtr
->nMeasureItemHeight
= 0;
9568 infoPtr
->xTrackLine
= -1; /* no track line */
9569 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9570 infoPtr
->iVersion
= COMCTL32_VERSION
;
9571 infoPtr
->colRectsDirty
= FALSE
;
9573 /* get default font (icon title) */
9574 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9575 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9576 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9577 LISTVIEW_SaveTextMetrics(infoPtr
);
9579 /* allocate memory for the data structure */
9580 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9581 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9582 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9583 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9584 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9585 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9587 return DefWindowProcW(hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
9590 DestroyWindow(infoPtr
->hwndHeader
);
9591 ranges_destroy(infoPtr
->selectionRanges
);
9592 DPA_Destroy(infoPtr
->hdpaItems
);
9593 DPA_Destroy(infoPtr
->hdpaItemIds
);
9594 DPA_Destroy(infoPtr
->hdpaPosX
);
9595 DPA_Destroy(infoPtr
->hdpaPosY
);
9596 DPA_Destroy(infoPtr
->hdpaColumns
);
9603 * Creates the listview control - the WM_CREATE phase. Most of the data is
9604 * already set up in LISTVIEW_NCCreate
9607 * [I] hwnd : window handle
9608 * [I] lpcs : the create parameters
9614 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9616 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9618 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9620 infoPtr
->dwStyle
= lpcs
->style
;
9621 map_style_view(infoPtr
);
9623 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9624 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9625 /* on error defaulting to ANSI notifications */
9626 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9627 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9629 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9631 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9634 infoPtr
->hwndHeader
= 0;
9636 /* init item size to avoid division by 0 */
9637 LISTVIEW_UpdateItemSize (infoPtr
);
9638 LISTVIEW_UpdateSize (infoPtr
);
9640 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9642 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9644 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9646 LISTVIEW_UpdateScroll(infoPtr
);
9647 /* send WM_MEASUREITEM notification */
9648 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9651 OpenThemeData(hwnd
, themeClass
);
9653 /* initialize the icon sizes */
9654 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9655 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9661 * Destroys the listview control.
9664 * [I] infoPtr : valid pointer to the listview structure
9670 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9672 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9673 CloseThemeData(theme
);
9675 /* delete all items */
9676 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9683 * Enables the listview control.
9686 * [I] infoPtr : valid pointer to the listview structure
9687 * [I] bEnable : specifies whether to enable or disable the window
9693 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9695 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9696 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9702 * Erases the background of the listview control.
9705 * [I] infoPtr : valid pointer to the listview structure
9706 * [I] hdc : device context handle
9712 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9716 TRACE("(hdc=%p)\n", hdc
);
9718 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9720 if (infoPtr
->clrBk
== CLR_NONE
)
9722 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9723 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9724 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9726 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9729 /* for double buffered controls we need to do this during refresh */
9730 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9732 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9738 * Helper function for LISTVIEW_[HV]Scroll *only*.
9739 * Performs vertical/horizontal scrolling by a give amount.
9742 * [I] infoPtr : valid pointer to the listview structure
9743 * [I] dx : amount of horizontal scroll
9744 * [I] dy : amount of vertical scroll
9746 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9748 /* now we can scroll the list */
9749 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9750 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9751 /* if we have focus, adjust rect */
9752 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9753 UpdateWindow(infoPtr
->hwndSelf
);
9758 * Performs vertical scrolling.
9761 * [I] infoPtr : valid pointer to the listview structure
9762 * [I] nScrollCode : scroll code
9763 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9764 * [I] hScrollWnd : scrollbar control window handle
9770 * SB_LINEUP/SB_LINEDOWN:
9771 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9772 * for LVS_REPORT is 1 line
9773 * for LVS_LIST cannot occur
9776 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9779 INT nOldScrollPos
, nNewScrollPos
;
9780 SCROLLINFO scrollInfo
;
9783 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9784 debugscrollcode(nScrollCode
), nScrollDiff
);
9786 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9788 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9789 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9791 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9793 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9795 nOldScrollPos
= scrollInfo
.nPos
;
9796 switch (nScrollCode
)
9802 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9806 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9810 nScrollDiff
= -scrollInfo
.nPage
;
9814 nScrollDiff
= scrollInfo
.nPage
;
9817 case SB_THUMBPOSITION
:
9819 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9826 /* quit right away if pos isn't changing */
9827 if (nScrollDiff
== 0) return 0;
9829 /* calculate new position, and handle overflows */
9830 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9831 if (nScrollDiff
> 0) {
9832 if (nNewScrollPos
< nOldScrollPos
||
9833 nNewScrollPos
> scrollInfo
.nMax
)
9834 nNewScrollPos
= scrollInfo
.nMax
;
9836 if (nNewScrollPos
> nOldScrollPos
||
9837 nNewScrollPos
< scrollInfo
.nMin
)
9838 nNewScrollPos
= scrollInfo
.nMin
;
9841 /* set the new position, and reread in case it changed */
9842 scrollInfo
.fMask
= SIF_POS
;
9843 scrollInfo
.nPos
= nNewScrollPos
;
9844 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9846 /* carry on only if it really changed */
9847 if (nNewScrollPos
== nOldScrollPos
) return 0;
9849 /* now adjust to client coordinates */
9850 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9851 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9853 /* and scroll the window */
9854 scroll_list(infoPtr
, 0, nScrollDiff
);
9861 * Performs horizontal scrolling.
9864 * [I] infoPtr : valid pointer to the listview structure
9865 * [I] nScrollCode : scroll code
9866 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9867 * [I] hScrollWnd : scrollbar control window handle
9873 * SB_LINELEFT/SB_LINERIGHT:
9874 * for LVS_ICON, LVS_SMALLICON 1 pixel
9875 * for LVS_REPORT is 1 pixel
9876 * for LVS_LIST is 1 column --> which is a 1 because the
9877 * scroll is based on columns not pixels
9880 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9883 INT nOldScrollPos
, nNewScrollPos
;
9884 SCROLLINFO scrollInfo
;
9887 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9888 debugscrollcode(nScrollCode
), nScrollDiff
);
9890 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9892 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9893 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9895 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9897 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9899 nOldScrollPos
= scrollInfo
.nPos
;
9901 switch (nScrollCode
)
9907 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9911 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9915 nScrollDiff
= -scrollInfo
.nPage
;
9919 nScrollDiff
= scrollInfo
.nPage
;
9922 case SB_THUMBPOSITION
:
9924 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9931 /* quit right away if pos isn't changing */
9932 if (nScrollDiff
== 0) return 0;
9934 /* calculate new position, and handle overflows */
9935 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9936 if (nScrollDiff
> 0) {
9937 if (nNewScrollPos
< nOldScrollPos
||
9938 nNewScrollPos
> scrollInfo
.nMax
)
9939 nNewScrollPos
= scrollInfo
.nMax
;
9941 if (nNewScrollPos
> nOldScrollPos
||
9942 nNewScrollPos
< scrollInfo
.nMin
)
9943 nNewScrollPos
= scrollInfo
.nMin
;
9946 /* set the new position, and reread in case it changed */
9947 scrollInfo
.fMask
= SIF_POS
;
9948 scrollInfo
.nPos
= nNewScrollPos
;
9949 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9951 /* carry on only if it really changed */
9952 if (nNewScrollPos
== nOldScrollPos
) return 0;
9954 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9956 /* now adjust to client coordinates */
9957 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9958 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9960 /* and scroll the window */
9961 scroll_list(infoPtr
, nScrollDiff
, 0);
9966 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9968 INT pulScrollLines
= 3;
9970 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9972 switch(infoPtr
->uView
)
9975 case LV_VIEW_SMALLICON
:
9977 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9978 * should be fixed in the future.
9980 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9981 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9984 case LV_VIEW_DETAILS
:
9985 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9987 /* if scrolling changes direction, ignore left overs */
9988 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9989 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9990 infoPtr
->cWheelRemainder
+= wheelDelta
;
9992 infoPtr
->cWheelRemainder
= wheelDelta
;
9993 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9996 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9997 cLineScroll
= pulScrollLines
* infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9998 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ pulScrollLines
;
9999 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
10004 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
10015 * [I] infoPtr : valid pointer to the listview structure
10016 * [I] nVirtualKey : virtual key
10017 * [I] lKeyData : key data
10022 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
10024 HWND hwndSelf
= infoPtr
->hwndSelf
;
10026 NMLVKEYDOWN nmKeyDown
;
10028 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
10030 /* send LVN_KEYDOWN notification */
10031 nmKeyDown
.wVKey
= nVirtualKey
;
10032 nmKeyDown
.flags
= 0;
10033 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
10034 if (!IsWindow(hwndSelf
))
10037 switch (nVirtualKey
)
10040 nItem
= infoPtr
->nFocusedItem
;
10041 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
10042 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
10046 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
10048 if (!notify(infoPtr
, NM_RETURN
)) return 0;
10049 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
10054 if (infoPtr
->nItemCount
> 0)
10059 if (infoPtr
->nItemCount
> 0)
10060 nItem
= infoPtr
->nItemCount
- 1;
10064 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
10068 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
10072 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
10076 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
10080 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10082 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10083 if (infoPtr
->nFocusedItem
== topidx
)
10084 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
10089 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
10090 * LISTVIEW_GetCountPerRow(infoPtr
);
10091 if(nItem
< 0) nItem
= 0;
10095 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10097 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10098 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10099 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10100 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10102 nItem
= topidx
+ cnt
- 1;
10105 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10106 * LISTVIEW_GetCountPerRow(infoPtr
);
10107 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10111 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10112 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10122 * [I] infoPtr : valid pointer to the listview structure
10127 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10131 /* drop any left over scroll amount */
10132 infoPtr
->cWheelRemainder
= 0;
10134 /* if we did not have the focus, there's nothing more to do */
10135 if (!infoPtr
->bFocus
) return 0;
10137 /* send NM_KILLFOCUS notification */
10138 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10140 /* if we have a focus rectangle, get rid of it */
10141 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10143 /* if have a marquee selection, stop it */
10144 if (infoPtr
->bMarqueeSelect
)
10146 /* Remove the marquee rectangle and release our mouse capture */
10147 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10150 SetRectEmpty(&infoPtr
->marqueeRect
);
10152 infoPtr
->bMarqueeSelect
= FALSE
;
10153 infoPtr
->bScrolling
= FALSE
;
10154 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10157 /* set window focus flag */
10158 infoPtr
->bFocus
= FALSE
;
10160 /* invalidate the selected items before resetting focus flag */
10161 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10168 * Processes double click messages (left mouse button).
10171 * [I] infoPtr : valid pointer to the listview structure
10172 * [I] wKey : key flag
10173 * [I] x,y : mouse coordinate
10178 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10180 LVHITTESTINFO htInfo
;
10182 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10184 /* Cancel the item edition if any */
10185 if (infoPtr
->itemEdit
.fEnabled
)
10187 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10188 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10191 /* send NM_RELEASEDCAPTURE notification */
10192 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10197 /* send NM_DBLCLK notification */
10198 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10199 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10201 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10202 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10207 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10212 r
.top
= r
.bottom
= pt
.y
;
10213 r
.left
= r
.right
= pt
.x
;
10215 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10217 SetCapture(infoPtr
->hwndSelf
);
10221 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10223 if (msg
.message
== WM_MOUSEMOVE
)
10225 pt
.x
= (short)LOWORD(msg
.lParam
);
10226 pt
.y
= (short)HIWORD(msg
.lParam
);
10227 if (PtInRect(&r
, pt
))
10235 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10236 msg
.message
<= WM_RBUTTONDBLCLK
)
10241 DispatchMessageW(&msg
);
10244 if (GetCapture() != infoPtr
->hwndSelf
)
10255 * Processes mouse down messages (left mouse button).
10258 * infoPtr [I ] valid pointer to the listview structure
10259 * wKey [I ] key flag
10260 * x,y [I ] mouse coordinate
10265 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10267 LVHITTESTINFO lvHitTestInfo
;
10268 static BOOL bGroupSelect
= TRUE
;
10269 POINT pt
= { x
, y
};
10272 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10274 /* send NM_RELEASEDCAPTURE notification */
10275 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10277 /* set left button down flag and record the click position */
10278 infoPtr
->bLButtonDown
= TRUE
;
10279 infoPtr
->ptClickPos
= pt
;
10280 infoPtr
->bDragging
= FALSE
;
10281 infoPtr
->bMarqueeSelect
= FALSE
;
10282 infoPtr
->bScrolling
= FALSE
;
10284 lvHitTestInfo
.pt
.x
= x
;
10285 lvHitTestInfo
.pt
.y
= y
;
10287 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10288 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10289 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10291 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10293 notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
);
10294 toggle_checkbox_state(infoPtr
, nItem
);
10295 infoPtr
->bLButtonDown
= FALSE
;
10299 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10301 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10302 infoPtr
->nEditLabelItem
= nItem
;
10304 LISTVIEW_SetSelection(infoPtr
, nItem
);
10308 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10312 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10313 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10314 infoPtr
->nSelectionMark
= nItem
;
10320 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10321 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10323 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10324 infoPtr
->nSelectionMark
= nItem
;
10327 else if (wKey
& MK_CONTROL
)
10331 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10333 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10334 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10335 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10336 infoPtr
->nSelectionMark
= nItem
;
10338 else if (wKey
& MK_SHIFT
)
10340 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10344 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10346 infoPtr
->nEditLabelItem
= nItem
;
10347 infoPtr
->nLButtonDownItem
= nItem
;
10349 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10352 /* set selection (clears other pre-existing selections) */
10353 LISTVIEW_SetSelection(infoPtr
, nItem
);
10357 if (!infoPtr
->bFocus
)
10358 SetFocus(infoPtr
->hwndSelf
);
10360 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10361 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10365 if (!infoPtr
->bFocus
)
10366 SetFocus(infoPtr
->hwndSelf
);
10368 /* remove all selections */
10369 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10370 LISTVIEW_DeselectAll(infoPtr
);
10379 * Processes mouse up messages (left mouse button).
10382 * infoPtr [I ] valid pointer to the listview structure
10383 * wKey [I ] key flag
10384 * x,y [I ] mouse coordinate
10389 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10391 LVHITTESTINFO lvHitTestInfo
;
10393 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10395 if (!infoPtr
->bLButtonDown
) return 0;
10397 lvHitTestInfo
.pt
.x
= x
;
10398 lvHitTestInfo
.pt
.y
= y
;
10400 /* send NM_CLICK notification */
10401 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10402 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10404 /* set left button flag */
10405 infoPtr
->bLButtonDown
= FALSE
;
10407 /* set a single selection, reset others */
10408 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10409 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10410 infoPtr
->nLButtonDownItem
= -1;
10412 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10414 /* Remove the marquee rectangle and release our mouse capture */
10415 if (infoPtr
->bMarqueeSelect
)
10417 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10421 SetRectEmpty(&infoPtr
->marqueeRect
);
10422 SetRectEmpty(&infoPtr
->marqueeDrawRect
);
10424 infoPtr
->bDragging
= FALSE
;
10425 infoPtr
->bMarqueeSelect
= FALSE
;
10426 infoPtr
->bScrolling
= FALSE
;
10428 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10432 /* if we clicked on a selected item, edit the label */
10433 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10435 /* we want to make sure the user doesn't want to do a double click. So we will
10436 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10438 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10439 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10440 SetTimer(infoPtr
->hwndSelf
,
10441 (UINT_PTR
)&infoPtr
->itemEdit
,
10442 GetDoubleClickTime(),
10443 LISTVIEW_DelayedEditItem
);
10451 * Destroys the listview control (called after WM_DESTROY).
10454 * [I] infoPtr : valid pointer to the listview structure
10459 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10465 /* destroy data structure */
10466 DPA_Destroy(infoPtr
->hdpaItems
);
10467 DPA_Destroy(infoPtr
->hdpaItemIds
);
10468 DPA_Destroy(infoPtr
->hdpaPosX
);
10469 DPA_Destroy(infoPtr
->hdpaPosY
);
10471 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10472 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10473 DPA_Destroy(infoPtr
->hdpaColumns
);
10474 ranges_destroy(infoPtr
->selectionRanges
);
10476 /* destroy image lists */
10477 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10479 ImageList_Destroy(infoPtr
->himlNormal
);
10480 ImageList_Destroy(infoPtr
->himlSmall
);
10481 ImageList_Destroy(infoPtr
->himlState
);
10484 /* destroy font, bkgnd brush */
10485 infoPtr
->hFont
= 0;
10486 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10487 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10489 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10491 /* free listview info pointer*/
10499 * Handles notifications.
10502 * [I] infoPtr : valid pointer to the listview structure
10503 * [I] lpnmhdr : notification information
10508 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10512 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10514 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10516 /* remember: HDN_LAST < HDN_FIRST */
10517 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10518 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10520 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10522 switch (lpnmhdr
->code
)
10527 COLUMN_INFO
*lpColumnInfo
;
10531 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10534 /* remove the old line (if any) */
10535 LISTVIEW_DrawTrackLine(infoPtr
);
10537 /* compute & draw the new line */
10538 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10539 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10540 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10541 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10542 LISTVIEW_DrawTrackLine(infoPtr
);
10543 return notify_forward_header(infoPtr
, lpnmh
);
10546 case HDN_ENDTRACKA
:
10547 case HDN_ENDTRACKW
:
10548 /* remove the track line (if any) */
10549 LISTVIEW_DrawTrackLine(infoPtr
);
10550 infoPtr
->xTrackLine
= -1;
10551 return notify_forward_header(infoPtr
, lpnmh
);
10553 case HDN_BEGINDRAG
:
10554 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10555 return notify_forward_header(infoPtr
, lpnmh
);
10558 infoPtr
->colRectsDirty
= TRUE
;
10559 LISTVIEW_InvalidateList(infoPtr
);
10560 return notify_forward_header(infoPtr
, lpnmh
);
10562 case HDN_ITEMCHANGEDW
:
10563 case HDN_ITEMCHANGEDA
:
10565 COLUMN_INFO
*lpColumnInfo
;
10569 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10571 hdi
.mask
= HDI_WIDTH
;
10572 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10576 cxy
= lpnmh
->pitem
->cxy
;
10578 /* determine how much we change since the last know position */
10579 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10580 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10583 lpColumnInfo
->rcHeader
.right
+= dx
;
10585 hdi
.mask
= HDI_ORDER
;
10586 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10588 /* not the rightmost one */
10589 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10591 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10592 hdi
.iOrder
+ 1, 0);
10593 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10597 /* only needs to update the scrolls */
10598 infoPtr
->nItemWidth
+= dx
;
10599 LISTVIEW_UpdateScroll(infoPtr
);
10601 LISTVIEW_UpdateItemSize(infoPtr
);
10602 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10605 RECT rcCol
= lpColumnInfo
->rcHeader
;
10607 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10608 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10610 rcCol
.top
= infoPtr
->rcList
.top
;
10611 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10613 /* resizing left-aligned columns leaves most of the left side untouched */
10614 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10616 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10619 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10622 /* when shrinking the last column clear the now unused field */
10623 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10629 /* deal with right from rightmost column area */
10630 right
.left
= rcCol
.right
;
10631 right
.top
= rcCol
.top
;
10632 right
.bottom
= rcCol
.bottom
;
10633 right
.right
= infoPtr
->rcList
.right
;
10635 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10638 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10644 case HDN_ITEMCLICKW
:
10645 case HDN_ITEMCLICKA
:
10647 /* Handle sorting by Header Column */
10650 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10652 nmlv
.iSubItem
= lpnmh
->iItem
;
10653 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10654 return notify_forward_header(infoPtr
, lpnmh
);
10657 case HDN_DIVIDERDBLCLICKW
:
10658 case HDN_DIVIDERDBLCLICKA
:
10659 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10660 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10661 split needed for that */
10662 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10663 return notify_forward_header(infoPtr
, lpnmh
);
10670 * Paint non-client area of control.
10673 * [I] infoPtr : valid pointer to the listview structureof the sender
10674 * [I] region : update region
10677 * TRUE - frame was painted
10678 * FALSE - call default window proc
10680 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10682 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10686 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10687 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10690 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10692 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10694 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10695 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10696 if (region
!= (HRGN
)1)
10697 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10698 OffsetRect(&r
, -r
.left
, -r
.top
);
10700 #ifdef __REACTOS__ /* r73789 */
10701 dc
= GetWindowDC(infoPtr
->hwndSelf
);
10702 /* Exclude client part */
10703 ExcludeClipRect(dc
, r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10704 r
.right
- cxEdge
, r
.bottom
-cyEdge
);
10706 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10707 OffsetRect(&r
, -r
.left
, -r
.top
);
10710 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10711 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10712 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10713 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10715 /* Call default proc to get the scrollbars etc. painted */
10716 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10723 * Determines the type of structure to use.
10726 * [I] infoPtr : valid pointer to the listview structureof the sender
10727 * [I] hwndFrom : listview window handle
10728 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10733 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10735 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10737 if (nCommand
== NF_REQUERY
)
10738 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10740 return infoPtr
->notifyFormat
;
10745 * Paints/Repaints the listview control. Internal use.
10748 * [I] infoPtr : valid pointer to the listview structure
10749 * [I] hdc : device context handle
10754 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10756 TRACE("(hdc=%p)\n", hdc
);
10758 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10760 infoPtr
->bNoItemMetrics
= FALSE
;
10761 LISTVIEW_UpdateItemSize(infoPtr
);
10762 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10763 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10764 LISTVIEW_UpdateScroll(infoPtr
);
10767 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10770 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10775 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10776 if (!hdc
) return 1;
10777 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10778 EndPaint(infoPtr
->hwndSelf
, &ps
);
10786 * Paints/Repaints the listview control, WM_PAINT handler.
10789 * [I] infoPtr : valid pointer to the listview structure
10790 * [I] hdc : device context handle
10795 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10797 TRACE("(hdc=%p)\n", hdc
);
10799 if (!is_redrawing(infoPtr
))
10800 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10802 return LISTVIEW_Paint(infoPtr
, hdc
);
10807 * Paints/Repaints the listview control.
10810 * [I] infoPtr : valid pointer to the listview structure
10811 * [I] hdc : device context handle
10812 * [I] options : drawing options
10817 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10819 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10822 if (options
& ~(PRF_ERASEBKGND
|PRF_CLIENT
))
10823 FIXME("(hdc=%p options=0x%08x) partial stub\n", hdc
, options
);
10825 if (options
& PRF_ERASEBKGND
)
10826 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10828 if (options
& PRF_CLIENT
)
10829 LISTVIEW_Paint(infoPtr
, hdc
);
10837 * Processes double click messages (right mouse button).
10840 * [I] infoPtr : valid pointer to the listview structure
10841 * [I] wKey : key flag
10842 * [I] x,y : mouse coordinate
10847 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10849 LVHITTESTINFO lvHitTestInfo
;
10851 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10853 /* send NM_RELEASEDCAPTURE notification */
10854 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10856 /* send NM_RDBLCLK notification */
10857 lvHitTestInfo
.pt
.x
= x
;
10858 lvHitTestInfo
.pt
.y
= y
;
10859 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10860 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10867 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10870 * [I] infoPtr : valid pointer to the listview structure
10871 * [I] wKey : key flag
10872 * [I] x, y : mouse coordinate
10877 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10882 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10884 /* send NM_RELEASEDCAPTURE notification */
10885 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10887 /* determine the index of the selected item */
10890 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10892 /* make sure the listview control window has the focus */
10893 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10895 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10897 LISTVIEW_SetItemFocus(infoPtr
, item
);
10898 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10899 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10900 LISTVIEW_SetSelection(infoPtr
, item
);
10903 LISTVIEW_DeselectAll(infoPtr
);
10905 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10907 if (ht
.iItem
!= -1)
10911 memset(&nmlv
, 0, sizeof(nmlv
));
10912 nmlv
.iItem
= ht
.iItem
;
10913 nmlv
.ptAction
= ht
.pt
;
10915 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10920 SetFocus(infoPtr
->hwndSelf
);
10924 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10926 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10928 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10929 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10930 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10942 * [I] infoPtr : valid pointer to the listview structure
10943 * [I] hwnd : window handle of window containing the cursor
10944 * [I] nHittest : hit-test code
10945 * [I] wMouseMsg : ideintifier of the mouse message
10948 * TRUE if cursor is set
10951 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10953 LVHITTESTINFO lvHitTestInfo
;
10955 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10957 if (!infoPtr
->hHotCursor
) goto forward
;
10959 GetCursorPos(&lvHitTestInfo
.pt
);
10960 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10962 SetCursor(infoPtr
->hHotCursor
);
10968 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10976 * [I] infoPtr : valid pointer to the listview structure
10977 * [I] hwndLoseFocus : handle of previously focused window
10982 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10984 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10986 /* if we have the focus already, there's nothing to do */
10987 if (infoPtr
->bFocus
) return 0;
10989 /* send NM_SETFOCUS notification */
10990 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10992 /* set window focus flag */
10993 infoPtr
->bFocus
= TRUE
;
10995 /* put the focus rect back on */
10996 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10998 /* redraw all visible selected items */
10999 LISTVIEW_InvalidateSelectedItems(infoPtr
);
11009 * [I] infoPtr : valid pointer to the listview structure
11010 * [I] fRedraw : font handle
11011 * [I] fRedraw : redraw flag
11016 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
11018 HFONT oldFont
= infoPtr
->hFont
;
11019 INT oldHeight
= infoPtr
->nItemHeight
;
11021 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
11023 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
11024 if (infoPtr
->hFont
== oldFont
) return 0;
11026 LISTVIEW_SaveTextMetrics(infoPtr
);
11028 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
11030 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
11032 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
11033 LISTVIEW_UpdateSize(infoPtr
);
11034 LISTVIEW_UpdateScroll(infoPtr
);
11036 else if (infoPtr
->nItemHeight
!= oldHeight
)
11037 LISTVIEW_UpdateScroll(infoPtr
);
11039 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
11046 * Message handling for WM_SETREDRAW.
11047 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
11050 * [I] infoPtr : valid pointer to the listview structure
11051 * [I] redraw: state of redraw flag
11056 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL redraw
)
11058 TRACE("old=%d, new=%d\n", infoPtr
->redraw
, redraw
);
11060 if (infoPtr
->redraw
== !!redraw
)
11063 if (!(infoPtr
->redraw
= !!redraw
))
11066 if (is_autoarrange(infoPtr
))
11067 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11068 LISTVIEW_UpdateScroll(infoPtr
);
11070 /* despite what the WM_SETREDRAW docs says, apps expect us
11071 * to invalidate the listview here... stupid! */
11072 LISTVIEW_InvalidateList(infoPtr
);
11079 * Resizes the listview control. This function processes WM_SIZE
11080 * messages. At this time, the width and height are not used.
11083 * [I] infoPtr : valid pointer to the listview structure
11084 * [I] Width : new width
11085 * [I] Height : new height
11090 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
11092 RECT rcOld
= infoPtr
->rcList
;
11094 TRACE("(width=%d, height=%d)\n", Width
, Height
);
11096 LISTVIEW_UpdateSize(infoPtr
);
11097 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
11099 /* do not bother with display related stuff if we're not redrawing */
11100 if (!is_redrawing(infoPtr
)) return 0;
11102 if (is_autoarrange(infoPtr
))
11103 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11105 LISTVIEW_UpdateScroll(infoPtr
);
11107 /* refresh all only for lists whose height changed significantly */
11108 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11109 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11110 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11111 LISTVIEW_InvalidateList(infoPtr
);
11118 * Sets the size information.
11121 * [I] infoPtr : valid pointer to the listview structure
11126 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11128 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11130 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11132 if (infoPtr
->uView
== LV_VIEW_LIST
)
11134 /* Apparently the "LIST" style is supposed to have the same
11135 * number of items in a column even if there is no scroll bar.
11136 * Since if a scroll bar already exists then the bottom is already
11137 * reduced, only reduce if the scroll bar does not currently exist.
11138 * The "2" is there to mimic the native control. I think it may be
11139 * related to either padding or edges. (GLA 7/2002)
11141 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11142 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11143 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11146 /* When ListView control is created invisible, header isn't created right away. */
11147 if (infoPtr
->hwndHeader
)
11154 LISTVIEW_GetOrigin(infoPtr
, &origin
);
11156 rect
= infoPtr
->rcList
;
11157 rect
.left
+= origin
.x
;
11158 rect
.top
+= origin
.y
;
11162 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11163 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11165 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11166 wp
.flags
|= SWP_SHOWWINDOW
;
11169 wp
.flags
|= SWP_HIDEWINDOW
;
11173 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11174 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11176 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11178 /* extra padding for grid */
11179 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11180 infoPtr
->rcList
.top
+= 2;
11182 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11187 * Processes WM_STYLECHANGED messages.
11190 * [I] infoPtr : valid pointer to the listview structure
11191 * [I] wStyleType : window style type (normal or extended)
11192 * [I] lpss : window style information
11197 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11198 const STYLESTRUCT
*lpss
)
11200 UINT uNewView
, uOldView
;
11203 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11204 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11206 if (wStyleType
!= GWL_STYLE
|| lpss
->styleNew
== infoPtr
->dwStyle
) return 0;
11208 infoPtr
->dwStyle
= lpss
->styleNew
;
11210 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11211 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11212 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11214 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11215 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11216 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11218 uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11219 uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11221 if (uNewView
!= uOldView
)
11225 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11226 changing style updates current view only when view bits change. */
11227 map_style_view(infoPtr
);
11228 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11229 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11231 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11232 SetRectEmpty(&infoPtr
->rcFocus
);
11234 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11235 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11237 if (uNewView
== LVS_REPORT
)
11242 LISTVIEW_CreateHeader( infoPtr
);
11244 hl
.prc
= &infoPtr
->rcList
;
11246 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11247 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11248 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11249 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11252 LISTVIEW_UpdateItemSize(infoPtr
);
11255 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11257 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11259 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11261 /* Turn off the header control */
11262 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11263 TRACE("Hide header control, was 0x%08x\n", style
);
11264 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11266 /* Turn on the header control */
11267 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11269 TRACE("Show header control, was 0x%08x\n", style
);
11270 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11276 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11277 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11278 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11280 /* update the size of the client area */
11281 LISTVIEW_UpdateSize(infoPtr
);
11283 /* add scrollbars if needed */
11284 LISTVIEW_UpdateScroll(infoPtr
);
11286 /* invalidate client area + erase background */
11287 LISTVIEW_InvalidateList(infoPtr
);
11294 * Processes WM_STYLECHANGING messages.
11297 * [I] wStyleType : window style type (normal or extended)
11298 * [I0] lpss : window style information
11303 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11306 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11307 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11309 /* don't forward LVS_OWNERDATA only if not already set to */
11310 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11312 if (lpss
->styleOld
& LVS_OWNERDATA
)
11313 lpss
->styleNew
|= LVS_OWNERDATA
;
11315 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11323 * Processes WM_SHOWWINDOW messages.
11326 * [I] infoPtr : valid pointer to the listview structure
11327 * [I] bShown : window is being shown (FALSE when hidden)
11328 * [I] iStatus : window show status
11333 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11335 /* header delayed creation */
11336 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11338 LISTVIEW_CreateHeader(infoPtr
);
11340 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11341 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11344 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11349 * Processes CCM_GETVERSION messages.
11352 * [I] infoPtr : valid pointer to the listview structure
11357 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11359 return infoPtr
->iVersion
;
11364 * Processes CCM_SETVERSION messages.
11367 * [I] infoPtr : valid pointer to the listview structure
11368 * [I] iVersion : version to be set
11371 * -1 when requested version is greater than DLL version;
11372 * previous version otherwise
11374 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11376 INT iOldVersion
= infoPtr
->iVersion
;
11378 if (iVersion
> COMCTL32_VERSION
)
11381 infoPtr
->iVersion
= iVersion
;
11383 TRACE("new version %d\n", iVersion
);
11385 return iOldVersion
;
11390 * Window procedure of the listview control.
11393 static LRESULT WINAPI
11394 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11396 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11398 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11400 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11401 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11405 case LVM_APPROXIMATEVIEWRECT
:
11406 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11407 LOWORD(lParam
), HIWORD(lParam
));
11409 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11411 case LVM_CANCELEDITLABEL
:
11412 return LISTVIEW_CancelEditLabel(infoPtr
);
11414 case LVM_CREATEDRAGIMAGE
:
11415 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11417 case LVM_DELETEALLITEMS
:
11418 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11420 case LVM_DELETECOLUMN
:
11421 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11423 case LVM_DELETEITEM
:
11424 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11426 case LVM_EDITLABELA
:
11427 case LVM_EDITLABELW
:
11428 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11429 uMsg
== LVM_EDITLABELW
);
11430 /* case LVM_ENABLEGROUPVIEW: */
11432 case LVM_ENSUREVISIBLE
:
11433 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11435 case LVM_FINDITEMW
:
11436 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11438 case LVM_FINDITEMA
:
11439 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11441 case LVM_GETBKCOLOR
:
11442 return infoPtr
->clrBk
;
11444 /* case LVM_GETBKIMAGE: */
11446 case LVM_GETCALLBACKMASK
:
11447 return infoPtr
->uCallbackMask
;
11449 case LVM_GETCOLUMNA
:
11450 case LVM_GETCOLUMNW
:
11451 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11452 uMsg
== LVM_GETCOLUMNW
);
11454 case LVM_GETCOLUMNORDERARRAY
:
11455 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11457 case LVM_GETCOLUMNWIDTH
:
11458 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11460 case LVM_GETCOUNTPERPAGE
:
11461 return LISTVIEW_GetCountPerPage(infoPtr
);
11463 case LVM_GETEDITCONTROL
:
11464 return (LRESULT
)infoPtr
->hwndEdit
;
11466 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11467 return infoPtr
->dwLvExStyle
;
11469 /* case LVM_GETGROUPINFO: */
11471 /* case LVM_GETGROUPMETRICS: */
11473 case LVM_GETHEADER
:
11474 return (LRESULT
)infoPtr
->hwndHeader
;
11476 case LVM_GETHOTCURSOR
:
11477 return (LRESULT
)infoPtr
->hHotCursor
;
11479 case LVM_GETHOTITEM
:
11480 return infoPtr
->nHotItem
;
11482 case LVM_GETHOVERTIME
:
11483 return infoPtr
->dwHoverTime
;
11485 case LVM_GETIMAGELIST
:
11486 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11488 /* case LVM_GETINSERTMARK: */
11490 /* case LVM_GETINSERTMARKCOLOR: */
11492 /* case LVM_GETINSERTMARKRECT: */
11494 case LVM_GETISEARCHSTRINGA
:
11495 case LVM_GETISEARCHSTRINGW
:
11496 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11501 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11503 case LVM_GETITEMCOUNT
:
11504 return infoPtr
->nItemCount
;
11506 case LVM_GETITEMPOSITION
:
11507 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11509 case LVM_GETITEMRECT
:
11510 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11512 case LVM_GETITEMSPACING
:
11513 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11515 case LVM_GETITEMSTATE
:
11516 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11518 case LVM_GETITEMTEXTA
:
11519 case LVM_GETITEMTEXTW
:
11520 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11521 uMsg
== LVM_GETITEMTEXTW
);
11523 case LVM_GETNEXTITEM
:
11524 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11526 case LVM_GETNUMBEROFWORKAREAS
:
11527 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11530 case LVM_GETORIGIN
:
11531 if (!lParam
) return FALSE
;
11532 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11533 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11534 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11537 /* case LVM_GETOUTLINECOLOR: */
11539 /* case LVM_GETSELECTEDCOLUMN: */
11541 case LVM_GETSELECTEDCOUNT
:
11542 return LISTVIEW_GetSelectedCount(infoPtr
);
11544 case LVM_GETSELECTIONMARK
:
11545 return infoPtr
->nSelectionMark
;
11547 case LVM_GETSTRINGWIDTHA
:
11548 case LVM_GETSTRINGWIDTHW
:
11549 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11550 uMsg
== LVM_GETSTRINGWIDTHW
);
11552 case LVM_GETSUBITEMRECT
:
11553 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11555 case LVM_GETTEXTBKCOLOR
:
11556 return infoPtr
->clrTextBk
;
11558 case LVM_GETTEXTCOLOR
:
11559 return infoPtr
->clrText
;
11561 /* case LVM_GETTILEINFO: */
11563 /* case LVM_GETTILEVIEWINFO: */
11565 case LVM_GETTOOLTIPS
:
11566 if( !infoPtr
->hwndToolTip
)
11567 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11568 return (LRESULT
)infoPtr
->hwndToolTip
;
11570 case LVM_GETTOPINDEX
:
11571 return LISTVIEW_GetTopIndex(infoPtr
);
11573 case LVM_GETUNICODEFORMAT
:
11574 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11577 return infoPtr
->uView
;
11579 case LVM_GETVIEWRECT
:
11580 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11582 case LVM_GETWORKAREAS
:
11583 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11586 /* case LVM_HASGROUP: */
11589 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11591 case LVM_INSERTCOLUMNA
:
11592 case LVM_INSERTCOLUMNW
:
11593 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11594 uMsg
== LVM_INSERTCOLUMNW
);
11596 /* case LVM_INSERTGROUP: */
11598 /* case LVM_INSERTGROUPSORTED: */
11600 case LVM_INSERTITEMA
:
11601 case LVM_INSERTITEMW
:
11602 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11604 /* case LVM_INSERTMARKHITTEST: */
11606 /* case LVM_ISGROUPVIEWENABLED: */
11608 case LVM_ISITEMVISIBLE
:
11609 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11611 case LVM_MAPIDTOINDEX
:
11612 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11614 case LVM_MAPINDEXTOID
:
11615 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11617 /* case LVM_MOVEGROUP: */
11619 /* case LVM_MOVEITEMTOGROUP: */
11621 case LVM_REDRAWITEMS
:
11622 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11624 /* case LVM_REMOVEALLGROUPS: */
11626 /* case LVM_REMOVEGROUP: */
11629 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11631 case LVM_SETBKCOLOR
:
11632 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11634 /* case LVM_SETBKIMAGE: */
11636 case LVM_SETCALLBACKMASK
:
11637 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11640 case LVM_SETCOLUMNA
:
11641 case LVM_SETCOLUMNW
:
11642 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11643 uMsg
== LVM_SETCOLUMNW
);
11645 case LVM_SETCOLUMNORDERARRAY
:
11646 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11648 case LVM_SETCOLUMNWIDTH
:
11649 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11651 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11652 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11654 /* case LVM_SETGROUPINFO: */
11656 /* case LVM_SETGROUPMETRICS: */
11658 case LVM_SETHOTCURSOR
:
11659 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11661 case LVM_SETHOTITEM
:
11662 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11664 case LVM_SETHOVERTIME
:
11665 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11667 case LVM_SETICONSPACING
:
11669 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11670 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11672 case LVM_SETIMAGELIST
:
11673 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11675 /* case LVM_SETINFOTIP: */
11677 /* case LVM_SETINSERTMARK: */
11679 /* case LVM_SETINSERTMARKCOLOR: */
11684 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11685 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11688 case LVM_SETITEMCOUNT
:
11689 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11691 case LVM_SETITEMPOSITION
:
11694 pt
.x
= (short)LOWORD(lParam
);
11695 pt
.y
= (short)HIWORD(lParam
);
11696 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11699 case LVM_SETITEMPOSITION32
:
11700 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11702 case LVM_SETITEMSTATE
:
11703 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11705 case LVM_SETITEMTEXTA
:
11706 case LVM_SETITEMTEXTW
:
11707 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11708 uMsg
== LVM_SETITEMTEXTW
);
11710 /* case LVM_SETOUTLINECOLOR: */
11712 /* case LVM_SETSELECTEDCOLUMN: */
11714 case LVM_SETSELECTIONMARK
:
11715 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11717 case LVM_SETTEXTBKCOLOR
:
11718 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11720 case LVM_SETTEXTCOLOR
:
11721 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11723 /* case LVM_SETTILEINFO: */
11725 /* case LVM_SETTILEVIEWINFO: */
11727 /* case LVM_SETTILEWIDTH: */
11729 case LVM_SETTOOLTIPS
:
11730 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11732 case LVM_SETUNICODEFORMAT
:
11733 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11736 return LISTVIEW_SetView(infoPtr
, wParam
);
11738 /* case LVM_SETWORKAREAS: */
11740 /* case LVM_SORTGROUPS: */
11742 case LVM_SORTITEMS
:
11743 case LVM_SORTITEMSEX
:
11744 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11745 uMsg
== LVM_SORTITEMSEX
);
11746 case LVM_SUBITEMHITTEST
:
11747 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11750 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11752 case CCM_GETVERSION
:
11753 return LISTVIEW_GetVersion(infoPtr
);
11755 case CCM_SETVERSION
:
11756 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11759 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11762 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11765 return LISTVIEW_NCCreate(hwnd
, wParam
, (LPCREATESTRUCTW
)lParam
);
11768 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11771 return LISTVIEW_Destroy(infoPtr
);
11774 return LISTVIEW_Enable(infoPtr
);
11776 case WM_ERASEBKGND
:
11777 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11779 case WM_GETDLGCODE
:
11780 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11783 return (LRESULT
)infoPtr
->hFont
;
11786 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11789 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11792 return LISTVIEW_KillFocus(infoPtr
);
11794 case WM_LBUTTONDBLCLK
:
11795 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11797 case WM_LBUTTONDOWN
:
11798 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11801 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11804 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11806 case WM_MOUSEHOVER
:
11807 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11810 return LISTVIEW_NCDestroy(infoPtr
);
11813 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11816 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11818 case WM_NOTIFYFORMAT
:
11819 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11821 case WM_PRINTCLIENT
:
11822 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11825 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11827 case WM_RBUTTONDBLCLK
:
11828 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11830 case WM_RBUTTONDOWN
:
11831 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11834 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11837 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11840 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11843 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11845 case WM_SHOWWINDOW
:
11846 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11848 case WM_STYLECHANGED
:
11849 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11851 case WM_STYLECHANGING
:
11852 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11854 case WM_SYSCOLORCHANGE
:
11855 COMCTL32_RefreshSysColors();
11857 if (infoPtr
->bDefaultBkColor
)
11859 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
11860 infoPtr
->bDefaultBkColor
= TRUE
;
11861 LISTVIEW_InvalidateList(infoPtr
);
11866 /* case WM_TIMER: */
11867 case WM_THEMECHANGED
:
11868 return LISTVIEW_ThemeChanged(infoPtr
);
11871 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11873 case WM_MOUSEWHEEL
:
11874 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11875 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11876 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11878 case WM_WINDOWPOSCHANGED
:
11879 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11881 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11882 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11884 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11886 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11888 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11890 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11892 /* case WM_WININICHANGE: */
11895 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11896 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11898 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11905 * Registers the window class.
11913 void LISTVIEW_Register(void)
11915 WNDCLASSW wndClass
;
11917 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11918 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11919 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11920 wndClass
.cbClsExtra
= 0;
11921 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11922 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11923 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11924 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11925 RegisterClassW(&wndClass
);
11930 * Unregisters the window class.
11938 void LISTVIEW_Unregister(void)
11940 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11945 * Handle any WM_COMMAND messages
11948 * [I] infoPtr : valid pointer to the listview structure
11949 * [I] wParam : the first message parameter
11950 * [I] lParam : the second message parameter
11955 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11958 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11960 if (!infoPtr
->hwndEdit
) return 0;
11962 switch (HIWORD(wParam
))
11967 * Adjust the edit window size
11969 WCHAR buffer
[1024];
11970 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11971 HFONT hFont
, hOldFont
= 0;
11975 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11976 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, ARRAY_SIZE(buffer
));
11977 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11979 /* Select font to get the right dimension of the string */
11980 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11983 hOldFont
= SelectObject(hdc
, hFont
);
11986 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11988 TEXTMETRICW textMetric
;
11990 /* Add Extra spacing for the next character */
11991 GetTextMetricsW(hdc
, &textMetric
);
11992 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11994 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11995 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11998 SelectObject(hdc
, hOldFont
);
12000 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
12006 if (infoPtr
->notify_mask
& NOTIFY_MASK_END_LABEL_EDIT
)
12007 LISTVIEW_CancelEditLabel(infoPtr
);
12012 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);