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
))
2280 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
| LVIS_CUT
))
2282 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2284 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2286 iterator_destroy(&i
);
2291 * DESCRIPTION: [INTERNAL]
2292 * Computes an item's (left,top) corner, relative to rcView.
2293 * That is, the position has NOT been made relative to the Origin.
2294 * This is deliberate, to avoid computing the Origin over, and
2295 * over again, when this function is called in a loop. Instead,
2296 * one can factor the computation of the Origin before the loop,
2297 * and offset the value returned by this function, on every iteration.
2300 * [I] infoPtr : valid pointer to the listview structure
2301 * [I] nItem : item number
2302 * [O] lpptOrig : item top, left corner
2307 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2309 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2311 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2313 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2314 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2316 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2318 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2319 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2320 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2322 else /* LV_VIEW_DETAILS */
2324 lpptPosition
->x
= REPORT_MARGINX
;
2325 /* item is always at zero indexed column */
2326 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2327 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2328 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2333 * DESCRIPTION: [INTERNAL]
2334 * Compute the rectangles of an item. This is to localize all
2335 * the computations in one place. If you are not interested in some
2336 * of these values, simply pass in a NULL -- the function is smart
2337 * enough to compute only what's necessary. The function computes
2338 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2339 * one, the BOX rectangle. This rectangle is very cheap to compute,
2340 * and is guaranteed to contain all the other rectangles. Computing
2341 * the ICON rect is also cheap, but all the others are potentially
2342 * expensive. This gives an easy and effective optimization when
2343 * searching (like point inclusion, or rectangle intersection):
2344 * first test against the BOX, and if TRUE, test against the desired
2346 * If the function does not have all the necessary information
2347 * to computed the requested rectangles, will crash with a
2348 * failed assertion. This is done so we catch all programming
2349 * errors, given that the function is called only from our code.
2351 * We have the following 'special' meanings for a few fields:
2352 * * If LVIS_FOCUSED is set, we assume the item has the focus
2353 * This is important in ICON mode, where it might get a larger
2354 * then usual rectangle
2356 * Please note that subitem support works only in REPORT mode.
2359 * [I] infoPtr : valid pointer to the listview structure
2360 * [I] lpLVItem : item to compute the measures for
2361 * [O] lprcBox : ptr to Box rectangle
2362 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2363 * [0] lprcSelectBox : ptr to select box rectangle
2364 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2365 * [O] lprcIcon : ptr to Icon rectangle
2366 * Same as LVM_GETITEMRECT with LVIR_ICON
2367 * [O] lprcStateIcon: ptr to State Icon rectangle
2368 * [O] lprcLabel : ptr to Label rectangle
2369 * Same as LVM_GETITEMRECT with LVIR_LABEL
2374 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2375 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2376 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2378 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2379 RECT Box
, SelectBox
, Icon
, Label
;
2380 COLUMN_INFO
*lpColumnInfo
= NULL
;
2381 SIZE labelSize
= { 0, 0 };
2383 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2385 /* Be smart and try to figure out the minimum we have to do */
2386 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2387 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2389 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2390 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2392 if (lprcSelectBox
) doSelectBox
= TRUE
;
2393 if (lprcLabel
) doLabel
= TRUE
;
2394 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2401 /************************************************************/
2402 /* compute the box rectangle (it should be cheap to do) */
2403 /************************************************************/
2404 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2405 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2407 if (lpLVItem
->iSubItem
)
2409 Box
= lpColumnInfo
->rcHeader
;
2414 Box
.right
= infoPtr
->nItemWidth
;
2417 Box
.bottom
= infoPtr
->nItemHeight
;
2419 /******************************************************************/
2420 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2421 /******************************************************************/
2424 LONG state_width
= 0;
2426 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2427 state_width
= infoPtr
->iconStateSize
.cx
;
2429 if (infoPtr
->uView
== LV_VIEW_ICON
)
2431 Icon
.left
= Box
.left
+ state_width
;
2432 if (infoPtr
->himlNormal
)
2433 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2434 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2435 Icon
.right
= Icon
.left
;
2436 Icon
.bottom
= Icon
.top
;
2437 if (infoPtr
->himlNormal
)
2439 Icon
.right
+= infoPtr
->iconSize
.cx
;
2440 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2443 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2445 Icon
.left
= Box
.left
+ state_width
;
2447 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2449 /* we need the indent in report mode */
2450 assert(lpLVItem
->mask
& LVIF_INDENT
);
2451 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2455 Icon
.right
= Icon
.left
;
2456 if (infoPtr
->himlSmall
&&
2457 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2458 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2459 Icon
.right
+= infoPtr
->iconSize
.cx
;
2460 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2462 if(lprcIcon
) *lprcIcon
= Icon
;
2463 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2465 /* TODO: is this correct? */
2468 lprcStateIcon
->left
= Icon
.left
- state_width
;
2469 lprcStateIcon
->right
= Icon
.left
;
2470 lprcStateIcon
->top
= Icon
.top
;
2471 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2472 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2475 else Icon
.right
= 0;
2477 /************************************************************/
2478 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2479 /************************************************************/
2482 /* calculate how far to the right can the label stretch */
2483 Label
.right
= Box
.right
;
2484 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2486 if (lpLVItem
->iSubItem
== 0)
2488 /* we need a zero based rect here */
2489 Label
= lpColumnInfo
->rcHeader
;
2490 OffsetRect(&Label
, -Label
.left
, 0);
2494 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2496 labelSize
.cx
= infoPtr
->nItemWidth
;
2497 labelSize
.cy
= infoPtr
->nItemHeight
;
2501 /* we need the text in non owner draw mode */
2502 assert(lpLVItem
->mask
& LVIF_TEXT
);
2503 if (is_text(lpLVItem
->pszText
))
2505 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2506 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2507 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2511 /* compute rough rectangle where the label will go */
2512 SetRectEmpty(&rcText
);
2513 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2514 rcText
.bottom
= infoPtr
->nItemHeight
;
2515 if (infoPtr
->uView
== LV_VIEW_ICON
)
2516 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2518 /* now figure out the flags */
2519 if (infoPtr
->uView
== LV_VIEW_ICON
)
2520 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2522 uFormat
= LV_SL_DT_FLAGS
;
2524 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2526 if (rcText
.right
!= rcText
.left
)
2527 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2529 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2531 SelectObject(hdc
, hOldFont
);
2532 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2536 if (infoPtr
->uView
== LV_VIEW_ICON
)
2538 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2539 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2540 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2541 Label
.right
= Label
.left
+ labelSize
.cx
;
2542 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2543 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2545 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2546 labelSize
.cy
/= infoPtr
->ntmHeight
;
2547 labelSize
.cy
= max(labelSize
.cy
, 1);
2548 labelSize
.cy
*= infoPtr
->ntmHeight
;
2550 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2552 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2554 Label
.left
= Icon
.right
;
2555 Label
.top
= Box
.top
;
2556 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2557 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2558 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2560 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2562 Label
.left
= Icon
.right
;
2563 Label
.top
= Box
.top
;
2564 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2565 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2568 if (lprcLabel
) *lprcLabel
= Label
;
2569 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2572 /************************************************************/
2573 /* compute SELECT bounding box */
2574 /************************************************************/
2577 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2579 SelectBox
.left
= Icon
.left
;
2580 SelectBox
.top
= Box
.top
;
2581 SelectBox
.bottom
= Box
.bottom
;
2584 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2586 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2590 UnionRect(&SelectBox
, &Icon
, &Label
);
2592 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2593 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2596 /* Fix the Box if necessary */
2599 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2600 else *lprcBox
= Box
;
2602 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2606 * DESCRIPTION: [INTERNAL]
2609 * [I] infoPtr : valid pointer to the listview structure
2610 * [I] nItem : item number
2611 * [O] lprcBox : ptr to Box rectangle
2616 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2618 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2619 POINT Position
, Origin
;
2622 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2623 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2625 /* Be smart and try to figure out the minimum we have to do */
2627 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2628 lvItem
.mask
|= LVIF_TEXT
;
2629 lvItem
.iItem
= nItem
;
2630 lvItem
.iSubItem
= 0;
2631 lvItem
.pszText
= szDispText
;
2632 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2633 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2634 if (infoPtr
->uView
== LV_VIEW_ICON
)
2636 lvItem
.mask
|= LVIF_STATE
;
2637 lvItem
.stateMask
= LVIS_FOCUSED
;
2638 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2640 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2642 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2643 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2645 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2648 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2651 /* LISTVIEW_MapIdToIndex helper */
2652 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2654 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2655 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2657 if (id1
->id
== id2
->id
) return 0;
2659 return (id1
->id
< id2
->id
) ? -1 : 1;
2664 * Returns the item index for id specified.
2667 * [I] infoPtr : valid pointer to the listview structure
2668 * [I] iID : item id to get index for
2671 * Item index, or -1 on failure.
2673 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2678 TRACE("iID=%d\n", iID
);
2680 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2681 if (infoPtr
->nItemCount
== 0) return -1;
2684 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2688 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2689 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2697 * Returns the item id for index given.
2700 * [I] infoPtr : valid pointer to the listview structure
2701 * [I] iItem : item index to get id for
2706 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2711 TRACE("iItem=%d\n", iItem
);
2713 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2714 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2716 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2717 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2719 return lpItem
->id
->id
;
2724 * Returns the current icon position, and advances it along the top.
2725 * The returned position is not offset by Origin.
2728 * [I] infoPtr : valid pointer to the listview structure
2729 * [O] lpPos : will get the current icon position
2730 * [I] nItem : item id to get position for
2736 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
, INT nItem
)
2738 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2741 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2743 *lpPos
= infoPtr
->currIconPos
;
2745 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2746 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2748 infoPtr
->currIconPos
.x
= 0;
2749 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2755 * Returns the current icon position, and advances it down the left edge.
2756 * The returned position is not offset by Origin.
2759 * [I] infoPtr : valid pointer to the listview structure
2760 * [O] lpPos : will get the current icon position
2761 * [I] nItem : item id to get position for
2767 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
, INT nItem
)
2769 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2772 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2774 *lpPos
= infoPtr
->currIconPos
;
2776 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2777 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2779 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2780 infoPtr
->currIconPos
.y
= 0;
2787 * Returns the grid position closest to the already placed icon.
2788 * The returned position is not offset by Origin.
2791 * [I] infoPtr : valid pointer to the listview structure
2792 * [O] lpPos : will get the current icon position
2793 * [I] nItem : item id to get position for
2798 static void LISTVIEW_NextIconPosSnap(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
, INT nItem
)
2800 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2801 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2802 INT nMaxColumns
= nListWidth
/ infoPtr
->nItemWidth
;
2803 INT nMaxRows
= nListHeight
/ infoPtr
->nItemHeight
;
2806 // get the existing x and y position and then snap to the closest grid square
2807 oldPosition
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2808 oldPosition
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2810 // FIXME: This could should deal with multiple icons in the same grid square
2811 // equivalent of max(0, round(oldPosition / itemSize) * itemSize), but without need for 'round' function
2812 (*lpPos
).x
= max(0, oldPosition
.x
+ (infoPtr
->nItemWidth
>> 1) - (oldPosition
.x
+ (infoPtr
->nItemWidth
>> 1)) % infoPtr
->nItemWidth
);
2813 (*lpPos
).y
= max(0, oldPosition
.y
+ (infoPtr
->nItemHeight
>> 1) - (oldPosition
.y
+ (infoPtr
->nItemHeight
>> 1)) % infoPtr
->nItemHeight
);
2815 // deal with any icons that have gone out of range
2816 if ((*lpPos
).x
> nListWidth
) (*lpPos
).x
= nMaxColumns
* infoPtr
->nItemWidth
;
2817 if ((*lpPos
).y
> nListHeight
) (*lpPos
).y
= nMaxRows
* infoPtr
->nItemHeight
;
2824 * Moves an icon to the specified position.
2825 * It takes care of invalidating the item, etc.
2828 * [I] infoPtr : valid pointer to the listview structure
2829 * [I] nItem : the item to move
2830 * [I] lpPos : the new icon position
2831 * [I] isNew : flags the item as being new
2837 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2843 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2844 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2846 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2847 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2850 /* Allocating a POINTER for every item is too resource intensive,
2851 * so we'll keep the (x,y) in different arrays */
2852 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2853 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2855 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2862 * Arranges listview items in icon display mode.
2865 * [I] infoPtr : valid pointer to the listview structure
2866 * [I] nAlignCode : alignment code
2872 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2875 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
, INT
);
2877 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2882 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2884 TRACE("nAlignCode=%d\n", nAlignCode
);
2886 if (nAlignCode
== LVA_DEFAULT
)
2888 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2889 else nAlignCode
= LVA_ALIGNTOP
;
2894 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2895 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2897 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosSnap
; break;
2899 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2901 default: return FALSE
;
2904 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2905 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2908 next_pos(infoPtr
, &pos
, i
);
2910 next_pos(infoPtr
, &pos
);
2912 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2920 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2921 * For LVS_REPORT always returns empty rectangle.
2924 * [I] infoPtr : valid pointer to the listview structure
2925 * [O] lprcView : bounding rectangle
2931 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2935 SetRectEmpty(lprcView
);
2937 switch (infoPtr
->uView
)
2940 case LV_VIEW_SMALLICON
:
2941 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2943 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2944 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2945 lprcView
->right
= max(lprcView
->right
, x
);
2946 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2948 if (infoPtr
->nItemCount
> 0)
2950 lprcView
->right
+= infoPtr
->nItemWidth
;
2951 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2956 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2957 x
= infoPtr
->nItemCount
/ y
;
2958 if (infoPtr
->nItemCount
% y
) x
++;
2959 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2960 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2967 * Retrieves the bounding rectangle of all the items.
2970 * [I] infoPtr : valid pointer to the listview structure
2971 * [O] lprcView : bounding rectangle
2977 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2981 TRACE("(lprcView=%p)\n", lprcView
);
2983 if (!lprcView
) return FALSE
;
2985 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2987 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2989 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2990 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2993 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
3000 * Retrieves the subitem pointer associated with the subitem index.
3003 * [I] hdpaSubItems : DPA handle for a specific item
3004 * [I] nSubItem : index of subitem
3007 * SUCCESS : subitem pointer
3010 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
3012 SUBITEM_INFO
*lpSubItem
;
3015 /* we should binary search here if need be */
3016 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
3018 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
3019 if (lpSubItem
->iSubItem
== nSubItem
)
3029 * Calculates the desired item width.
3032 * [I] infoPtr : valid pointer to the listview structure
3035 * The desired item width.
3037 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
3041 TRACE("uView=%d\n", infoPtr
->uView
);
3043 if (infoPtr
->uView
== LV_VIEW_ICON
)
3044 nItemWidth
= infoPtr
->iconSpacing
.cx
;
3045 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
3047 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
3052 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
3053 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
3055 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
3056 nItemWidth
= rcHeader
.right
;
3059 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
3061 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
3065 lvItem
.mask
= LVIF_TEXT
;
3066 lvItem
.iSubItem
= 0;
3068 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3071 lvItem
.pszText
= szDispText
;
3072 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
3073 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
3074 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
3078 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
3079 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
3081 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
3089 * Calculates the desired item height.
3092 * [I] infoPtr : valid pointer to the listview structure
3095 * The desired item height.
3097 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
3101 TRACE("uView=%d\n", infoPtr
->uView
);
3103 if (infoPtr
->uView
== LV_VIEW_ICON
)
3104 nItemHeight
= infoPtr
->iconSpacing
.cy
;
3107 nItemHeight
= infoPtr
->ntmHeight
;
3108 if (infoPtr
->himlState
)
3109 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
3110 if (infoPtr
->himlSmall
)
3111 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
3112 nItemHeight
+= HEIGHT_PADDING
;
3113 if (infoPtr
->nMeasureItemHeight
> 0)
3114 nItemHeight
= infoPtr
->nMeasureItemHeight
;
3117 return max(nItemHeight
, 1);
3122 * Updates the width, and height of an item.
3125 * [I] infoPtr : valid pointer to the listview structure
3130 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
3132 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
3133 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3139 * Retrieves and saves important text metrics info for the current
3143 * [I] infoPtr : valid pointer to the listview structure
3146 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3148 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3149 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3150 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3154 if (GetTextMetricsW(hdc
, &tm
))
3156 infoPtr
->ntmHeight
= tm
.tmHeight
;
3157 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3160 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3161 infoPtr
->nEllipsisWidth
= sz
.cx
;
3163 SelectObject(hdc
, hOldFont
);
3164 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3166 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3171 * A compare function for ranges
3174 * [I] range1 : pointer to range 1;
3175 * [I] range2 : pointer to range 2;
3179 * > 0 : if range 1 > range 2
3180 * < 0 : if range 2 > range 1
3181 * = 0 : if range intersects range 2
3183 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3187 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3189 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3194 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3199 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3201 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3206 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3208 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3209 ranges_dump(ranges
);
3210 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3212 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3213 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3214 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3216 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3217 assert (prev
->upper
<= curr
->lower
);
3218 assert (curr
->lower
< curr
->upper
);
3222 TRACE("--- Done checking---\n");
3225 static RANGES
ranges_create(int count
)
3227 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3228 if (!ranges
) return NULL
;
3229 ranges
->hdpa
= DPA_Create(count
);
3230 if (ranges
->hdpa
) return ranges
;
3235 static void ranges_clear(RANGES ranges
)
3239 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3240 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3241 DPA_DeleteAllPtrs(ranges
->hdpa
);
3245 static void ranges_destroy(RANGES ranges
)
3247 if (!ranges
) return;
3248 ranges_clear(ranges
);
3249 DPA_Destroy(ranges
->hdpa
);
3253 static RANGES
ranges_clone(RANGES ranges
)
3258 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3260 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3262 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3263 if (!newrng
) goto fail
;
3264 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3265 if (!DPA_SetPtr(clone
->hdpa
, i
, newrng
))
3274 TRACE ("clone failed\n");
3275 ranges_destroy(clone
);
3279 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3283 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3284 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3289 static void ranges_dump(RANGES ranges
)
3293 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3294 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3297 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3299 RANGE srchrng
= { nItem
, nItem
+ 1 };
3301 TRACE("(nItem=%d)\n", nItem
);
3302 ranges_check(ranges
, "before contain");
3303 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3306 static INT
ranges_itemcount(RANGES ranges
)
3310 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3312 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3313 count
+= sel
->upper
- sel
->lower
;
3319 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3321 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3324 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3325 if (index
== -1) return TRUE
;
3327 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3329 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3330 if (chkrng
->lower
>= nItem
)
3331 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3332 if (chkrng
->upper
> nItem
)
3333 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3338 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3343 TRACE("(%s)\n", debugrange(&range
));
3344 ranges_check(ranges
, "before add");
3346 /* try find overlapping regions first */
3347 srchrgn
.lower
= range
.lower
- 1;
3348 srchrgn
.upper
= range
.upper
+ 1;
3349 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3355 TRACE("Adding new range\n");
3357 /* create the brand new range to insert */
3358 newrgn
= Alloc(sizeof(RANGE
));
3359 if(!newrgn
) goto fail
;
3362 /* figure out where to insert it */
3363 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3364 TRACE("index=%d\n", index
);
3365 if (index
== -1) index
= 0;
3367 /* and get it over with */
3368 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3376 RANGE
*chkrgn
, *mrgrgn
;
3377 INT fromindex
, mergeindex
;
3379 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3380 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3382 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3383 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3385 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3387 /* merge now common ranges */
3389 srchrgn
.lower
= chkrgn
->lower
- 1;
3390 srchrgn
.upper
= chkrgn
->upper
+ 1;
3394 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3395 if (mergeindex
== -1) break;
3396 if (mergeindex
== index
)
3398 fromindex
= index
+ 1;
3402 TRACE("Merge with index %i\n", mergeindex
);
3404 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3405 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3406 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3408 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3409 if (mergeindex
< index
) index
--;
3413 ranges_check(ranges
, "after add");
3417 ranges_check(ranges
, "failed add");
3421 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3426 TRACE("(%s)\n", debugrange(&range
));
3427 ranges_check(ranges
, "before del");
3429 /* we don't use DPAS_SORTED here, since we need *
3430 * to find the first overlapping range */
3431 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3434 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3436 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3438 /* case 1: Same range */
3439 if ( (chkrgn
->upper
== range
.upper
) &&
3440 (chkrgn
->lower
== range
.lower
) )
3442 DPA_DeletePtr(ranges
->hdpa
, index
);
3446 /* case 2: engulf */
3447 else if ( (chkrgn
->upper
<= range
.upper
) &&
3448 (chkrgn
->lower
>= range
.lower
) )
3450 DPA_DeletePtr(ranges
->hdpa
, index
);
3453 /* case 3: overlap upper */
3454 else if ( (chkrgn
->upper
<= range
.upper
) &&
3455 (chkrgn
->lower
< range
.lower
) )
3457 chkrgn
->upper
= range
.lower
;
3459 /* case 4: overlap lower */
3460 else if ( (chkrgn
->upper
> range
.upper
) &&
3461 (chkrgn
->lower
>= range
.lower
) )
3463 chkrgn
->lower
= range
.upper
;
3466 /* case 5: fully internal */
3471 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3472 newrgn
->lower
= chkrgn
->lower
;
3473 newrgn
->upper
= range
.lower
;
3474 chkrgn
->lower
= range
.upper
;
3475 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3483 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3486 ranges_check(ranges
, "after del");
3490 ranges_check(ranges
, "failed del");
3496 * Removes all selection ranges
3499 * [I] infoPtr : valid pointer to the listview structure
3500 * [I] toSkip : item range to skip removing the selection
3506 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3515 lvItem
.stateMask
= LVIS_SELECTED
;
3517 /* need to clone the DPA because callbacks can change it */
3518 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3519 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3520 while(iterator_next(&i
))
3521 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3522 /* note that the iterator destructor will free the cloned range */
3523 iterator_destroy(&i
);
3528 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3532 if (!(toSkip
= ranges_create(1))) return FALSE
;
3533 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3534 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3535 ranges_destroy(toSkip
);
3539 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3541 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3546 * Retrieves the number of items that are marked as selected.
3549 * [I] infoPtr : valid pointer to the listview structure
3552 * Number of items selected.
3554 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3556 INT nSelectedCount
= 0;
3558 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3561 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3563 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3568 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3570 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3571 return nSelectedCount
;
3576 * Manages the item focus.
3579 * [I] infoPtr : valid pointer to the listview structure
3580 * [I] nItem : item index
3583 * TRUE : focused item changed
3584 * FALSE : focused item has NOT changed
3586 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3588 INT oldFocus
= infoPtr
->nFocusedItem
;
3591 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3593 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3594 lvItem
.stateMask
= LVIS_FOCUSED
;
3595 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3597 return oldFocus
!= infoPtr
->nFocusedItem
;
3600 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3602 if (nShiftItem
< nItem
) return nShiftItem
;
3604 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3606 if (direction
> 0) return nShiftItem
+ direction
;
3608 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3611 /* This function updates focus index.
3614 focus : current focus index
3615 item : index of item to be added/removed
3616 direction : add/remove flag
3618 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3620 DWORD old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3622 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3623 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3624 if (focus
!= infoPtr
->nFocusedItem
)
3625 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3626 infoPtr
->notify_mask
|= old_mask
;
3631 * Updates the various indices after an item has been inserted or deleted.
3634 * [I] infoPtr : valid pointer to the listview structure
3635 * [I] nItem : item index
3636 * [I] direction : Direction of shift, +1 or -1.
3641 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3643 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3645 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3646 assert(abs(direction
) == 1);
3647 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3649 /* But we are not supposed to modify nHotItem! */
3654 * Adds a block of selections.
3657 * [I] infoPtr : valid pointer to the listview structure
3658 * [I] nItem : item index
3661 * Whether the window is still valid.
3663 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3665 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3666 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3667 HWND hwndSelf
= infoPtr
->hwndSelf
;
3668 NMLVODSTATECHANGE nmlv
;
3673 /* Temporarily disable change notification
3674 * If the control is LVS_OWNERDATA, we need to send
3675 * only one LVN_ODSTATECHANGED notification.
3676 * See MSDN documentation for LVN_ITEMCHANGED.
3678 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3679 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3680 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3682 if (nFirst
== -1) nFirst
= nItem
;
3684 item
.state
= LVIS_SELECTED
;
3685 item
.stateMask
= LVIS_SELECTED
;
3687 for (i
= nFirst
; i
<= nLast
; i
++)
3688 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3690 ZeroMemory(&nmlv
, sizeof(nmlv
));
3691 nmlv
.iFrom
= nFirst
;
3694 nmlv
.uNewState
= item
.state
;
3696 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3697 if (!IsWindow(hwndSelf
))
3699 infoPtr
->notify_mask
|= old_mask
;
3706 * Sets a single group selection.
3709 * [I] infoPtr : valid pointer to the listview structure
3710 * [I] nItem : item index
3715 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3722 if (!(selection
= ranges_create(100))) return;
3724 item
.state
= LVIS_SELECTED
;
3725 item
.stateMask
= LVIS_SELECTED
;
3727 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3729 if (infoPtr
->nSelectionMark
== -1)
3731 infoPtr
->nSelectionMark
= nItem
;
3732 ranges_additem(selection
, nItem
);
3738 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3739 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3740 ranges_add(selection
, sel
);
3745 RECT rcItem
, rcSel
, rcSelMark
;
3748 rcItem
.left
= LVIR_BOUNDS
;
3749 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3750 ranges_destroy (selection
);
3753 rcSelMark
.left
= LVIR_BOUNDS
;
3754 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3755 ranges_destroy (selection
);
3758 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3759 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3760 while(iterator_next(&i
))
3762 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3763 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3765 iterator_destroy(&i
);
3768 /* disable per item notifications on LVS_OWNERDATA style
3769 FIXME: single LVN_ODSTATECHANGED should be used */
3770 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
3771 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3772 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
3774 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3777 iterator_rangesitems(&i
, selection
);
3778 while(iterator_next(&i
))
3779 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3780 /* this will also destroy the selection */
3781 iterator_destroy(&i
);
3783 infoPtr
->notify_mask
|= old_mask
;
3784 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3789 * Sets a single selection.
3792 * [I] infoPtr : valid pointer to the listview structure
3793 * [I] nItem : item index
3798 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3802 TRACE("nItem=%d\n", nItem
);
3804 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3806 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3807 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3808 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3810 infoPtr
->nSelectionMark
= nItem
;
3815 * Set selection(s) with keyboard.
3818 * [I] infoPtr : valid pointer to the listview structure
3819 * [I] nItem : item index
3820 * [I] space : VK_SPACE code sent
3823 * SUCCESS : TRUE (needs to be repainted)
3824 * FAILURE : FALSE (nothing has changed)
3826 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3828 /* FIXME: pass in the state */
3829 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3830 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3831 BOOL bResult
= FALSE
;
3833 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3834 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3838 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3839 LISTVIEW_SetSelection(infoPtr
, nItem
);
3843 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3847 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3848 lvItem
.stateMask
= LVIS_SELECTED
;
3851 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3852 if (lvItem
.state
& LVIS_SELECTED
)
3853 infoPtr
->nSelectionMark
= nItem
;
3855 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3858 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3861 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3865 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3867 LVHITTESTINFO lvHitTestInfo
;
3869 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3870 lvHitTestInfo
.pt
.x
= pt
.x
;
3871 lvHitTestInfo
.pt
.y
= pt
.y
;
3873 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3875 lpLVItem
->mask
= LVIF_PARAM
;
3876 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3877 lpLVItem
->iSubItem
= 0;
3879 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3882 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3884 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3885 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3886 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3891 * Called when the mouse is being actively tracked and has hovered for a specified
3895 * [I] infoPtr : valid pointer to the listview structure
3896 * [I] fwKeys : key indicator
3897 * [I] x,y : mouse position
3900 * 0 if the message was processed, non-zero if there was an error
3903 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3904 * over the item for a certain period of time.
3907 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3911 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3913 if (LISTVIEW_IsHotTracking(infoPtr
))
3921 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3922 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3924 SetFocus(infoPtr
->hwndSelf
);
3930 #define SCROLL_LEFT 0x1
3931 #define SCROLL_RIGHT 0x2
3932 #define SCROLL_UP 0x4
3933 #define SCROLL_DOWN 0x8
3937 * Utility routine to draw and highlight items within a marquee selection rectangle.
3940 * [I] infoPtr : valid pointer to the listview structure
3941 * [I] coords_orig : original co-ordinates of the cursor
3942 * [I] coords_offs : offsetted coordinates of the cursor
3943 * [I] offset : offset amount
3944 * [I] scroll : Bitmask of which directions we should scroll, if at all
3949 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3952 BOOL controlDown
= FALSE
;
3954 ITERATOR old_elems
, new_elems
;
3956 POINT coords_offs
, offset
;
3958 /* Ensure coordinates are within client bounds */
3959 coords_offs
.x
= max(min(coords_orig
->x
, infoPtr
->rcList
.right
), 0);
3960 coords_offs
.y
= max(min(coords_orig
->y
, infoPtr
->rcList
.bottom
), 0);
3963 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3965 /* Offset coordinates by the appropriate amount */
3966 coords_offs
.x
-= offset
.x
;
3967 coords_offs
.y
-= offset
.y
;
3969 if (coords_offs
.x
> infoPtr
->marqueeOrigin
.x
)
3971 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3972 rect
.right
= coords_offs
.x
;
3976 rect
.left
= coords_offs
.x
;
3977 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3980 if (coords_offs
.y
> infoPtr
->marqueeOrigin
.y
)
3982 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3983 rect
.bottom
= coords_offs
.y
;
3987 rect
.top
= coords_offs
.y
;
3988 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3991 /* Cancel out the old marquee rectangle and draw the new one */
3992 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3994 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3995 the cursor is further away */
3997 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3998 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
4000 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
4001 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
4003 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
4004 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
4006 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
4007 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
4009 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
4011 infoPtr
->marqueeRect
= rect
;
4012 infoPtr
->marqueeDrawRect
= rect
;
4013 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
.x
, offset
.y
);
4015 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
4016 iterator_remove_common_items(&old_elems
, &new_elems
);
4018 /* Iterate over no longer selected items */
4019 while (iterator_next(&old_elems
))
4021 if (old_elems
.nItem
> -1)
4023 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
4026 item
.state
= LVIS_SELECTED
;
4028 item
.stateMask
= LVIS_SELECTED
;
4030 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
4033 iterator_destroy(&old_elems
);
4036 /* Iterate over newly selected items */
4037 if (GetKeyState(VK_CONTROL
) & 0x8000)
4040 while (iterator_next(&new_elems
))
4042 if (new_elems
.nItem
> -1)
4044 /* If CTRL is pressed, invert. If not, always select the item. */
4045 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
4048 item
.state
= LVIS_SELECTED
;
4050 item
.stateMask
= LVIS_SELECTED
;
4052 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
4055 iterator_destroy(&new_elems
);
4057 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
4062 * Called when we are in a marquee selection that involves scrolling the listview (ie,
4063 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
4066 * [I] hwnd : Handle to the listview
4067 * [I] uMsg : WM_TIMER (ignored)
4068 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
4069 * [I] dwTimer : The elapsed time (ignored)
4074 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
4076 LISTVIEW_INFO
*infoPtr
;
4077 SCROLLINFO scrollInfo
;
4081 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
4086 /* Get the current cursor position and convert to client coordinates */
4087 GetCursorPos(&coords
);
4088 ScreenToClient(hWnd
, &coords
);
4090 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4091 scrollInfo
.fMask
= SIF_ALL
;
4093 /* Work out in which directions we can scroll */
4094 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4096 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
4097 scroll
|= SCROLL_UP
;
4099 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
4100 scroll
|= SCROLL_DOWN
;
4103 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4105 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
4106 scroll
|= SCROLL_LEFT
;
4108 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
4109 scroll
|= SCROLL_RIGHT
;
4112 if (((coords
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
4113 ((coords
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
4114 ((coords
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
4115 ((coords
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
4117 LISTVIEW_MarqueeHighlight(infoPtr
, &coords
, scroll
);
4123 * Called whenever WM_MOUSEMOVE is received.
4126 * [I] infoPtr : valid pointer to the listview structure
4127 * [I] fwKeys : key indicator
4128 * [I] x,y : mouse position
4131 * 0 if the message is processed, non-zero if there was an error
4133 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4142 if (!(fwKeys
& MK_LBUTTON
))
4143 infoPtr
->bLButtonDown
= FALSE
;
4145 if (infoPtr
->bLButtonDown
)
4147 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4148 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4150 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4152 if (infoPtr
->bMarqueeSelect
)
4154 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4155 move the mouse again */
4157 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4158 (y
>= infoPtr
->rcList
.bottom
))
4160 if (!infoPtr
->bScrolling
)
4162 infoPtr
->bScrolling
= TRUE
;
4163 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4168 infoPtr
->bScrolling
= FALSE
;
4169 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4172 LISTVIEW_MarqueeHighlight(infoPtr
, &pt
, 0);
4177 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4179 /* reset item marker */
4180 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4181 infoPtr
->nLButtonDownItem
= -1;
4183 if (!PtInRect(&rect
, pt
))
4185 /* this path covers the following:
4186 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4187 2. change focus with keys
4188 3. move mouse over item from step 1 selects it and moves focus on it */
4189 if (infoPtr
->nLButtonDownItem
!= -1 &&
4190 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4194 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4195 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4197 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4198 infoPtr
->nLButtonDownItem
= -1;
4201 if (!infoPtr
->bDragging
)
4203 ht
.pt
= infoPtr
->ptClickPos
;
4204 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4206 /* If the click is outside the range of an item, begin a
4207 highlight. If not, begin an item drag. */
4212 /* If we're allowing multiple selections, send notification.
4213 If return value is non-zero, cancel. */
4214 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4216 /* Store the absolute coordinates of the click */
4218 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4220 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4221 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4223 /* Begin selection and capture mouse */
4224 infoPtr
->bMarqueeSelect
= TRUE
;
4225 infoPtr
->marqueeRect
= rect
;
4226 SetCapture(infoPtr
->hwndSelf
);
4233 ZeroMemory(&nmlv
, sizeof(nmlv
));
4234 nmlv
.iItem
= ht
.iItem
;
4235 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4237 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4238 infoPtr
->bDragging
= TRUE
;
4246 /* see if we are supposed to be tracking mouse hovering */
4247 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4248 TRACKMOUSEEVENT trackinfo
;
4251 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4252 trackinfo
.dwFlags
= TME_QUERY
;
4254 /* see if we are already tracking this hwnd */
4255 _TrackMouseEvent(&trackinfo
);
4258 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
4261 if((trackinfo
.dwFlags
& flags
) != flags
|| trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4262 trackinfo
.dwFlags
= flags
;
4263 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4264 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4266 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4267 _TrackMouseEvent(&trackinfo
);
4276 * Tests whether the item is assignable to a list with style lStyle
4278 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4280 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4281 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4282 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4290 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4293 * [I] infoPtr : valid pointer to the listview structure
4294 * [I] lpLVItem : valid pointer to new item attributes
4295 * [I] isNew : the item being set is being inserted
4296 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4297 * [O] bChanged : will be set to TRUE if the item really changed
4303 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4309 /* stateMask is ignored for LVM_INSERTITEM */
4310 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4314 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4316 if (lpLVItem
->mask
== 0) return TRUE
;
4318 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4320 /* a virtual listview only stores selection and focus */
4321 if (lpLVItem
->mask
& ~LVIF_STATE
)
4327 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4328 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4332 /* we need to get the lParam and state of the item */
4333 item
.iItem
= lpLVItem
->iItem
;
4334 item
.iSubItem
= lpLVItem
->iSubItem
;
4335 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4336 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4340 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4342 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4343 /* determine what fields will change */
4344 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4345 uChanged
|= LVIF_STATE
;
4347 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4348 uChanged
|= LVIF_IMAGE
;
4350 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4351 uChanged
|= LVIF_PARAM
;
4353 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4354 uChanged
|= LVIF_INDENT
;
4356 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4357 uChanged
|= LVIF_TEXT
;
4359 TRACE("change mask=0x%x\n", uChanged
);
4361 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4362 nmlv
.iItem
= lpLVItem
->iItem
;
4363 if (lpLVItem
->mask
& LVIF_STATE
)
4365 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4366 nmlv
.uOldState
= item
.state
;
4368 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4369 nmlv
.lParam
= item
.lParam
;
4371 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4372 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4373 are enabled. Even nothing really changed we still need to send this,
4374 in this case uChanged mask is just set to passed item mask. */
4375 if (lpItem
&& !isNew
&& (infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
))
4377 HWND hwndSelf
= infoPtr
->hwndSelf
;
4379 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4381 if (!IsWindow(hwndSelf
))
4385 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4386 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4387 /* this means we won't hit a focus change path later */
4388 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4390 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4391 infoPtr
->nFocusedItem
++;
4394 if (!uChanged
) return TRUE
;
4397 /* copy information */
4398 if (lpLVItem
->mask
& LVIF_TEXT
)
4399 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4401 if (lpLVItem
->mask
& LVIF_IMAGE
)
4402 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4404 if (lpLVItem
->mask
& LVIF_PARAM
)
4405 lpItem
->lParam
= lpLVItem
->lParam
;
4407 if (lpLVItem
->mask
& LVIF_INDENT
)
4408 lpItem
->iIndent
= lpLVItem
->iIndent
;
4410 if (uChanged
& LVIF_STATE
)
4412 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4414 lpItem
->state
&= ~stateMask
;
4415 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4417 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4419 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4420 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4422 else if (stateMask
& LVIS_SELECTED
)
4424 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4426 /* If we are asked to change focus, and we manage it, do it.
4427 It's important to have all new item data stored at this point,
4428 because changing existing focus could result in a redrawing operation,
4429 which in turn could ask for disp data, application should see all data
4430 for inserted item when processing LVN_GETDISPINFO.
4432 The way this works application will see nested item change notifications -
4433 changed item notifications interrupted by ones from item losing focus. */
4434 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4436 if (lpLVItem
->state
& LVIS_FOCUSED
)
4438 /* update selection mark */
4439 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4440 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4442 if (infoPtr
->nFocusedItem
!= -1)
4444 /* remove current focus */
4445 item
.mask
= LVIF_STATE
;
4447 item
.stateMask
= LVIS_FOCUSED
;
4449 /* recurse with redrawing an item */
4450 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4453 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4454 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4456 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4458 infoPtr
->nFocusedItem
= -1;
4463 /* if we're inserting the item, we're done */
4464 if (isNew
) return TRUE
;
4466 /* send LVN_ITEMCHANGED notification */
4467 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4468 if (infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
)
4469 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4476 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4479 * [I] infoPtr : valid pointer to the listview structure
4480 * [I] lpLVItem : valid pointer to new subitem attributes
4481 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4482 * [O] bChanged : will be set to TRUE if the item really changed
4488 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4491 SUBITEM_INFO
*lpSubItem
;
4493 /* we do not support subitems for virtual listviews */
4494 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4496 /* set subitem only if column is present */
4497 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4499 /* First do some sanity checks */
4500 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4501 particularly useful. We currently do not actually do anything with
4502 the flag on subitems.
4504 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4505 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4507 /* get the subitem structure, and create it if not there */
4508 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4509 assert (hdpaSubItems
);
4511 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4514 SUBITEM_INFO
*tmpSubItem
;
4517 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4518 if (!lpSubItem
) return FALSE
;
4519 /* we could binary search here, if need be...*/
4520 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4522 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4523 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4525 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4530 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4531 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4535 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4537 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4541 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4543 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4552 * Sets item attributes.
4555 * [I] infoPtr : valid pointer to the listview structure
4556 * [I] lpLVItem : new item attributes
4557 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4563 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4565 HWND hwndSelf
= infoPtr
->hwndSelf
;
4566 LPWSTR pszText
= NULL
;
4567 BOOL bResult
, bChanged
= FALSE
;
4570 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4572 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4575 /* Store old item area */
4576 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4578 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4579 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4581 pszText
= lpLVItem
->pszText
;
4582 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4585 /* actually set the fields */
4586 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4588 if (lpLVItem
->iSubItem
)
4589 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4591 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4592 if (!IsWindow(hwndSelf
))
4595 /* redraw item, if necessary */
4596 if (bChanged
&& !infoPtr
->bIsDrawing
)
4598 /* this little optimization eliminates some nasty flicker */
4599 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4600 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4601 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4602 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4605 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4606 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4612 textfreeT(lpLVItem
->pszText
, isW
);
4613 lpLVItem
->pszText
= pszText
;
4621 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4624 * [I] infoPtr : valid pointer to the listview structure
4629 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4632 SCROLLINFO scrollInfo
;
4634 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4635 scrollInfo
.fMask
= SIF_POS
;
4637 if (infoPtr
->uView
== LV_VIEW_LIST
)
4639 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4640 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4642 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4644 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4645 nItem
= scrollInfo
.nPos
;
4649 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4650 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4653 TRACE("nItem=%d\n", nItem
);
4661 * Erases the background of the given rectangle
4664 * [I] infoPtr : valid pointer to the listview structure
4665 * [I] hdc : device context handle
4666 * [I] lprcBox : clipping rectangle
4672 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4674 if (!infoPtr
->hBkBrush
) return FALSE
;
4676 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4678 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4681 /* Draw main item or subitem */
4682 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4684 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4685 const RECT
*background
;
4690 /* now check if we need to update the focus rectangle */
4691 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4692 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4694 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4695 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4696 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4697 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4698 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4699 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4700 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4701 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4702 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4704 /* FIXME: temporary hack */
4705 rcSelect
.left
= rcLabel
.left
;
4707 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4709 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4710 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4711 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4712 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4713 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4716 /* in icon mode, the label rect is really what we want to draw the
4718 /* in detail mode, we want to paint background for label rect when
4719 * item is not selected or listview has full row select; otherwise paint
4720 * background for text only */
4721 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4722 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4723 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4724 background
= &rcLabel
;
4726 background
= &rcSelect
;
4728 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4729 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4731 if (item
->state
& LVIS_FOCUSED
)
4733 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4735 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4737 /* we have to update left focus bound too if item isn't in leftmost column
4738 and reduce right box bound */
4739 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4743 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4745 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4746 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4747 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4749 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4750 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4753 rcSelect
.right
= rcBox
.right
;
4755 infoPtr
->rcFocus
= rcSelect
;
4758 infoPtr
->rcFocus
= rcLabel
;
4762 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4764 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4767 TRACE("stateimage=%d\n", stateimage
);
4768 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4773 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4774 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4778 TRACE("iImage=%d\n", item
->iImage
);
4780 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4781 style
= ILD_SELECTED
;
4785 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4786 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4787 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4788 style
| (item
->state
& LVIS_OVERLAYMASK
));
4791 /* Don't bother painting item being edited */
4792 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4794 /* figure out the text drawing flags */
4795 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4796 if (infoPtr
->uView
== LV_VIEW_ICON
)
4797 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4798 else if (item
->iSubItem
)
4800 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4802 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4803 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4804 default: format
|= DT_LEFT
;
4807 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4809 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4810 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4812 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4814 /* for GRIDLINES reduce the bottom so the text formats correctly */
4815 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4819 if ((!(item
->state
& LVIS_SELECTED
) || !infoPtr
->bFocus
) && (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTSHADOWTEXT
))
4820 DrawShadowText(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
, RGB(255, 255, 255), RGB(0, 0, 0), 2, 2);
4823 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4831 * [I] infoPtr : valid pointer to the listview structure
4832 * [I] hdc : device context handle
4833 * [I] nItem : item index
4834 * [I] nSubItem : subitem index
4835 * [I] pos : item position in client coordinates
4836 * [I] cdmode : custom draw mode
4842 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4844 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4845 static WCHAR callbackW
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4846 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4848 NMLVCUSTOMDRAW nmlvcd
;
4851 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4853 /* get information needed for drawing the item */
4854 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4855 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4856 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4857 lvItem
.iItem
= nItem
;
4858 lvItem
.iSubItem
= 0;
4861 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4862 lvItem
.pszText
= szDispText
;
4863 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4864 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4865 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4867 /* now check if we need to update the focus rectangle */
4868 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4869 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4871 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4872 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4874 /* Full custom draw stage sequence looks like this:
4879 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4880 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item itself
4881 - CDDS_ITEMPOSTPAINT
4886 - CDDS_ITEMPOSTPAINT
4889 /* fill in the custom draw structure */
4890 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4891 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4892 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4893 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4897 while (iterator_next(subitems
))
4899 DWORD subitemstage
= CDRF_DODEFAULT
;
4900 NMLVCUSTOMDRAW temp_nmlvcd
;
4902 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4903 if (subitems
->nItem
)
4905 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4906 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4907 lvItem
.iItem
= nItem
;
4908 lvItem
.iSubItem
= subitems
->nItem
;
4911 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4912 lvItem
.pszText
= szDispText
;
4913 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4914 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4915 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4916 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4917 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4919 /* update custom draw data */
4920 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4921 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4922 nmlvcd
.iSubItem
= subitems
->nItem
;
4925 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4926 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4929 * A selection should neither affect the colors in the post paint notification nor
4930 * affect the colors of the next drawn subitem. Copy the structure to prevent this.
4932 temp_nmlvcd
= nmlvcd
;
4933 prepaint_setup(infoPtr
, hdc
, &temp_nmlvcd
, subitems
->nItem
);
4935 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4936 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &temp_nmlvcd
, &pos
);
4938 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4939 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4944 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4945 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4949 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4951 nmlvcd
.iSubItem
= 0;
4952 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4960 * Draws listview items when in owner draw mode.
4963 * [I] infoPtr : valid pointer to the listview structure
4964 * [I] hdc : device context handle
4969 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4971 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4972 DWORD cditemmode
= CDRF_DODEFAULT
;
4973 NMLVCUSTOMDRAW nmlvcd
;
4974 POINT Origin
, Position
;
4980 ZeroMemory(&dis
, sizeof(dis
));
4982 /* Get scroll info once before loop */
4983 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4985 /* iterate through the invalidated rows */
4986 while(iterator_next(i
))
4988 item
.iItem
= i
->nItem
;
4990 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4991 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4992 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4994 dis
.CtlType
= ODT_LISTVIEW
;
4996 dis
.itemID
= item
.iItem
;
4997 dis
.itemAction
= ODA_DRAWENTIRE
;
4999 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
5000 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
5001 dis
.hwndItem
= infoPtr
->hwndSelf
;
5003 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
5004 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
5005 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
5006 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
5007 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
5008 dis
.itemData
= item
.lParam
;
5010 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
5013 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
5014 * structure for the rest. of the paint cycle
5016 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
5017 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
5018 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5020 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
5022 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
5023 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
5026 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
5027 notify_postpaint(infoPtr
, &nmlvcd
);
5033 * Draws listview items when in report display mode.
5036 * [I] infoPtr : valid pointer to the listview structure
5037 * [I] hdc : device context handle
5038 * [I] cdmode : custom draw mode
5043 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5046 RECT rcClip
, rcItem
;
5054 /* figure out what to draw */
5055 rgntype
= GetClipBox(hdc
, &rcClip
);
5056 if (rgntype
== NULLREGION
) return;
5058 /* Get scroll info once before loop */
5059 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5061 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5063 /* narrow down the columns we need to paint */
5064 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5066 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5068 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5069 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5070 ranges_additem(colRanges
, index
);
5072 iterator_rangesitems(&j
, colRanges
);
5074 /* in full row select, we _have_ to draw the main item */
5075 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
5078 /* iterate through the invalidated rows */
5079 while(iterator_next(i
))
5085 SelectObject(hdc
, infoPtr
->hFont
);
5086 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5087 Position
.x
= Origin
.x
;
5088 Position
.y
+= Origin
.y
;
5090 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5092 /* iterate through the invalidated columns */
5093 while(iterator_next(&j
))
5095 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5097 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
5100 rcItem
.bottom
= infoPtr
->nItemHeight
;
5101 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
5102 if (!RectVisible(hdc
, &rcItem
)) continue;
5105 ranges_additem(subitems
, j
.nItem
);
5108 iterator_rangesitems(&k
, subitems
);
5109 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
5110 iterator_destroy(&k
);
5112 iterator_destroy(&j
);
5117 * Draws the gridlines if necessary when in report display mode.
5120 * [I] infoPtr : valid pointer to the listview structure
5121 * [I] hdc : device context handle
5126 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
5132 RECT rcClip
, rcItem
= {0};
5140 /* figure out what to draw */
5141 rgntype
= GetClipBox(hdc
, &rcClip
);
5142 if (rgntype
== NULLREGION
) return;
5144 /* Get scroll info once before loop */
5145 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5147 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5149 /* narrow down the columns we need to paint */
5150 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5152 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5154 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5155 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5156 ranges_additem(colRanges
, index
);
5159 /* is right most vertical line visible? */
5160 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5162 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5163 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5164 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5167 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5169 hOldPen
= SelectObject ( hdc
, hPen
);
5171 /* draw the vertical lines for the columns */
5172 iterator_rangesitems(&j
, colRanges
);
5173 while(iterator_next(&j
))
5175 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5176 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5177 rcItem
.left
+= Origin
.x
;
5178 rcItem
.right
+= Origin
.x
;
5179 rcItem
.top
= infoPtr
->rcList
.top
;
5180 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5181 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5182 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5183 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5185 iterator_destroy(&j
);
5186 /* draw rightmost grid line if visible */
5189 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5190 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5191 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5193 rcItem
.right
+= Origin
.x
;
5195 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5196 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5199 /* draw the horizontal lines for the rows */
5200 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5201 rcItem
.left
= infoPtr
->rcList
.left
;
5202 rcItem
.right
= infoPtr
->rcList
.right
;
5203 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5205 rcItem
.bottom
= rcItem
.top
= y
;
5206 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5207 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5208 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5211 SelectObject( hdc
, hOldPen
);
5212 DeleteObject( hPen
);
5215 ranges_destroy(colRanges
);
5220 * Draws listview items when in list display mode.
5223 * [I] infoPtr : valid pointer to the listview structure
5224 * [I] hdc : device context handle
5225 * [I] cdmode : custom draw mode
5230 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5232 POINT Origin
, Position
;
5234 /* Get scroll info once before loop */
5235 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5237 while(iterator_prev(i
))
5239 SelectObject(hdc
, infoPtr
->hFont
);
5240 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5241 Position
.x
+= Origin
.x
;
5242 Position
.y
+= Origin
.y
;
5244 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5251 * Draws listview items.
5254 * [I] infoPtr : valid pointer to the listview structure
5255 * [I] hdc : device context handle
5256 * [I] prcErase : rect to be erased before refresh (may be NULL)
5261 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5263 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5264 NMLVCUSTOMDRAW nmlvcd
;
5271 HBITMAP hbmp
= NULL
;
5274 LISTVIEW_DUMP(infoPtr
);
5276 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5277 TRACE("double buffering\n");
5279 hdc
= CreateCompatibleDC(hdcOrig
);
5281 ERR("Failed to create DC for backbuffer\n");
5284 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5285 infoPtr
->rcList
.bottom
);
5287 ERR("Failed to create bitmap for backbuffer\n");
5292 SelectObject(hdc
, hbmp
);
5293 SelectObject(hdc
, infoPtr
->hFont
);
5295 if(GetClipBox(hdcOrig
, &rcClient
))
5296 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5298 /* Save dc values we're gonna trash while drawing
5299 * FIXME: Should be done in LISTVIEW_DrawItem() */
5300 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5301 oldBkMode
= GetBkMode(hdc
);
5302 oldBkColor
= GetBkColor(hdc
);
5303 oldTextColor
= GetTextColor(hdc
);
5306 infoPtr
->bIsDrawing
= TRUE
;
5309 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5310 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5311 /* If no erasing was done (usually because RedrawWindow was called
5312 * with RDW_INVALIDATE only) we need to copy the old contents into
5313 * the backbuffer before continuing. */
5314 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5315 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5316 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5317 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5320 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5321 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5322 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5323 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5325 /* nothing to draw */
5326 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5328 /* figure out what we need to draw */
5329 iterator_visibleitems(&i
, infoPtr
, hdc
);
5330 range
= iterator_range(&i
);
5332 /* send cache hint notification */
5333 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5337 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5338 nmlv
.iFrom
= range
.lower
;
5339 nmlv
.iTo
= range
.upper
- 1;
5340 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5343 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5344 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5347 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5348 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5349 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5350 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5352 /* if we have a focus rect and it's visible, draw it */
5353 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5354 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5355 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5357 iterator_destroy(&i
);
5360 /* For LVS_EX_GRIDLINES go and draw lines */
5361 /* This includes the case where there were *no* items */
5362 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5363 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5365 /* Draw marquee rectangle if appropriate */
5366 if (infoPtr
->bMarqueeSelect
)
5369 SetBkColor(hdc
, RGB(255, 255, 255));
5370 SetTextColor(hdc
, RGB(0, 0, 0));
5371 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5374 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5377 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5378 notify_postpaint(infoPtr
, &nmlvcd
);
5381 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5382 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5383 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5384 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5389 SelectObject(hdc
, hOldFont
);
5390 SetBkMode(hdc
, oldBkMode
);
5391 SetBkColor(hdc
, oldBkColor
);
5392 SetTextColor(hdc
, oldTextColor
);
5395 infoPtr
->bIsDrawing
= FALSE
;
5401 * Calculates the approximate width and height of a given number of items.
5404 * [I] infoPtr : valid pointer to the listview structure
5405 * [I] nItemCount : number of items
5406 * [I] wWidth : width
5407 * [I] wHeight : height
5410 * Returns a DWORD. The width in the low word and the height in high word.
5412 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5413 WORD wWidth
, WORD wHeight
)
5415 DWORD dwViewRect
= 0;
5417 if (nItemCount
== -1)
5418 nItemCount
= infoPtr
->nItemCount
;
5420 if (infoPtr
->uView
== LV_VIEW_LIST
)
5422 INT nItemCountPerColumn
= 1;
5423 INT nColumnCount
= 0;
5425 if (wHeight
== 0xFFFF)
5427 /* use current height */
5428 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5431 if (wHeight
< infoPtr
->nItemHeight
)
5432 wHeight
= infoPtr
->nItemHeight
;
5436 if (infoPtr
->nItemHeight
> 0)
5438 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5439 if (nItemCountPerColumn
== 0)
5440 nItemCountPerColumn
= 1;
5442 if (nItemCount
% nItemCountPerColumn
!= 0)
5443 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5445 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5449 /* Microsoft padding magic */
5450 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5451 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5453 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5455 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5459 if (infoPtr
->nItemCount
> 0)
5461 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5462 wWidth
= rcBox
.right
- rcBox
.left
;
5463 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5467 /* use current height and width */
5468 if (wHeight
== 0xffff)
5469 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5470 if (wWidth
== 0xffff)
5471 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5474 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5476 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5482 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5483 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5485 if (wWidth
== 0xffff)
5486 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5488 if (wWidth
< nItemWidth
)
5489 wWidth
= nItemWidth
;
5491 cols
= wWidth
/ nItemWidth
;
5492 if (cols
> nItemCount
)
5499 rows
= nItemCount
/ cols
;
5500 if (nItemCount
% cols
)
5506 wHeight
= (nItemHeight
* rows
)+2;
5507 wWidth
= (nItemWidth
* cols
)+2;
5509 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5511 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5512 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5519 * Cancel edit label with saving item text.
5522 * [I] infoPtr : valid pointer to the listview structure
5525 * Always returns TRUE.
5527 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5529 if (infoPtr
->hwndEdit
)
5531 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5532 HWND edit
= infoPtr
->hwndEdit
;
5534 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5535 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5543 * Create a drag image list for the specified item.
5546 * [I] infoPtr : valid pointer to the listview structure
5547 * [I] iItem : index of item
5548 * [O] lppt : Upper-left corner of the image
5551 * Returns a handle to the image list if successful, NULL otherwise.
5553 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5559 HBITMAP hbmp
, hOldbmp
;
5561 HIMAGELIST dragList
= 0;
5562 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5564 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5567 rcItem
.left
= LVIR_BOUNDS
;
5568 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5571 lppt
->x
= rcItem
.left
;
5572 lppt
->y
= rcItem
.top
;
5574 size
.cx
= rcItem
.right
- rcItem
.left
;
5575 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5577 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5578 hdc
= CreateCompatibleDC(hdcOrig
);
5579 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5580 hOldbmp
= SelectObject(hdc
, hbmp
);
5581 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5583 SetRect(&rcItem
, 0, 0, size
.cx
, size
.cy
);
5584 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5587 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5589 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5590 SelectObject(hdc
, hOldbmp
);
5591 ImageList_Add(dragList
, hbmp
, 0);
5594 SelectObject(hdc
, hOldbmp
);
5596 SelectObject(hdc
, hOldFont
);
5599 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5601 TRACE("ret=%p\n", dragList
);
5609 * Removes all listview items and subitems.
5612 * [I] infoPtr : valid pointer to the listview structure
5618 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5620 HDPA hdpaSubItems
= NULL
;
5621 BOOL suppress
= FALSE
;
5629 /* we do it directly, to avoid notifications */
5630 ranges_clear(infoPtr
->selectionRanges
);
5631 infoPtr
->nSelectionMark
= -1;
5632 infoPtr
->nFocusedItem
= -1;
5633 SetRectEmpty(&infoPtr
->rcFocus
);
5634 /* But we are supposed to leave nHotItem as is! */
5636 /* send LVN_DELETEALLITEMS notification */
5637 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5641 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5643 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5646 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5648 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5650 /* send LVN_DELETEITEM notification, if not suppressed
5651 and if it is not a virtual listview */
5652 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5653 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5654 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5655 /* free id struct */
5656 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5657 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5658 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5660 /* both item and subitem start with ITEMHDR header */
5661 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5663 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5664 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5667 DPA_Destroy(hdpaSubItems
);
5668 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5670 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5671 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5672 infoPtr
->nItemCount
--;
5677 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5678 LISTVIEW_UpdateScroll(infoPtr
);
5680 LISTVIEW_InvalidateList(infoPtr
);
5687 * Scrolls, and updates the columns, when a column is changing width.
5690 * [I] infoPtr : valid pointer to the listview structure
5691 * [I] nColumn : column to scroll
5692 * [I] dx : amount of scroll, in pixels
5697 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5699 COLUMN_INFO
*lpColumnInfo
;
5705 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5706 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5707 rcCol
= lpColumnInfo
->rcHeader
;
5708 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5709 rcCol
.left
= rcCol
.right
;
5711 /* adjust the other columns */
5712 hdi
.mask
= HDI_ORDER
;
5713 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5715 INT nOrder
= hdi
.iOrder
;
5716 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5718 hdi
.mask
= HDI_ORDER
;
5719 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5720 if (hdi
.iOrder
>= nOrder
) {
5721 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5722 lpColumnInfo
->rcHeader
.left
+= dx
;
5723 lpColumnInfo
->rcHeader
.right
+= dx
;
5728 /* do not update screen if not in report mode */
5729 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5731 /* Need to reset the item width when inserting a new column */
5732 infoPtr
->nItemWidth
+= dx
;
5734 LISTVIEW_UpdateScroll(infoPtr
);
5735 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5737 /* scroll to cover the deleted column, and invalidate for redraw */
5738 rcOld
= infoPtr
->rcList
;
5739 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5740 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5745 * Removes a column from the listview control.
5748 * [I] infoPtr : valid pointer to the listview structure
5749 * [I] nColumn : column index
5755 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5759 TRACE("nColumn=%d\n", nColumn
);
5761 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5764 /* While the MSDN specifically says that column zero should not be deleted,
5765 what actually happens is that the column itself is deleted but no items or subitems
5769 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5771 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5774 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5775 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5777 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5779 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5781 INT nItem
, nSubItem
, i
;
5783 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5785 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5788 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5790 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5791 if (lpSubItem
->iSubItem
== nColumn
)
5794 lpDelItem
= lpSubItem
;
5796 else if (lpSubItem
->iSubItem
> nColumn
)
5798 lpSubItem
->iSubItem
--;
5802 /* if we found our subitem, zap it */
5806 if (is_text(lpDelItem
->hdr
.pszText
))
5807 Free(lpDelItem
->hdr
.pszText
);
5812 /* free dpa memory */
5813 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5818 /* update the other column info */
5819 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5820 LISTVIEW_InvalidateList(infoPtr
);
5822 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5823 LISTVIEW_UpdateItemSize(infoPtr
);
5830 * Invalidates the listview after an item's insertion or deletion.
5833 * [I] infoPtr : valid pointer to the listview structure
5834 * [I] nItem : item index
5835 * [I] dir : -1 if deleting, 1 if inserting
5840 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5842 INT nPerCol
, nItemCol
, nItemRow
;
5846 /* if we don't refresh, what's the point of scrolling? */
5847 if (!is_redrawing(infoPtr
)) return;
5849 assert (abs(dir
) == 1);
5851 /* arrange icons if autoarrange is on */
5852 if (is_autoarrange(infoPtr
))
5854 BOOL arrange
= TRUE
;
5855 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5856 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5857 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5860 /* scrollbars need updating */
5861 LISTVIEW_UpdateScroll(infoPtr
);
5863 /* figure out the item's position */
5864 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5865 nPerCol
= infoPtr
->nItemCount
+ 1;
5866 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5867 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5868 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5871 nItemCol
= nItem
/ nPerCol
;
5872 nItemRow
= nItem
% nPerCol
;
5873 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5875 /* move the items below up a slot */
5876 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5877 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5878 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5879 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5880 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5881 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5882 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5884 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5885 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5888 /* report has only that column, so we're done */
5889 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5891 /* now for LISTs, we have to deal with the columns to the right */
5892 SetRect(&rcScroll
, (nItemCol
+ 1) * infoPtr
->nItemWidth
, 0,
5893 (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
,
5894 nPerCol
* infoPtr
->nItemHeight
);
5895 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5896 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5897 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5902 * Removes an item from the listview control.
5905 * [I] infoPtr : valid pointer to the listview structure
5906 * [I] nItem : item index
5912 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5915 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5916 INT focus
= infoPtr
->nFocusedItem
;
5918 TRACE("(nItem=%d)\n", nItem
);
5920 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5922 /* remove selection, and focus */
5924 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5925 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5927 /* send LVN_DELETEITEM notification. */
5928 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5930 /* we need to do this here, because we'll be deleting stuff */
5932 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5934 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5942 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5943 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5945 /* free id struct */
5946 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5947 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5948 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5950 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5952 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5953 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5956 DPA_Destroy(hdpaSubItems
);
5961 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5962 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5965 infoPtr
->nItemCount
--;
5966 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5967 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5969 /* now is the invalidation fun */
5971 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5978 * Callback implementation for editlabel control
5981 * [I] infoPtr : valid pointer to the listview structure
5982 * [I] storeText : store edit box text as item text
5983 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5989 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5991 HWND hwndSelf
= infoPtr
->hwndSelf
;
5992 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5993 NMLVDISPINFOW dispInfo
;
5994 INT editedItem
= infoPtr
->nEditLabelItem
;
5996 WCHAR
*pszText
= NULL
;
6001 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
6005 if (!(pszText
= Alloc(len
* (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
6009 GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
);
6011 GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
);
6015 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
6017 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6018 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6019 dispInfo
.item
.iItem
= editedItem
;
6020 dispInfo
.item
.iSubItem
= 0;
6021 dispInfo
.item
.stateMask
= ~0;
6022 dispInfo
.item
.pszText
= szDispText
;
6023 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6024 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
6031 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
6034 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
6035 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
6036 textfreeT(tmp
, FALSE
);
6039 /* add the text from the edit in */
6040 dispInfo
.item
.mask
|= LVIF_TEXT
;
6041 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
6042 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
6044 infoPtr
->notify_mask
&= ~NOTIFY_MASK_END_LABEL_EDIT
;
6046 /* Do we need to update the Item Text */
6047 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
6049 infoPtr
->notify_mask
|= NOTIFY_MASK_END_LABEL_EDIT
;
6051 infoPtr
->nEditLabelItem
= -1;
6052 infoPtr
->hwndEdit
= 0;
6054 if (!res
) goto cleanup
;
6056 if (!IsWindow(hwndSelf
))
6061 if (!pszText
) return TRUE
;
6068 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
6070 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
6071 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6072 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
6074 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
6080 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6081 dispInfo
.item
.mask
= LVIF_TEXT
;
6082 dispInfo
.item
.iItem
= editedItem
;
6083 dispInfo
.item
.iSubItem
= 0;
6084 dispInfo
.item
.pszText
= pszText
;
6085 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
6086 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
6096 * Subclassed edit control windproc function
6099 * [I] hwnd : the edit window handle
6100 * [I] uMsg : the message that is to be processed
6101 * [I] wParam : first message parameter
6102 * [I] lParam : second message parameter
6103 * [I] isW : TRUE if input is Unicode
6108 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
6110 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
6113 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
6114 hwnd
, uMsg
, wParam
, lParam
, isW
);
6119 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
6123 WNDPROC editProc
= infoPtr
->EditWndProc
;
6124 infoPtr
->EditWndProc
= 0;
6125 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
6126 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6130 if (VK_ESCAPE
== (INT
)wParam
)
6135 else if (VK_RETURN
== (INT
)wParam
)
6139 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6143 if (infoPtr
->hwndEdit
)
6144 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
6146 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6152 * Subclassed edit control Unicode windproc function
6155 * [I] hwnd : the edit window handle
6156 * [I] uMsg : the message that is to be processed
6157 * [I] wParam : first message parameter
6158 * [I] lParam : second message parameter
6162 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6164 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6169 * Subclassed edit control ANSI windproc function
6172 * [I] hwnd : the edit window handle
6173 * [I] uMsg : the message that is to be processed
6174 * [I] wParam : first message parameter
6175 * [I] lParam : second message parameter
6179 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6181 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6186 * Creates a subclassed edit control
6189 * [I] infoPtr : valid pointer to the listview structure
6190 * [I] text : initial text for the edit
6191 * [I] style : the window style
6192 * [I] isW : TRUE if input is Unicode
6196 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6198 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6199 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6202 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6204 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6206 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6208 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6210 if (!hedit
) return 0;
6212 infoPtr
->EditWndProc
= (WNDPROC
)
6213 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6214 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6216 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6217 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6224 * Begin in place editing of specified list view item
6227 * [I] infoPtr : valid pointer to the listview structure
6228 * [I] nItem : item index
6229 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6235 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6237 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6238 HWND hwndSelf
= infoPtr
->hwndSelf
;
6239 NMLVDISPINFOW dispInfo
;
6240 HFONT hOldFont
= NULL
;
6246 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6248 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6250 /* remove existing edit box */
6251 if (infoPtr
->hwndEdit
)
6253 SetFocus(infoPtr
->hwndSelf
);
6254 infoPtr
->hwndEdit
= 0;
6257 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6259 infoPtr
->nEditLabelItem
= nItem
;
6261 LISTVIEW_SetSelection(infoPtr
, nItem
);
6262 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6263 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6265 rect
.left
= LVIR_LABEL
;
6266 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6268 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6269 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6270 dispInfo
.item
.iItem
= nItem
;
6271 dispInfo
.item
.iSubItem
= 0;
6272 dispInfo
.item
.stateMask
= ~0;
6273 dispInfo
.item
.pszText
= disptextW
;
6274 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6275 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6277 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6278 if (!infoPtr
->hwndEdit
) return 0;
6280 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6282 if (!IsWindow(hwndSelf
))
6284 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6285 infoPtr
->hwndEdit
= 0;
6289 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6291 /* position and display edit box */
6292 hdc
= GetDC(infoPtr
->hwndSelf
);
6294 /* select the font to get appropriate metric dimensions */
6296 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6298 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6299 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6300 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6302 /* get string length in pixels */
6303 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6305 /* add extra spacing for the next character */
6306 GetTextMetricsW(hdc
, &tm
);
6307 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6310 SelectObject(hdc
, hOldFont
);
6312 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6314 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6317 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6318 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6319 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6320 SetFocus(infoPtr
->hwndEdit
);
6321 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6322 return infoPtr
->hwndEdit
;
6328 * Ensures the specified item is visible, scrolling into view if necessary.
6331 * [I] infoPtr : valid pointer to the listview structure
6332 * [I] nItem : item index
6333 * [I] bPartial : partially or entirely visible
6339 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6341 INT nScrollPosHeight
= 0;
6342 INT nScrollPosWidth
= 0;
6343 INT nHorzAdjust
= 0;
6344 INT nVertAdjust
= 0;
6347 RECT rcItem
, rcTemp
;
6349 rcItem
.left
= LVIR_BOUNDS
;
6350 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6352 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6354 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6356 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6357 if (infoPtr
->uView
== LV_VIEW_LIST
)
6358 nScrollPosWidth
= infoPtr
->nItemWidth
;
6359 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6360 nScrollPosWidth
= 1;
6362 if (rcItem
.left
< infoPtr
->rcList
.left
)
6365 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6370 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6374 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6376 /* scroll up/down, but not in LVS_LIST mode */
6377 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6378 nScrollPosHeight
= infoPtr
->nItemHeight
;
6379 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6380 nScrollPosHeight
= 1;
6382 if (rcItem
.top
< infoPtr
->rcList
.top
)
6385 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6390 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6394 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6396 if (nScrollPosWidth
)
6398 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6399 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6400 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6403 if (nScrollPosHeight
)
6405 INT diff
= nVertDiff
/ nScrollPosHeight
;
6406 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6407 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6415 * Searches for an item with specific characteristics.
6418 * [I] hwnd : window handle
6419 * [I] nStart : base item index
6420 * [I] lpFindInfo : item information to look for
6423 * SUCCESS : index of item
6426 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6427 const LVFINDINFOW
*lpFindInfo
)
6429 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6430 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6431 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6432 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6433 POINT Position
, Destination
;
6436 /* Search in virtual listviews should be done by application, not by
6437 listview control, so we just send LVN_ODFINDITEMW and return the result */
6438 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6442 nmlv
.iStart
= nStart
;
6443 nmlv
.lvfi
= *lpFindInfo
;
6444 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6447 if (!lpFindInfo
|| nItem
< 0) return -1;
6450 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6452 lvItem
.mask
|= LVIF_TEXT
;
6453 lvItem
.pszText
= szDispText
;
6454 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6457 if (lpFindInfo
->flags
& LVFI_WRAP
)
6460 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6461 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6466 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6467 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6468 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6469 switch(lpFindInfo
->vkDirection
)
6471 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6472 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6473 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6474 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6475 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6476 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6477 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6479 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6480 Destination
.x
= rcArea
.right
;
6481 Destination
.y
= rcArea
.bottom
;
6483 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6487 else Destination
.x
= Destination
.y
= 0;
6489 /* if LVFI_PARAM is specified, all other flags are ignored */
6490 if (lpFindInfo
->flags
& LVFI_PARAM
)
6492 lvItem
.mask
|= LVIF_PARAM
;
6494 lvItem
.mask
&= ~LVIF_TEXT
;
6497 nItem
= bNearest
? -1 : nStart
+ 1;
6500 for (; nItem
< nLast
; nItem
++)
6502 lvItem
.iItem
= nItem
;
6503 lvItem
.iSubItem
= 0;
6504 lvItem
.pszText
= szDispText
;
6505 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6507 if (lvItem
.mask
& LVIF_PARAM
)
6509 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6515 if (lvItem
.mask
& LVIF_TEXT
)
6517 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6519 WCHAR
*p
= wcsstr(lvItem
.pszText
, lpFindInfo
->psz
);
6520 if (!p
|| p
!= lvItem
.pszText
) continue;
6524 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6528 if (!bNearest
) return nItem
;
6530 /* This is very inefficient. To do a good job here,
6531 * we need a sorted array of (x,y) item positions */
6532 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6534 /* compute the distance^2 to the destination */
6535 xdist
= Destination
.x
- Position
.x
;
6536 ydist
= Destination
.y
- Position
.y
;
6537 dist
= xdist
* xdist
+ ydist
* ydist
;
6539 /* remember the distance, and item if it's closer */
6543 nNearestItem
= nItem
;
6550 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6555 return nNearestItem
;
6560 * Searches for an item with specific characteristics.
6563 * [I] hwnd : window handle
6564 * [I] nStart : base item index
6565 * [I] lpFindInfo : item information to look for
6568 * SUCCESS : index of item
6571 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6572 const LVFINDINFOA
*lpFindInfo
)
6578 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6579 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
| LVFI_SUBSTRING
))
6580 fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6581 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6582 textfreeT(strW
, FALSE
);
6588 * Retrieves column attributes.
6591 * [I] infoPtr : valid pointer to the listview structure
6592 * [I] nColumn : column index
6593 * [IO] lpColumn : column information
6594 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6595 * otherwise it is in fact a LPLVCOLUMNA
6601 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6603 COLUMN_INFO
*lpColumnInfo
;
6606 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6607 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6609 /* initialize memory */
6610 ZeroMemory(&hdi
, sizeof(hdi
));
6612 if (lpColumn
->mask
& LVCF_TEXT
)
6614 hdi
.mask
|= HDI_TEXT
;
6615 hdi
.pszText
= lpColumn
->pszText
;
6616 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6619 if (lpColumn
->mask
& LVCF_IMAGE
)
6620 hdi
.mask
|= HDI_IMAGE
;
6622 if (lpColumn
->mask
& LVCF_ORDER
)
6623 hdi
.mask
|= HDI_ORDER
;
6625 if (lpColumn
->mask
& LVCF_SUBITEM
)
6626 hdi
.mask
|= HDI_LPARAM
;
6628 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6630 if (lpColumn
->mask
& LVCF_FMT
)
6631 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6633 if (lpColumn
->mask
& LVCF_WIDTH
)
6634 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6636 if (lpColumn
->mask
& LVCF_IMAGE
)
6637 lpColumn
->iImage
= hdi
.iImage
;
6639 if (lpColumn
->mask
& LVCF_ORDER
)
6640 lpColumn
->iOrder
= hdi
.iOrder
;
6642 if (lpColumn
->mask
& LVCF_SUBITEM
)
6643 lpColumn
->iSubItem
= hdi
.lParam
;
6645 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6646 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6651 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6653 if (!infoPtr
->hwndHeader
) return FALSE
;
6654 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6659 * Retrieves the column width.
6662 * [I] infoPtr : valid pointer to the listview structure
6663 * [I] int : column index
6666 * SUCCESS : column width
6669 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6671 INT nColumnWidth
= 0;
6674 TRACE("nColumn=%d\n", nColumn
);
6676 /* we have a 'column' in LIST and REPORT mode only */
6677 switch(infoPtr
->uView
)
6680 nColumnWidth
= infoPtr
->nItemWidth
;
6682 case LV_VIEW_DETAILS
:
6683 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6684 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6685 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6687 hdItem
.mask
= HDI_WIDTH
;
6688 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6690 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6693 nColumnWidth
= hdItem
.cxy
;
6697 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6698 return nColumnWidth
;
6703 * In list or report display mode, retrieves the number of items that can fit
6704 * vertically in the visible area. In icon or small icon display mode,
6705 * retrieves the total number of visible items.
6708 * [I] infoPtr : valid pointer to the listview structure
6711 * Number of fully visible items.
6713 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6715 switch (infoPtr
->uView
)
6718 case LV_VIEW_SMALLICON
:
6719 return infoPtr
->nItemCount
;
6720 case LV_VIEW_DETAILS
:
6721 return LISTVIEW_GetCountPerColumn(infoPtr
);
6723 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6731 * Retrieves an image list handle.
6734 * [I] infoPtr : valid pointer to the listview structure
6735 * [I] nImageList : image list identifier
6738 * SUCCESS : image list handle
6741 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6745 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6746 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6747 case LVSIL_STATE
: return infoPtr
->himlState
;
6748 case LVSIL_GROUPHEADER
:
6749 FIXME("LVSIL_GROUPHEADER not supported\n");
6752 WARN("got unknown imagelist index - %d\n", nImageList
);
6757 /* LISTVIEW_GetISearchString */
6761 * Retrieves item attributes.
6764 * [I] hwnd : window handle
6765 * [IO] lpLVItem : item info
6766 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6767 * if FALSE, then lpLVItem is a LPLVITEMA.
6770 * This is the internal 'GetItem' interface -- it tries to
6771 * be smart and avoid text copies, if possible, by modifying
6772 * lpLVItem->pszText to point to the text string. Please note
6773 * that this is not always possible (e.g. OWNERDATA), so on
6774 * entry you *must* supply valid values for pszText, and cchTextMax.
6775 * The only difference to the documented interface is that upon
6776 * return, you should use *only* the lpLVItem->pszText, rather than
6777 * the buffer pointer you provided on input. Most code already does
6778 * that, so it's not a problem.
6779 * For the two cases when the text must be copied (that is,
6780 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6786 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6788 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6789 NMLVDISPINFOW dispInfo
;
6795 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6797 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6800 if (lpLVItem
->mask
== 0) return TRUE
;
6801 TRACE("mask=%x\n", lpLVItem
->mask
);
6803 /* make a local copy */
6804 isubitem
= lpLVItem
->iSubItem
;
6806 if (isubitem
&& (lpLVItem
->mask
& LVIF_STATE
))
6807 lpLVItem
->state
= 0;
6809 /* a quick optimization if all we're asked is the focus state
6810 * these queries are worth optimising since they are common,
6811 * and can be answered in constant time, without the heavy accesses */
6812 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6813 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6815 lpLVItem
->state
= 0;
6816 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
&& isubitem
== 0)
6817 lpLVItem
->state
|= LVIS_FOCUSED
;
6821 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6823 /* if the app stores all the data, handle it separately */
6824 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6826 dispInfo
.item
.state
= 0;
6828 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6829 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6830 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6832 UINT mask
= lpLVItem
->mask
;
6834 /* NOTE: copy only fields which we _know_ are initialized, some apps
6835 * depend on the uninitialized fields being 0 */
6836 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6837 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6838 dispInfo
.item
.iSubItem
= isubitem
;
6839 if (lpLVItem
->mask
& LVIF_TEXT
)
6841 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6843 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6846 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6847 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6850 if (lpLVItem
->mask
& LVIF_STATE
)
6851 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6852 /* could be zeroed on LVIF_NORECOMPUTE case */
6853 if (dispInfo
.item
.mask
)
6855 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6856 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6857 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6859 /* full size structure expected - _WIN32IE >= 0x560 */
6860 *lpLVItem
= dispInfo
.item
;
6862 else if (lpLVItem
->mask
& LVIF_INDENT
)
6864 /* indent member expected - _WIN32IE >= 0x300 */
6865 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6869 /* minimal structure expected */
6870 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6872 lpLVItem
->mask
= mask
;
6873 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6877 /* make sure lParam is zeroed out */
6878 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6880 /* callback marked pointer required here */
6881 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6882 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6884 /* we store only a little state, so if we're not asked, we're done */
6885 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6887 /* if focus is handled by us, report it */
6888 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6890 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6891 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6892 lpLVItem
->state
|= LVIS_FOCUSED
;
6895 /* and do the same for selection, if we handle it */
6896 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6898 lpLVItem
->state
&= ~LVIS_SELECTED
;
6899 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6900 lpLVItem
->state
|= LVIS_SELECTED
;
6906 /* find the item and subitem structures before we proceed */
6907 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6908 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6913 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6914 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6917 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6922 pItemHdr
= &lpItem
->hdr
;
6924 /* Do we need to query the state from the app? */
6925 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6927 dispInfo
.item
.mask
|= LVIF_STATE
;
6928 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6931 /* Do we need to enquire about the image? */
6932 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6933 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6935 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6936 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6939 /* Only items support indentation */
6940 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6943 dispInfo
.item
.mask
|= LVIF_INDENT
;
6944 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6947 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6948 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6949 !is_text(pItemHdr
->pszText
))
6951 dispInfo
.item
.mask
|= LVIF_TEXT
;
6952 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6953 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6954 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6955 *dispInfo
.item
.pszText
= '\0';
6958 /* If we don't have all the requested info, query the application */
6959 if (dispInfo
.item
.mask
)
6961 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6962 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6963 dispInfo
.item
.lParam
= lpItem
->lParam
;
6964 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6965 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6968 /* we should not store values for subitems */
6969 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6971 /* Now, handle the iImage field */
6972 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6974 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6975 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6976 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6978 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6980 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6981 lpLVItem
->iImage
= pItemHdr
->iImage
;
6983 lpLVItem
->iImage
= 0;
6986 /* The pszText field */
6987 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6989 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6990 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6992 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6994 else if (lpLVItem
->mask
& LVIF_TEXT
)
6996 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6997 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6998 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
7001 /* Next is the lParam field */
7002 if (dispInfo
.item
.mask
& LVIF_PARAM
)
7004 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
7005 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
7006 lpItem
->lParam
= dispInfo
.item
.lParam
;
7008 else if (lpLVItem
->mask
& LVIF_PARAM
)
7009 lpLVItem
->lParam
= lpItem
->lParam
;
7011 /* if this is a subitem, we're done */
7012 if (isubitem
) return TRUE
;
7014 /* ... the state field (this one is different due to uCallbackmask) */
7015 if (lpLVItem
->mask
& LVIF_STATE
)
7017 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
7018 if (dispInfo
.item
.mask
& LVIF_STATE
)
7020 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
7021 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
7023 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
7025 lpLVItem
->state
&= ~LVIS_FOCUSED
;
7026 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
7027 lpLVItem
->state
|= LVIS_FOCUSED
;
7029 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
7031 lpLVItem
->state
&= ~LVIS_SELECTED
;
7032 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
7033 lpLVItem
->state
|= LVIS_SELECTED
;
7037 /* and last, but not least, the indent field */
7038 if (dispInfo
.item
.mask
& LVIF_INDENT
)
7040 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
7041 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
7042 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
7044 else if (lpLVItem
->mask
& LVIF_INDENT
)
7046 lpLVItem
->iIndent
= lpItem
->iIndent
;
7054 * Retrieves item attributes.
7057 * [I] hwnd : window handle
7058 * [IO] lpLVItem : item info
7059 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
7060 * if FALSE, then lpLVItem is a LPLVITEMA.
7063 * This is the external 'GetItem' interface -- it properly copies
7064 * the text in the provided buffer.
7070 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
7075 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
7078 pszText
= lpLVItem
->pszText
;
7079 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
7080 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
7082 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
7083 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
7085 pszText
= LPSTR_TEXTCALLBACKW
;
7087 lpLVItem
->pszText
= pszText
;
7095 * Retrieves the position (upper-left) of the listview control item.
7096 * Note that for LVS_ICON style, the upper-left is that of the icon
7097 * and not the bounding box.
7100 * [I] infoPtr : valid pointer to the listview structure
7101 * [I] nItem : item index
7102 * [O] lpptPosition : coordinate information
7108 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
7112 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
7114 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7116 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7117 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
7119 if (infoPtr
->uView
== LV_VIEW_ICON
)
7121 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
7122 lpptPosition
->y
+= ICON_TOP_PADDING
;
7124 lpptPosition
->x
+= Origin
.x
;
7125 lpptPosition
->y
+= Origin
.y
;
7127 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
7134 * Retrieves the bounding rectangle for a listview control item.
7137 * [I] infoPtr : valid pointer to the listview structure
7138 * [I] nItem : item index
7139 * [IO] lprc : bounding rectangle coordinates
7140 * lprc->left specifies the portion of the item for which the bounding
7141 * rectangle will be retrieved.
7143 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
7144 * including the icon and label.
7147 * * Experiment shows that native control returns:
7148 * * width = min (48, length of text line)
7149 * * .left = position.x - (width - iconsize.cx)/2
7150 * * .right = .left + width
7151 * * height = #lines of text * ntmHeight + icon height + 8
7152 * * .top = position.y - 2
7153 * * .bottom = .top + height
7154 * * separation between items .y = itemSpacing.cy - height
7155 * * .x = itemSpacing.cx - width
7156 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7159 * * Experiment shows that native control returns:
7160 * * width = iconSize.cx + 16
7161 * * .left = position.x - (width - iconsize.cx)/2
7162 * * .right = .left + width
7163 * * height = iconSize.cy + 4
7164 * * .top = position.y - 2
7165 * * .bottom = .top + height
7166 * * separation between items .y = itemSpacing.cy - height
7167 * * .x = itemSpacing.cx - width
7168 * LVIR_LABEL Returns the bounding rectangle of the item text.
7171 * * Experiment shows that native control returns:
7172 * * width = text length
7173 * * .left = position.x - width/2
7174 * * .right = .left + width
7175 * * height = ntmH * linecount + 2
7176 * * .top = position.y + iconSize.cy + 6
7177 * * .bottom = .top + height
7178 * * separation between items .y = itemSpacing.cy - height
7179 * * .x = itemSpacing.cx - width
7180 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7181 * rectangles, but excludes columns in report view.
7188 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7189 * upon whether the window has the focus currently and on whether the item
7190 * is the one with the focus. Ensure that the control's record of which
7191 * item has the focus agrees with the items' records.
7193 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7195 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7196 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7197 POINT Position
, Origin
;
7201 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7203 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7205 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7206 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7208 /* Be smart and try to figure out the minimum we have to do */
7209 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7210 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7211 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7212 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7213 oversizedBox
= TRUE
;
7215 /* get what we need from the item before hand, so we make
7216 * only one request. This can speed up things, if data
7217 * is stored on the app side */
7219 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7220 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7221 lvItem
.iItem
= nItem
;
7222 lvItem
.iSubItem
= 0;
7223 lvItem
.pszText
= szDispText
;
7224 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7225 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7226 /* we got the state already up, simulate it here, to avoid a reget */
7227 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7229 lvItem
.mask
|= LVIF_STATE
;
7230 lvItem
.stateMask
= LVIS_FOCUSED
;
7231 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7234 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7235 lprc
->left
= LVIR_BOUNDS
;
7241 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7245 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7249 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7252 case LVIR_SELECTBOUNDS
:
7253 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7257 WARN("Unknown value: %d\n", lprc
->left
);
7261 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7263 if (mode
!= LVIR_BOUNDS
)
7264 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7265 Position
.y
+ Origin
.y
);
7267 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7270 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7272 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7279 * Retrieves the spacing between listview control items.
7282 * [I] infoPtr : valid pointer to the listview structure
7283 * [IO] lprc : rectangle to receive the output
7284 * on input, lprc->top = nSubItem
7285 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7287 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7288 * not only those of the first column.
7294 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7296 RECT rect
= { 0, 0, 0, 0 };
7300 if (!lprc
) return FALSE
;
7302 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7303 /* Subitem of '0' means item itself, and this works for all control view modes */
7305 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7307 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7309 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7310 /* this works for any item index, no matter if it exists or not */
7311 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7313 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7316 rect
.bottom
= infoPtr
->nItemHeight
;
7320 /* Native implementation is broken for this case and garbage is left for left and right fields,
7321 we zero them to get predictable output */
7322 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7323 lprc
->bottom
= infoPtr
->nItemHeight
;
7324 OffsetRect(lprc
, origin
.x
, y
);
7325 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7333 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7334 if (infoPtr
->himlSmall
)
7335 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7337 rect
.right
= rect
.left
;
7339 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7347 ERR("Unknown bounds=%d\n", lprc
->left
);
7351 OffsetRect(&rect
, origin
.x
, y
);
7353 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7360 * Retrieves the spacing between listview control items.
7363 * [I] infoPtr : valid pointer to the listview structure
7364 * [I] bSmall : flag for small or large icon
7367 * Horizontal + vertical spacing
7369 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7375 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7379 if (infoPtr
->uView
== LV_VIEW_ICON
)
7380 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7382 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7389 * Retrieves the state of a listview control item.
7392 * [I] infoPtr : valid pointer to the listview structure
7393 * [I] nItem : item index
7394 * [I] uMask : state mask
7397 * State specified by the mask.
7399 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7403 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7405 lvItem
.iItem
= nItem
;
7406 lvItem
.iSubItem
= 0;
7407 lvItem
.mask
= LVIF_STATE
;
7408 lvItem
.stateMask
= uMask
;
7409 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7411 return lvItem
.state
& uMask
;
7416 * Retrieves the text of a listview control item or subitem.
7419 * [I] hwnd : window handle
7420 * [I] nItem : item index
7421 * [IO] lpLVItem : item information
7422 * [I] isW : TRUE if lpLVItem is Unicode
7425 * SUCCESS : string length
7428 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7430 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7432 lpLVItem
->mask
= LVIF_TEXT
;
7433 lpLVItem
->iItem
= nItem
;
7434 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7436 return textlenT(lpLVItem
->pszText
, isW
);
7441 * Searches for an item based on properties + relationships.
7444 * [I] infoPtr : valid pointer to the listview structure
7445 * [I] nItem : item index
7446 * [I] uFlags : relationship flag
7449 * SUCCESS : item index
7452 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7455 LVFINDINFOW lvFindInfo
;
7456 INT nCountPerColumn
;
7462 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7463 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7465 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7467 if (uFlags
& LVNI_CUT
)
7470 if (uFlags
& LVNI_DROPHILITED
)
7471 uMask
|= LVIS_DROPHILITED
;
7473 if (uFlags
& LVNI_FOCUSED
)
7474 uMask
|= LVIS_FOCUSED
;
7476 if (uFlags
& LVNI_SELECTED
)
7477 uMask
|= LVIS_SELECTED
;
7479 /* if we're asked for the focused item, that's only one,
7480 * so it's worth optimizing */
7481 if (uFlags
& LVNI_FOCUSED
)
7483 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7484 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7487 if (uFlags
& LVNI_ABOVE
)
7489 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7494 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7501 /* Special case for autoarrange - move 'til the top of a list */
7502 if (is_autoarrange(infoPtr
))
7504 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7505 while (nItem
- nCountPerRow
>= 0)
7507 nItem
-= nCountPerRow
;
7508 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7514 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7515 lvFindInfo
.vkDirection
= VK_UP
;
7516 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7517 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7519 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7524 else if (uFlags
& LVNI_BELOW
)
7526 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7528 while (nItem
< infoPtr
->nItemCount
)
7531 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7538 /* Special case for autoarrange - move 'til the bottom of a list */
7539 if (is_autoarrange(infoPtr
))
7541 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7542 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7544 nItem
+= nCountPerRow
;
7545 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7551 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7552 lvFindInfo
.vkDirection
= VK_DOWN
;
7553 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7554 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7556 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7561 else if (uFlags
& LVNI_TOLEFT
)
7563 if (infoPtr
->uView
== LV_VIEW_LIST
)
7565 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7566 while (nItem
- nCountPerColumn
>= 0)
7568 nItem
-= nCountPerColumn
;
7569 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7573 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7576 /* Special case for autoarrange - move 'til the beginning of a row */
7577 if (is_autoarrange(infoPtr
))
7579 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7580 while (nItem
% nCountPerRow
> 0)
7583 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7589 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7590 lvFindInfo
.vkDirection
= VK_LEFT
;
7591 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7592 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7594 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7599 else if (uFlags
& LVNI_TORIGHT
)
7601 if (infoPtr
->uView
== LV_VIEW_LIST
)
7603 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7604 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7606 nItem
+= nCountPerColumn
;
7607 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7611 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7614 /* Special case for autoarrange - move 'til the end of a row */
7615 if (is_autoarrange(infoPtr
))
7617 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7618 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7621 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7627 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7628 lvFindInfo
.vkDirection
= VK_RIGHT
;
7629 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7630 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7632 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7641 /* search by index */
7642 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7644 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7652 /* LISTVIEW_GetNumberOfWorkAreas */
7656 * Retrieves the origin coordinates when in icon or small icon display mode.
7659 * [I] infoPtr : valid pointer to the listview structure
7660 * [O] lpptOrigin : coordinate information
7665 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7667 INT nHorzPos
= 0, nVertPos
= 0;
7668 SCROLLINFO scrollInfo
;
7670 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7671 scrollInfo
.fMask
= SIF_POS
;
7673 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7674 nHorzPos
= scrollInfo
.nPos
;
7675 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7676 nVertPos
= scrollInfo
.nPos
;
7678 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7680 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7681 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7682 if (infoPtr
->uView
== LV_VIEW_LIST
)
7683 nHorzPos
*= infoPtr
->nItemWidth
;
7684 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7685 nVertPos
*= infoPtr
->nItemHeight
;
7687 lpptOrigin
->x
-= nHorzPos
;
7688 lpptOrigin
->y
-= nVertPos
;
7690 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7695 * Retrieves the width of a string.
7698 * [I] hwnd : window handle
7699 * [I] lpszText : text string to process
7700 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7703 * SUCCESS : string width (in pixels)
7706 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7711 if (is_text(lpszText
))
7713 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7714 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7715 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7718 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7720 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7721 SelectObject(hdc
, hOldFont
);
7722 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7724 return stringSize
.cx
;
7729 * Determines which listview item is located at the specified position.
7732 * [I] infoPtr : valid pointer to the listview structure
7733 * [IO] lpht : hit test information
7734 * [I] subitem : fill out iSubItem.
7735 * [I] select : return the index only if the hit selects the item
7738 * (mm 20001022): We must not allow iSubItem to be touched, for
7739 * an app might pass only a structure with space up to iItem!
7740 * (MS Office 97 does that for instance in the file open dialog)
7743 * SUCCESS : item index
7746 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7748 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7749 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7750 POINT Origin
, Position
, opt
;
7756 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7760 if (subitem
) lpht
->iSubItem
= 0;
7762 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7764 /* set whole list relation flags */
7765 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7767 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7768 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7769 lpht
->flags
|= LVHT_TOLEFT
;
7771 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7772 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7776 if (infoPtr
->rcList
.bottom
< opt
.y
)
7777 lpht
->flags
|= LVHT_BELOW
;
7781 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7782 lpht
->flags
|= LVHT_TOLEFT
;
7783 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7784 lpht
->flags
|= LVHT_TORIGHT
;
7786 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7787 lpht
->flags
|= LVHT_ABOVE
;
7788 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7789 lpht
->flags
|= LVHT_BELOW
;
7792 /* even if item is invalid try to find subitem */
7793 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7798 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7800 lpht
->iSubItem
= -1;
7801 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7803 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7805 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7811 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7813 /* if we're outside horizontal columns bounds there's nothing to test further */
7814 if (lpht
->iSubItem
== -1)
7817 lpht
->flags
= LVHT_NOWHERE
;
7822 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7823 if (lpht
->flags
) return -1;
7825 lpht
->flags
|= LVHT_NOWHERE
;
7827 /* first deal with the large items */
7828 rcSearch
.left
= lpht
->pt
.x
;
7829 rcSearch
.top
= lpht
->pt
.y
;
7830 rcSearch
.right
= rcSearch
.left
+ 1;
7831 rcSearch
.bottom
= rcSearch
.top
+ 1;
7833 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7834 iterator_next(&i
); /* go to first item in the sequence */
7836 iterator_destroy(&i
);
7838 TRACE("lpht->iItem=%d\n", iItem
);
7839 if (iItem
== -1) return -1;
7841 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7842 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7843 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7844 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7845 lvItem
.iItem
= iItem
;
7846 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7847 lvItem
.pszText
= szDispText
;
7848 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7849 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7850 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7852 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7853 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7854 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7856 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7857 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7859 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7861 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7864 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7865 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7869 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7870 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7872 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7873 if (!PtInRect(&rcBounds
, opt
)) return -1;
7875 /* That's a special case - row rectangle is used as item rectangle and
7876 returned flags contain all item parts. */
7877 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7879 if (PtInRect(&rcIcon
, opt
))
7880 lpht
->flags
|= LVHT_ONITEMICON
;
7881 else if (PtInRect(&rcLabel
, opt
))
7882 lpht
->flags
|= LVHT_ONITEMLABEL
;
7883 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7884 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7885 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7887 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7889 if (lpht
->flags
& LVHT_ONITEM
)
7890 lpht
->flags
&= ~LVHT_NOWHERE
;
7891 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7893 if (select
&& !is_fullrow
)
7895 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7897 /* get main item bounds */
7898 lvItem
.iSubItem
= 0;
7899 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7900 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7901 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7903 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7905 return lpht
->iItem
= iItem
;
7910 * Inserts a new item in the listview control.
7913 * [I] infoPtr : valid pointer to the listview structure
7914 * [I] lpLVItem : item information
7915 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7918 * SUCCESS : new item index
7921 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7928 BOOL is_sorted
, has_changed
;
7930 HWND hwndSelf
= infoPtr
->hwndSelf
;
7932 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7934 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7936 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7937 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7939 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7941 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7943 /* insert item in listview control data structure */
7944 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7945 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7947 /* link with id struct */
7948 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7950 lpID
->item
= hdpaSubItems
;
7951 lpID
->id
= get_next_itemid(infoPtr
);
7952 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7954 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7955 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7957 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7959 /* calculate new item index */
7967 textW
= textdupTtoW(lpLVItem
->pszText
, isW
);
7969 while (i
< infoPtr
->nItemCount
)
7971 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7972 item_s
= DPA_GetPtr(hItem
, 0);
7974 cmpv
= textcmpWT(item_s
->hdr
.pszText
, textW
, TRUE
);
7975 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7977 if (cmpv
>= 0) break;
7981 textfreeT(textW
, isW
);
7986 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7988 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7989 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7990 if (nItem
== -1) goto fail
;
7991 infoPtr
->nItemCount
++;
7993 /* shift indices first so they don't get tangled */
7994 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7996 /* set the item attributes */
7997 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7999 /* full size structure expected - _WIN32IE >= 0x560 */
8002 else if (lpLVItem
->mask
& LVIF_INDENT
)
8004 /* indent member expected - _WIN32IE >= 0x300 */
8005 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
8009 /* minimal structure expected */
8010 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
8013 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8015 if (item
.mask
& LVIF_STATE
)
8017 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
8018 item
.state
&= ~LVIS_STATEIMAGEMASK
;
8019 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
8023 item
.mask
|= LVIF_STATE
;
8024 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8025 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8029 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
8031 /* make room for the position, if we are in the right mode */
8032 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
8034 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
8036 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
8038 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
8043 /* send LVN_INSERTITEM notification */
8044 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
8046 nmlv
.lParam
= lpItem
->lParam
;
8047 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
8048 if (!IsWindow(hwndSelf
))
8051 /* align items (set position of each item) */
8052 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
8057 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
8058 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
, nItem
);
8060 LISTVIEW_NextIconPosTop(infoPtr
, &pt
, nItem
);
8062 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
8063 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
8065 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
8068 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
8071 /* now is the invalidation fun */
8072 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
8076 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
8077 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
8078 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
8079 infoPtr
->nItemCount
--;
8081 DPA_DeletePtr(hdpaSubItems
, 0);
8082 DPA_Destroy (hdpaSubItems
);
8089 * Checks item visibility.
8092 * [I] infoPtr : valid pointer to the listview structure
8093 * [I] nFirst : item index to check for
8096 * Item visible : TRUE
8097 * Item invisible or failure : FALSE
8099 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
8101 POINT Origin
, Position
;
8106 TRACE("nItem=%d\n", nItem
);
8108 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
8110 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8111 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
8112 rcItem
.left
= Position
.x
+ Origin
.x
;
8113 rcItem
.top
= Position
.y
+ Origin
.y
;
8114 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
8115 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
8117 hdc
= GetDC(infoPtr
->hwndSelf
);
8118 if (!hdc
) return FALSE
;
8119 ret
= RectVisible(hdc
, &rcItem
);
8120 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8127 * Redraws a range of items.
8130 * [I] infoPtr : valid pointer to the listview structure
8131 * [I] nFirst : first item
8132 * [I] nLast : last item
8138 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
8142 for (i
= max(nFirst
, 0); i
<= min(nLast
, infoPtr
->nItemCount
- 1); i
++)
8143 LISTVIEW_InvalidateItem(infoPtr
, i
);
8150 * Scroll the content of a listview.
8153 * [I] infoPtr : valid pointer to the listview structure
8154 * [I] dx : horizontal scroll amount in pixels
8155 * [I] dy : vertical scroll amount in pixels
8162 * If the control is in report view (LV_VIEW_DETAILS) the control can
8163 * be scrolled only in line increments. "dy" will be rounded to the
8164 * nearest number of pixels that are a whole line. Ex: if line height
8165 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
8166 * is passed, then the scroll will be 0. (per MSDN 7/2002)
8168 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8170 switch(infoPtr
->uView
) {
8171 case LV_VIEW_DETAILS
:
8172 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
8173 dy
/= infoPtr
->nItemHeight
;
8176 if (dy
!= 0) return FALSE
;
8182 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8183 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8190 * Sets the background color.
8193 * [I] infoPtr : valid pointer to the listview structure
8194 * [I] color : background color
8200 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8202 TRACE("(color=%x)\n", color
);
8205 infoPtr
->bDefaultBkColor
= FALSE
;
8207 if(infoPtr
->clrBk
!= color
) {
8208 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8209 infoPtr
->clrBk
= color
;
8210 if (color
== CLR_NONE
)
8211 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8214 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8215 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8222 /* LISTVIEW_SetBkImage */
8224 /*** Helper for {Insert,Set}ColumnT *only* */
8225 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8226 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8228 if (lpColumn
->mask
& LVCF_FMT
)
8230 /* format member is valid */
8231 lphdi
->mask
|= HDI_FORMAT
;
8233 /* set text alignment (leftmost column must be left-aligned) */
8234 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8235 lphdi
->fmt
|= HDF_LEFT
;
8236 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8237 lphdi
->fmt
|= HDF_RIGHT
;
8238 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8239 lphdi
->fmt
|= HDF_CENTER
;
8241 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8242 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8244 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8246 lphdi
->fmt
|= HDF_IMAGE
;
8247 lphdi
->iImage
= I_IMAGECALLBACK
;
8250 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8251 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8254 if (lpColumn
->mask
& LVCF_WIDTH
)
8256 lphdi
->mask
|= HDI_WIDTH
;
8257 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8259 /* make it fill the remainder of the controls width */
8263 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8265 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8266 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8269 /* retrieve the layout of the header */
8270 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8271 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8273 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8276 lphdi
->cxy
= lpColumn
->cx
;
8279 if (lpColumn
->mask
& LVCF_TEXT
)
8281 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8282 lphdi
->fmt
|= HDF_STRING
;
8283 lphdi
->pszText
= lpColumn
->pszText
;
8284 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8287 if (lpColumn
->mask
& LVCF_IMAGE
)
8289 lphdi
->mask
|= HDI_IMAGE
;
8290 lphdi
->iImage
= lpColumn
->iImage
;
8293 if (lpColumn
->mask
& LVCF_ORDER
)
8295 lphdi
->mask
|= HDI_ORDER
;
8296 lphdi
->iOrder
= lpColumn
->iOrder
;
8303 * Inserts a new column.
8306 * [I] infoPtr : valid pointer to the listview structure
8307 * [I] nColumn : column index
8308 * [I] lpColumn : column information
8309 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8312 * SUCCESS : new column index
8315 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8316 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8318 COLUMN_INFO
*lpColumnInfo
;
8322 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8324 if (!lpColumn
|| nColumn
< 0) return -1;
8325 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8327 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8328 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8331 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8332 * (can be seen in SPY) otherwise column never gets added.
8334 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8335 hdi
.mask
|= HDI_WIDTH
;
8340 * when the iSubItem is available Windows copies it to the header lParam. It seems
8341 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8343 if (lpColumn
->mask
& LVCF_SUBITEM
)
8345 hdi
.mask
|= HDI_LPARAM
;
8346 hdi
.lParam
= lpColumn
->iSubItem
;
8349 /* create header if not present */
8350 LISTVIEW_CreateHeader(infoPtr
);
8351 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8352 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8354 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8357 /* insert item in header control */
8358 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8359 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8360 nColumn
, (LPARAM
)&hdi
);
8361 if (nNewColumn
== -1) return -1;
8362 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8364 /* create our own column info */
8365 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8366 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8368 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8369 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8370 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8373 /* now we have to actually adjust the data */
8374 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8376 SUBITEM_INFO
*lpSubItem
;
8382 item
.iSubItem
= nNewColumn
;
8383 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8384 item
.iImage
= I_IMAGECALLBACK
;
8385 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8387 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8389 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8390 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8392 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8393 if (lpSubItem
->iSubItem
>= nNewColumn
)
8394 lpSubItem
->iSubItem
++;
8397 /* add new subitem for each item */
8399 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8403 /* make space for the new column */
8404 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8405 LISTVIEW_UpdateItemSize(infoPtr
);
8410 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8413 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8421 * Sets the attributes of a header item.
8424 * [I] infoPtr : valid pointer to the listview structure
8425 * [I] nColumn : column index
8426 * [I] lpColumn : column attributes
8427 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8433 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8434 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8436 HDITEMW hdi
, hdiget
;
8439 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8441 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8443 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8444 if (lpColumn
->mask
& LVCF_FMT
)
8446 hdi
.mask
|= HDI_FORMAT
;
8447 hdiget
.mask
= HDI_FORMAT
;
8448 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8449 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8451 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8453 /* set header item attributes */
8454 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8455 if (!bResult
) return FALSE
;
8457 if (lpColumn
->mask
& LVCF_FMT
)
8459 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8460 INT oldFmt
= lpColumnInfo
->fmt
;
8462 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8463 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8465 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8469 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8470 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8477 * Sets the column order array
8480 * [I] infoPtr : valid pointer to the listview structure
8481 * [I] iCount : number of elements in column order array
8482 * [I] lpiArray : pointer to column order array
8488 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8490 if (!infoPtr
->hwndHeader
) return FALSE
;
8491 infoPtr
->colRectsDirty
= TRUE
;
8492 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8497 * Sets the width of a column
8500 * [I] infoPtr : valid pointer to the listview structure
8501 * [I] nColumn : column index
8502 * [I] cx : column width
8508 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8510 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8514 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8516 /* set column width only if in report or list mode */
8517 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8519 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8520 with _USEHEADER being the lowest */
8521 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8522 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8524 /* resize all columns if in LV_VIEW_LIST mode */
8525 if(infoPtr
->uView
== LV_VIEW_LIST
)
8527 infoPtr
->nItemWidth
= cx
;
8528 LISTVIEW_InvalidateList(infoPtr
);
8532 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8534 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8539 lvItem
.mask
= LVIF_TEXT
;
8541 lvItem
.iSubItem
= nColumn
;
8542 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8543 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8545 lvItem
.pszText
= szDispText
;
8546 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8547 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8548 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8550 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8551 max_cx
+= infoPtr
->iconSize
.cx
;
8552 max_cx
+= TRAILING_LABEL_PADDING
;
8553 if (nColumn
== 0 && (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
))
8554 max_cx
+= GetSystemMetrics(SM_CXSMICON
);
8557 /* autosize based on listview items width */
8558 if(cx
== LVSCW_AUTOSIZE
)
8560 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8562 /* if iCol is the last column make it fill the remainder of the controls width */
8563 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8568 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8569 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8571 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8575 /* Despite what the MS docs say, if this is not the last
8576 column, then MS resizes the column to the width of the
8577 largest text string in the column, including headers
8578 and items. This is different from LVSCW_AUTOSIZE in that
8579 LVSCW_AUTOSIZE ignores the header string length. */
8582 /* retrieve header text */
8583 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8584 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8585 hdi
.pszText
= szDispText
;
8586 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8588 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8589 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8590 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8591 INT bitmap_margin
= 0;
8594 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8595 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8597 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8598 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8600 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8602 INT icon_cx
, icon_cy
;
8604 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8605 cx
+= icon_cx
+ 2*bitmap_margin
;
8607 else if (hdi
.fmt
& HDF_BITMAP
)
8611 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8612 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8615 SelectObject(hdc
, old_font
);
8616 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8618 cx
= max (cx
, max_cx
);
8622 if (cx
< 0) return FALSE
;
8624 /* call header to update the column change */
8625 hdi
.mask
= HDI_WIDTH
;
8626 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8627 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8628 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8632 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8635 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8638 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8640 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8641 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8644 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8645 ILC_COLOR
| ILC_MASK
, 2, 2);
8646 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8647 hdc
= CreateCompatibleDC(hdc_wnd
);
8648 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8649 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8650 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8652 SetRect(&rc
, 0, 0, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8653 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8654 FillRect(hdc
, &rc
, hbr_white
);
8655 InflateRect(&rc
, -2, -2);
8656 FillRect(hdc
, &rc
, hbr_black
);
8658 SelectObject(hdc
, hbm_im
);
8659 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8660 SelectObject(hdc
, hbm_orig
);
8661 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8663 SelectObject(hdc
, hbm_im
);
8664 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8665 SelectObject(hdc
, hbm_orig
);
8666 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8668 DeleteObject(hbm_mask
);
8669 DeleteObject(hbm_im
);
8677 * Sets the extended listview style.
8680 * [I] infoPtr : valid pointer to the listview structure
8682 * [I] dwStyle : style
8685 * SUCCESS : previous style
8688 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8690 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8692 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8696 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8698 infoPtr
->dwLvExStyle
= ex_style
;
8700 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8702 HIMAGELIST himl
= 0;
8703 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8706 item
.mask
= LVIF_STATE
;
8707 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8708 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8709 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8711 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8712 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8713 ImageList_Destroy(infoPtr
->himlState
);
8715 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8716 /* checkbox list replaces previous custom list or... */
8717 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8718 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8719 /* ...previous was checkbox list */
8720 (old_ex_style
& LVS_EX_CHECKBOXES
))
8721 ImageList_Destroy(himl
);
8724 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8728 /* if not already created */
8729 LISTVIEW_CreateHeader(infoPtr
);
8731 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8732 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8733 style
|= HDS_DRAGDROP
;
8735 style
&= ~HDS_DRAGDROP
;
8736 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8739 /* GRIDLINES adds decoration at top so changes sizes */
8740 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8742 LISTVIEW_CreateHeader(infoPtr
);
8743 LISTVIEW_UpdateSize(infoPtr
);
8746 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8748 LISTVIEW_CreateHeader(infoPtr
);
8751 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8753 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8754 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8757 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8759 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8760 LISTVIEW_CreateHeader(infoPtr
);
8762 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8763 LISTVIEW_UpdateSize(infoPtr
);
8764 LISTVIEW_UpdateScroll(infoPtr
);
8768 if ((infoPtr
->dwLvExStyle
& LVS_EX_SNAPTOGRID
) > (old_ex_style
& LVS_EX_SNAPTOGRID
))
8770 LISTVIEW_Arrange(infoPtr
, LVA_SNAPTOGRID
);
8774 LISTVIEW_InvalidateList(infoPtr
);
8775 return old_ex_style
;
8780 * Sets the new hot cursor used during hot tracking and hover selection.
8783 * [I] infoPtr : valid pointer to the listview structure
8784 * [I] hCursor : the new hot cursor handle
8787 * Returns the previous hot cursor
8789 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8791 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8793 infoPtr
->hHotCursor
= hCursor
;
8801 * Sets the hot item index.
8804 * [I] infoPtr : valid pointer to the listview structure
8805 * [I] iIndex : index
8808 * SUCCESS : previous hot item index
8809 * FAILURE : -1 (no hot item)
8811 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8813 INT iOldIndex
= infoPtr
->nHotItem
;
8815 infoPtr
->nHotItem
= iIndex
;
8823 * Sets the amount of time the cursor must hover over an item before it is selected.
8826 * [I] infoPtr : valid pointer to the listview structure
8827 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8830 * Returns the previous hover time
8832 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8834 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8836 infoPtr
->dwHoverTime
= dwHoverTime
;
8838 return oldHoverTime
;
8843 * Sets spacing for icons of LVS_ICON style.
8846 * [I] infoPtr : valid pointer to the listview structure
8847 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8848 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8851 * MAKELONG(oldcx, oldcy)
8853 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8855 INT iconWidth
= 0, iconHeight
= 0;
8856 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8858 TRACE("requested=(%d,%d)\n", cx
, cy
);
8860 /* set to defaults, if instructed to */
8861 if (cx
== -1 && cy
== -1)
8863 infoPtr
->autoSpacing
= TRUE
;
8864 if (infoPtr
->himlNormal
)
8865 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8866 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8867 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8870 infoPtr
->autoSpacing
= FALSE
;
8872 /* if 0 then keep width */
8874 infoPtr
->iconSpacing
.cx
= cx
;
8876 /* if 0 then keep height */
8878 infoPtr
->iconSpacing
.cy
= cy
;
8880 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8881 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8882 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8883 infoPtr
->ntmHeight
);
8885 /* these depend on the iconSpacing */
8886 LISTVIEW_UpdateItemSize(infoPtr
);
8891 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL is_small
)
8895 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8902 size
->cx
= GetSystemMetrics(is_small
? SM_CXSMICON
: SM_CXICON
);
8903 size
->cy
= GetSystemMetrics(is_small
? SM_CYSMICON
: SM_CYICON
);
8912 * [I] infoPtr : valid pointer to the listview structure
8913 * [I] nType : image list type
8914 * [I] himl : image list handle
8917 * SUCCESS : old image list
8920 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8922 INT oldHeight
= infoPtr
->nItemHeight
;
8923 HIMAGELIST himlOld
= 0;
8925 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8930 himlOld
= infoPtr
->himlNormal
;
8931 infoPtr
->himlNormal
= himl
;
8932 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8933 if (infoPtr
->autoSpacing
)
8934 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8938 himlOld
= infoPtr
->himlSmall
;
8939 infoPtr
->himlSmall
= himl
;
8940 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8941 if (infoPtr
->hwndHeader
)
8942 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8946 himlOld
= infoPtr
->himlState
;
8947 infoPtr
->himlState
= himl
;
8948 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8949 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8953 ERR("Unknown icon type=%d\n", nType
);
8957 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8958 if (infoPtr
->nItemHeight
!= oldHeight
)
8959 LISTVIEW_UpdateScroll(infoPtr
);
8966 * Preallocates memory (does *not* set the actual count of items !)
8969 * [I] infoPtr : valid pointer to the listview structure
8970 * [I] nItems : item count (projected number of items to allocate)
8971 * [I] dwFlags : update flags
8977 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8979 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8981 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8983 INT nOldCount
= infoPtr
->nItemCount
;
8984 infoPtr
->nItemCount
= nItems
;
8986 if (nItems
< nOldCount
)
8988 RANGE range
= { nItems
, nOldCount
};
8989 ranges_del(infoPtr
->selectionRanges
, range
);
8990 if (infoPtr
->nFocusedItem
>= nItems
)
8992 LISTVIEW_SetItemFocus(infoPtr
, -1);
8993 infoPtr
->nFocusedItem
= -1;
8994 SetRectEmpty(&infoPtr
->rcFocus
);
8998 LISTVIEW_UpdateScroll(infoPtr
);
9000 /* the flags are valid only in ownerdata report and list modes */
9001 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
9003 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
9004 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
9006 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
9007 LISTVIEW_InvalidateList(infoPtr
);
9014 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
9015 nFrom
= min(nOldCount
, nItems
);
9016 nTo
= max(nOldCount
, nItems
);
9018 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9020 SetRect(&rcErase
, 0, nFrom
* infoPtr
->nItemHeight
, infoPtr
->nItemWidth
,
9021 nTo
* infoPtr
->nItemHeight
);
9022 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
9023 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
9024 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
9026 else /* LV_VIEW_LIST */
9028 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
9030 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
9031 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
9032 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
9033 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
9034 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
9035 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
9036 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
9038 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
9040 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
9041 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
9042 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
9043 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
9044 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
9050 /* According to MSDN for non-LVS_OWNERDATA this is just
9051 * a performance issue. The control allocates its internal
9052 * data structures for the number of items specified. It
9053 * cuts down on the number of memory allocations. Therefore
9054 * we will just issue a WARN here
9056 WARN("for non-ownerdata performance option not implemented.\n");
9064 * Sets the position of an item.
9067 * [I] infoPtr : valid pointer to the listview structure
9068 * [I] nItem : item index
9069 * [I] pt : coordinate
9075 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
9079 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
9081 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
9082 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
9085 /* FIXME: This should really call snap to grid if auto-arrange is enabled
9086 and limit the size of the grid to nItemCount elements */
9087 if (is_autoarrange(infoPtr
)) return FALSE
;
9091 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
9093 /* This point value seems to be an undocumented feature.
9094 * The best guess is that it means either at the origin,
9095 * or at true beginning of the list. I will assume the origin. */
9096 if ((Pt
.x
== -1) && (Pt
.y
== -1))
9099 if (infoPtr
->uView
== LV_VIEW_ICON
)
9101 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
9102 Pt
.y
-= ICON_TOP_PADDING
;
9108 if (infoPtr
->dwLvExStyle
& LVS_EX_SNAPTOGRID
)
9110 Pt
.x
= max(0, Pt
.x
+ (infoPtr
->nItemWidth
>> 1) - (Pt
.x
+ (infoPtr
->nItemWidth
>> 1)) % infoPtr
->nItemWidth
);
9111 Pt
.y
= max(0, Pt
.y
+ (infoPtr
->nItemHeight
>> 1) - (Pt
.y
+ (infoPtr
->nItemHeight
>> 1)) % infoPtr
->nItemHeight
);
9115 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
9120 * Sets the state of one or many items.
9123 * [I] infoPtr : valid pointer to the listview structure
9124 * [I] nItem : item index
9125 * [I] item : item or subitem info
9131 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
9136 if (!item
) return FALSE
;
9138 lvItem
.iItem
= nItem
;
9139 lvItem
.iSubItem
= 0;
9140 lvItem
.mask
= LVIF_STATE
;
9141 lvItem
.state
= item
->state
;
9142 lvItem
.stateMask
= item
->stateMask
;
9143 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
9150 /* special case optimization for recurring attempt to deselect all */
9151 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
9154 /* select all isn't allowed in LVS_SINGLESEL */
9155 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
9158 /* focus all isn't allowed */
9159 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
9161 old_mask
= infoPtr
->notify_mask
& NOTIFY_MASK_ITEM_CHANGE
;
9162 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9164 infoPtr
->notify_mask
&= ~NOTIFY_MASK_ITEM_CHANGE
;
9165 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
9166 oldstate
|= LVIS_SELECTED
;
9167 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
9170 /* apply to all items */
9171 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
9172 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
9174 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9178 infoPtr
->notify_mask
|= old_mask
;
9182 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
9183 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
9184 nmlv
.uChanged
= LVIF_STATE
;
9185 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
9188 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
9192 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9199 * Sets the text of an item or subitem.
9202 * [I] hwnd : window handle
9203 * [I] nItem : item index
9204 * [I] lpLVItem : item or subitem info
9205 * [I] isW : TRUE if input is Unicode
9211 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9215 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9216 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9218 lvItem
.iItem
= nItem
;
9219 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9220 lvItem
.mask
= LVIF_TEXT
;
9221 lvItem
.pszText
= lpLVItem
->pszText
;
9222 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9224 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9226 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9231 * Set item index that marks the start of a multiple selection.
9234 * [I] infoPtr : valid pointer to the listview structure
9235 * [I] nIndex : index
9238 * Index number or -1 if there is no selection mark.
9240 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9242 INT nOldIndex
= infoPtr
->nSelectionMark
;
9244 TRACE("(nIndex=%d)\n", nIndex
);
9246 if (nIndex
>= -1 && nIndex
< infoPtr
->nItemCount
)
9247 infoPtr
->nSelectionMark
= nIndex
;
9254 * Sets the text background color.
9257 * [I] infoPtr : valid pointer to the listview structure
9258 * [I] color : text background color
9264 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9266 TRACE("(color=%x)\n", color
);
9268 infoPtr
->clrTextBk
= color
;
9274 * Sets the text foreground color.
9277 * [I] infoPtr : valid pointer to the listview structure
9278 * [I] color : text color
9284 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9286 TRACE("(color=%x)\n", color
);
9288 infoPtr
->clrText
= color
;
9294 * Sets new ToolTip window to ListView control.
9297 * [I] infoPtr : valid pointer to the listview structure
9298 * [I] hwndNewToolTip : handle to new ToolTip
9303 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9305 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9306 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9307 return hwndOldToolTip
;
9312 * sets the Unicode character format flag for the control
9314 * [I] infoPtr :valid pointer to the listview structure
9315 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9318 * Old Unicode Format
9320 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9322 SHORT rc
= infoPtr
->notifyFormat
;
9323 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9324 return rc
== NFR_UNICODE
;
9329 * sets the control view mode
9331 * [I] infoPtr :valid pointer to the listview structure
9332 * [I] nView :new view mode value
9338 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9342 if (infoPtr
->uView
== nView
) return 1;
9344 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9345 if (nView
== LV_VIEW_TILE
)
9347 FIXME("View LV_VIEW_TILE unimplemented\n");
9351 infoPtr
->uView
= nView
;
9353 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9354 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9356 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9357 SetRectEmpty(&infoPtr
->rcFocus
);
9359 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9360 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9365 case LV_VIEW_SMALLICON
:
9366 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9368 case LV_VIEW_DETAILS
:
9373 LISTVIEW_CreateHeader( infoPtr
);
9375 hl
.prc
= &infoPtr
->rcList
;
9377 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9378 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9379 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9386 LISTVIEW_UpdateItemSize(infoPtr
);
9387 LISTVIEW_UpdateSize(infoPtr
);
9388 LISTVIEW_UpdateScroll(infoPtr
);
9389 LISTVIEW_InvalidateList(infoPtr
);
9391 TRACE("nView=%d\n", nView
);
9396 /* LISTVIEW_SetWorkAreas */
9400 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9403 * [I] first : pointer to first ITEM_INFO to compare
9404 * [I] second : pointer to second ITEM_INFO to compare
9405 * [I] lParam : HWND of control
9408 * if first comes before second : negative
9409 * if first comes after second : positive
9410 * if first and second are equivalent : zero
9412 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9414 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9415 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9416 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9418 /* Forward the call to the client defined callback */
9419 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9424 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9427 * [I] first : pointer to first ITEM_INFO to compare
9428 * [I] second : pointer to second ITEM_INFO to compare
9429 * [I] lParam : HWND of control
9432 * if first comes before second : negative
9433 * if first comes after second : positive
9434 * if first and second are equivalent : zero
9436 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9438 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9439 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9440 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9442 /* Forward the call to the client defined callback */
9443 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9448 * Sorts the listview items.
9451 * [I] infoPtr : valid pointer to the listview structure
9452 * [I] pfnCompare : application-defined value
9453 * [I] lParamSort : pointer to comparison callback
9454 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9460 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9461 LPARAM lParamSort
, BOOL IsEx
)
9465 LPVOID selectionMarkItem
= NULL
;
9466 LPVOID focusedItem
= NULL
;
9469 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9471 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9473 if (!pfnCompare
) return FALSE
;
9474 if (!infoPtr
->hdpaItems
) return FALSE
;
9476 /* if there are 0 or 1 items, there is no need to sort */
9477 if (infoPtr
->nItemCount
< 2) return TRUE
;
9479 /* clear selection */
9480 ranges_clear(infoPtr
->selectionRanges
);
9482 /* save selection mark and focused item */
9483 if (infoPtr
->nSelectionMark
>= 0)
9484 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9485 if (infoPtr
->nFocusedItem
>= 0)
9486 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9488 infoPtr
->pfnCompare
= pfnCompare
;
9489 infoPtr
->lParamSort
= lParamSort
;
9491 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9493 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9495 /* restore selection ranges */
9496 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9498 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9499 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9501 if (lpItem
->state
& LVIS_SELECTED
)
9502 ranges_additem(infoPtr
->selectionRanges
, i
);
9504 /* restore selection mark and focused item */
9505 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9506 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9508 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9510 /* refresh the display */
9511 LISTVIEW_InvalidateList(infoPtr
);
9517 * Update theme handle after a theme change.
9520 * [I] infoPtr : valid pointer to the listview structure
9524 * FAILURE : something else
9526 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9528 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9529 CloseThemeData(theme
);
9530 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9536 * Updates an items or rearranges the listview control.
9539 * [I] infoPtr : valid pointer to the listview structure
9540 * [I] nItem : item index
9546 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9548 TRACE("(nItem=%d)\n", nItem
);
9550 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9552 /* rearrange with default alignment style */
9553 if (is_autoarrange(infoPtr
))
9554 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9556 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9563 * Draw the track line at the place defined in the infoPtr structure.
9564 * The line is drawn with a XOR pen so drawing the line for the second time
9565 * in the same place erases the line.
9568 * [I] infoPtr : valid pointer to the listview structure
9574 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9578 if (infoPtr
->xTrackLine
== -1)
9581 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9583 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9584 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9585 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9591 * Called when an edit control should be displayed. This function is called after
9592 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9595 * [I] hwnd : Handle to the listview
9596 * [I] uMsg : WM_TIMER (ignored)
9597 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9598 * [I] dwTimer : The elapsed time (ignored)
9603 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9605 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9606 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9608 KillTimer(hwnd
, idEvent
);
9609 editItem
->fEnabled
= FALSE
;
9610 /* check if the item is still selected */
9611 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9612 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9617 * Creates the listview control - the WM_NCCREATE phase.
9620 * [I] hwnd : window handle
9621 * [I] lpcs : the create parameters
9627 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, WPARAM wParam
, const CREATESTRUCTW
*lpcs
)
9629 LISTVIEW_INFO
*infoPtr
;
9632 TRACE("(lpcs=%p)\n", lpcs
);
9634 /* initialize info pointer */
9635 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9636 if (!infoPtr
) return FALSE
;
9638 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9640 infoPtr
->hwndSelf
= hwnd
;
9641 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9642 map_style_view(infoPtr
);
9643 /* determine the type of structures to use */
9644 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9645 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9647 /* initialize color information */
9648 infoPtr
->clrBk
= CLR_NONE
;
9649 infoPtr
->clrText
= CLR_DEFAULT
;
9650 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9651 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9653 infoPtr
->bDefaultBkColor
= TRUE
;
9656 /* set default values */
9657 infoPtr
->nFocusedItem
= -1;
9658 infoPtr
->nSelectionMark
= -1;
9659 infoPtr
->nHotItem
= -1;
9660 infoPtr
->redraw
= TRUE
;
9661 infoPtr
->bNoItemMetrics
= TRUE
;
9662 infoPtr
->notify_mask
= NOTIFY_MASK_UNMASK_ALL
;
9663 infoPtr
->autoSpacing
= TRUE
;
9664 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9665 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9666 infoPtr
->nEditLabelItem
= -1;
9667 infoPtr
->nLButtonDownItem
= -1;
9668 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9669 infoPtr
->cWheelRemainder
= 0;
9670 infoPtr
->nMeasureItemHeight
= 0;
9671 infoPtr
->xTrackLine
= -1; /* no track line */
9672 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9673 infoPtr
->iVersion
= COMCTL32_VERSION
;
9674 infoPtr
->colRectsDirty
= FALSE
;
9676 /* get default font (icon title) */
9677 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9678 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9679 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9680 LISTVIEW_SaveTextMetrics(infoPtr
);
9682 /* allocate memory for the data structure */
9683 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9684 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9685 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9686 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9687 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9688 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9690 return DefWindowProcW(hwnd
, WM_NCCREATE
, wParam
, (LPARAM
)lpcs
);
9693 DestroyWindow(infoPtr
->hwndHeader
);
9694 ranges_destroy(infoPtr
->selectionRanges
);
9695 DPA_Destroy(infoPtr
->hdpaItems
);
9696 DPA_Destroy(infoPtr
->hdpaItemIds
);
9697 DPA_Destroy(infoPtr
->hdpaPosX
);
9698 DPA_Destroy(infoPtr
->hdpaPosY
);
9699 DPA_Destroy(infoPtr
->hdpaColumns
);
9706 * Creates the listview control - the WM_CREATE phase. Most of the data is
9707 * already set up in LISTVIEW_NCCreate
9710 * [I] hwnd : window handle
9711 * [I] lpcs : the create parameters
9717 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9719 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9721 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9723 infoPtr
->dwStyle
= lpcs
->style
;
9724 map_style_view(infoPtr
);
9726 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9727 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9728 /* on error defaulting to ANSI notifications */
9729 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9730 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9732 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9734 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9737 infoPtr
->hwndHeader
= 0;
9739 /* init item size to avoid division by 0 */
9740 LISTVIEW_UpdateItemSize (infoPtr
);
9741 LISTVIEW_UpdateSize (infoPtr
);
9743 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9745 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9747 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9749 LISTVIEW_UpdateScroll(infoPtr
);
9750 /* send WM_MEASUREITEM notification */
9751 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9754 OpenThemeData(hwnd
, themeClass
);
9756 /* initialize the icon sizes */
9757 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9758 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9764 * Destroys the listview control.
9767 * [I] infoPtr : valid pointer to the listview structure
9773 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9775 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9776 CloseThemeData(theme
);
9778 /* delete all items */
9779 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9786 * Enables the listview control.
9789 * [I] infoPtr : valid pointer to the listview structure
9790 * [I] bEnable : specifies whether to enable or disable the window
9796 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9798 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9799 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9805 * Erases the background of the listview control.
9808 * [I] infoPtr : valid pointer to the listview structure
9809 * [I] hdc : device context handle
9815 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9819 TRACE("(hdc=%p)\n", hdc
);
9821 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9823 if (infoPtr
->clrBk
== CLR_NONE
)
9825 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9826 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9827 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9829 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9832 /* for double buffered controls we need to do this during refresh */
9833 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9835 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9841 * Helper function for LISTVIEW_[HV]Scroll *only*.
9842 * Performs vertical/horizontal scrolling by a give amount.
9845 * [I] infoPtr : valid pointer to the listview structure
9846 * [I] dx : amount of horizontal scroll
9847 * [I] dy : amount of vertical scroll
9849 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9851 /* now we can scroll the list */
9852 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9853 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9854 /* if we have focus, adjust rect */
9855 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9856 UpdateWindow(infoPtr
->hwndSelf
);
9861 * Performs vertical 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_LINEUP/SB_LINEDOWN:
9874 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9875 * for LVS_REPORT is 1 line
9876 * for LVS_LIST cannot occur
9879 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9882 INT nOldScrollPos
, nNewScrollPos
;
9883 SCROLLINFO scrollInfo
;
9886 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9887 debugscrollcode(nScrollCode
), nScrollDiff
);
9889 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9891 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9892 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9894 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9896 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9898 nOldScrollPos
= scrollInfo
.nPos
;
9899 switch (nScrollCode
)
9905 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9909 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9913 nScrollDiff
= -scrollInfo
.nPage
;
9917 nScrollDiff
= scrollInfo
.nPage
;
9920 case SB_THUMBPOSITION
:
9922 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9929 /* quit right away if pos isn't changing */
9930 if (nScrollDiff
== 0) return 0;
9932 /* calculate new position, and handle overflows */
9933 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9934 if (nScrollDiff
> 0) {
9935 if (nNewScrollPos
< nOldScrollPos
||
9936 nNewScrollPos
> scrollInfo
.nMax
)
9937 nNewScrollPos
= scrollInfo
.nMax
;
9939 if (nNewScrollPos
> nOldScrollPos
||
9940 nNewScrollPos
< scrollInfo
.nMin
)
9941 nNewScrollPos
= scrollInfo
.nMin
;
9944 /* set the new position, and reread in case it changed */
9945 scrollInfo
.fMask
= SIF_POS
;
9946 scrollInfo
.nPos
= nNewScrollPos
;
9947 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9949 /* carry on only if it really changed */
9950 if (nNewScrollPos
== nOldScrollPos
) return 0;
9952 /* now adjust to client coordinates */
9953 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9954 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9956 /* and scroll the window */
9957 scroll_list(infoPtr
, 0, nScrollDiff
);
9964 * Performs horizontal scrolling.
9967 * [I] infoPtr : valid pointer to the listview structure
9968 * [I] nScrollCode : scroll code
9969 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9970 * [I] hScrollWnd : scrollbar control window handle
9976 * SB_LINELEFT/SB_LINERIGHT:
9977 * for LVS_ICON, LVS_SMALLICON 1 pixel
9978 * for LVS_REPORT is 1 pixel
9979 * for LVS_LIST is 1 column --> which is a 1 because the
9980 * scroll is based on columns not pixels
9983 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9986 INT nOldScrollPos
, nNewScrollPos
;
9987 SCROLLINFO scrollInfo
;
9990 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9991 debugscrollcode(nScrollCode
), nScrollDiff
);
9993 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9995 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9996 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9998 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
10000 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
10002 nOldScrollPos
= scrollInfo
.nPos
;
10004 switch (nScrollCode
)
10010 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
10014 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
10018 nScrollDiff
= -scrollInfo
.nPage
;
10022 nScrollDiff
= scrollInfo
.nPage
;
10025 case SB_THUMBPOSITION
:
10026 case SB_THUMBTRACK
:
10027 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
10034 /* quit right away if pos isn't changing */
10035 if (nScrollDiff
== 0) return 0;
10037 /* calculate new position, and handle overflows */
10038 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
10039 if (nScrollDiff
> 0) {
10040 if (nNewScrollPos
< nOldScrollPos
||
10041 nNewScrollPos
> scrollInfo
.nMax
)
10042 nNewScrollPos
= scrollInfo
.nMax
;
10044 if (nNewScrollPos
> nOldScrollPos
||
10045 nNewScrollPos
< scrollInfo
.nMin
)
10046 nNewScrollPos
= scrollInfo
.nMin
;
10049 /* set the new position, and reread in case it changed */
10050 scrollInfo
.fMask
= SIF_POS
;
10051 scrollInfo
.nPos
= nNewScrollPos
;
10052 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
10054 /* carry on only if it really changed */
10055 if (nNewScrollPos
== nOldScrollPos
) return 0;
10057 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
10059 /* now adjust to client coordinates */
10060 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
10061 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
10063 /* and scroll the window */
10064 scroll_list(infoPtr
, nScrollDiff
, 0);
10069 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
10071 INT pulScrollLines
= 3;
10073 TRACE("(wheelDelta=%d)\n", wheelDelta
);
10075 switch(infoPtr
->uView
)
10078 case LV_VIEW_SMALLICON
:
10080 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
10081 * should be fixed in the future.
10083 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
10084 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
10087 case LV_VIEW_DETAILS
:
10088 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
10090 /* if scrolling changes direction, ignore left overs */
10091 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
10092 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
10093 infoPtr
->cWheelRemainder
+= wheelDelta
;
10095 infoPtr
->cWheelRemainder
= wheelDelta
;
10096 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
10099 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
10100 cLineScroll
= pulScrollLines
* infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
10101 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ pulScrollLines
;
10102 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
10107 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
10118 * [I] infoPtr : valid pointer to the listview structure
10119 * [I] nVirtualKey : virtual key
10120 * [I] lKeyData : key data
10125 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
10127 HWND hwndSelf
= infoPtr
->hwndSelf
;
10129 NMLVKEYDOWN nmKeyDown
;
10131 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
10133 /* send LVN_KEYDOWN notification */
10134 nmKeyDown
.wVKey
= nVirtualKey
;
10135 nmKeyDown
.flags
= 0;
10136 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
10137 if (!IsWindow(hwndSelf
))
10140 switch (nVirtualKey
)
10143 nItem
= infoPtr
->nFocusedItem
;
10144 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
10145 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
10149 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
10151 if (!notify(infoPtr
, NM_RETURN
)) return 0;
10152 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
10157 if (infoPtr
->nItemCount
> 0)
10162 if (infoPtr
->nItemCount
> 0)
10163 nItem
= infoPtr
->nItemCount
- 1;
10167 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
10171 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
10175 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
10179 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
10183 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10185 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10186 if (infoPtr
->nFocusedItem
== topidx
)
10187 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
10192 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
10193 * LISTVIEW_GetCountPerRow(infoPtr
);
10194 if(nItem
< 0) nItem
= 0;
10198 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10200 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10201 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10202 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10203 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10205 nItem
= topidx
+ cnt
- 1;
10208 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10209 * LISTVIEW_GetCountPerRow(infoPtr
);
10210 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10214 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10215 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10225 * [I] infoPtr : valid pointer to the listview structure
10230 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10234 /* drop any left over scroll amount */
10235 infoPtr
->cWheelRemainder
= 0;
10237 /* if we did not have the focus, there's nothing more to do */
10238 if (!infoPtr
->bFocus
) return 0;
10240 /* send NM_KILLFOCUS notification */
10241 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10243 /* if we have a focus rectangle, get rid of it */
10244 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10246 /* if have a marquee selection, stop it */
10247 if (infoPtr
->bMarqueeSelect
)
10249 /* Remove the marquee rectangle and release our mouse capture */
10250 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10253 SetRectEmpty(&infoPtr
->marqueeRect
);
10255 infoPtr
->bMarqueeSelect
= FALSE
;
10256 infoPtr
->bScrolling
= FALSE
;
10257 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10260 /* set window focus flag */
10261 infoPtr
->bFocus
= FALSE
;
10263 /* invalidate the selected items before resetting focus flag */
10264 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10271 * Processes double click messages (left mouse button).
10274 * [I] infoPtr : valid pointer to the listview structure
10275 * [I] wKey : key flag
10276 * [I] x,y : mouse coordinate
10281 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10283 LVHITTESTINFO htInfo
;
10285 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10287 /* Cancel the item edition if any */
10288 if (infoPtr
->itemEdit
.fEnabled
)
10290 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10291 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10294 /* send NM_RELEASEDCAPTURE notification */
10295 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10300 /* send NM_DBLCLK notification */
10301 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10302 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10304 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10305 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10310 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10315 r
.top
= r
.bottom
= pt
.y
;
10316 r
.left
= r
.right
= pt
.x
;
10318 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10320 SetCapture(infoPtr
->hwndSelf
);
10324 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10326 if (msg
.message
== WM_MOUSEMOVE
)
10328 pt
.x
= (short)LOWORD(msg
.lParam
);
10329 pt
.y
= (short)HIWORD(msg
.lParam
);
10330 if (PtInRect(&r
, pt
))
10338 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10339 msg
.message
<= WM_RBUTTONDBLCLK
)
10344 DispatchMessageW(&msg
);
10347 if (GetCapture() != infoPtr
->hwndSelf
)
10358 * Processes mouse down messages (left mouse button).
10361 * infoPtr [I ] valid pointer to the listview structure
10362 * wKey [I ] key flag
10363 * x,y [I ] mouse coordinate
10368 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10370 LVHITTESTINFO lvHitTestInfo
;
10371 static BOOL bGroupSelect
= TRUE
;
10372 POINT pt
= { x
, y
};
10375 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10377 /* send NM_RELEASEDCAPTURE notification */
10378 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10380 /* set left button down flag and record the click position */
10381 infoPtr
->bLButtonDown
= TRUE
;
10382 infoPtr
->ptClickPos
= pt
;
10383 infoPtr
->bDragging
= FALSE
;
10384 infoPtr
->bMarqueeSelect
= FALSE
;
10385 infoPtr
->bScrolling
= FALSE
;
10387 lvHitTestInfo
.pt
.x
= x
;
10388 lvHitTestInfo
.pt
.y
= y
;
10390 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10391 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10392 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10394 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10396 notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
);
10397 toggle_checkbox_state(infoPtr
, nItem
);
10398 infoPtr
->bLButtonDown
= FALSE
;
10402 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10404 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10405 infoPtr
->nEditLabelItem
= nItem
;
10407 LISTVIEW_SetSelection(infoPtr
, nItem
);
10411 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10415 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10416 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10417 infoPtr
->nSelectionMark
= nItem
;
10423 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10424 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10426 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10427 infoPtr
->nSelectionMark
= nItem
;
10430 else if (wKey
& MK_CONTROL
)
10434 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10436 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10437 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10438 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10439 infoPtr
->nSelectionMark
= nItem
;
10441 else if (wKey
& MK_SHIFT
)
10443 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10447 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10449 infoPtr
->nEditLabelItem
= nItem
;
10450 infoPtr
->nLButtonDownItem
= nItem
;
10452 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10455 /* set selection (clears other pre-existing selections) */
10456 LISTVIEW_SetSelection(infoPtr
, nItem
);
10460 if (!infoPtr
->bFocus
)
10461 SetFocus(infoPtr
->hwndSelf
);
10463 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10464 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10468 if (!infoPtr
->bFocus
)
10469 SetFocus(infoPtr
->hwndSelf
);
10471 /* remove all selections */
10472 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10473 LISTVIEW_DeselectAll(infoPtr
);
10482 * Processes mouse up messages (left mouse button).
10485 * infoPtr [I ] valid pointer to the listview structure
10486 * wKey [I ] key flag
10487 * x,y [I ] mouse coordinate
10492 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10494 LVHITTESTINFO lvHitTestInfo
;
10496 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10498 if (!infoPtr
->bLButtonDown
) return 0;
10500 lvHitTestInfo
.pt
.x
= x
;
10501 lvHitTestInfo
.pt
.y
= y
;
10503 /* send NM_CLICK notification */
10504 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10505 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10507 /* set left button flag */
10508 infoPtr
->bLButtonDown
= FALSE
;
10510 /* set a single selection, reset others */
10511 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10512 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10513 infoPtr
->nLButtonDownItem
= -1;
10515 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10517 /* Remove the marquee rectangle and release our mouse capture */
10518 if (infoPtr
->bMarqueeSelect
)
10520 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10524 SetRectEmpty(&infoPtr
->marqueeRect
);
10525 SetRectEmpty(&infoPtr
->marqueeDrawRect
);
10527 infoPtr
->bDragging
= FALSE
;
10528 infoPtr
->bMarqueeSelect
= FALSE
;
10529 infoPtr
->bScrolling
= FALSE
;
10531 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10535 /* if we clicked on a selected item, edit the label */
10536 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10538 /* we want to make sure the user doesn't want to do a double click. So we will
10539 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10541 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10542 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10543 SetTimer(infoPtr
->hwndSelf
,
10544 (UINT_PTR
)&infoPtr
->itemEdit
,
10545 GetDoubleClickTime(),
10546 LISTVIEW_DelayedEditItem
);
10554 * Destroys the listview control (called after WM_DESTROY).
10557 * [I] infoPtr : valid pointer to the listview structure
10562 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10568 /* destroy data structure */
10569 DPA_Destroy(infoPtr
->hdpaItems
);
10570 DPA_Destroy(infoPtr
->hdpaItemIds
);
10571 DPA_Destroy(infoPtr
->hdpaPosX
);
10572 DPA_Destroy(infoPtr
->hdpaPosY
);
10574 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10575 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10576 DPA_Destroy(infoPtr
->hdpaColumns
);
10577 ranges_destroy(infoPtr
->selectionRanges
);
10579 /* destroy image lists */
10580 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10582 ImageList_Destroy(infoPtr
->himlNormal
);
10583 ImageList_Destroy(infoPtr
->himlSmall
);
10584 ImageList_Destroy(infoPtr
->himlState
);
10587 /* destroy font, bkgnd brush */
10588 infoPtr
->hFont
= 0;
10589 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10590 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10592 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10594 /* free listview info pointer*/
10602 * Handles notifications.
10605 * [I] infoPtr : valid pointer to the listview structure
10606 * [I] lpnmhdr : notification information
10611 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10615 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10617 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10619 /* remember: HDN_LAST < HDN_FIRST */
10620 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10621 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10623 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10625 switch (lpnmhdr
->code
)
10630 COLUMN_INFO
*lpColumnInfo
;
10634 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10637 /* remove the old line (if any) */
10638 LISTVIEW_DrawTrackLine(infoPtr
);
10640 /* compute & draw the new line */
10641 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10642 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10643 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10644 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10645 LISTVIEW_DrawTrackLine(infoPtr
);
10646 return notify_forward_header(infoPtr
, lpnmh
);
10649 case HDN_ENDTRACKA
:
10650 case HDN_ENDTRACKW
:
10651 /* remove the track line (if any) */
10652 LISTVIEW_DrawTrackLine(infoPtr
);
10653 infoPtr
->xTrackLine
= -1;
10654 return notify_forward_header(infoPtr
, lpnmh
);
10656 case HDN_BEGINDRAG
:
10657 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10658 return notify_forward_header(infoPtr
, lpnmh
);
10661 infoPtr
->colRectsDirty
= TRUE
;
10662 LISTVIEW_InvalidateList(infoPtr
);
10663 return notify_forward_header(infoPtr
, lpnmh
);
10665 case HDN_ITEMCHANGEDW
:
10666 case HDN_ITEMCHANGEDA
:
10668 COLUMN_INFO
*lpColumnInfo
;
10672 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10674 hdi
.mask
= HDI_WIDTH
;
10675 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10679 cxy
= lpnmh
->pitem
->cxy
;
10681 /* determine how much we change since the last know position */
10682 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10683 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10686 lpColumnInfo
->rcHeader
.right
+= dx
;
10688 hdi
.mask
= HDI_ORDER
;
10689 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10691 /* not the rightmost one */
10692 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10694 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10695 hdi
.iOrder
+ 1, 0);
10696 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10700 /* only needs to update the scrolls */
10701 infoPtr
->nItemWidth
+= dx
;
10702 LISTVIEW_UpdateScroll(infoPtr
);
10704 LISTVIEW_UpdateItemSize(infoPtr
);
10705 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10708 RECT rcCol
= lpColumnInfo
->rcHeader
;
10710 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10711 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10713 rcCol
.top
= infoPtr
->rcList
.top
;
10714 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10716 /* resizing left-aligned columns leaves most of the left side untouched */
10717 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10719 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10722 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10725 /* when shrinking the last column clear the now unused field */
10726 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10732 /* deal with right from rightmost column area */
10733 right
.left
= rcCol
.right
;
10734 right
.top
= rcCol
.top
;
10735 right
.bottom
= rcCol
.bottom
;
10736 right
.right
= infoPtr
->rcList
.right
;
10738 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10741 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10747 case HDN_ITEMCLICKW
:
10748 case HDN_ITEMCLICKA
:
10750 /* Handle sorting by Header Column */
10753 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10755 nmlv
.iSubItem
= lpnmh
->iItem
;
10756 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10757 return notify_forward_header(infoPtr
, lpnmh
);
10760 case HDN_DIVIDERDBLCLICKW
:
10761 case HDN_DIVIDERDBLCLICKA
:
10762 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10763 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10764 split needed for that */
10765 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10766 return notify_forward_header(infoPtr
, lpnmh
);
10773 * Paint non-client area of control.
10776 * [I] infoPtr : valid pointer to the listview structureof the sender
10777 * [I] region : update region
10780 * TRUE - frame was painted
10781 * FALSE - call default window proc
10783 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10785 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10789 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10790 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10793 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10795 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10797 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10798 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10799 if (region
!= (HRGN
)1)
10800 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10801 OffsetRect(&r
, -r
.left
, -r
.top
);
10803 #ifdef __REACTOS__ /* r73789 */
10804 dc
= GetWindowDC(infoPtr
->hwndSelf
);
10805 /* Exclude client part */
10806 ExcludeClipRect(dc
, r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10807 r
.right
- cxEdge
, r
.bottom
-cyEdge
);
10809 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10810 OffsetRect(&r
, -r
.left
, -r
.top
);
10813 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10814 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10815 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10816 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10818 /* Call default proc to get the scrollbars etc. painted */
10819 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10820 DeleteObject(cliprgn
);
10827 * Determines the type of structure to use.
10830 * [I] infoPtr : valid pointer to the listview structureof the sender
10831 * [I] hwndFrom : listview window handle
10832 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10837 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10839 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10841 if (nCommand
== NF_REQUERY
)
10842 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10844 return infoPtr
->notifyFormat
;
10849 * Paints/Repaints the listview control. Internal use.
10852 * [I] infoPtr : valid pointer to the listview structure
10853 * [I] hdc : device context handle
10858 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10860 TRACE("(hdc=%p)\n", hdc
);
10862 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10864 infoPtr
->bNoItemMetrics
= FALSE
;
10865 LISTVIEW_UpdateItemSize(infoPtr
);
10866 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10867 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10868 LISTVIEW_UpdateScroll(infoPtr
);
10871 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10874 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10879 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10880 if (!hdc
) return 1;
10881 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10882 EndPaint(infoPtr
->hwndSelf
, &ps
);
10890 * Paints/Repaints the listview control, WM_PAINT handler.
10893 * [I] infoPtr : valid pointer to the listview structure
10894 * [I] hdc : device context handle
10899 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10901 TRACE("(hdc=%p)\n", hdc
);
10903 if (!is_redrawing(infoPtr
))
10904 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10906 return LISTVIEW_Paint(infoPtr
, hdc
);
10911 * Paints/Repaints the listview control.
10914 * [I] infoPtr : valid pointer to the listview structure
10915 * [I] hdc : device context handle
10916 * [I] options : drawing options
10921 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10923 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10926 if (options
& ~(PRF_ERASEBKGND
|PRF_CLIENT
))
10927 FIXME("(hdc=%p options=0x%08x) partial stub\n", hdc
, options
);
10929 if (options
& PRF_ERASEBKGND
)
10930 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10932 if (options
& PRF_CLIENT
)
10933 LISTVIEW_Paint(infoPtr
, hdc
);
10941 * Processes double click messages (right mouse button).
10944 * [I] infoPtr : valid pointer to the listview structure
10945 * [I] wKey : key flag
10946 * [I] x,y : mouse coordinate
10951 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10953 LVHITTESTINFO lvHitTestInfo
;
10955 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10957 /* send NM_RELEASEDCAPTURE notification */
10958 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10960 /* send NM_RDBLCLK notification */
10961 lvHitTestInfo
.pt
.x
= x
;
10962 lvHitTestInfo
.pt
.y
= y
;
10963 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10964 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10971 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10974 * [I] infoPtr : valid pointer to the listview structure
10975 * [I] wKey : key flag
10976 * [I] x, y : mouse coordinate
10981 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10986 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10988 /* send NM_RELEASEDCAPTURE notification */
10989 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10991 /* determine the index of the selected item */
10994 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10996 /* make sure the listview control window has the focus */
10997 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10999 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
11001 LISTVIEW_SetItemFocus(infoPtr
, item
);
11002 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
11003 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
11004 LISTVIEW_SetSelection(infoPtr
, item
);
11007 LISTVIEW_DeselectAll(infoPtr
);
11009 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
11011 if (ht
.iItem
!= -1)
11015 memset(&nmlv
, 0, sizeof(nmlv
));
11016 nmlv
.iItem
= ht
.iItem
;
11017 nmlv
.ptAction
= ht
.pt
;
11019 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
11024 SetFocus(infoPtr
->hwndSelf
);
11028 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
11030 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
11032 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
11033 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
11034 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
11046 * [I] infoPtr : valid pointer to the listview structure
11047 * [I] hwnd : window handle of window containing the cursor
11048 * [I] nHittest : hit-test code
11049 * [I] wMouseMsg : ideintifier of the mouse message
11052 * TRUE if cursor is set
11055 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11057 LVHITTESTINFO lvHitTestInfo
;
11059 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
11061 if (!infoPtr
->hHotCursor
) goto forward
;
11063 GetCursorPos(&lvHitTestInfo
.pt
);
11064 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
11066 SetCursor(infoPtr
->hHotCursor
);
11072 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
11080 * [I] infoPtr : valid pointer to the listview structure
11081 * [I] hwndLoseFocus : handle of previously focused window
11086 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
11088 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
11090 /* if we have the focus already, there's nothing to do */
11091 if (infoPtr
->bFocus
) return 0;
11093 /* send NM_SETFOCUS notification */
11094 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
11096 /* set window focus flag */
11097 infoPtr
->bFocus
= TRUE
;
11099 /* put the focus rect back on */
11100 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
11102 /* redraw all visible selected items */
11103 LISTVIEW_InvalidateSelectedItems(infoPtr
);
11113 * [I] infoPtr : valid pointer to the listview structure
11114 * [I] fRedraw : font handle
11115 * [I] fRedraw : redraw flag
11120 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
11122 HFONT oldFont
= infoPtr
->hFont
;
11123 INT oldHeight
= infoPtr
->nItemHeight
;
11125 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
11127 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
11128 if (infoPtr
->hFont
== oldFont
) return 0;
11130 LISTVIEW_SaveTextMetrics(infoPtr
);
11132 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
11134 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
11136 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
11137 LISTVIEW_UpdateSize(infoPtr
);
11138 LISTVIEW_UpdateScroll(infoPtr
);
11140 else if (infoPtr
->nItemHeight
!= oldHeight
)
11141 LISTVIEW_UpdateScroll(infoPtr
);
11143 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
11150 * Message handling for WM_SETREDRAW.
11151 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
11154 * [I] infoPtr : valid pointer to the listview structure
11155 * [I] redraw: state of redraw flag
11160 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL redraw
)
11162 TRACE("old=%d, new=%d\n", infoPtr
->redraw
, redraw
);
11164 if (infoPtr
->redraw
== !!redraw
)
11167 if (!(infoPtr
->redraw
= !!redraw
))
11170 if (is_autoarrange(infoPtr
))
11171 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11172 LISTVIEW_UpdateScroll(infoPtr
);
11174 /* despite what the WM_SETREDRAW docs says, apps expect us
11175 * to invalidate the listview here... stupid! */
11176 LISTVIEW_InvalidateList(infoPtr
);
11183 * Resizes the listview control. This function processes WM_SIZE
11184 * messages. At this time, the width and height are not used.
11187 * [I] infoPtr : valid pointer to the listview structure
11188 * [I] Width : new width
11189 * [I] Height : new height
11194 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
11196 RECT rcOld
= infoPtr
->rcList
;
11198 TRACE("(width=%d, height=%d)\n", Width
, Height
);
11200 LISTVIEW_UpdateSize(infoPtr
);
11201 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
11203 /* do not bother with display related stuff if we're not redrawing */
11204 if (!is_redrawing(infoPtr
)) return 0;
11206 if (is_autoarrange(infoPtr
))
11207 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11209 LISTVIEW_UpdateScroll(infoPtr
);
11211 /* refresh all only for lists whose height changed significantly */
11212 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11213 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11214 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11215 LISTVIEW_InvalidateList(infoPtr
);
11222 * Sets the size information.
11225 * [I] infoPtr : valid pointer to the listview structure
11230 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11232 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11234 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11236 if (infoPtr
->uView
== LV_VIEW_LIST
)
11238 /* Apparently the "LIST" style is supposed to have the same
11239 * number of items in a column even if there is no scroll bar.
11240 * Since if a scroll bar already exists then the bottom is already
11241 * reduced, only reduce if the scroll bar does not currently exist.
11242 * The "2" is there to mimic the native control. I think it may be
11243 * related to either padding or edges. (GLA 7/2002)
11245 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11246 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11247 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11250 /* When ListView control is created invisible, header isn't created right away. */
11251 if (infoPtr
->hwndHeader
)
11258 LISTVIEW_GetOrigin(infoPtr
, &origin
);
11260 rect
= infoPtr
->rcList
;
11261 rect
.left
+= origin
.x
;
11265 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11266 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11268 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11269 wp
.flags
|= SWP_SHOWWINDOW
;
11272 wp
.flags
|= SWP_HIDEWINDOW
;
11276 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11277 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11279 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11281 /* extra padding for grid */
11282 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11283 infoPtr
->rcList
.top
+= 2;
11285 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11290 * Processes WM_STYLECHANGED messages.
11293 * [I] infoPtr : valid pointer to the listview structure
11294 * [I] wStyleType : window style type (normal or extended)
11295 * [I] lpss : window style information
11300 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11301 const STYLESTRUCT
*lpss
)
11303 UINT uNewView
, uOldView
;
11306 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11307 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11309 if (wStyleType
!= GWL_STYLE
|| lpss
->styleNew
== infoPtr
->dwStyle
) return 0;
11311 infoPtr
->dwStyle
= lpss
->styleNew
;
11313 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11314 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11315 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11317 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11318 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11319 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11321 uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11322 uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11324 if (uNewView
!= uOldView
)
11328 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11329 changing style updates current view only when view bits change. */
11330 map_style_view(infoPtr
);
11331 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11332 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11334 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11335 SetRectEmpty(&infoPtr
->rcFocus
);
11337 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11338 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11340 if (uNewView
== LVS_REPORT
)
11345 LISTVIEW_CreateHeader( infoPtr
);
11347 hl
.prc
= &infoPtr
->rcList
;
11349 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11350 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11351 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11352 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11355 LISTVIEW_UpdateItemSize(infoPtr
);
11358 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11360 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11362 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11364 /* Turn off the header control */
11365 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11366 TRACE("Hide header control, was 0x%08x\n", style
);
11367 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11369 /* Turn on the header control */
11370 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11372 TRACE("Show header control, was 0x%08x\n", style
);
11373 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11379 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11380 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11381 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11383 /* update the size of the client area */
11384 LISTVIEW_UpdateSize(infoPtr
);
11386 /* add scrollbars if needed */
11387 LISTVIEW_UpdateScroll(infoPtr
);
11389 /* invalidate client area + erase background */
11390 LISTVIEW_InvalidateList(infoPtr
);
11397 * Processes WM_STYLECHANGING messages.
11400 * [I] wStyleType : window style type (normal or extended)
11401 * [I0] lpss : window style information
11406 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11409 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11410 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11412 /* don't forward LVS_OWNERDATA only if not already set to */
11413 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11415 if (lpss
->styleOld
& LVS_OWNERDATA
)
11416 lpss
->styleNew
|= LVS_OWNERDATA
;
11418 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11426 * Processes WM_SHOWWINDOW messages.
11429 * [I] infoPtr : valid pointer to the listview structure
11430 * [I] bShown : window is being shown (FALSE when hidden)
11431 * [I] iStatus : window show status
11436 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11438 /* header delayed creation */
11439 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11441 LISTVIEW_CreateHeader(infoPtr
);
11443 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11444 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11447 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11452 * Processes CCM_GETVERSION messages.
11455 * [I] infoPtr : valid pointer to the listview structure
11460 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11462 return infoPtr
->iVersion
;
11467 * Processes CCM_SETVERSION messages.
11470 * [I] infoPtr : valid pointer to the listview structure
11471 * [I] iVersion : version to be set
11474 * -1 when requested version is greater than DLL version;
11475 * previous version otherwise
11477 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11479 INT iOldVersion
= infoPtr
->iVersion
;
11481 if (iVersion
> COMCTL32_VERSION
)
11484 infoPtr
->iVersion
= iVersion
;
11486 TRACE("new version %d\n", iVersion
);
11488 return iOldVersion
;
11493 * Window procedure of the listview control.
11496 static LRESULT WINAPI
11497 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11499 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11501 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11503 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11504 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11508 case LVM_APPROXIMATEVIEWRECT
:
11509 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11510 LOWORD(lParam
), HIWORD(lParam
));
11512 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11514 case LVM_CANCELEDITLABEL
:
11515 return LISTVIEW_CancelEditLabel(infoPtr
);
11517 case LVM_CREATEDRAGIMAGE
:
11518 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11520 case LVM_DELETEALLITEMS
:
11521 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11523 case LVM_DELETECOLUMN
:
11524 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11526 case LVM_DELETEITEM
:
11527 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11529 case LVM_EDITLABELA
:
11530 case LVM_EDITLABELW
:
11531 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11532 uMsg
== LVM_EDITLABELW
);
11533 /* case LVM_ENABLEGROUPVIEW: */
11535 case LVM_ENSUREVISIBLE
:
11536 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11538 case LVM_FINDITEMW
:
11539 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11541 case LVM_FINDITEMA
:
11542 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11544 case LVM_GETBKCOLOR
:
11545 return infoPtr
->clrBk
;
11547 /* case LVM_GETBKIMAGE: */
11549 case LVM_GETCALLBACKMASK
:
11550 return infoPtr
->uCallbackMask
;
11552 case LVM_GETCOLUMNA
:
11553 case LVM_GETCOLUMNW
:
11554 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11555 uMsg
== LVM_GETCOLUMNW
);
11557 case LVM_GETCOLUMNORDERARRAY
:
11558 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11560 case LVM_GETCOLUMNWIDTH
:
11561 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11563 case LVM_GETCOUNTPERPAGE
:
11564 return LISTVIEW_GetCountPerPage(infoPtr
);
11566 case LVM_GETEDITCONTROL
:
11567 return (LRESULT
)infoPtr
->hwndEdit
;
11569 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11570 return infoPtr
->dwLvExStyle
;
11572 /* case LVM_GETGROUPINFO: */
11574 /* case LVM_GETGROUPMETRICS: */
11576 case LVM_GETHEADER
:
11577 return (LRESULT
)infoPtr
->hwndHeader
;
11579 case LVM_GETHOTCURSOR
:
11580 return (LRESULT
)infoPtr
->hHotCursor
;
11582 case LVM_GETHOTITEM
:
11583 return infoPtr
->nHotItem
;
11585 case LVM_GETHOVERTIME
:
11586 return infoPtr
->dwHoverTime
;
11588 case LVM_GETIMAGELIST
:
11589 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11591 /* case LVM_GETINSERTMARK: */
11593 /* case LVM_GETINSERTMARKCOLOR: */
11595 /* case LVM_GETINSERTMARKRECT: */
11597 case LVM_GETISEARCHSTRINGA
:
11598 case LVM_GETISEARCHSTRINGW
:
11599 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11604 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11606 case LVM_GETITEMCOUNT
:
11607 return infoPtr
->nItemCount
;
11609 case LVM_GETITEMPOSITION
:
11610 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11612 case LVM_GETITEMRECT
:
11613 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11615 case LVM_GETITEMSPACING
:
11616 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11618 case LVM_GETITEMSTATE
:
11619 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11621 case LVM_GETITEMTEXTA
:
11622 case LVM_GETITEMTEXTW
:
11623 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11624 uMsg
== LVM_GETITEMTEXTW
);
11626 case LVM_GETNEXTITEM
:
11627 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11629 case LVM_GETNUMBEROFWORKAREAS
:
11630 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11633 case LVM_GETORIGIN
:
11634 if (!lParam
) return FALSE
;
11635 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11636 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11637 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11640 /* case LVM_GETOUTLINECOLOR: */
11642 /* case LVM_GETSELECTEDCOLUMN: */
11644 case LVM_GETSELECTEDCOUNT
:
11645 return LISTVIEW_GetSelectedCount(infoPtr
);
11647 case LVM_GETSELECTIONMARK
:
11648 return infoPtr
->nSelectionMark
;
11650 case LVM_GETSTRINGWIDTHA
:
11651 case LVM_GETSTRINGWIDTHW
:
11652 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11653 uMsg
== LVM_GETSTRINGWIDTHW
);
11655 case LVM_GETSUBITEMRECT
:
11656 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11658 case LVM_GETTEXTBKCOLOR
:
11659 return infoPtr
->clrTextBk
;
11661 case LVM_GETTEXTCOLOR
:
11662 return infoPtr
->clrText
;
11664 /* case LVM_GETTILEINFO: */
11666 /* case LVM_GETTILEVIEWINFO: */
11668 case LVM_GETTOOLTIPS
:
11669 if( !infoPtr
->hwndToolTip
)
11670 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11671 return (LRESULT
)infoPtr
->hwndToolTip
;
11673 case LVM_GETTOPINDEX
:
11674 return LISTVIEW_GetTopIndex(infoPtr
);
11676 case LVM_GETUNICODEFORMAT
:
11677 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11680 return infoPtr
->uView
;
11682 case LVM_GETVIEWRECT
:
11683 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11685 case LVM_GETWORKAREAS
:
11686 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11689 /* case LVM_HASGROUP: */
11692 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11694 case LVM_INSERTCOLUMNA
:
11695 case LVM_INSERTCOLUMNW
:
11696 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11697 uMsg
== LVM_INSERTCOLUMNW
);
11699 /* case LVM_INSERTGROUP: */
11701 /* case LVM_INSERTGROUPSORTED: */
11703 case LVM_INSERTITEMA
:
11704 case LVM_INSERTITEMW
:
11705 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11707 /* case LVM_INSERTMARKHITTEST: */
11709 /* case LVM_ISGROUPVIEWENABLED: */
11711 case LVM_ISITEMVISIBLE
:
11712 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11714 case LVM_MAPIDTOINDEX
:
11715 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11717 case LVM_MAPINDEXTOID
:
11718 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11720 /* case LVM_MOVEGROUP: */
11722 /* case LVM_MOVEITEMTOGROUP: */
11724 case LVM_REDRAWITEMS
:
11725 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11727 /* case LVM_REMOVEALLGROUPS: */
11729 /* case LVM_REMOVEGROUP: */
11732 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11734 case LVM_SETBKCOLOR
:
11735 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11737 /* case LVM_SETBKIMAGE: */
11739 case LVM_SETCALLBACKMASK
:
11740 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11743 case LVM_SETCOLUMNA
:
11744 case LVM_SETCOLUMNW
:
11745 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11746 uMsg
== LVM_SETCOLUMNW
);
11748 case LVM_SETCOLUMNORDERARRAY
:
11749 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11751 case LVM_SETCOLUMNWIDTH
:
11752 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11754 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11755 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11757 /* case LVM_SETGROUPINFO: */
11759 /* case LVM_SETGROUPMETRICS: */
11761 case LVM_SETHOTCURSOR
:
11762 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11764 case LVM_SETHOTITEM
:
11765 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11767 case LVM_SETHOVERTIME
:
11768 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11770 case LVM_SETICONSPACING
:
11772 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11773 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11775 case LVM_SETIMAGELIST
:
11776 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11778 /* case LVM_SETINFOTIP: */
11780 /* case LVM_SETINSERTMARK: */
11782 /* case LVM_SETINSERTMARKCOLOR: */
11787 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11788 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11791 case LVM_SETITEMCOUNT
:
11792 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11794 case LVM_SETITEMPOSITION
:
11797 pt
.x
= (short)LOWORD(lParam
);
11798 pt
.y
= (short)HIWORD(lParam
);
11799 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11802 case LVM_SETITEMPOSITION32
:
11803 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11805 case LVM_SETITEMSTATE
:
11806 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11808 case LVM_SETITEMTEXTA
:
11809 case LVM_SETITEMTEXTW
:
11810 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11811 uMsg
== LVM_SETITEMTEXTW
);
11813 /* case LVM_SETOUTLINECOLOR: */
11815 /* case LVM_SETSELECTEDCOLUMN: */
11817 case LVM_SETSELECTIONMARK
:
11818 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11820 case LVM_SETTEXTBKCOLOR
:
11821 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11823 case LVM_SETTEXTCOLOR
:
11824 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11826 /* case LVM_SETTILEINFO: */
11828 /* case LVM_SETTILEVIEWINFO: */
11830 /* case LVM_SETTILEWIDTH: */
11832 case LVM_SETTOOLTIPS
:
11833 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11835 case LVM_SETUNICODEFORMAT
:
11836 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11839 return LISTVIEW_SetView(infoPtr
, wParam
);
11841 /* case LVM_SETWORKAREAS: */
11843 /* case LVM_SORTGROUPS: */
11845 case LVM_SORTITEMS
:
11846 case LVM_SORTITEMSEX
:
11847 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11848 uMsg
== LVM_SORTITEMSEX
);
11849 case LVM_SUBITEMHITTEST
:
11850 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11853 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11855 case CCM_GETVERSION
:
11856 return LISTVIEW_GetVersion(infoPtr
);
11858 case CCM_SETVERSION
:
11859 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11862 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11865 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11868 return LISTVIEW_NCCreate(hwnd
, wParam
, (LPCREATESTRUCTW
)lParam
);
11871 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11874 return LISTVIEW_Destroy(infoPtr
);
11877 return LISTVIEW_Enable(infoPtr
);
11879 case WM_ERASEBKGND
:
11880 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11882 case WM_GETDLGCODE
:
11883 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11886 return (LRESULT
)infoPtr
->hFont
;
11889 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11892 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11895 return LISTVIEW_KillFocus(infoPtr
);
11897 case WM_LBUTTONDBLCLK
:
11898 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11900 case WM_LBUTTONDOWN
:
11901 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11904 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11907 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11909 case WM_MOUSEHOVER
:
11910 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11913 return LISTVIEW_NCDestroy(infoPtr
);
11916 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11919 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11921 case WM_NOTIFYFORMAT
:
11922 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11924 case WM_PRINTCLIENT
:
11925 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11928 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11930 case WM_RBUTTONDBLCLK
:
11931 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11933 case WM_RBUTTONDOWN
:
11934 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11937 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11940 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11943 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11946 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11948 case WM_SHOWWINDOW
:
11949 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11951 case WM_STYLECHANGED
:
11952 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11954 case WM_STYLECHANGING
:
11955 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11957 case WM_SYSCOLORCHANGE
:
11958 COMCTL32_RefreshSysColors();
11960 if (infoPtr
->bDefaultBkColor
)
11962 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
11963 infoPtr
->bDefaultBkColor
= TRUE
;
11964 LISTVIEW_InvalidateList(infoPtr
);
11969 /* case WM_TIMER: */
11970 case WM_THEMECHANGED
:
11971 return LISTVIEW_ThemeChanged(infoPtr
);
11974 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11976 case WM_MOUSEWHEEL
:
11977 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11978 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11979 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11981 case WM_WINDOWPOSCHANGED
:
11982 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11984 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11985 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11987 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11989 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11991 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11993 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11995 /* case WM_WININICHANGE: */
11998 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11999 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
12001 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
12008 * Registers the window class.
12016 void LISTVIEW_Register(void)
12018 WNDCLASSW wndClass
;
12020 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
12021 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
12022 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
12023 wndClass
.cbClsExtra
= 0;
12024 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
12025 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
12026 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
12027 wndClass
.lpszClassName
= WC_LISTVIEWW
;
12028 RegisterClassW(&wndClass
);
12033 * Unregisters the window class.
12041 void LISTVIEW_Unregister(void)
12043 UnregisterClassW(WC_LISTVIEWW
, NULL
);
12048 * Handle any WM_COMMAND messages
12051 * [I] infoPtr : valid pointer to the listview structure
12052 * [I] wParam : the first message parameter
12053 * [I] lParam : the second message parameter
12058 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
12061 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
12063 if (!infoPtr
->hwndEdit
) return 0;
12065 switch (HIWORD(wParam
))
12070 * Adjust the edit window size
12072 WCHAR buffer
[1024];
12073 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
12074 HFONT hFont
, hOldFont
= 0;
12078 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
12079 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, ARRAY_SIZE(buffer
));
12080 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
12082 /* Select font to get the right dimension of the string */
12083 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
12086 hOldFont
= SelectObject(hdc
, hFont
);
12089 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
12091 TEXTMETRICW textMetric
;
12093 /* Add Extra spacing for the next character */
12094 GetTextMetricsW(hdc
, &textMetric
);
12095 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
12097 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
12098 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
12101 SelectObject(hdc
, hOldFont
);
12103 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
12109 if (infoPtr
->notify_mask
& NOTIFY_MASK_END_LABEL_EDIT
)
12110 LISTVIEW_CancelEditLabel(infoPtr
);
12115 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);