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 * This code was audited for completeness against the documented features
30 * of Comctl32.dll version 6.0 on May. 20, 2005, by James Hawkins.
32 * Unless otherwise noted, we believe this code to be complete, as per
33 * the specification mentioned above.
34 * If you discover missing features, or bugs, please note them below.
38 * Default Message Processing
39 * -- WM_CREATE: create the icon and small icon image lists at this point only if
40 * the LVS_SHAREIMAGELISTS style is not specified.
41 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
42 * or small icon and the LVS_AUTOARRANGE style is specified.
47 * -- Hot item handling, mouse hovering
48 * -- Workareas support
53 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
54 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
55 * -- LVA_SNAPTOGRID not implemented
56 * -- LISTVIEW_ApproximateViewRect partially implemented
57 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
60 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
61 * linear in the number of items in the list, and this is
62 * unacceptable for large lists.
63 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
64 * binary search to calculate item index (e.g. DPA_Search()).
65 * This requires sorted state to be reliably tracked in item modifiers.
66 * -- we should keep an ordered array of coordinates in iconic mode
67 * this would allow to frame items (iterator_frameditems),
68 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
75 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
80 * -- LVS_NOSCROLL (see Q137520)
84 * -- LVS_EX_BORDERSELECT
88 * -- LVS_EX_MULTIWORKAREAS
90 * -- LVS_EX_SIMPLESELECT
91 * -- LVS_EX_TWOCLICKACTIVATE
92 * -- LVS_EX_UNDERLINECOLD
93 * -- LVS_EX_UNDERLINEHOT
96 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
102 * -- LVM_ENABLEGROUPVIEW
103 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
104 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
105 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
106 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
107 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
108 * -- LVM_GETINSERTMARKRECT
109 * -- LVM_GETNUMBEROFWORKAREAS
110 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
111 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
112 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
113 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
114 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
115 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
116 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
117 * -- LVM_INSERTGROUPSORTED
118 * -- LVM_INSERTMARKHITTEST
119 * -- LVM_ISGROUPVIEWENABLED
121 * -- LVM_MOVEITEMTOGROUP
123 * -- LVM_SETTILEWIDTH
127 * -- ListView_GetHoverTime, ListView_SetHoverTime
128 * -- ListView_GetISearchString
129 * -- ListView_GetNumberOfWorkAreas
130 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
137 #include "wine/port.h"
152 #include "commctrl.h"
153 #include "comctl32.h"
156 #include "wine/debug.h"
157 #include "wine/unicode.h"
159 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
161 typedef struct tagCOLUMN_INFO
163 RECT rcHeader
; /* tracks the header's rectangle */
164 INT fmt
; /* same as LVCOLUMN.fmt */
168 typedef struct tagITEMHDR
172 } ITEMHDR
, *LPITEMHDR
;
174 typedef struct tagSUBITEM_INFO
180 typedef struct tagITEM_ID ITEM_ID
;
182 typedef struct tagITEM_INFO
193 UINT id
; /* item id */
194 HDPA item
; /* link to item data */
197 typedef struct tagRANGE
203 typedef struct tagRANGES
208 typedef struct tagITERATOR
217 typedef struct tagDELAYED_ITEM_EDIT
223 typedef struct tagLISTVIEW_INFO
227 RECT rcList
; /* This rectangle is really the window
228 * client rectangle possibly reduced by the
229 * horizontal scroll bar and/or header - see
230 * LISTVIEW_UpdateSize. This rectangle offset
231 * by the LISTVIEW_GetOrigin value is in
232 * client coordinates */
234 /* notification window */
237 BOOL bDoChangeNotify
; /* send change notification messages? */
244 INT nItemCount
; /* the number of items in the list */
245 HDPA hdpaItems
; /* array ITEM_INFO pointers */
246 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
247 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
248 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
249 RANGES selectionRanges
;
250 INT nSelectionMark
; /* item to start next multiselection from */
252 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
255 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
256 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
259 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
264 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
268 DWORD dwStyle
; /* the cached window GWL_STYLE */
269 DWORD dwLvExStyle
; /* extended listview style */
270 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
276 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
279 HIMAGELIST himlNormal
;
280 HIMAGELIST himlSmall
;
281 HIMAGELIST himlState
;
286 POINT currIconPos
; /* this is the position next icon will be placed */
290 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
292 /* marquee selection */
293 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
295 RECT marqueeRect
; /* absolute coordinates of marquee selection */
296 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
297 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
300 BOOL bFocus
; /* control has focus */
302 RECT rcFocus
; /* focus bounds */
313 INT ntmHeight
; /* Some cached metrics of the font used */
314 INT ntmMaxCharWidth
; /* by the listview to draw items */
317 /* mouse operation */
320 POINT ptClickPos
; /* point where the user clicked */
321 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
326 /* keyboard operation */
327 DWORD lastKeyPressTimestamp
;
329 INT nSearchParamLength
;
330 WCHAR szSearchParam
[ MAX_PATH
];
333 BOOL bIsDrawing
; /* Drawing in progress */
334 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
335 BOOL bRedraw
; /* WM_SETREDRAW switch */
338 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
344 /* How many we debug buffer to allocate */
345 #define DEBUG_BUFFERS 20
346 /* The size of a single debug buffer */
347 #define DEBUG_BUFFER_SIZE 256
349 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
350 #define SB_INTERNAL -1
352 /* maximum size of a label */
353 #define DISP_TEXT_SIZE 260
355 /* padding for items in list and small icon display modes */
356 #define WIDTH_PADDING 12
358 /* padding for items in list, report and small icon display modes */
359 #define HEIGHT_PADDING 1
361 /* offset of items in report display mode */
362 #define REPORT_MARGINX 2
364 /* padding for icon in large icon display mode
365 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
366 * that HITTEST will see.
367 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
368 * ICON_TOP_PADDING - sum of the two above.
369 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
370 * LABEL_HOR_PADDING - between text and sides of box
371 * LABEL_VERT_PADDING - between bottom of text and end of box
373 * ICON_LR_PADDING - additional width above icon size.
374 * ICON_LR_HALF - half of the above value
376 #define ICON_TOP_PADDING_NOTHITABLE 2
377 #define ICON_TOP_PADDING_HITABLE 2
378 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
379 #define ICON_BOTTOM_PADDING 4
380 #define LABEL_HOR_PADDING 5
381 #define LABEL_VERT_PADDING 7
382 #define ICON_LR_PADDING 16
383 #define ICON_LR_HALF (ICON_LR_PADDING/2)
385 /* default label width for items in list and small icon display modes */
386 #define DEFAULT_LABEL_WIDTH 40
387 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
388 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
390 /* default column width for items in list display mode */
391 #define DEFAULT_COLUMN_WIDTH 128
393 /* Size of "line" scroll for V & H scrolls */
394 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
396 /* Padding between image and label */
397 #define IMAGE_PADDING 2
399 /* Padding behind the label */
400 #define TRAILING_LABEL_PADDING 12
401 #define TRAILING_HEADER_PADDING 11
403 /* Border for the icon caption */
404 #define CAPTION_BORDER 2
406 /* Standard DrawText flags */
407 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
408 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
409 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
411 /* Image index from state */
412 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
414 /* The time in milliseconds to reset the search in the list */
415 #define KEY_DELAY 450
417 /* Dump the LISTVIEW_INFO structure to the debug channel */
418 #define LISTVIEW_DUMP(iP) do { \
419 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
420 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
421 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
422 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
423 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
424 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
425 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
426 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
427 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
428 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
431 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
434 * forward declarations
436 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
437 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
438 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
439 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
440 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
441 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
442 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
443 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
444 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
445 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
446 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
447 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
448 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
449 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
450 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
451 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
452 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
453 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
454 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
455 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
457 /******** Text handling functions *************************************/
459 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
460 * text string. The string may be ANSI or Unicode, in which case
461 * the boolean isW tells us the type of the string.
463 * The name of the function tell what type of strings it expects:
464 * W: Unicode, T: ANSI/Unicode - function of isW
467 static inline BOOL
is_text(LPCWSTR text
)
469 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
472 static inline int textlenT(LPCWSTR text
, BOOL isW
)
474 return !is_text(text
) ? 0 :
475 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
478 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
481 if (isSrcW
) lstrcpynW(dest
, src
, max
);
482 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
484 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
485 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
488 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
490 LPWSTR wstr
= (LPWSTR
)text
;
492 if (!isW
&& is_text(text
))
494 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
495 wstr
= Alloc(len
* sizeof(WCHAR
));
496 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
498 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
502 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
504 if (!isW
&& is_text(wstr
)) Free (wstr
);
508 * dest is a pointer to a Unicode string
509 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
511 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
515 if (src
== LPSTR_TEXTCALLBACKW
)
517 if (is_text(*dest
)) Free(*dest
);
518 *dest
= LPSTR_TEXTCALLBACKW
;
522 LPWSTR pszText
= textdupTtoW(src
, isW
);
523 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
524 bResult
= Str_SetPtrW(dest
, pszText
);
525 textfreeT(pszText
, isW
);
531 * compares a Unicode to a Unicode/ANSI text string
533 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
535 if (!aw
) return bt
? -1 : 0;
537 if (aw
== LPSTR_TEXTCALLBACKW
)
538 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
539 if (bt
!= LPSTR_TEXTCALLBACKW
)
541 LPWSTR bw
= textdupTtoW(bt
, isW
);
542 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
550 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
552 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
553 return CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
) - CSTR_EQUAL
;
556 /******** Debugging functions *****************************************/
558 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
560 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
561 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
564 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
566 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
567 n
= min(textlenT(text
, isW
), n
);
568 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
571 static char* debug_getbuf(void)
573 static int index
= 0;
574 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
575 return buffers
[index
++ % DEBUG_BUFFERS
];
578 static inline const char* debugrange(const RANGE
*lprng
)
580 if (!lprng
) return "(null)";
581 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
584 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
586 char* buf
= debug_getbuf(), *text
= buf
;
587 int len
, size
= DEBUG_BUFFER_SIZE
;
589 if (pScrollInfo
== NULL
) return "(null)";
590 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
591 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
592 if (pScrollInfo
->fMask
& SIF_RANGE
)
593 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
595 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
596 if (pScrollInfo
->fMask
& SIF_PAGE
)
597 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
599 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
600 if (pScrollInfo
->fMask
& SIF_POS
)
601 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
603 if (len
== -1) goto end
; 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
; buf
+= len
;
610 buf
= text
+ strlen(text
);
612 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
616 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
618 if (!plvnm
) return "(null)";
619 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
620 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
621 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
622 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
625 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
627 char* buf
= debug_getbuf(), *text
= buf
;
628 int len
, size
= DEBUG_BUFFER_SIZE
;
630 if (lpLVItem
== NULL
) return "(null)";
631 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
632 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
633 if (lpLVItem
->mask
& LVIF_STATE
)
634 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
636 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
637 if (lpLVItem
->mask
& LVIF_TEXT
)
638 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
640 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
641 if (lpLVItem
->mask
& LVIF_IMAGE
)
642 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
644 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
645 if (lpLVItem
->mask
& LVIF_PARAM
)
646 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
648 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
649 if (lpLVItem
->mask
& LVIF_INDENT
)
650 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
652 if (len
== -1) goto end
; buf
+= len
;
655 buf
= text
+ strlen(text
);
657 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
661 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
663 char* buf
= debug_getbuf(), *text
= buf
;
664 int len
, size
= DEBUG_BUFFER_SIZE
;
666 if (lpColumn
== NULL
) return "(null)";
667 len
= snprintf(buf
, size
, "{");
668 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
669 if (lpColumn
->mask
& LVCF_SUBITEM
)
670 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
672 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
673 if (lpColumn
->mask
& LVCF_FMT
)
674 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
676 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
677 if (lpColumn
->mask
& LVCF_WIDTH
)
678 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
680 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
681 if (lpColumn
->mask
& LVCF_TEXT
)
682 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
684 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
685 if (lpColumn
->mask
& LVCF_IMAGE
)
686 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
688 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
689 if (lpColumn
->mask
& LVCF_ORDER
)
690 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
692 if (len
== -1) goto end
; buf
+= len
;
695 buf
= text
+ strlen(text
);
697 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
701 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
703 if (!lpht
) return "(null)";
705 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
706 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
709 /* Return the corresponding text for a given scroll value */
710 static inline LPCSTR
debugscrollcode(int nScrollCode
)
714 case SB_LINELEFT
: return "SB_LINELEFT";
715 case SB_LINERIGHT
: return "SB_LINERIGHT";
716 case SB_PAGELEFT
: return "SB_PAGELEFT";
717 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
718 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
719 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
720 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
721 case SB_INTERNAL
: return "SB_INTERNAL";
722 default: return "unknown";
727 /******** Notification functions ************************************/
729 static int get_ansi_notification(UINT unicodeNotificationCode
)
731 switch (unicodeNotificationCode
)
733 case LVN_BEGINLABELEDITA
:
734 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
735 case LVN_ENDLABELEDITA
:
736 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
737 case LVN_GETDISPINFOA
:
738 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
739 case LVN_SETDISPINFOA
:
740 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
741 case LVN_ODFINDITEMA
:
742 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
743 case LVN_GETINFOTIPA
:
744 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
745 /* header forwards */
747 case HDN_TRACKW
: return HDN_TRACKA
;
749 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
750 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
751 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
752 case HDN_ITEMCHANGINGA
:
753 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
754 case HDN_ITEMCHANGEDA
:
755 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
757 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
758 case HDN_DIVIDERDBLCLICKA
:
759 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
762 FIXME("unknown notification %x\n", unicodeNotificationCode
);
763 return unicodeNotificationCode
;
766 /* forwards header notifications to listview parent */
767 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
769 LPCWSTR text
= NULL
, filter
= NULL
;
771 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
773 /* on unicode format exit earlier */
774 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
775 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
778 /* header always supplies unicode notifications,
779 all we have to do is to convert strings to ANSI */
782 /* convert item text */
783 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
785 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
786 lpnmh
->pitem
->pszText
= NULL
;
787 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
789 /* convert filter text */
790 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
791 lpnmh
->pitem
->pvFilter
)
793 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
794 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= NULL
;
795 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
798 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
800 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
806 Free(lpnmh
->pitem
->pszText
);
807 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
811 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
812 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
818 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
822 TRACE("(code=%d)\n", code
);
824 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
825 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
827 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
829 TRACE(" <= %ld\n", result
);
834 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
837 HWND hwnd
= infoPtr
->hwndSelf
;
838 notify_hdr(infoPtr
, code
, &nmh
);
839 return IsWindow(hwnd
);
842 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
853 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
854 item
.iItem
= htInfo
->iItem
;
856 item
.stateMask
= (UINT
)-1;
857 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
858 nmia
.lParam
= item
.lParam
;
859 nmia
.uOldState
= item
.state
;
860 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
861 nmia
.uChanged
= LVIF_STATE
;
864 nmia
.iItem
= htInfo
->iItem
;
865 nmia
.iSubItem
= htInfo
->iSubItem
;
866 nmia
.ptAction
= htInfo
->pt
;
868 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
869 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
870 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
872 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
875 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
877 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
878 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
881 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
882 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
886 HWND hwnd
= infoPtr
->hwndSelf
;
889 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
890 ZeroMemory(&nmia
, sizeof(nmia
));
891 nmia
.iItem
= lvht
->iItem
;
892 nmia
.iSubItem
= lvht
->iSubItem
;
893 nmia
.ptAction
= lvht
->pt
;
894 item
.mask
= LVIF_PARAM
;
895 item
.iItem
= lvht
->iItem
;
897 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
898 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
899 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
902 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
906 HWND hwnd
= infoPtr
->hwndSelf
;
908 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
910 item
.mask
= LVIF_PARAM
;
913 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
914 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
915 return IsWindow(hwnd
);
919 Send notification. depends on dispinfoW having same
920 structure as dispinfoA.
921 infoPtr : listview struct
922 code : *Unicode* notification code
923 pdi : dispinfo structure (can be unicode or ansi)
924 isW : TRUE if dispinfo is Unicode
926 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
928 INT length
= 0, ret_length
;
929 LPWSTR buffer
= NULL
, ret_text
;
930 BOOL return_ansi
= FALSE
;
931 BOOL return_unicode
= FALSE
;
934 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
936 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
937 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
940 ret_length
= pdi
->item
.cchTextMax
;
941 ret_text
= pdi
->item
.pszText
;
943 if (return_unicode
|| return_ansi
)
945 if (code
!= LVN_GETDISPINFOW
)
947 length
= return_ansi
?
948 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
949 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
953 length
= pdi
->item
.cchTextMax
;
954 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
957 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
958 if (!buffer
) return FALSE
;
961 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
964 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
967 pdi
->item
.pszText
= buffer
;
968 pdi
->item
.cchTextMax
= length
;
971 if (infoPtr
->notifyFormat
== NFR_ANSI
)
972 code
= get_ansi_notification(code
);
974 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
975 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
976 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
978 if (return_ansi
|| return_unicode
)
980 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
982 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
984 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
986 strcpyW(ret_text
, pdi
->item
.pszText
);
988 else if (return_ansi
) /* note : pointer can be changed by app ! */
990 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
991 ret_length
, NULL
, NULL
);
994 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
995 ret_text
, ret_length
);
997 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
998 pdi
->item
.cchTextMax
= ret_length
;
1004 /* if dipsinfo holder changed notification code then convert */
1005 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1007 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1009 buffer
= Alloc(length
* sizeof(CHAR
));
1010 if (!buffer
) return FALSE
;
1012 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1013 ret_length
, NULL
, NULL
);
1015 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1022 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1023 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1025 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1026 lpnmlvcd
->nmcd
.hdc
= hdc
;
1027 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1028 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1029 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1030 if (!lplvItem
) return;
1031 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1032 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1033 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1034 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1035 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1036 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1039 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1041 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1044 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1045 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1046 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1047 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1048 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1049 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1053 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1055 COLORREF backcolor
, textcolor
;
1057 /* apparently, for selected items, we have to override the returned values */
1060 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1062 if (infoPtr
->bFocus
)
1064 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1065 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1067 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1069 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1070 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1075 backcolor
= lpnmlvcd
->clrTextBk
;
1076 textcolor
= lpnmlvcd
->clrText
;
1078 if (backcolor
== CLR_DEFAULT
)
1079 backcolor
= comctl32_color
.clrWindow
;
1080 if (textcolor
== CLR_DEFAULT
)
1081 textcolor
= comctl32_color
.clrWindowText
;
1083 /* Set the text attributes */
1084 if (backcolor
!= CLR_NONE
)
1086 SetBkMode(hdc
, OPAQUE
);
1087 SetBkColor(hdc
, backcolor
);
1090 SetBkMode(hdc
, TRANSPARENT
);
1091 SetTextColor(hdc
, textcolor
);
1094 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1096 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1099 /* returns TRUE when repaint needed, FALSE otherwise */
1100 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1102 MEASUREITEMSTRUCT mis
;
1103 mis
.CtlType
= ODT_LISTVIEW
;
1104 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1108 mis
.itemHeight
= infoPtr
->nItemHeight
;
1109 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1110 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1112 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1118 /******** Item iterator functions **********************************/
1120 static RANGES
ranges_create(int count
);
1121 static void ranges_destroy(RANGES ranges
);
1122 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1123 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1124 static void ranges_dump(RANGES ranges
);
1126 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1128 RANGE range
= { nItem
, nItem
+ 1 };
1130 return ranges_add(ranges
, range
);
1133 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1135 RANGE range
= { nItem
, nItem
+ 1 };
1137 return ranges_del(ranges
, range
);
1141 * ITERATOR DOCUMENTATION
1143 * The iterator functions allow for easy, and convenient iteration
1144 * over items of interest in the list. Typically, you create an
1145 * iterator, use it, and destroy it, as such:
1148 * iterator_xxxitems(&i, ...);
1149 * while (iterator_{prev,next}(&i)
1151 * //code which uses i.nItem
1153 * iterator_destroy(&i);
1155 * where xxx is either: framed, or visible.
1156 * Note that it is important that the code destroys the iterator
1157 * after it's done with it, as the creation of the iterator may
1158 * allocate memory, which thus needs to be freed.
1160 * You can iterate both forwards, and backwards through the list,
1161 * by using iterator_next or iterator_prev respectively.
1163 * Lower numbered items are draw on top of higher number items in
1164 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1165 * items may overlap). So, to test items, you should use
1167 * which lists the items top to bottom (in Z-order).
1168 * For drawing items, you should use
1170 * which lists the items bottom to top (in Z-order).
1171 * If you keep iterating over the items after the end-of-items
1172 * marker (-1) is returned, the iterator will start from the
1173 * beginning. Typically, you don't need to test for -1,
1174 * because iterator_{next,prev} will return TRUE if more items
1175 * are to be iterated over, or FALSE otherwise.
1177 * Note: the iterator is defined to be bidirectional. That is,
1178 * any number of prev followed by any number of next, or
1179 * five versa, should leave the iterator at the same item:
1180 * prev * n, next * n = next * n, prev * n
1182 * The iterator has a notion of an out-of-order, special item,
1183 * which sits at the start of the list. This is used in
1184 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1185 * which needs to be first, as it may overlap other items.
1187 * The code is a bit messy because we have:
1188 * - a special item to deal with
1189 * - simple range, or composite range
1191 * If you find bugs, or want to add features, please make sure you
1192 * always check/modify *both* iterator_prev, and iterator_next.
1196 * This function iterates through the items in increasing order,
1197 * but prefixed by the special item, then -1. That is:
1198 * special, 1, 2, 3, ..., n, -1.
1199 * Each item is listed only once.
1201 static inline BOOL
iterator_next(ITERATOR
* i
)
1205 i
->nItem
= i
->nSpecial
;
1206 if (i
->nItem
!= -1) return TRUE
;
1208 if (i
->nItem
== i
->nSpecial
)
1210 if (i
->ranges
) i
->index
= 0;
1216 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1217 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1222 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1223 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1226 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1228 i
->nItem
= i
->range
.lower
;
1229 if (i
->nItem
>= 0) goto testitem
;
1236 * This function iterates through the items in decreasing order,
1237 * followed by the special item, then -1. That is:
1238 * n, n-1, ..., 3, 2, 1, special, -1.
1239 * Each item is listed only once.
1241 static inline BOOL
iterator_prev(ITERATOR
* i
)
1248 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1251 if (i
->nItem
== i
->nSpecial
)
1259 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1260 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1266 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1269 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1271 i
->nItem
= i
->range
.upper
;
1272 if (i
->nItem
> 0) goto testitem
;
1274 return (i
->nItem
= i
->nSpecial
) != -1;
1277 static RANGE
iterator_range(const ITERATOR
*i
)
1281 if (!i
->ranges
) return i
->range
;
1283 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1285 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1286 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1288 else range
.lower
= range
.upper
= 0;
1294 * Releases resources associated with this iterator.
1296 static inline void iterator_destroy(const ITERATOR
*i
)
1298 ranges_destroy(i
->ranges
);
1302 * Create an empty iterator.
1304 static inline BOOL
iterator_empty(ITERATOR
* i
)
1306 ZeroMemory(i
, sizeof(*i
));
1307 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1312 * Create an iterator over a range.
1314 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1322 * Create an iterator over a bunch of ranges.
1323 * Please note that the iterator will take ownership of the ranges,
1324 * and will free them upon destruction.
1326 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1334 * Creates an iterator over the items which intersect frame.
1335 * Uses absolute coordinates rather than compensating for the current offset.
1337 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1339 RECT rcItem
, rcTemp
;
1341 /* in case we fail, we want to return an empty iterator */
1342 if (!iterator_empty(i
)) return FALSE
;
1344 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1346 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1350 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1352 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1353 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1354 i
->nSpecial
= infoPtr
->nFocusedItem
;
1356 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1357 /* to do better here, we need to have PosX, and PosY sorted */
1358 TRACE("building icon ranges:\n");
1359 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1361 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1362 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1363 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1364 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1365 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1366 ranges_additem(i
->ranges
, nItem
);
1370 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1374 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1375 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1377 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1378 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1379 if (range
.upper
<= range
.lower
) return TRUE
;
1380 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1381 TRACE(" report=%s\n", debugrange(&i
->range
));
1385 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1386 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1387 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1394 if (infoPtr
->nItemWidth
)
1396 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1397 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1401 nFirstCol
= max(frame
->left
, 0);
1402 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1405 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1407 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1408 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1410 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1412 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1413 TRACE("building list ranges:\n");
1414 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1416 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1417 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1418 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1419 TRACE(" list=%s\n", debugrange(&item_range
));
1420 ranges_add(i
->ranges
, item_range
);
1428 * Creates an iterator over the items which intersect lprc.
1430 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1435 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1437 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1438 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1440 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1444 * Creates an iterator over the items which intersect the visible region of hdc.
1446 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1448 POINT Origin
, Position
;
1449 RECT rcItem
, rcClip
;
1452 rgntype
= GetClipBox(hdc
, &rcClip
);
1453 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1454 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1455 if (rgntype
== SIMPLEREGION
) return TRUE
;
1457 /* first deal with the special item */
1458 if (i
->nSpecial
!= -1)
1460 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1461 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1464 /* if we can't deal with the region, we'll just go with the simple range */
1465 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1466 TRACE("building visible range:\n");
1467 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1469 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1470 if (!ranges_add(i
->ranges
, i
->range
))
1472 ranges_destroy(i
->ranges
);
1478 /* now delete the invisible items from the list */
1479 while(iterator_next(i
))
1481 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1482 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1483 rcItem
.top
= Position
.y
+ Origin
.y
;
1484 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1485 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1486 if (!RectVisible(hdc
, &rcItem
))
1487 ranges_delitem(i
->ranges
, i
->nItem
);
1489 /* the iterator should restart on the next iterator_next */
1495 /* Remove common elements from two iterators */
1496 /* Passed iterators have to point on the first elements */
1497 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1499 if(!iter1
->ranges
|| !iter2
->ranges
) {
1502 if(iter1
->ranges
|| iter2
->ranges
||
1503 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1504 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1505 ERR("result is not a one range iterator\n");
1509 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1512 lower
= iter1
->range
.lower
;
1513 upper
= iter1
->range
.upper
;
1515 if(lower
< iter2
->range
.lower
)
1516 iter1
->range
.upper
= iter2
->range
.lower
;
1517 else if(upper
> iter2
->range
.upper
)
1518 iter1
->range
.lower
= iter2
->range
.upper
;
1520 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1522 if(iter2
->range
.lower
< lower
)
1523 iter2
->range
.upper
= lower
;
1524 else if(iter2
->range
.upper
> upper
)
1525 iter2
->range
.lower
= upper
;
1527 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1532 iterator_next(iter1
);
1533 iterator_next(iter2
);
1536 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1539 if(iter1
->nItem
== iter2
->nItem
) {
1540 int delete = iter1
->nItem
;
1542 iterator_prev(iter1
);
1543 iterator_prev(iter2
);
1544 ranges_delitem(iter1
->ranges
, delete);
1545 ranges_delitem(iter2
->ranges
, delete);
1546 iterator_next(iter1
);
1547 iterator_next(iter2
);
1548 } else if(iter1
->nItem
> iter2
->nItem
)
1549 iterator_next(iter2
);
1551 iterator_next(iter1
);
1554 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1555 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1559 /******** Misc helper functions ************************************/
1561 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1562 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1564 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1565 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1568 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1570 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1571 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1574 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1576 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1577 if(state
== 1 || state
== 2)
1581 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1582 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1583 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1587 /* this should be called after window style got updated,
1588 it used to reset view state to match current window style */
1589 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1591 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1594 infoPtr
->uView
= LV_VIEW_ICON
;
1597 infoPtr
->uView
= LV_VIEW_DETAILS
;
1600 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1603 infoPtr
->uView
= LV_VIEW_LIST
;
1607 /* computes next item id value */
1608 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1610 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1614 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1615 return lpID
->id
+ 1;
1620 /******** Internal API functions ************************************/
1622 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1624 static COLUMN_INFO mainItem
;
1626 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1627 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1629 /* update cached column rectangles */
1630 if (infoPtr
->colRectsDirty
)
1633 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1636 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1637 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1638 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1640 Ptr
->colRectsDirty
= FALSE
;
1643 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1646 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1648 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1651 if (infoPtr
->hwndHeader
) return 0;
1653 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1655 /* setup creation flags */
1656 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1657 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1659 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1662 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1663 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1664 if (!infoPtr
->hwndHeader
) return -1;
1666 /* set header unicode format */
1667 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1669 /* set header font */
1670 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1672 /* set header image list */
1673 if (infoPtr
->himlSmall
)
1674 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1676 LISTVIEW_UpdateSize(infoPtr
);
1681 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1683 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1686 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1688 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1689 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1690 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1693 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1695 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1698 /* used to handle collapse main item column case */
1699 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1701 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1702 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1705 /* Listview invalidation functions: use _only_ these functions to invalidate */
1707 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1709 return infoPtr
->bRedraw
;
1712 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1714 if(!is_redrawing(infoPtr
)) return;
1715 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1716 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1719 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1723 if(!is_redrawing(infoPtr
)) return;
1724 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1725 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1728 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1730 POINT Origin
, Position
;
1733 if(!is_redrawing(infoPtr
)) return;
1734 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1735 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1736 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1737 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1739 rcBox
.bottom
= infoPtr
->nItemHeight
;
1740 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1741 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1744 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1746 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1749 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1753 if(!is_redrawing(infoPtr
)) return;
1754 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1755 rcCol
.top
= infoPtr
->rcList
.top
;
1756 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1757 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1762 * Retrieves the number of items that can fit vertically in the client area.
1765 * [I] infoPtr : valid pointer to the listview structure
1768 * Number of items per row.
1770 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1772 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1774 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1779 * Retrieves the number of items that can fit horizontally in the client
1783 * [I] infoPtr : valid pointer to the listview structure
1786 * Number of items per column.
1788 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1790 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1792 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1796 /*************************************************************************
1797 * LISTVIEW_ProcessLetterKeys
1799 * Processes keyboard messages generated by pressing the letter keys
1801 * What this does is perform a case insensitive search from the
1802 * current position with the following quirks:
1803 * - If two chars or more are pressed in quick succession we search
1804 * for the corresponding string (e.g. 'abc').
1805 * - If there is a delay we wipe away the current search string and
1806 * restart with just that char.
1807 * - If the user keeps pressing the same character, whether slowly or
1808 * fast, so that the search string is entirely composed of this
1809 * character ('aaaaa' for instance), then we search for first item
1810 * that starting with that character.
1811 * - If the user types the above character in quick succession, then
1812 * we must also search for the corresponding string ('aaaaa'), and
1813 * go to that string if there is a match.
1816 * [I] hwnd : handle to the window
1817 * [I] charCode : the character code, the actual character
1818 * [I] keyData : key data
1826 * - The current implementation has a list of characters it will
1827 * accept and it ignores everything else. In particular it will
1828 * ignore accentuated characters which seems to match what
1829 * Windows does. But I'm not sure it makes sense to follow
1831 * - We don't sound a beep when the search fails.
1835 * TREEVIEW_ProcessLetterKeys
1837 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1839 WCHAR buffer
[MAX_PATH
];
1846 /* simple parameter checking */
1847 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1849 /* only allow the valid WM_CHARs through */
1850 if (!isalnumW(charCode
) &&
1851 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1852 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1853 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1854 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1855 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1856 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1857 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1858 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1859 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1862 /* update the search parameters */
1863 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1864 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1865 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1867 if (diff
>= 0 && diff
< KEY_DELAY
)
1869 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1870 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1872 if (infoPtr
->charCode
!= charCode
)
1873 infoPtr
->charCode
= charCode
= 0;
1877 infoPtr
->charCode
= charCode
;
1878 infoPtr
->szSearchParam
[0] = charCode
;
1879 infoPtr
->nSearchParamLength
= 1;
1882 /* should start from next after focused item, so next item that matches
1883 will be selected, if there isn't any and focused matches it will be selected
1884 on second search stage from beginning of the list */
1885 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1887 /* with some accumulated search data available start with current focus, otherwise
1888 it's excluded from search */
1889 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1890 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1895 /* let application handle this for virtual listview */
1896 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1900 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1901 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1902 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1903 nmlv
.iStart
= startidx
;
1905 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1907 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1911 int i
= startidx
, endidx
;
1913 /* and search from the current position */
1915 endidx
= infoPtr
->nItemCount
;
1917 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1920 /* start from first item if not found with >= startidx */
1921 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1927 for (i
= startidx
; i
< endidx
; i
++)
1930 item
.mask
= LVIF_TEXT
;
1933 item
.pszText
= buffer
;
1934 item
.cchTextMax
= MAX_PATH
;
1935 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1937 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1942 /* this is used to find first char match when search string is not available yet,
1943 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1944 already waiting for user to complete a string */
1945 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1947 /* this would work but we must keep looking for a longer match */
1952 if ( nItem
!= -1 || /* found something */
1953 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1954 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1960 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1965 /*************************************************************************
1966 * LISTVIEW_UpdateHeaderSize [Internal]
1968 * Function to resize the header control
1971 * [I] hwnd : handle to a window
1972 * [I] nNewScrollPos : scroll pos to set
1977 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1982 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1984 if (!infoPtr
->hwndHeader
) return;
1986 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1987 point
[0].x
= winRect
.left
;
1988 point
[0].y
= winRect
.top
;
1989 point
[1].x
= winRect
.right
;
1990 point
[1].y
= winRect
.bottom
;
1992 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1993 point
[0].x
= -nNewScrollPos
;
1994 point
[1].x
+= nNewScrollPos
;
1996 SetWindowPos(infoPtr
->hwndHeader
,0,
1997 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1998 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1999 SWP_NOZORDER
| SWP_NOACTIVATE
);
2004 * Update the scrollbars. This functions should be called whenever
2005 * the content, size or view changes.
2008 * [I] infoPtr : valid pointer to the listview structure
2013 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2015 SCROLLINFO horzInfo
, vertInfo
;
2018 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2020 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2021 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2022 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2024 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2025 if (infoPtr
->uView
== LV_VIEW_LIST
)
2027 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2028 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2030 /* scroll by at least one column per page */
2031 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2032 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2034 if (infoPtr
->nItemWidth
)
2035 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2037 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2039 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2041 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2045 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2048 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2050 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2055 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2056 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2058 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2059 horzInfo
.nMax
= rcHeader
.right
;
2060 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2064 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2065 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2066 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2067 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2068 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2070 /* Setting the horizontal scroll can change the listview size
2071 * (and potentially everything else) so we need to recompute
2072 * everything again for the vertical scroll
2075 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2076 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2077 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2079 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2081 vertInfo
.nMax
= infoPtr
->nItemCount
;
2083 /* scroll by at least one page */
2084 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2085 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2087 if (infoPtr
->nItemHeight
> 0)
2088 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2090 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2094 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2097 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2098 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2099 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2100 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2101 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2103 /* Change of the range may have changed the scroll pos. If so move the content */
2104 if (dx
!= 0 || dy
!= 0)
2107 listRect
= infoPtr
->rcList
;
2108 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2109 SW_ERASE
| SW_INVALIDATE
);
2112 /* Update the Header Control */
2113 if (infoPtr
->hwndHeader
)
2115 horzInfo
.fMask
= SIF_POS
;
2116 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2117 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2124 * Shows/hides the focus rectangle.
2127 * [I] infoPtr : valid pointer to the listview structure
2128 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2133 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2137 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2139 if (infoPtr
->nFocusedItem
< 0) return;
2141 /* we need some gymnastics in ICON mode to handle large items */
2142 if (infoPtr
->uView
== LV_VIEW_ICON
)
2146 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2147 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2149 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2154 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2156 /* for some reason, owner draw should work only in report mode */
2157 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2162 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2163 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2165 item
.iItem
= infoPtr
->nFocusedItem
;
2167 item
.mask
= LVIF_PARAM
;
2168 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2170 ZeroMemory(&dis
, sizeof(dis
));
2171 dis
.CtlType
= ODT_LISTVIEW
;
2172 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2173 dis
.itemID
= item
.iItem
;
2174 dis
.itemAction
= ODA_FOCUS
;
2175 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2176 dis
.hwndItem
= infoPtr
->hwndSelf
;
2178 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2179 dis
.itemData
= item
.lParam
;
2181 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2183 SelectObject(hdc
, hOldFont
);
2187 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2190 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2194 * Invalidates all visible selected items.
2196 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2200 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2201 while(iterator_next(&i
))
2203 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2204 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2206 iterator_destroy(&i
);
2211 * DESCRIPTION: [INTERNAL]
2212 * Computes an item's (left,top) corner, relative to rcView.
2213 * That is, the position has NOT been made relative to the Origin.
2214 * This is deliberate, to avoid computing the Origin over, and
2215 * over again, when this function is called in a loop. Instead,
2216 * one can factor the computation of the Origin before the loop,
2217 * and offset the value returned by this function, on every iteration.
2220 * [I] infoPtr : valid pointer to the listview structure
2221 * [I] nItem : item number
2222 * [O] lpptOrig : item top, left corner
2227 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2229 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2231 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2233 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2234 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2236 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2238 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2239 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2240 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2242 else /* LV_VIEW_DETAILS */
2244 lpptPosition
->x
= REPORT_MARGINX
;
2245 /* item is always at zero indexed column */
2246 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2247 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2248 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2253 * DESCRIPTION: [INTERNAL]
2254 * Compute the rectangles of an item. This is to localize all
2255 * the computations in one place. If you are not interested in some
2256 * of these values, simply pass in a NULL -- the function is smart
2257 * enough to compute only what's necessary. The function computes
2258 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2259 * one, the BOX rectangle. This rectangle is very cheap to compute,
2260 * and is guaranteed to contain all the other rectangles. Computing
2261 * the ICON rect is also cheap, but all the others are potentially
2262 * expensive. This gives an easy and effective optimization when
2263 * searching (like point inclusion, or rectangle intersection):
2264 * first test against the BOX, and if TRUE, test against the desired
2266 * If the function does not have all the necessary information
2267 * to computed the requested rectangles, will crash with a
2268 * failed assertion. This is done so we catch all programming
2269 * errors, given that the function is called only from our code.
2271 * We have the following 'special' meanings for a few fields:
2272 * * If LVIS_FOCUSED is set, we assume the item has the focus
2273 * This is important in ICON mode, where it might get a larger
2274 * then usual rectangle
2276 * Please note that subitem support works only in REPORT mode.
2279 * [I] infoPtr : valid pointer to the listview structure
2280 * [I] lpLVItem : item to compute the measures for
2281 * [O] lprcBox : ptr to Box rectangle
2282 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2283 * [0] lprcSelectBox : ptr to select box rectangle
2284 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2285 * [O] lprcIcon : ptr to Icon rectangle
2286 * Same as LVM_GETITEMRECT with LVIR_ICON
2287 * [O] lprcStateIcon: ptr to State Icon rectangle
2288 * [O] lprcLabel : ptr to Label rectangle
2289 * Same as LVM_GETITEMRECT with LVIR_LABEL
2294 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2295 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2296 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2298 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2299 RECT Box
, SelectBox
, Icon
, Label
;
2300 COLUMN_INFO
*lpColumnInfo
= NULL
;
2301 SIZE labelSize
= { 0, 0 };
2303 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2305 /* Be smart and try to figure out the minimum we have to do */
2306 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2307 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2309 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2310 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2312 if (lprcSelectBox
) doSelectBox
= TRUE
;
2313 if (lprcLabel
) doLabel
= TRUE
;
2314 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2321 /************************************************************/
2322 /* compute the box rectangle (it should be cheap to do) */
2323 /************************************************************/
2324 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2325 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2327 if (lpLVItem
->iSubItem
)
2329 Box
= lpColumnInfo
->rcHeader
;
2334 Box
.right
= infoPtr
->nItemWidth
;
2337 Box
.bottom
= infoPtr
->nItemHeight
;
2339 /******************************************************************/
2340 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2341 /******************************************************************/
2344 LONG state_width
= 0;
2346 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2347 state_width
= infoPtr
->iconStateSize
.cx
;
2349 if (infoPtr
->uView
== LV_VIEW_ICON
)
2351 Icon
.left
= Box
.left
+ state_width
;
2352 if (infoPtr
->himlNormal
)
2353 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2354 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2355 Icon
.right
= Icon
.left
;
2356 Icon
.bottom
= Icon
.top
;
2357 if (infoPtr
->himlNormal
)
2359 Icon
.right
+= infoPtr
->iconSize
.cx
;
2360 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2363 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2365 Icon
.left
= Box
.left
+ state_width
;
2367 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2369 /* we need the indent in report mode */
2370 assert(lpLVItem
->mask
& LVIF_INDENT
);
2371 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2375 Icon
.right
= Icon
.left
;
2376 if (infoPtr
->himlSmall
&&
2377 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2378 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2379 Icon
.right
+= infoPtr
->iconSize
.cx
;
2380 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2382 if(lprcIcon
) *lprcIcon
= Icon
;
2383 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2385 /* TODO: is this correct? */
2388 lprcStateIcon
->left
= Icon
.left
- state_width
;
2389 lprcStateIcon
->right
= Icon
.left
;
2390 lprcStateIcon
->top
= Icon
.top
;
2391 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2392 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2395 else Icon
.right
= 0;
2397 /************************************************************/
2398 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2399 /************************************************************/
2402 /* calculate how far to the right can the label stretch */
2403 Label
.right
= Box
.right
;
2404 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2406 if (lpLVItem
->iSubItem
== 0)
2408 /* we need a zero based rect here */
2409 Label
= lpColumnInfo
->rcHeader
;
2410 OffsetRect(&Label
, -Label
.left
, 0);
2414 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2416 labelSize
.cx
= infoPtr
->nItemWidth
;
2417 labelSize
.cy
= infoPtr
->nItemHeight
;
2421 /* we need the text in non owner draw mode */
2422 assert(lpLVItem
->mask
& LVIF_TEXT
);
2423 if (is_text(lpLVItem
->pszText
))
2425 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2426 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2427 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2431 /* compute rough rectangle where the label will go */
2432 SetRectEmpty(&rcText
);
2433 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2434 rcText
.bottom
= infoPtr
->nItemHeight
;
2435 if (infoPtr
->uView
== LV_VIEW_ICON
)
2436 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2438 /* now figure out the flags */
2439 if (infoPtr
->uView
== LV_VIEW_ICON
)
2440 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2442 uFormat
= LV_SL_DT_FLAGS
;
2444 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2446 if (rcText
.right
!= rcText
.left
)
2447 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2449 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2451 SelectObject(hdc
, hOldFont
);
2452 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2456 if (infoPtr
->uView
== LV_VIEW_ICON
)
2458 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2459 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2460 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2461 Label
.right
= Label
.left
+ labelSize
.cx
;
2462 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2463 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2465 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2466 labelSize
.cy
/= infoPtr
->ntmHeight
;
2467 labelSize
.cy
= max(labelSize
.cy
, 1);
2468 labelSize
.cy
*= infoPtr
->ntmHeight
;
2470 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2472 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2474 Label
.left
= Icon
.right
;
2475 Label
.top
= Box
.top
;
2476 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2477 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2478 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2480 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2482 Label
.left
= Icon
.right
;
2483 Label
.top
= Box
.top
;
2484 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2485 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2488 if (lprcLabel
) *lprcLabel
= Label
;
2489 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2492 /************************************************************/
2493 /* compute SELECT bounding box */
2494 /************************************************************/
2497 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2499 SelectBox
.left
= Icon
.left
;
2500 SelectBox
.top
= Box
.top
;
2501 SelectBox
.bottom
= Box
.bottom
;
2504 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2506 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2510 UnionRect(&SelectBox
, &Icon
, &Label
);
2512 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2513 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2516 /* Fix the Box if necessary */
2519 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2520 else *lprcBox
= Box
;
2522 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2526 * DESCRIPTION: [INTERNAL]
2529 * [I] infoPtr : valid pointer to the listview structure
2530 * [I] nItem : item number
2531 * [O] lprcBox : ptr to Box rectangle
2536 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2538 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2539 POINT Position
, Origin
;
2542 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2543 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2545 /* Be smart and try to figure out the minimum we have to do */
2547 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2548 lvItem
.mask
|= LVIF_TEXT
;
2549 lvItem
.iItem
= nItem
;
2550 lvItem
.iSubItem
= 0;
2551 lvItem
.pszText
= szDispText
;
2552 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2553 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2554 if (infoPtr
->uView
== LV_VIEW_ICON
)
2556 lvItem
.mask
|= LVIF_STATE
;
2557 lvItem
.stateMask
= LVIS_FOCUSED
;
2558 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2560 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2562 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2563 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2565 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2568 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2571 /* LISTVIEW_MapIdToIndex helper */
2572 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2574 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2575 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2577 if (id1
->id
== id2
->id
) return 0;
2579 return (id1
->id
< id2
->id
) ? -1 : 1;
2584 * Returns the item index for id specified.
2587 * [I] infoPtr : valid pointer to the listview structure
2588 * [I] iID : item id to get index for
2591 * Item index, or -1 on failure.
2593 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2598 TRACE("iID=%d\n", iID
);
2600 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2601 if (infoPtr
->nItemCount
== 0) return -1;
2604 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2608 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2609 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2617 * Returns the item id for index given.
2620 * [I] infoPtr : valid pointer to the listview structure
2621 * [I] iItem : item index to get id for
2626 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2631 TRACE("iItem=%d\n", iItem
);
2633 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2634 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2636 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2637 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2639 return lpItem
->id
->id
;
2644 * Returns the current icon position, and advances it along the top.
2645 * The returned position is not offset by Origin.
2648 * [I] infoPtr : valid pointer to the listview structure
2649 * [O] lpPos : will get the current icon position
2654 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2656 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2658 *lpPos
= infoPtr
->currIconPos
;
2660 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2661 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2663 infoPtr
->currIconPos
.x
= 0;
2664 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2670 * Returns the current icon position, and advances it down the left edge.
2671 * The returned position is not offset by Origin.
2674 * [I] infoPtr : valid pointer to the listview structure
2675 * [O] lpPos : will get the current icon position
2680 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2682 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2684 *lpPos
= infoPtr
->currIconPos
;
2686 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2687 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2689 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2690 infoPtr
->currIconPos
.y
= 0;
2696 * Moves an icon to the specified position.
2697 * It takes care of invalidating the item, etc.
2700 * [I] infoPtr : valid pointer to the listview structure
2701 * [I] nItem : the item to move
2702 * [I] lpPos : the new icon position
2703 * [I] isNew : flags the item as being new
2709 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2715 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2716 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2718 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2719 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2722 /* Allocating a POINTER for every item is too resource intensive,
2723 * so we'll keep the (x,y) in different arrays */
2724 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2725 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2727 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2734 * Arranges listview items in icon display mode.
2737 * [I] infoPtr : valid pointer to the listview structure
2738 * [I] nAlignCode : alignment code
2744 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2746 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2750 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2752 TRACE("nAlignCode=%d\n", nAlignCode
);
2754 if (nAlignCode
== LVA_DEFAULT
)
2756 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2757 else nAlignCode
= LVA_ALIGNTOP
;
2762 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2763 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2764 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2765 default: return FALSE
;
2768 infoPtr
->bAutoarrange
= TRUE
;
2769 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2770 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2772 next_pos(infoPtr
, &pos
);
2773 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2781 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2782 * For LVS_REPORT always returns empty rectangle.
2785 * [I] infoPtr : valid pointer to the listview structure
2786 * [O] lprcView : bounding rectangle
2792 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2796 SetRectEmpty(lprcView
);
2798 switch (infoPtr
->uView
)
2801 case LV_VIEW_SMALLICON
:
2802 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2804 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2805 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2806 lprcView
->right
= max(lprcView
->right
, x
);
2807 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2809 if (infoPtr
->nItemCount
> 0)
2811 lprcView
->right
+= infoPtr
->nItemWidth
;
2812 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2817 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2818 x
= infoPtr
->nItemCount
/ y
;
2819 if (infoPtr
->nItemCount
% y
) x
++;
2820 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2821 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2828 * Retrieves the bounding rectangle of all the items.
2831 * [I] infoPtr : valid pointer to the listview structure
2832 * [O] lprcView : bounding rectangle
2838 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2842 TRACE("(lprcView=%p)\n", lprcView
);
2844 if (!lprcView
) return FALSE
;
2846 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2848 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2850 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2851 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2854 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2861 * Retrieves the subitem pointer associated with the subitem index.
2864 * [I] hdpaSubItems : DPA handle for a specific item
2865 * [I] nSubItem : index of subitem
2868 * SUCCESS : subitem pointer
2871 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2873 SUBITEM_INFO
*lpSubItem
;
2876 /* we should binary search here if need be */
2877 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2879 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2880 if (lpSubItem
->iSubItem
== nSubItem
)
2890 * Calculates the desired item width.
2893 * [I] infoPtr : valid pointer to the listview structure
2896 * The desired item width.
2898 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2902 TRACE("uView=%d\n", infoPtr
->uView
);
2904 if (infoPtr
->uView
== LV_VIEW_ICON
)
2905 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2906 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2908 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2913 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2914 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2916 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2917 nItemWidth
= rcHeader
.right
;
2920 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2922 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2926 lvItem
.mask
= LVIF_TEXT
;
2927 lvItem
.iSubItem
= 0;
2929 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2932 lvItem
.pszText
= szDispText
;
2933 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2934 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2935 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2939 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2940 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2942 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2950 * Calculates the desired item height.
2953 * [I] infoPtr : valid pointer to the listview structure
2956 * The desired item height.
2958 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2962 TRACE("uView=%d\n", infoPtr
->uView
);
2964 if (infoPtr
->uView
== LV_VIEW_ICON
)
2965 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2968 nItemHeight
= infoPtr
->ntmHeight
;
2969 if (infoPtr
->himlState
)
2970 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2971 if (infoPtr
->himlSmall
)
2972 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2973 nItemHeight
+= HEIGHT_PADDING
;
2974 if (infoPtr
->nMeasureItemHeight
> 0)
2975 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2978 return max(nItemHeight
, 1);
2983 * Updates the width, and height of an item.
2986 * [I] infoPtr : valid pointer to the listview structure
2991 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2993 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2994 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3000 * Retrieves and saves important text metrics info for the current
3004 * [I] infoPtr : valid pointer to the listview structure
3007 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3009 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3010 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3011 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3015 if (GetTextMetricsW(hdc
, &tm
))
3017 infoPtr
->ntmHeight
= tm
.tmHeight
;
3018 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3021 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3022 infoPtr
->nEllipsisWidth
= sz
.cx
;
3024 SelectObject(hdc
, hOldFont
);
3025 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3027 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3032 * A compare function for ranges
3035 * [I] range1 : pointer to range 1;
3036 * [I] range2 : pointer to range 2;
3040 * > 0 : if range 1 > range 2
3041 * < 0 : if range 2 > range 1
3042 * = 0 : if range intersects range 2
3044 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3048 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3050 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3055 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3060 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3062 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3067 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3069 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3070 ranges_dump(ranges
);
3071 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3073 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3074 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3075 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3077 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3078 assert (prev
->upper
<= curr
->lower
);
3079 assert (curr
->lower
< curr
->upper
);
3083 TRACE("--- Done checking---\n");
3086 static RANGES
ranges_create(int count
)
3088 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3089 if (!ranges
) return NULL
;
3090 ranges
->hdpa
= DPA_Create(count
);
3091 if (ranges
->hdpa
) return ranges
;
3096 static void ranges_clear(RANGES ranges
)
3100 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3101 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3102 DPA_DeleteAllPtrs(ranges
->hdpa
);
3106 static void ranges_destroy(RANGES ranges
)
3108 if (!ranges
) return;
3109 ranges_clear(ranges
);
3110 DPA_Destroy(ranges
->hdpa
);
3114 static RANGES
ranges_clone(RANGES ranges
)
3119 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3121 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3123 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3124 if (!newrng
) goto fail
;
3125 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3126 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
3131 TRACE ("clone failed\n");
3132 ranges_destroy(clone
);
3136 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3140 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3141 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3146 static void ranges_dump(RANGES ranges
)
3150 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3151 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3154 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3156 RANGE srchrng
= { nItem
, nItem
+ 1 };
3158 TRACE("(nItem=%d)\n", nItem
);
3159 ranges_check(ranges
, "before contain");
3160 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3163 static INT
ranges_itemcount(RANGES ranges
)
3167 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3169 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3170 count
+= sel
->upper
- sel
->lower
;
3176 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3178 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3181 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3182 if (index
== -1) return TRUE
;
3184 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3186 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3187 if (chkrng
->lower
>= nItem
)
3188 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3189 if (chkrng
->upper
> nItem
)
3190 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3195 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3200 TRACE("(%s)\n", debugrange(&range
));
3201 ranges_check(ranges
, "before add");
3203 /* try find overlapping regions first */
3204 srchrgn
.lower
= range
.lower
- 1;
3205 srchrgn
.upper
= range
.upper
+ 1;
3206 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3212 TRACE("Adding new range\n");
3214 /* create the brand new range to insert */
3215 newrgn
= Alloc(sizeof(RANGE
));
3216 if(!newrgn
) goto fail
;
3219 /* figure out where to insert it */
3220 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3221 TRACE("index=%d\n", index
);
3222 if (index
== -1) index
= 0;
3224 /* and get it over with */
3225 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3233 RANGE
*chkrgn
, *mrgrgn
;
3234 INT fromindex
, mergeindex
;
3236 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3237 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3239 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3240 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3242 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3244 /* merge now common ranges */
3246 srchrgn
.lower
= chkrgn
->lower
- 1;
3247 srchrgn
.upper
= chkrgn
->upper
+ 1;
3251 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3252 if (mergeindex
== -1) break;
3253 if (mergeindex
== index
)
3255 fromindex
= index
+ 1;
3259 TRACE("Merge with index %i\n", mergeindex
);
3261 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3262 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3263 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3265 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3266 if (mergeindex
< index
) index
--;
3270 ranges_check(ranges
, "after add");
3274 ranges_check(ranges
, "failed add");
3278 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3283 TRACE("(%s)\n", debugrange(&range
));
3284 ranges_check(ranges
, "before del");
3286 /* we don't use DPAS_SORTED here, since we need *
3287 * to find the first overlapping range */
3288 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3291 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3293 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3295 /* case 1: Same range */
3296 if ( (chkrgn
->upper
== range
.upper
) &&
3297 (chkrgn
->lower
== range
.lower
) )
3299 DPA_DeletePtr(ranges
->hdpa
, index
);
3303 /* case 2: engulf */
3304 else if ( (chkrgn
->upper
<= range
.upper
) &&
3305 (chkrgn
->lower
>= range
.lower
) )
3307 DPA_DeletePtr(ranges
->hdpa
, index
);
3310 /* case 3: overlap upper */
3311 else if ( (chkrgn
->upper
<= range
.upper
) &&
3312 (chkrgn
->lower
< range
.lower
) )
3314 chkrgn
->upper
= range
.lower
;
3316 /* case 4: overlap lower */
3317 else if ( (chkrgn
->upper
> range
.upper
) &&
3318 (chkrgn
->lower
>= range
.lower
) )
3320 chkrgn
->lower
= range
.upper
;
3323 /* case 5: fully internal */
3328 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3329 newrgn
->lower
= chkrgn
->lower
;
3330 newrgn
->upper
= range
.lower
;
3331 chkrgn
->lower
= range
.upper
;
3332 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3340 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3343 ranges_check(ranges
, "after del");
3347 ranges_check(ranges
, "failed del");
3353 * Removes all selection ranges
3356 * [I] infoPtr : valid pointer to the listview structure
3357 * [I] toSkip : item range to skip removing the selection
3363 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3372 lvItem
.stateMask
= LVIS_SELECTED
;
3374 /* need to clone the DPA because callbacks can change it */
3375 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3376 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3377 while(iterator_next(&i
))
3378 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3379 /* note that the iterator destructor will free the cloned range */
3380 iterator_destroy(&i
);
3385 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3389 if (!(toSkip
= ranges_create(1))) return FALSE
;
3390 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3391 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3392 ranges_destroy(toSkip
);
3396 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3398 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3403 * Retrieves the number of items that are marked as selected.
3406 * [I] infoPtr : valid pointer to the listview structure
3409 * Number of items selected.
3411 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3413 INT nSelectedCount
= 0;
3415 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3418 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3420 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3425 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3427 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3428 return nSelectedCount
;
3433 * Manages the item focus.
3436 * [I] infoPtr : valid pointer to the listview structure
3437 * [I] nItem : item index
3440 * TRUE : focused item changed
3441 * FALSE : focused item has NOT changed
3443 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3445 INT oldFocus
= infoPtr
->nFocusedItem
;
3448 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3450 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3451 lvItem
.stateMask
= LVIS_FOCUSED
;
3452 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3454 return oldFocus
!= infoPtr
->nFocusedItem
;
3457 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3459 if (nShiftItem
< nItem
) return nShiftItem
;
3461 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3463 if (direction
> 0) return nShiftItem
+ direction
;
3465 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3468 /* This function updates focus index.
3471 focus : current focus index
3472 item : index of item to be added/removed
3473 direction : add/remove flag
3475 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3477 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3479 infoPtr
->bDoChangeNotify
= FALSE
;
3480 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3481 if (focus
!= infoPtr
->nFocusedItem
)
3482 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3483 infoPtr
->bDoChangeNotify
= old_change
;
3488 * Updates the various indices after an item has been inserted or deleted.
3491 * [I] infoPtr : valid pointer to the listview structure
3492 * [I] nItem : item index
3493 * [I] direction : Direction of shift, +1 or -1.
3498 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3500 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3502 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3503 assert(abs(direction
) == 1);
3504 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3506 /* But we are not supposed to modify nHotItem! */
3511 * Adds a block of selections.
3514 * [I] infoPtr : valid pointer to the listview structure
3515 * [I] nItem : item index
3518 * Whether the window is still valid.
3520 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3522 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3523 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3524 HWND hwndSelf
= infoPtr
->hwndSelf
;
3525 NMLVODSTATECHANGE nmlv
;
3530 /* Temporarily disable change notification
3531 * If the control is LVS_OWNERDATA, we need to send
3532 * only one LVN_ODSTATECHANGED notification.
3533 * See MSDN documentation for LVN_ITEMCHANGED.
3535 bOldChange
= infoPtr
->bDoChangeNotify
;
3536 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3538 if (nFirst
== -1) nFirst
= nItem
;
3540 item
.state
= LVIS_SELECTED
;
3541 item
.stateMask
= LVIS_SELECTED
;
3543 for (i
= nFirst
; i
<= nLast
; i
++)
3544 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3546 ZeroMemory(&nmlv
, sizeof(nmlv
));
3547 nmlv
.iFrom
= nFirst
;
3550 nmlv
.uNewState
= item
.state
;
3552 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3553 if (!IsWindow(hwndSelf
))
3555 infoPtr
->bDoChangeNotify
= bOldChange
;
3562 * Sets a single group selection.
3565 * [I] infoPtr : valid pointer to the listview structure
3566 * [I] nItem : item index
3571 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3578 if (!(selection
= ranges_create(100))) return;
3580 item
.state
= LVIS_SELECTED
;
3581 item
.stateMask
= LVIS_SELECTED
;
3583 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3585 if (infoPtr
->nSelectionMark
== -1)
3587 infoPtr
->nSelectionMark
= nItem
;
3588 ranges_additem(selection
, nItem
);
3594 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3595 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3596 ranges_add(selection
, sel
);
3601 RECT rcItem
, rcSel
, rcSelMark
;
3604 rcItem
.left
= LVIR_BOUNDS
;
3605 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3606 ranges_destroy (selection
);
3609 rcSelMark
.left
= LVIR_BOUNDS
;
3610 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3611 ranges_destroy (selection
);
3614 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3615 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3616 while(iterator_next(&i
))
3618 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3619 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3621 iterator_destroy(&i
);
3624 /* disable per item notifications on LVS_OWNERDATA style
3625 FIXME: single LVN_ODSTATECHANGED should be used */
3626 bOldChange
= infoPtr
->bDoChangeNotify
;
3627 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3629 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3632 iterator_rangesitems(&i
, selection
);
3633 while(iterator_next(&i
))
3634 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3635 /* this will also destroy the selection */
3636 iterator_destroy(&i
);
3638 infoPtr
->bDoChangeNotify
= bOldChange
;
3640 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3645 * Sets a single selection.
3648 * [I] infoPtr : valid pointer to the listview structure
3649 * [I] nItem : item index
3654 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3658 TRACE("nItem=%d\n", nItem
);
3660 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3662 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3663 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3664 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3666 infoPtr
->nSelectionMark
= nItem
;
3671 * Set selection(s) with keyboard.
3674 * [I] infoPtr : valid pointer to the listview structure
3675 * [I] nItem : item index
3676 * [I] space : VK_SPACE code sent
3679 * SUCCESS : TRUE (needs to be repainted)
3680 * FAILURE : FALSE (nothing has changed)
3682 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3684 /* FIXME: pass in the state */
3685 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3686 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3687 BOOL bResult
= FALSE
;
3689 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3690 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3694 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3695 LISTVIEW_SetSelection(infoPtr
, nItem
);
3699 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3703 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3704 lvItem
.stateMask
= LVIS_SELECTED
;
3707 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3708 if (lvItem
.state
& LVIS_SELECTED
)
3709 infoPtr
->nSelectionMark
= nItem
;
3711 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3714 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3717 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3721 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3723 LVHITTESTINFO lvHitTestInfo
;
3725 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3726 lvHitTestInfo
.pt
.x
= pt
.x
;
3727 lvHitTestInfo
.pt
.y
= pt
.y
;
3729 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3731 lpLVItem
->mask
= LVIF_PARAM
;
3732 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3733 lpLVItem
->iSubItem
= 0;
3735 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3738 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3740 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3741 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3742 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3747 * Called when the mouse is being actively tracked and has hovered for a specified
3751 * [I] infoPtr : valid pointer to the listview structure
3752 * [I] fwKeys : key indicator
3753 * [I] x,y : mouse position
3756 * 0 if the message was processed, non-zero if there was an error
3759 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3760 * over the item for a certain period of time.
3763 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3767 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3769 if (LISTVIEW_IsHotTracking(infoPtr
))
3777 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3778 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3780 SetFocus(infoPtr
->hwndSelf
);
3786 #define SCROLL_LEFT 0x1
3787 #define SCROLL_RIGHT 0x2
3788 #define SCROLL_UP 0x4
3789 #define SCROLL_DOWN 0x8
3793 * Utility routine to draw and highlight items within a marquee selection rectangle.
3796 * [I] infoPtr : valid pointer to the listview structure
3797 * [I] coords_orig : original co-ordinates of the cursor
3798 * [I] coords_offs : offsetted coordinates of the cursor
3799 * [I] offset : offset amount
3800 * [I] scroll : Bitmask of which directions we should scroll, if at all
3805 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3806 const POINT
*coords_offs
, const POINT
*offset
,
3809 BOOL controlDown
= FALSE
;
3811 ITERATOR old_elems
, new_elems
;
3814 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3816 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3817 rect
.right
= coords_offs
->x
;
3821 rect
.left
= coords_offs
->x
;
3822 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3825 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3827 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3828 rect
.bottom
= coords_offs
->y
;
3832 rect
.top
= coords_offs
->y
;
3833 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3836 /* Cancel out the old marquee rectangle and draw the new one */
3837 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3839 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3840 the cursor is further away */
3842 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3843 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3845 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3846 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3848 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3849 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3851 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3852 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3854 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3856 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3858 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3859 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3861 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3862 iterator_remove_common_items(&old_elems
, &new_elems
);
3864 /* Iterate over no longer selected items */
3865 while (iterator_next(&old_elems
))
3867 if (old_elems
.nItem
> -1)
3869 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3872 item
.state
= LVIS_SELECTED
;
3874 item
.stateMask
= LVIS_SELECTED
;
3876 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3879 iterator_destroy(&old_elems
);
3882 /* Iterate over newly selected items */
3883 if (GetKeyState(VK_CONTROL
) & 0x8000)
3886 while (iterator_next(&new_elems
))
3888 if (new_elems
.nItem
> -1)
3890 /* If CTRL is pressed, invert. If not, always select the item. */
3891 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3894 item
.state
= LVIS_SELECTED
;
3896 item
.stateMask
= LVIS_SELECTED
;
3898 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3901 iterator_destroy(&new_elems
);
3903 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3908 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3909 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3912 * [I] hwnd : Handle to the listview
3913 * [I] uMsg : WM_TIMER (ignored)
3914 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3915 * [I] dwTimer : The elapsed time (ignored)
3920 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3922 LISTVIEW_INFO
*infoPtr
;
3923 SCROLLINFO scrollInfo
;
3929 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3934 /* Get the current cursor position and convert to client coordinates */
3935 GetCursorPos(&coords_orig
);
3936 ScreenToClient(hWnd
, &coords_orig
);
3938 /* Ensure coordinates are within client bounds */
3939 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3940 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3943 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3945 /* Offset coordinates by the appropriate amount */
3946 coords_offs
.x
-= offset
.x
;
3947 coords_offs
.y
-= offset
.y
;
3949 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3950 scrollInfo
.fMask
= SIF_ALL
;
3952 /* Work out in which directions we can scroll */
3953 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3955 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3956 scroll
|= SCROLL_UP
;
3958 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3959 scroll
|= SCROLL_DOWN
;
3962 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3964 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3965 scroll
|= SCROLL_LEFT
;
3967 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3968 scroll
|= SCROLL_RIGHT
;
3971 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3972 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3973 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3974 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3976 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3982 * Called whenever WM_MOUSEMOVE is received.
3985 * [I] infoPtr : valid pointer to the listview structure
3986 * [I] fwKeys : key indicator
3987 * [I] x,y : mouse position
3990 * 0 if the message is processed, non-zero if there was an error
3992 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3998 if (!(fwKeys
& MK_LBUTTON
))
3999 infoPtr
->bLButtonDown
= FALSE
;
4001 if (infoPtr
->bLButtonDown
)
4003 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4004 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4006 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4008 if (infoPtr
->bMarqueeSelect
)
4018 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4020 /* Ensure coordinates are within client bounds */
4021 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4022 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4024 /* Offset coordinates by the appropriate amount */
4025 coords_offs
.x
-= offset
.x
;
4026 coords_offs
.y
-= offset
.y
;
4028 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4029 move the mouse again */
4031 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4032 (y
>= infoPtr
->rcList
.bottom
))
4034 if (!infoPtr
->bScrolling
)
4036 infoPtr
->bScrolling
= TRUE
;
4037 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4042 infoPtr
->bScrolling
= FALSE
;
4043 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4046 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4054 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4056 /* reset item marker */
4057 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4058 infoPtr
->nLButtonDownItem
= -1;
4060 if (!PtInRect(&rect
, pt
))
4062 /* this path covers the following:
4063 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4064 2. change focus with keys
4065 3. move mouse over item from step 1 selects it and moves focus on it */
4066 if (infoPtr
->nLButtonDownItem
!= -1 &&
4067 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4071 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4072 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4074 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4075 infoPtr
->nLButtonDownItem
= -1;
4078 if (!infoPtr
->bDragging
)
4080 ht
.pt
= infoPtr
->ptClickPos
;
4081 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4083 /* If the click is outside the range of an item, begin a
4084 highlight. If not, begin an item drag. */
4089 /* If we're allowing multiple selections, send notification.
4090 If return value is non-zero, cancel. */
4091 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4093 /* Store the absolute coordinates of the click */
4095 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4097 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4098 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4100 /* Begin selection and capture mouse */
4101 infoPtr
->bMarqueeSelect
= TRUE
;
4102 SetCapture(infoPtr
->hwndSelf
);
4109 ZeroMemory(&nmlv
, sizeof(nmlv
));
4110 nmlv
.iItem
= ht
.iItem
;
4111 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4113 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4114 infoPtr
->bDragging
= TRUE
;
4122 /* see if we are supposed to be tracking mouse hovering */
4123 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4124 TRACKMOUSEEVENT trackinfo
;
4126 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4127 trackinfo
.dwFlags
= TME_QUERY
;
4129 /* see if we are already tracking this hwnd */
4130 _TrackMouseEvent(&trackinfo
);
4132 if(!(trackinfo
.dwFlags
& TME_HOVER
) || trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4133 trackinfo
.dwFlags
= TME_HOVER
;
4134 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4135 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4137 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4138 _TrackMouseEvent(&trackinfo
);
4147 * Tests whether the item is assignable to a list with style lStyle
4149 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4151 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4152 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4153 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4161 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4164 * [I] infoPtr : valid pointer to the listview structure
4165 * [I] lpLVItem : valid pointer to new item attributes
4166 * [I] isNew : the item being set is being inserted
4167 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4168 * [O] bChanged : will be set to TRUE if the item really changed
4174 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4180 /* stateMask is ignored for LVM_INSERTITEM */
4181 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4185 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4187 if (lpLVItem
->mask
== 0) return TRUE
;
4189 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4191 /* a virtual listview only stores selection and focus */
4192 if (lpLVItem
->mask
& ~LVIF_STATE
)
4198 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4199 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4203 /* we need to get the lParam and state of the item */
4204 item
.iItem
= lpLVItem
->iItem
;
4205 item
.iSubItem
= lpLVItem
->iSubItem
;
4206 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4207 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4211 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4213 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4214 /* determine what fields will change */
4215 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4216 uChanged
|= LVIF_STATE
;
4218 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4219 uChanged
|= LVIF_IMAGE
;
4221 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4222 uChanged
|= LVIF_PARAM
;
4224 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4225 uChanged
|= LVIF_INDENT
;
4227 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4228 uChanged
|= LVIF_TEXT
;
4230 TRACE("change mask=0x%x\n", uChanged
);
4232 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4233 nmlv
.iItem
= lpLVItem
->iItem
;
4234 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4235 nmlv
.uOldState
= item
.state
;
4236 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4237 nmlv
.lParam
= item
.lParam
;
4239 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4240 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4241 are enabled. Even nothing really changed we still need to send this,
4242 in this case uChanged mask is just set to passed item mask. */
4243 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4245 HWND hwndSelf
= infoPtr
->hwndSelf
;
4247 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4249 if (!IsWindow(hwndSelf
))
4253 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4254 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4255 /* this means we won't hit a focus change path later */
4256 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4258 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4259 infoPtr
->nFocusedItem
++;
4262 if (!uChanged
) return TRUE
;
4265 /* copy information */
4266 if (lpLVItem
->mask
& LVIF_TEXT
)
4267 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4269 if (lpLVItem
->mask
& LVIF_IMAGE
)
4270 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4272 if (lpLVItem
->mask
& LVIF_PARAM
)
4273 lpItem
->lParam
= lpLVItem
->lParam
;
4275 if (lpLVItem
->mask
& LVIF_INDENT
)
4276 lpItem
->iIndent
= lpLVItem
->iIndent
;
4278 if (uChanged
& LVIF_STATE
)
4280 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4282 lpItem
->state
&= ~stateMask
;
4283 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4285 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4287 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4288 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4290 else if (stateMask
& LVIS_SELECTED
)
4292 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4294 /* If we are asked to change focus, and we manage it, do it.
4295 It's important to have all new item data stored at this point,
4296 because changing existing focus could result in a redrawing operation,
4297 which in turn could ask for disp data, application should see all data
4298 for inserted item when processing LVN_GETDISPINFO.
4300 The way this works application will see nested item change notifications -
4301 changed item notifications interrupted by ones from item losing focus. */
4302 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4304 if (lpLVItem
->state
& LVIS_FOCUSED
)
4306 /* update selection mark */
4307 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4308 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4310 if (infoPtr
->nFocusedItem
!= -1)
4312 /* remove current focus */
4313 item
.mask
= LVIF_STATE
;
4315 item
.stateMask
= LVIS_FOCUSED
;
4317 /* recurse with redrawing an item */
4318 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4321 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4322 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4324 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4326 infoPtr
->nFocusedItem
= -1;
4331 /* if we're inserting the item, we're done */
4332 if (isNew
) return TRUE
;
4334 /* send LVN_ITEMCHANGED notification */
4335 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4336 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4343 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4346 * [I] infoPtr : valid pointer to the listview structure
4347 * [I] lpLVItem : valid pointer to new subitem attributes
4348 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4349 * [O] bChanged : will be set to TRUE if the item really changed
4355 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4358 SUBITEM_INFO
*lpSubItem
;
4360 /* we do not support subitems for virtual listviews */
4361 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4363 /* set subitem only if column is present */
4364 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4366 /* First do some sanity checks */
4367 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4368 particularly useful. We currently do not actually do anything with
4369 the flag on subitems.
4371 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4372 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4374 /* get the subitem structure, and create it if not there */
4375 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4376 assert (hdpaSubItems
);
4378 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4381 SUBITEM_INFO
*tmpSubItem
;
4384 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4385 if (!lpSubItem
) return FALSE
;
4386 /* we could binary search here, if need be...*/
4387 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4389 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4390 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4392 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4397 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4398 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4402 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4404 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4408 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4410 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4419 * Sets item attributes.
4422 * [I] infoPtr : valid pointer to the listview structure
4423 * [I] lpLVItem : new item attributes
4424 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4430 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4432 HWND hwndSelf
= infoPtr
->hwndSelf
;
4433 LPWSTR pszText
= NULL
;
4434 BOOL bResult
, bChanged
= FALSE
;
4437 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4439 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4442 /* Store old item area */
4443 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4445 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4446 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4448 pszText
= lpLVItem
->pszText
;
4449 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4452 /* actually set the fields */
4453 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4455 if (lpLVItem
->iSubItem
)
4456 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4458 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4459 if (!IsWindow(hwndSelf
))
4462 /* redraw item, if necessary */
4463 if (bChanged
&& !infoPtr
->bIsDrawing
)
4465 /* this little optimization eliminates some nasty flicker */
4466 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4467 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4468 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4469 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4472 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4473 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4479 textfreeT(lpLVItem
->pszText
, isW
);
4480 lpLVItem
->pszText
= pszText
;
4488 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4491 * [I] infoPtr : valid pointer to the listview structure
4496 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4499 SCROLLINFO scrollInfo
;
4501 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4502 scrollInfo
.fMask
= SIF_POS
;
4504 if (infoPtr
->uView
== LV_VIEW_LIST
)
4506 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4507 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4509 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4511 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4512 nItem
= scrollInfo
.nPos
;
4516 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4517 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4520 TRACE("nItem=%d\n", nItem
);
4528 * Erases the background of the given rectangle
4531 * [I] infoPtr : valid pointer to the listview structure
4532 * [I] hdc : device context handle
4533 * [I] lprcBox : clipping rectangle
4539 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4541 if (!infoPtr
->hBkBrush
) return FALSE
;
4543 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4545 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4548 /* Draw main item or subitem */
4549 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4551 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4552 const RECT
*background
;
4557 /* now check if we need to update the focus rectangle */
4558 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4559 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4561 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4562 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4563 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4564 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4565 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4566 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4567 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4568 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4569 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4571 /* FIXME: temporary hack */
4572 rcSelect
.left
= rcLabel
.left
;
4574 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4576 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4577 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4578 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4579 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4580 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4583 /* in icon mode, the label rect is really what we want to draw the
4585 /* in detail mode, we want to paint background for label rect when
4586 * item is not selected or listview has full row select; otherwise paint
4587 * background for text only */
4588 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4589 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4590 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4591 background
= &rcLabel
;
4593 background
= &rcSelect
;
4595 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4596 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4598 if (item
->state
& LVIS_FOCUSED
)
4600 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4602 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4604 /* we have to update left focus bound too if item isn't in leftmost column
4605 and reduce right box bound */
4606 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4610 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4612 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4613 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4614 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4616 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4617 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4620 rcSelect
.right
= rcBox
.right
;
4622 infoPtr
->rcFocus
= rcSelect
;
4625 infoPtr
->rcFocus
= rcLabel
;
4629 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4631 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4634 TRACE("stateimage=%d\n", stateimage
);
4635 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4640 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4641 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4645 TRACE("iImage=%d\n", item
->iImage
);
4647 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4648 style
= ILD_SELECTED
;
4652 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4653 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4654 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4655 style
| (item
->state
& LVIS_OVERLAYMASK
));
4658 /* Don't bother painting item being edited */
4659 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4661 /* figure out the text drawing flags */
4662 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4663 if (infoPtr
->uView
== LV_VIEW_ICON
)
4664 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4665 else if (item
->iSubItem
)
4667 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4669 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4670 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4671 default: format
|= DT_LEFT
;
4674 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4676 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4677 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4679 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4681 /* for GRIDLINES reduce the bottom so the text formats correctly */
4682 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4685 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4693 * [I] infoPtr : valid pointer to the listview structure
4694 * [I] hdc : device context handle
4695 * [I] nItem : item index
4696 * [I] nSubItem : subitem index
4697 * [I] pos : item position in client coordinates
4698 * [I] cdmode : custom draw mode
4704 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4706 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4707 static WCHAR callbackW
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4708 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4710 NMLVCUSTOMDRAW nmlvcd
;
4713 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4715 /* get information needed for drawing the item */
4716 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4717 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4718 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4719 lvItem
.iItem
= nItem
;
4720 lvItem
.iSubItem
= 0;
4723 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4724 lvItem
.pszText
= szDispText
;
4725 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4726 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4727 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4729 /* now check if we need to update the focus rectangle */
4730 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4731 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4733 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4734 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4736 /* Full custom draw stage sequence looks like this:
4741 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4742 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item iself
4743 - CDDS_ITEMPOSTPAINT
4748 - CDDS_ITEMPOSTPAINT
4751 /* fill in the custom draw structure */
4752 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4753 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4754 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4755 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4759 while (iterator_next(subitems
))
4761 DWORD subitemstage
= CDRF_DODEFAULT
;
4763 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4764 if (subitems
->nItem
)
4766 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4767 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4768 lvItem
.iItem
= nItem
;
4769 lvItem
.iSubItem
= subitems
->nItem
;
4772 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4773 lvItem
.pszText
= szDispText
;
4774 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4775 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4776 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4777 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4778 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4780 /* update custom draw data */
4781 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4782 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4783 nmlvcd
.iSubItem
= subitems
->nItem
;
4786 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4787 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4790 nmlvcd
.clrTextBk
= infoPtr
->clrTextBk
;
4791 nmlvcd
.clrText
= infoPtr
->clrText
;
4794 if (subitems
->nItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4795 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4796 else if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4797 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4799 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4800 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4802 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4803 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4808 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4809 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4813 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4815 nmlvcd
.iSubItem
= 0;
4816 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4824 * Draws listview items when in owner draw mode.
4827 * [I] infoPtr : valid pointer to the listview structure
4828 * [I] hdc : device context handle
4833 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4835 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4836 DWORD cditemmode
= CDRF_DODEFAULT
;
4837 NMLVCUSTOMDRAW nmlvcd
;
4838 POINT Origin
, Position
;
4844 ZeroMemory(&dis
, sizeof(dis
));
4846 /* Get scroll info once before loop */
4847 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4849 /* iterate through the invalidated rows */
4850 while(iterator_next(i
))
4852 item
.iItem
= i
->nItem
;
4854 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4855 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4856 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4858 dis
.CtlType
= ODT_LISTVIEW
;
4860 dis
.itemID
= item
.iItem
;
4861 dis
.itemAction
= ODA_DRAWENTIRE
;
4863 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4864 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4865 dis
.hwndItem
= infoPtr
->hwndSelf
;
4867 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4868 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4869 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4870 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4871 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4872 dis
.itemData
= item
.lParam
;
4874 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4877 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4878 * structure for the rest. of the paint cycle
4880 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4881 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4882 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4884 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4886 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4887 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4890 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4891 notify_postpaint(infoPtr
, &nmlvcd
);
4897 * Draws listview items when in report display mode.
4900 * [I] infoPtr : valid pointer to the listview structure
4901 * [I] hdc : device context handle
4902 * [I] cdmode : custom draw mode
4907 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4910 RECT rcClip
, rcItem
;
4918 /* figure out what to draw */
4919 rgntype
= GetClipBox(hdc
, &rcClip
);
4920 if (rgntype
== NULLREGION
) return;
4922 /* Get scroll info once before loop */
4923 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4925 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4927 /* narrow down the columns we need to paint */
4928 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4930 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4932 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4933 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4934 ranges_additem(colRanges
, index
);
4936 iterator_rangesitems(&j
, colRanges
);
4938 /* in full row select, we _have_ to draw the main item */
4939 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4942 /* iterate through the invalidated rows */
4943 while(iterator_next(i
))
4949 SelectObject(hdc
, infoPtr
->hFont
);
4950 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4951 Position
.x
= Origin
.x
;
4952 Position
.y
+= Origin
.y
;
4954 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4956 /* iterate through the invalidated columns */
4957 while(iterator_next(&j
))
4959 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4961 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4964 rcItem
.bottom
= infoPtr
->nItemHeight
;
4965 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4966 if (!RectVisible(hdc
, &rcItem
)) continue;
4969 ranges_additem(subitems
, j
.nItem
);
4972 iterator_rangesitems(&k
, subitems
);
4973 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
4974 iterator_destroy(&k
);
4976 iterator_destroy(&j
);
4981 * Draws the gridlines if necessary when in report display mode.
4984 * [I] infoPtr : valid pointer to the listview structure
4985 * [I] hdc : device context handle
4990 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4996 RECT rcClip
, rcItem
= {0};
5004 /* figure out what to draw */
5005 rgntype
= GetClipBox(hdc
, &rcClip
);
5006 if (rgntype
== NULLREGION
) return;
5008 /* Get scroll info once before loop */
5009 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5011 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5013 /* narrow down the columns we need to paint */
5014 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5016 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5018 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5019 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5020 ranges_additem(colRanges
, index
);
5023 /* is right most vertical line visible? */
5024 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5026 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5027 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5028 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5031 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5033 hOldPen
= SelectObject ( hdc
, hPen
);
5035 /* draw the vertical lines for the columns */
5036 iterator_rangesitems(&j
, colRanges
);
5037 while(iterator_next(&j
))
5039 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5040 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5041 rcItem
.left
+= Origin
.x
;
5042 rcItem
.right
+= Origin
.x
;
5043 rcItem
.top
= infoPtr
->rcList
.top
;
5044 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5045 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5046 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5047 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5049 iterator_destroy(&j
);
5050 /* draw rightmost grid line if visible */
5053 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5054 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5055 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5057 rcItem
.right
+= Origin
.x
;
5059 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5060 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5063 /* draw the horizontal lines for the rows */
5064 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5065 rcItem
.left
= infoPtr
->rcList
.left
;
5066 rcItem
.right
= infoPtr
->rcList
.right
;
5067 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5069 rcItem
.bottom
= rcItem
.top
= y
;
5070 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5071 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5072 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5075 SelectObject( hdc
, hOldPen
);
5076 DeleteObject( hPen
);
5079 ranges_destroy(colRanges
);
5084 * Draws listview items when in list display mode.
5087 * [I] infoPtr : valid pointer to the listview structure
5088 * [I] hdc : device context handle
5089 * [I] cdmode : custom draw mode
5094 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5096 POINT Origin
, Position
;
5098 /* Get scroll info once before loop */
5099 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5101 while(iterator_prev(i
))
5103 SelectObject(hdc
, infoPtr
->hFont
);
5104 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5105 Position
.x
+= Origin
.x
;
5106 Position
.y
+= Origin
.y
;
5108 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5115 * Draws listview items.
5118 * [I] infoPtr : valid pointer to the listview structure
5119 * [I] hdc : device context handle
5120 * [I] prcErase : rect to be erased before refresh (may be NULL)
5125 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5127 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5128 NMLVCUSTOMDRAW nmlvcd
;
5135 HBITMAP hbmp
= NULL
;
5138 LISTVIEW_DUMP(infoPtr
);
5140 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5141 TRACE("double buffering\n");
5143 hdc
= CreateCompatibleDC(hdcOrig
);
5145 ERR("Failed to create DC for backbuffer\n");
5148 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5149 infoPtr
->rcList
.bottom
);
5151 ERR("Failed to create bitmap for backbuffer\n");
5156 SelectObject(hdc
, hbmp
);
5157 SelectObject(hdc
, infoPtr
->hFont
);
5159 if(GetClipBox(hdcOrig
, &rcClient
))
5160 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5162 /* Save dc values we're gonna trash while drawing
5163 * FIXME: Should be done in LISTVIEW_DrawItem() */
5164 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5165 oldBkMode
= GetBkMode(hdc
);
5166 oldBkColor
= GetBkColor(hdc
);
5167 oldTextColor
= GetTextColor(hdc
);
5170 infoPtr
->bIsDrawing
= TRUE
;
5173 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5174 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5175 /* If no erasing was done (usually because RedrawWindow was called
5176 * with RDW_INVALIDATE only) we need to copy the old contents into
5177 * the backbuffer before continuing. */
5178 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5179 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5180 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5181 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5184 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5185 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5186 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5187 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5189 /* nothing to draw */
5190 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5192 /* figure out what we need to draw */
5193 iterator_visibleitems(&i
, infoPtr
, hdc
);
5194 range
= iterator_range(&i
);
5196 /* send cache hint notification */
5197 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5201 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5202 nmlv
.iFrom
= range
.lower
;
5203 nmlv
.iTo
= range
.upper
- 1;
5204 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5207 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5208 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5211 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5212 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5213 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5214 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5216 /* if we have a focus rect and it's visible, draw it */
5217 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5218 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5219 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5221 iterator_destroy(&i
);
5224 /* For LVS_EX_GRIDLINES go and draw lines */
5225 /* This includes the case where there were *no* items */
5226 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5227 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5229 /* Draw marquee rectangle if appropriate */
5230 if (infoPtr
->bMarqueeSelect
)
5231 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5233 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5234 notify_postpaint(infoPtr
, &nmlvcd
);
5237 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5238 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5239 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5240 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5245 SelectObject(hdc
, hOldFont
);
5246 SetBkMode(hdc
, oldBkMode
);
5247 SetBkColor(hdc
, oldBkColor
);
5248 SetTextColor(hdc
, oldTextColor
);
5251 infoPtr
->bIsDrawing
= FALSE
;
5257 * Calculates the approximate width and height of a given number of items.
5260 * [I] infoPtr : valid pointer to the listview structure
5261 * [I] nItemCount : number of items
5262 * [I] wWidth : width
5263 * [I] wHeight : height
5266 * Returns a DWORD. The width in the low word and the height in high word.
5268 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5269 WORD wWidth
, WORD wHeight
)
5271 DWORD dwViewRect
= 0;
5273 if (nItemCount
== -1)
5274 nItemCount
= infoPtr
->nItemCount
;
5276 if (infoPtr
->uView
== LV_VIEW_LIST
)
5278 INT nItemCountPerColumn
= 1;
5279 INT nColumnCount
= 0;
5281 if (wHeight
== 0xFFFF)
5283 /* use current height */
5284 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5287 if (wHeight
< infoPtr
->nItemHeight
)
5288 wHeight
= infoPtr
->nItemHeight
;
5292 if (infoPtr
->nItemHeight
> 0)
5294 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5295 if (nItemCountPerColumn
== 0)
5296 nItemCountPerColumn
= 1;
5298 if (nItemCount
% nItemCountPerColumn
!= 0)
5299 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5301 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5305 /* Microsoft padding magic */
5306 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5307 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5309 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5311 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5315 if (infoPtr
->nItemCount
> 0)
5317 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5318 wWidth
= rcBox
.right
- rcBox
.left
;
5319 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5323 /* use current height and width */
5324 if (wHeight
== 0xffff)
5325 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5326 if (wWidth
== 0xffff)
5327 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5330 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5332 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5338 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5339 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5341 if (wWidth
== 0xffff)
5342 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5344 if (wWidth
< nItemWidth
)
5345 wWidth
= nItemWidth
;
5347 cols
= wWidth
/ nItemWidth
;
5348 if (cols
> nItemCount
)
5355 rows
= nItemCount
/ cols
;
5356 if (nItemCount
% cols
)
5362 wHeight
= (nItemHeight
* rows
)+2;
5363 wWidth
= (nItemWidth
* cols
)+2;
5365 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5367 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5368 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5375 * Cancel edit label with saving item text.
5378 * [I] infoPtr : valid pointer to the listview structure
5381 * Always returns TRUE.
5383 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5385 if (infoPtr
->hwndEdit
)
5387 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5388 HWND edit
= infoPtr
->hwndEdit
;
5390 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5391 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5399 * Create a drag image list for the specified item.
5402 * [I] infoPtr : valid pointer to the listview structure
5403 * [I] iItem : index of item
5404 * [O] lppt : Upper-left corner of the image
5407 * Returns a handle to the image list if successful, NULL otherwise.
5409 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5415 HBITMAP hbmp
, hOldbmp
;
5417 HIMAGELIST dragList
= 0;
5418 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5420 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5423 rcItem
.left
= LVIR_BOUNDS
;
5424 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5427 lppt
->x
= rcItem
.left
;
5428 lppt
->y
= rcItem
.top
;
5430 size
.cx
= rcItem
.right
- rcItem
.left
;
5431 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5433 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5434 hdc
= CreateCompatibleDC(hdcOrig
);
5435 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5436 hOldbmp
= SelectObject(hdc
, hbmp
);
5437 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5439 rcItem
.left
= rcItem
.top
= 0;
5440 rcItem
.right
= size
.cx
;
5441 rcItem
.bottom
= size
.cy
;
5442 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5445 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5447 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5448 SelectObject(hdc
, hOldbmp
);
5449 ImageList_Add(dragList
, hbmp
, 0);
5452 SelectObject(hdc
, hOldbmp
);
5454 SelectObject(hdc
, hOldFont
);
5457 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5459 TRACE("ret=%p\n", dragList
);
5467 * Removes all listview items and subitems.
5470 * [I] infoPtr : valid pointer to the listview structure
5476 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5478 HDPA hdpaSubItems
= NULL
;
5479 BOOL suppress
= FALSE
;
5487 /* we do it directly, to avoid notifications */
5488 ranges_clear(infoPtr
->selectionRanges
);
5489 infoPtr
->nSelectionMark
= -1;
5490 infoPtr
->nFocusedItem
= -1;
5491 SetRectEmpty(&infoPtr
->rcFocus
);
5492 /* But we are supposed to leave nHotItem as is! */
5494 /* send LVN_DELETEALLITEMS notification */
5495 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5499 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5501 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5504 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5506 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5508 /* send LVN_DELETEITEM notification, if not suppressed
5509 and if it is not a virtual listview */
5510 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5511 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5512 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5513 /* free id struct */
5514 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5515 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5516 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5518 /* both item and subitem start with ITEMHDR header */
5519 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5521 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5522 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5525 DPA_Destroy(hdpaSubItems
);
5526 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5528 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5529 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5530 infoPtr
->nItemCount
--;
5535 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5536 LISTVIEW_UpdateScroll(infoPtr
);
5538 LISTVIEW_InvalidateList(infoPtr
);
5545 * Scrolls, and updates the columns, when a column is changing width.
5548 * [I] infoPtr : valid pointer to the listview structure
5549 * [I] nColumn : column to scroll
5550 * [I] dx : amount of scroll, in pixels
5555 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5557 COLUMN_INFO
*lpColumnInfo
;
5563 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5564 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5565 rcCol
= lpColumnInfo
->rcHeader
;
5566 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5567 rcCol
.left
= rcCol
.right
;
5569 /* adjust the other columns */
5570 hdi
.mask
= HDI_ORDER
;
5571 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5573 INT nOrder
= hdi
.iOrder
;
5574 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5576 hdi
.mask
= HDI_ORDER
;
5577 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5578 if (hdi
.iOrder
>= nOrder
) {
5579 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5580 lpColumnInfo
->rcHeader
.left
+= dx
;
5581 lpColumnInfo
->rcHeader
.right
+= dx
;
5586 /* do not update screen if not in report mode */
5587 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5589 /* Need to reset the item width when inserting a new column */
5590 infoPtr
->nItemWidth
+= dx
;
5592 LISTVIEW_UpdateScroll(infoPtr
);
5593 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5595 /* scroll to cover the deleted column, and invalidate for redraw */
5596 rcOld
= infoPtr
->rcList
;
5597 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5598 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5603 * Removes a column from the listview control.
5606 * [I] infoPtr : valid pointer to the listview structure
5607 * [I] nColumn : column index
5613 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5617 TRACE("nColumn=%d\n", nColumn
);
5619 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5620 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5622 /* While the MSDN specifically says that column zero should not be deleted,
5623 what actually happens is that the column itself is deleted but no items or subitems
5627 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5629 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5632 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5633 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5635 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5637 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5639 INT nItem
, nSubItem
, i
;
5641 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5643 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5646 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5648 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5649 if (lpSubItem
->iSubItem
== nColumn
)
5652 lpDelItem
= lpSubItem
;
5654 else if (lpSubItem
->iSubItem
> nColumn
)
5656 lpSubItem
->iSubItem
--;
5660 /* if we found our subitem, zap it */
5664 if (is_text(lpDelItem
->hdr
.pszText
))
5665 Free(lpDelItem
->hdr
.pszText
);
5670 /* free dpa memory */
5671 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5676 /* update the other column info */
5677 LISTVIEW_UpdateItemSize(infoPtr
);
5678 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5679 LISTVIEW_InvalidateList(infoPtr
);
5681 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5688 * Invalidates the listview after an item's insertion or deletion.
5691 * [I] infoPtr : valid pointer to the listview structure
5692 * [I] nItem : item index
5693 * [I] dir : -1 if deleting, 1 if inserting
5698 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5700 INT nPerCol
, nItemCol
, nItemRow
;
5704 /* if we don't refresh, what's the point of scrolling? */
5705 if (!is_redrawing(infoPtr
)) return;
5707 assert (abs(dir
) == 1);
5709 /* arrange icons if autoarrange is on */
5710 if (is_autoarrange(infoPtr
))
5712 BOOL arrange
= TRUE
;
5713 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5714 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5715 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5718 /* scrollbars need updating */
5719 LISTVIEW_UpdateScroll(infoPtr
);
5721 /* figure out the item's position */
5722 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5723 nPerCol
= infoPtr
->nItemCount
+ 1;
5724 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5725 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5726 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5729 nItemCol
= nItem
/ nPerCol
;
5730 nItemRow
= nItem
% nPerCol
;
5731 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5733 /* move the items below up a slot */
5734 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5735 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5736 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5737 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5738 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5739 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5740 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5742 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5743 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5746 /* report has only that column, so we're done */
5747 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5749 /* now for LISTs, we have to deal with the columns to the right */
5750 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5752 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5753 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5754 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5755 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5756 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5761 * Removes an item from the listview control.
5764 * [I] infoPtr : valid pointer to the listview structure
5765 * [I] nItem : item index
5771 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5774 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5775 INT focus
= infoPtr
->nFocusedItem
;
5777 TRACE("(nItem=%d)\n", nItem
);
5779 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5781 /* remove selection, and focus */
5783 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5784 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5786 /* send LVN_DELETEITEM notification. */
5787 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5789 /* we need to do this here, because we'll be deleting stuff */
5791 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5793 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5801 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5802 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5804 /* free id struct */
5805 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5806 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5807 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5809 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5811 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5812 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5815 DPA_Destroy(hdpaSubItems
);
5820 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5821 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5824 infoPtr
->nItemCount
--;
5825 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5826 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5828 /* now is the invalidation fun */
5830 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5837 * Callback implementation for editlabel control
5840 * [I] infoPtr : valid pointer to the listview structure
5841 * [I] storeText : store edit box text as item text
5842 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5848 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5850 HWND hwndSelf
= infoPtr
->hwndSelf
;
5851 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5852 NMLVDISPINFOW dispInfo
;
5853 INT editedItem
= infoPtr
->nEditLabelItem
;
5855 WCHAR
*pszText
= NULL
;
5860 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5864 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5866 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5867 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5872 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5874 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5875 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5876 dispInfo
.item
.iItem
= editedItem
;
5877 dispInfo
.item
.iSubItem
= 0;
5878 dispInfo
.item
.stateMask
= ~0;
5879 dispInfo
.item
.pszText
= szDispText
;
5880 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5881 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5888 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5891 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5892 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5893 textfreeT(tmp
, FALSE
);
5896 /* add the text from the edit in */
5897 dispInfo
.item
.mask
|= LVIF_TEXT
;
5898 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5899 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5901 /* Do we need to update the Item Text */
5902 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5904 infoPtr
->nEditLabelItem
= -1;
5905 infoPtr
->hwndEdit
= 0;
5907 if (!res
) goto cleanup
;
5909 if (!IsWindow(hwndSelf
))
5914 if (!pszText
) return TRUE
;
5921 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5923 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5924 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5925 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5927 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5933 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5934 dispInfo
.item
.mask
= LVIF_TEXT
;
5935 dispInfo
.item
.iItem
= editedItem
;
5936 dispInfo
.item
.iSubItem
= 0;
5937 dispInfo
.item
.pszText
= pszText
;
5938 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5939 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5949 * Subclassed edit control windproc function
5952 * [I] hwnd : the edit window handle
5953 * [I] uMsg : the message that is to be processed
5954 * [I] wParam : first message parameter
5955 * [I] lParam : second message parameter
5956 * [I] isW : TRUE if input is Unicode
5961 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5963 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5966 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5967 hwnd
, uMsg
, wParam
, lParam
, isW
);
5972 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5976 WNDPROC editProc
= infoPtr
->EditWndProc
;
5977 infoPtr
->EditWndProc
= 0;
5978 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5979 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5983 if (VK_ESCAPE
== (INT
)wParam
)
5988 else if (VK_RETURN
== (INT
)wParam
)
5992 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5996 if (infoPtr
->hwndEdit
)
5997 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
5999 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6005 * Subclassed edit control Unicode windproc function
6008 * [I] hwnd : the edit window handle
6009 * [I] uMsg : the message that is to be processed
6010 * [I] wParam : first message parameter
6011 * [I] lParam : second message parameter
6015 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6017 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6022 * Subclassed edit control ANSI windproc function
6025 * [I] hwnd : the edit window handle
6026 * [I] uMsg : the message that is to be processed
6027 * [I] wParam : first message parameter
6028 * [I] lParam : second message parameter
6032 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6034 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6039 * Creates a subclassed edit control
6042 * [I] infoPtr : valid pointer to the listview structure
6043 * [I] text : initial text for the edit
6044 * [I] style : the window style
6045 * [I] isW : TRUE if input is Unicode
6049 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6051 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6052 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6055 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6057 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6059 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6061 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6063 if (!hedit
) return 0;
6065 infoPtr
->EditWndProc
= (WNDPROC
)
6066 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6067 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6069 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6070 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6077 * Begin in place editing of specified list view item
6080 * [I] infoPtr : valid pointer to the listview structure
6081 * [I] nItem : item index
6082 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6088 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6090 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6091 HWND hwndSelf
= infoPtr
->hwndSelf
;
6092 NMLVDISPINFOW dispInfo
;
6093 HFONT hOldFont
= NULL
;
6099 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6101 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6103 /* remove existing edit box */
6104 if (infoPtr
->hwndEdit
)
6106 SetFocus(infoPtr
->hwndSelf
);
6107 infoPtr
->hwndEdit
= 0;
6110 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6112 infoPtr
->nEditLabelItem
= nItem
;
6114 LISTVIEW_SetSelection(infoPtr
, nItem
);
6115 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6116 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6118 rect
.left
= LVIR_LABEL
;
6119 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6121 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6122 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6123 dispInfo
.item
.iItem
= nItem
;
6124 dispInfo
.item
.iSubItem
= 0;
6125 dispInfo
.item
.stateMask
= ~0;
6126 dispInfo
.item
.pszText
= disptextW
;
6127 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6128 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6130 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6131 if (!infoPtr
->hwndEdit
) return 0;
6133 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6135 if (!IsWindow(hwndSelf
))
6137 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6138 infoPtr
->hwndEdit
= 0;
6142 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6144 /* position and display edit box */
6145 hdc
= GetDC(infoPtr
->hwndSelf
);
6147 /* select the font to get appropriate metric dimensions */
6149 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6151 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6152 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6153 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6155 /* get string length in pixels */
6156 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6158 /* add extra spacing for the next character */
6159 GetTextMetricsW(hdc
, &tm
);
6160 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6163 SelectObject(hdc
, hOldFont
);
6165 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6167 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6170 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6171 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6172 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6173 SetFocus(infoPtr
->hwndEdit
);
6174 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6175 return infoPtr
->hwndEdit
;
6181 * Ensures the specified item is visible, scrolling into view if necessary.
6184 * [I] infoPtr : valid pointer to the listview structure
6185 * [I] nItem : item index
6186 * [I] bPartial : partially or entirely visible
6192 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6194 INT nScrollPosHeight
= 0;
6195 INT nScrollPosWidth
= 0;
6196 INT nHorzAdjust
= 0;
6197 INT nVertAdjust
= 0;
6200 RECT rcItem
, rcTemp
;
6202 rcItem
.left
= LVIR_BOUNDS
;
6203 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6205 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6207 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6209 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6210 if (infoPtr
->uView
== LV_VIEW_LIST
)
6211 nScrollPosWidth
= infoPtr
->nItemWidth
;
6212 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6213 nScrollPosWidth
= 1;
6215 if (rcItem
.left
< infoPtr
->rcList
.left
)
6218 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6223 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6227 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6229 /* scroll up/down, but not in LVS_LIST mode */
6230 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6231 nScrollPosHeight
= infoPtr
->nItemHeight
;
6232 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6233 nScrollPosHeight
= 1;
6235 if (rcItem
.top
< infoPtr
->rcList
.top
)
6238 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6243 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6247 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6249 if (nScrollPosWidth
)
6251 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6252 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6253 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6256 if (nScrollPosHeight
)
6258 INT diff
= nVertDiff
/ nScrollPosHeight
;
6259 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6260 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6268 * Searches for an item with specific characteristics.
6271 * [I] hwnd : window handle
6272 * [I] nStart : base item index
6273 * [I] lpFindInfo : item information to look for
6276 * SUCCESS : index of item
6279 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6280 const LVFINDINFOW
*lpFindInfo
)
6282 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6283 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6284 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6285 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6286 POINT Position
, Destination
;
6289 /* Search in virtual listviews should be done by application, not by
6290 listview control, so we just send LVN_ODFINDITEMW and return the result */
6291 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6295 nmlv
.iStart
= nStart
;
6296 nmlv
.lvfi
= *lpFindInfo
;
6297 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6300 if (!lpFindInfo
|| nItem
< 0) return -1;
6303 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6304 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6306 lvItem
.mask
|= LVIF_TEXT
;
6307 lvItem
.pszText
= szDispText
;
6308 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6311 if (lpFindInfo
->flags
& LVFI_WRAP
)
6314 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6315 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6320 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6321 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6322 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6323 switch(lpFindInfo
->vkDirection
)
6325 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6326 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6327 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6328 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6329 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6330 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6331 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6333 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6334 Destination
.x
= rcArea
.right
;
6335 Destination
.y
= rcArea
.bottom
;
6337 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6341 else Destination
.x
= Destination
.y
= 0;
6343 /* if LVFI_PARAM is specified, all other flags are ignored */
6344 if (lpFindInfo
->flags
& LVFI_PARAM
)
6346 lvItem
.mask
|= LVIF_PARAM
;
6348 lvItem
.mask
&= ~LVIF_TEXT
;
6352 for (; nItem
< nLast
; nItem
++)
6354 lvItem
.iItem
= nItem
;
6355 lvItem
.iSubItem
= 0;
6356 lvItem
.pszText
= szDispText
;
6357 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6359 if (lvItem
.mask
& LVIF_PARAM
)
6361 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6367 if (lvItem
.mask
& LVIF_TEXT
)
6369 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6371 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6372 if (!p
|| p
!= lvItem
.pszText
) continue;
6376 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6380 if (!bNearest
) return nItem
;
6382 /* This is very inefficient. To do a good job here,
6383 * we need a sorted array of (x,y) item positions */
6384 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6386 /* compute the distance^2 to the destination */
6387 xdist
= Destination
.x
- Position
.x
;
6388 ydist
= Destination
.y
- Position
.y
;
6389 dist
= xdist
* xdist
+ ydist
* ydist
;
6391 /* remember the distance, and item if it's closer */
6395 nNearestItem
= nItem
;
6402 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6407 return nNearestItem
;
6412 * Searches for an item with specific characteristics.
6415 * [I] hwnd : window handle
6416 * [I] nStart : base item index
6417 * [I] lpFindInfo : item information to look for
6420 * SUCCESS : index of item
6423 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6424 const LVFINDINFOA
*lpFindInfo
)
6426 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6427 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6432 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6433 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6434 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6435 textfreeT(strW
, FALSE
);
6441 * Retrieves column attributes.
6444 * [I] infoPtr : valid pointer to the listview structure
6445 * [I] nColumn : column index
6446 * [IO] lpColumn : column information
6447 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6448 * otherwise it is in fact a LPLVCOLUMNA
6454 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6456 COLUMN_INFO
*lpColumnInfo
;
6459 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6460 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6462 /* initialize memory */
6463 ZeroMemory(&hdi
, sizeof(hdi
));
6465 if (lpColumn
->mask
& LVCF_TEXT
)
6467 hdi
.mask
|= HDI_TEXT
;
6468 hdi
.pszText
= lpColumn
->pszText
;
6469 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6472 if (lpColumn
->mask
& LVCF_IMAGE
)
6473 hdi
.mask
|= HDI_IMAGE
;
6475 if (lpColumn
->mask
& LVCF_ORDER
)
6476 hdi
.mask
|= HDI_ORDER
;
6478 if (lpColumn
->mask
& LVCF_SUBITEM
)
6479 hdi
.mask
|= HDI_LPARAM
;
6481 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6483 if (lpColumn
->mask
& LVCF_FMT
)
6484 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6486 if (lpColumn
->mask
& LVCF_WIDTH
)
6487 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6489 if (lpColumn
->mask
& LVCF_IMAGE
)
6490 lpColumn
->iImage
= hdi
.iImage
;
6492 if (lpColumn
->mask
& LVCF_ORDER
)
6493 lpColumn
->iOrder
= hdi
.iOrder
;
6495 if (lpColumn
->mask
& LVCF_SUBITEM
)
6496 lpColumn
->iSubItem
= hdi
.lParam
;
6498 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6499 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6504 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6506 if (!infoPtr
->hwndHeader
) return FALSE
;
6507 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6512 * Retrieves the column width.
6515 * [I] infoPtr : valid pointer to the listview structure
6516 * [I] int : column index
6519 * SUCCESS : column width
6522 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6524 INT nColumnWidth
= 0;
6527 TRACE("nColumn=%d\n", nColumn
);
6529 /* we have a 'column' in LIST and REPORT mode only */
6530 switch(infoPtr
->uView
)
6533 nColumnWidth
= infoPtr
->nItemWidth
;
6535 case LV_VIEW_DETAILS
:
6536 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6537 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6538 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6540 hdItem
.mask
= HDI_WIDTH
;
6541 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6543 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6546 nColumnWidth
= hdItem
.cxy
;
6550 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6551 return nColumnWidth
;
6556 * In list or report display mode, retrieves the number of items that can fit
6557 * vertically in the visible area. In icon or small icon display mode,
6558 * retrieves the total number of visible items.
6561 * [I] infoPtr : valid pointer to the listview structure
6564 * Number of fully visible items.
6566 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6568 switch (infoPtr
->uView
)
6571 case LV_VIEW_SMALLICON
:
6572 return infoPtr
->nItemCount
;
6573 case LV_VIEW_DETAILS
:
6574 return LISTVIEW_GetCountPerColumn(infoPtr
);
6576 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6584 * Retrieves an image list handle.
6587 * [I] infoPtr : valid pointer to the listview structure
6588 * [I] nImageList : image list identifier
6591 * SUCCESS : image list handle
6594 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6598 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6599 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6600 case LVSIL_STATE
: return infoPtr
->himlState
;
6601 case LVSIL_GROUPHEADER
:
6602 FIXME("LVSIL_GROUPHEADER not supported\n");
6605 WARN("got unknown imagelist index - %d\n", nImageList
);
6610 /* LISTVIEW_GetISearchString */
6614 * Retrieves item attributes.
6617 * [I] hwnd : window handle
6618 * [IO] lpLVItem : item info
6619 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6620 * if FALSE, then lpLVItem is a LPLVITEMA.
6623 * This is the internal 'GetItem' interface -- it tries to
6624 * be smart and avoid text copies, if possible, by modifying
6625 * lpLVItem->pszText to point to the text string. Please note
6626 * that this is not always possible (e.g. OWNERDATA), so on
6627 * entry you *must* supply valid values for pszText, and cchTextMax.
6628 * The only difference to the documented interface is that upon
6629 * return, you should use *only* the lpLVItem->pszText, rather than
6630 * the buffer pointer you provided on input. Most code already does
6631 * that, so it's not a problem.
6632 * For the two cases when the text must be copied (that is,
6633 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6639 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6641 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6642 NMLVDISPINFOW dispInfo
;
6648 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6650 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6653 if (lpLVItem
->mask
== 0) return TRUE
;
6654 TRACE("mask=%x\n", lpLVItem
->mask
);
6656 /* make a local copy */
6657 isubitem
= lpLVItem
->iSubItem
;
6659 /* a quick optimization if all we're asked is the focus state
6660 * these queries are worth optimising since they are common,
6661 * and can be answered in constant time, without the heavy accesses */
6662 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6663 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6665 lpLVItem
->state
= 0;
6666 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6667 lpLVItem
->state
|= LVIS_FOCUSED
;
6671 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6673 /* if the app stores all the data, handle it separately */
6674 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6676 dispInfo
.item
.state
= 0;
6678 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6679 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6680 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6682 UINT mask
= lpLVItem
->mask
;
6684 /* NOTE: copy only fields which we _know_ are initialized, some apps
6685 * depend on the uninitialized fields being 0 */
6686 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6687 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6688 dispInfo
.item
.iSubItem
= isubitem
;
6689 if (lpLVItem
->mask
& LVIF_TEXT
)
6691 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6693 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6696 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6697 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6700 if (lpLVItem
->mask
& LVIF_STATE
)
6701 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6702 /* could be zeroed on LVIF_NORECOMPUTE case */
6703 if (dispInfo
.item
.mask
)
6705 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6706 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6707 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6709 /* full size structure expected - _WIN32IE >= 0x560 */
6710 *lpLVItem
= dispInfo
.item
;
6712 else if (lpLVItem
->mask
& LVIF_INDENT
)
6714 /* indent member expected - _WIN32IE >= 0x300 */
6715 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6719 /* minimal structure expected */
6720 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6722 lpLVItem
->mask
= mask
;
6723 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6727 /* make sure lParam is zeroed out */
6728 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6730 /* callback marked pointer required here */
6731 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6732 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6734 /* we store only a little state, so if we're not asked, we're done */
6735 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6737 /* if focus is handled by us, report it */
6738 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6740 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6741 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6742 lpLVItem
->state
|= LVIS_FOCUSED
;
6745 /* and do the same for selection, if we handle it */
6746 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6748 lpLVItem
->state
&= ~LVIS_SELECTED
;
6749 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6750 lpLVItem
->state
|= LVIS_SELECTED
;
6756 /* find the item and subitem structures before we proceed */
6757 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6758 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6763 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6764 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6767 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6772 pItemHdr
= &lpItem
->hdr
;
6774 /* Do we need to query the state from the app? */
6775 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6777 dispInfo
.item
.mask
|= LVIF_STATE
;
6778 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6781 /* Do we need to enquire about the image? */
6782 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6783 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6785 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6786 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6789 /* Only items support indentation */
6790 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6793 dispInfo
.item
.mask
|= LVIF_INDENT
;
6794 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6797 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6798 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6799 !is_text(pItemHdr
->pszText
))
6801 dispInfo
.item
.mask
|= LVIF_TEXT
;
6802 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6803 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6804 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6805 *dispInfo
.item
.pszText
= '\0';
6808 /* If we don't have all the requested info, query the application */
6809 if (dispInfo
.item
.mask
)
6811 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6812 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6813 dispInfo
.item
.lParam
= lpItem
->lParam
;
6814 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6815 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6818 /* we should not store values for subitems */
6819 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6821 /* Now, handle the iImage field */
6822 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6824 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6825 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6826 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6828 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6830 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6831 lpLVItem
->iImage
= pItemHdr
->iImage
;
6833 lpLVItem
->iImage
= 0;
6836 /* The pszText field */
6837 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6839 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6840 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6842 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6844 else if (lpLVItem
->mask
& LVIF_TEXT
)
6846 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6847 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6848 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6851 /* Next is the lParam field */
6852 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6854 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6855 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6856 lpItem
->lParam
= dispInfo
.item
.lParam
;
6858 else if (lpLVItem
->mask
& LVIF_PARAM
)
6859 lpLVItem
->lParam
= lpItem
->lParam
;
6861 /* if this is a subitem, we're done */
6862 if (isubitem
) return TRUE
;
6864 /* ... the state field (this one is different due to uCallbackmask) */
6865 if (lpLVItem
->mask
& LVIF_STATE
)
6867 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6868 if (dispInfo
.item
.mask
& LVIF_STATE
)
6870 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6871 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6873 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6875 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6876 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6877 lpLVItem
->state
|= LVIS_FOCUSED
;
6879 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6881 lpLVItem
->state
&= ~LVIS_SELECTED
;
6882 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6883 lpLVItem
->state
|= LVIS_SELECTED
;
6887 /* and last, but not least, the indent field */
6888 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6890 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6891 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6892 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6894 else if (lpLVItem
->mask
& LVIF_INDENT
)
6896 lpLVItem
->iIndent
= lpItem
->iIndent
;
6904 * Retrieves item attributes.
6907 * [I] hwnd : window handle
6908 * [IO] lpLVItem : item info
6909 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6910 * if FALSE, then lpLVItem is a LPLVITEMA.
6913 * This is the external 'GetItem' interface -- it properly copies
6914 * the text in the provided buffer.
6920 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6925 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6928 pszText
= lpLVItem
->pszText
;
6929 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6930 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6932 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6933 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6935 pszText
= LPSTR_TEXTCALLBACKW
;
6937 lpLVItem
->pszText
= pszText
;
6945 * Retrieves the position (upper-left) of the listview control item.
6946 * Note that for LVS_ICON style, the upper-left is that of the icon
6947 * and not the bounding box.
6950 * [I] infoPtr : valid pointer to the listview structure
6951 * [I] nItem : item index
6952 * [O] lpptPosition : coordinate information
6958 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6962 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6964 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6966 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6967 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6969 if (infoPtr
->uView
== LV_VIEW_ICON
)
6971 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6972 lpptPosition
->y
+= ICON_TOP_PADDING
;
6974 lpptPosition
->x
+= Origin
.x
;
6975 lpptPosition
->y
+= Origin
.y
;
6977 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6984 * Retrieves the bounding rectangle for a listview control item.
6987 * [I] infoPtr : valid pointer to the listview structure
6988 * [I] nItem : item index
6989 * [IO] lprc : bounding rectangle coordinates
6990 * lprc->left specifies the portion of the item for which the bounding
6991 * rectangle will be retrieved.
6993 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6994 * including the icon and label.
6997 * * Experiment shows that native control returns:
6998 * * width = min (48, length of text line)
6999 * * .left = position.x - (width - iconsize.cx)/2
7000 * * .right = .left + width
7001 * * height = #lines of text * ntmHeight + icon height + 8
7002 * * .top = position.y - 2
7003 * * .bottom = .top + height
7004 * * separation between items .y = itemSpacing.cy - height
7005 * * .x = itemSpacing.cx - width
7006 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7009 * * Experiment shows that native control returns:
7010 * * width = iconSize.cx + 16
7011 * * .left = position.x - (width - iconsize.cx)/2
7012 * * .right = .left + width
7013 * * height = iconSize.cy + 4
7014 * * .top = position.y - 2
7015 * * .bottom = .top + height
7016 * * separation between items .y = itemSpacing.cy - height
7017 * * .x = itemSpacing.cx - width
7018 * LVIR_LABEL Returns the bounding rectangle of the item text.
7021 * * Experiment shows that native control returns:
7022 * * width = text length
7023 * * .left = position.x - width/2
7024 * * .right = .left + width
7025 * * height = ntmH * linecount + 2
7026 * * .top = position.y + iconSize.cy + 6
7027 * * .bottom = .top + height
7028 * * separation between items .y = itemSpacing.cy - height
7029 * * .x = itemSpacing.cx - width
7030 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7031 * rectangles, but excludes columns in report view.
7038 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7039 * upon whether the window has the focus currently and on whether the item
7040 * is the one with the focus. Ensure that the control's record of which
7041 * item has the focus agrees with the items' records.
7043 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7045 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7046 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7047 POINT Position
, Origin
;
7051 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7053 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7055 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7056 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7058 /* Be smart and try to figure out the minimum we have to do */
7059 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7060 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7061 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7062 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7063 oversizedBox
= TRUE
;
7065 /* get what we need from the item before hand, so we make
7066 * only one request. This can speed up things, if data
7067 * is stored on the app side */
7069 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7070 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7071 lvItem
.iItem
= nItem
;
7072 lvItem
.iSubItem
= 0;
7073 lvItem
.pszText
= szDispText
;
7074 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7075 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7076 /* we got the state already up, simulate it here, to avoid a reget */
7077 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7079 lvItem
.mask
|= LVIF_STATE
;
7080 lvItem
.stateMask
= LVIS_FOCUSED
;
7081 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7084 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7085 lprc
->left
= LVIR_BOUNDS
;
7091 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7095 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7099 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7102 case LVIR_SELECTBOUNDS
:
7103 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7107 WARN("Unknown value: %d\n", lprc
->left
);
7111 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7113 if (mode
!= LVIR_BOUNDS
)
7114 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7115 Position
.y
+ Origin
.y
);
7117 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7120 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7122 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7129 * Retrieves the spacing between listview control items.
7132 * [I] infoPtr : valid pointer to the listview structure
7133 * [IO] lprc : rectangle to receive the output
7134 * on input, lprc->top = nSubItem
7135 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7137 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7138 * not only those of the first column.
7144 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7146 RECT rect
= { 0, 0, 0, 0 };
7150 if (!lprc
) return FALSE
;
7152 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7153 /* Subitem of '0' means item itself, and this works for all control view modes */
7155 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7157 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7159 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7160 /* this works for any item index, no matter if it exists or not */
7161 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7163 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7166 rect
.bottom
= infoPtr
->nItemHeight
;
7170 /* Native implementation is broken for this case and garbage is left for left and right fields,
7171 we zero them to get predictable output */
7172 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7173 lprc
->bottom
= infoPtr
->nItemHeight
;
7174 OffsetRect(lprc
, origin
.x
, y
);
7175 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7183 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7184 if (infoPtr
->himlSmall
)
7185 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7187 rect
.right
= rect
.left
;
7189 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7197 ERR("Unknown bounds=%d\n", lprc
->left
);
7201 OffsetRect(&rect
, origin
.x
, y
);
7203 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7210 * Retrieves the spacing between listview control items.
7213 * [I] infoPtr : valid pointer to the listview structure
7214 * [I] bSmall : flag for small or large icon
7217 * Horizontal + vertical spacing
7219 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7225 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7229 if (infoPtr
->uView
== LV_VIEW_ICON
)
7230 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7232 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7239 * Retrieves the state of a listview control item.
7242 * [I] infoPtr : valid pointer to the listview structure
7243 * [I] nItem : item index
7244 * [I] uMask : state mask
7247 * State specified by the mask.
7249 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7253 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7255 lvItem
.iItem
= nItem
;
7256 lvItem
.iSubItem
= 0;
7257 lvItem
.mask
= LVIF_STATE
;
7258 lvItem
.stateMask
= uMask
;
7259 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7261 return lvItem
.state
& uMask
;
7266 * Retrieves the text of a listview control item or subitem.
7269 * [I] hwnd : window handle
7270 * [I] nItem : item index
7271 * [IO] lpLVItem : item information
7272 * [I] isW : TRUE if lpLVItem is Unicode
7275 * SUCCESS : string length
7278 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7280 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7282 lpLVItem
->mask
= LVIF_TEXT
;
7283 lpLVItem
->iItem
= nItem
;
7284 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7286 return textlenT(lpLVItem
->pszText
, isW
);
7291 * Searches for an item based on properties + relationships.
7294 * [I] infoPtr : valid pointer to the listview structure
7295 * [I] nItem : item index
7296 * [I] uFlags : relationship flag
7299 * SUCCESS : item index
7302 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7305 LVFINDINFOW lvFindInfo
;
7306 INT nCountPerColumn
;
7310 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7311 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7313 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7315 if (uFlags
& LVNI_CUT
)
7318 if (uFlags
& LVNI_DROPHILITED
)
7319 uMask
|= LVIS_DROPHILITED
;
7321 if (uFlags
& LVNI_FOCUSED
)
7322 uMask
|= LVIS_FOCUSED
;
7324 if (uFlags
& LVNI_SELECTED
)
7325 uMask
|= LVIS_SELECTED
;
7327 /* if we're asked for the focused item, that's only one,
7328 * so it's worth optimizing */
7329 if (uFlags
& LVNI_FOCUSED
)
7331 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7332 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7335 if (uFlags
& LVNI_ABOVE
)
7337 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7342 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7348 /* Special case for autoarrange - move 'til the top of a list */
7349 if (is_autoarrange(infoPtr
))
7351 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7352 while (nItem
- nCountPerRow
>= 0)
7354 nItem
-= nCountPerRow
;
7355 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7360 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7361 lvFindInfo
.vkDirection
= VK_UP
;
7362 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7363 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7365 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7370 else if (uFlags
& LVNI_BELOW
)
7372 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7374 while (nItem
< infoPtr
->nItemCount
)
7377 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7383 /* Special case for autoarrange - move 'til the bottom of a list */
7384 if (is_autoarrange(infoPtr
))
7386 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7387 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7389 nItem
+= nCountPerRow
;
7390 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7395 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7396 lvFindInfo
.vkDirection
= VK_DOWN
;
7397 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7398 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7400 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7405 else if (uFlags
& LVNI_TOLEFT
)
7407 if (infoPtr
->uView
== LV_VIEW_LIST
)
7409 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7410 while (nItem
- nCountPerColumn
>= 0)
7412 nItem
-= nCountPerColumn
;
7413 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7417 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7419 /* Special case for autoarrange - move 'til the beginning of a row */
7420 if (is_autoarrange(infoPtr
))
7422 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7423 while (nItem
% nCountPerRow
> 0)
7426 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7431 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7432 lvFindInfo
.vkDirection
= VK_LEFT
;
7433 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7434 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7436 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7441 else if (uFlags
& LVNI_TORIGHT
)
7443 if (infoPtr
->uView
== LV_VIEW_LIST
)
7445 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7446 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7448 nItem
+= nCountPerColumn
;
7449 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7453 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7455 /* Special case for autoarrange - move 'til the end of a row */
7456 if (is_autoarrange(infoPtr
))
7458 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7459 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7462 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7467 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7468 lvFindInfo
.vkDirection
= VK_RIGHT
;
7469 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7470 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7472 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7481 /* search by index */
7482 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7484 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7492 /* LISTVIEW_GetNumberOfWorkAreas */
7496 * Retrieves the origin coordinates when in icon or small icon display mode.
7499 * [I] infoPtr : valid pointer to the listview structure
7500 * [O] lpptOrigin : coordinate information
7505 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7507 INT nHorzPos
= 0, nVertPos
= 0;
7508 SCROLLINFO scrollInfo
;
7510 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7511 scrollInfo
.fMask
= SIF_POS
;
7513 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7514 nHorzPos
= scrollInfo
.nPos
;
7515 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7516 nVertPos
= scrollInfo
.nPos
;
7518 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7520 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7521 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7522 if (infoPtr
->uView
== LV_VIEW_LIST
)
7523 nHorzPos
*= infoPtr
->nItemWidth
;
7524 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7525 nVertPos
*= infoPtr
->nItemHeight
;
7527 lpptOrigin
->x
-= nHorzPos
;
7528 lpptOrigin
->y
-= nVertPos
;
7530 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7535 * Retrieves the width of a string.
7538 * [I] hwnd : window handle
7539 * [I] lpszText : text string to process
7540 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7543 * SUCCESS : string width (in pixels)
7546 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7551 if (is_text(lpszText
))
7553 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7554 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7555 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7558 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7560 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7561 SelectObject(hdc
, hOldFont
);
7562 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7564 return stringSize
.cx
;
7569 * Determines which listview item is located at the specified position.
7572 * [I] infoPtr : valid pointer to the listview structure
7573 * [IO] lpht : hit test information
7574 * [I] subitem : fill out iSubItem.
7575 * [I] select : return the index only if the hit selects the item
7578 * (mm 20001022): We must not allow iSubItem to be touched, for
7579 * an app might pass only a structure with space up to iItem!
7580 * (MS Office 97 does that for instance in the file open dialog)
7583 * SUCCESS : item index
7586 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7588 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7589 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7590 POINT Origin
, Position
, opt
;
7596 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7600 if (subitem
) lpht
->iSubItem
= 0;
7602 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7604 /* set whole list relation flags */
7605 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7607 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7608 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7609 lpht
->flags
|= LVHT_TOLEFT
;
7611 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7612 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7616 if (infoPtr
->rcList
.bottom
< opt
.y
)
7617 lpht
->flags
|= LVHT_BELOW
;
7621 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7622 lpht
->flags
|= LVHT_TOLEFT
;
7623 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7624 lpht
->flags
|= LVHT_TORIGHT
;
7626 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7627 lpht
->flags
|= LVHT_ABOVE
;
7628 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7629 lpht
->flags
|= LVHT_BELOW
;
7632 /* even if item is invalid try to find subitem */
7633 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7638 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7640 lpht
->iSubItem
= -1;
7641 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7643 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7645 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7651 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7653 /* if we're outside horizontal columns bounds there's nothing to test further */
7654 if (lpht
->iSubItem
== -1)
7657 lpht
->flags
= LVHT_NOWHERE
;
7662 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7663 if (lpht
->flags
) return -1;
7665 lpht
->flags
|= LVHT_NOWHERE
;
7667 /* first deal with the large items */
7668 rcSearch
.left
= lpht
->pt
.x
;
7669 rcSearch
.top
= lpht
->pt
.y
;
7670 rcSearch
.right
= rcSearch
.left
+ 1;
7671 rcSearch
.bottom
= rcSearch
.top
+ 1;
7673 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7674 iterator_next(&i
); /* go to first item in the sequence */
7676 iterator_destroy(&i
);
7678 TRACE("lpht->iItem=%d\n", iItem
);
7679 if (iItem
== -1) return -1;
7681 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7682 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7683 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7684 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7685 lvItem
.iItem
= iItem
;
7686 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7687 lvItem
.pszText
= szDispText
;
7688 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7689 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7690 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7692 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7693 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7694 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7696 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7697 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7699 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7701 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7704 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7705 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7709 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7710 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7712 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7713 if (!PtInRect(&rcBounds
, opt
)) return -1;
7715 /* That's a special case - row rectangle is used as item rectangle and
7716 returned flags contain all item parts. */
7717 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7719 if (PtInRect(&rcIcon
, opt
))
7720 lpht
->flags
|= LVHT_ONITEMICON
;
7721 else if (PtInRect(&rcLabel
, opt
))
7722 lpht
->flags
|= LVHT_ONITEMLABEL
;
7723 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7724 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7725 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7727 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7729 if (lpht
->flags
& LVHT_ONITEM
)
7730 lpht
->flags
&= ~LVHT_NOWHERE
;
7731 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7733 if (select
&& !is_fullrow
)
7735 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7737 /* get main item bounds */
7738 lvItem
.iSubItem
= 0;
7739 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7740 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7741 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7743 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7745 return lpht
->iItem
= iItem
;
7750 * Inserts a new item in the listview control.
7753 * [I] infoPtr : valid pointer to the listview structure
7754 * [I] lpLVItem : item information
7755 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7758 * SUCCESS : new item index
7761 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7768 BOOL is_sorted
, has_changed
;
7770 HWND hwndSelf
= infoPtr
->hwndSelf
;
7772 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7774 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7776 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7777 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7779 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7781 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7783 /* insert item in listview control data structure */
7784 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7785 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7787 /* link with id struct */
7788 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7790 lpID
->item
= hdpaSubItems
;
7791 lpID
->id
= get_next_itemid(infoPtr
);
7792 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7794 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7795 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7797 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7799 /* calculate new item index */
7806 while (i
< infoPtr
->nItemCount
)
7808 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7809 item_s
= DPA_GetPtr(hItem
, 0);
7811 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7812 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7814 if (cmpv
>= 0) break;
7820 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7822 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7823 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7824 if (nItem
== -1) goto fail
;
7825 infoPtr
->nItemCount
++;
7827 /* shift indices first so they don't get tangled */
7828 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7830 /* set the item attributes */
7831 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7833 /* full size structure expected - _WIN32IE >= 0x560 */
7836 else if (lpLVItem
->mask
& LVIF_INDENT
)
7838 /* indent member expected - _WIN32IE >= 0x300 */
7839 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7843 /* minimal structure expected */
7844 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7847 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7849 item
.mask
|= LVIF_STATE
;
7850 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7851 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7852 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7855 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7857 /* make room for the position, if we are in the right mode */
7858 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7860 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7862 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7864 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7869 /* send LVN_INSERTITEM notification */
7870 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7872 nmlv
.lParam
= lpItem
->lParam
;
7873 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7874 if (!IsWindow(hwndSelf
))
7877 /* align items (set position of each item) */
7878 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7882 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7883 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7885 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7887 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7890 /* now is the invalidation fun */
7891 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7895 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7896 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7897 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7898 infoPtr
->nItemCount
--;
7900 DPA_DeletePtr(hdpaSubItems
, 0);
7901 DPA_Destroy (hdpaSubItems
);
7908 * Checks item visibility.
7911 * [I] infoPtr : valid pointer to the listview structure
7912 * [I] nFirst : item index to check for
7915 * Item visible : TRUE
7916 * Item invisible or failure : FALSE
7918 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7920 POINT Origin
, Position
;
7925 TRACE("nItem=%d\n", nItem
);
7927 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7929 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7930 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7931 rcItem
.left
= Position
.x
+ Origin
.x
;
7932 rcItem
.top
= Position
.y
+ Origin
.y
;
7933 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7934 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7936 hdc
= GetDC(infoPtr
->hwndSelf
);
7937 if (!hdc
) return FALSE
;
7938 ret
= RectVisible(hdc
, &rcItem
);
7939 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7946 * Redraws a range of items.
7949 * [I] infoPtr : valid pointer to the listview structure
7950 * [I] nFirst : first item
7951 * [I] nLast : last item
7957 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7961 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7962 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7965 for (i
= nFirst
; i
<= nLast
; i
++)
7966 LISTVIEW_InvalidateItem(infoPtr
, i
);
7973 * Scroll the content of a listview.
7976 * [I] infoPtr : valid pointer to the listview structure
7977 * [I] dx : horizontal scroll amount in pixels
7978 * [I] dy : vertical scroll amount in pixels
7985 * If the control is in report view (LV_VIEW_DETAILS) the control can
7986 * be scrolled only in line increments. "dy" will be rounded to the
7987 * nearest number of pixels that are a whole line. Ex: if line height
7988 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7989 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7991 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7993 switch(infoPtr
->uView
) {
7994 case LV_VIEW_DETAILS
:
7995 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7996 dy
/= infoPtr
->nItemHeight
;
7999 if (dy
!= 0) return FALSE
;
8005 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8006 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8013 * Sets the background color.
8016 * [I] infoPtr : valid pointer to the listview structure
8017 * [I] color : background color
8023 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8025 TRACE("(color=%x)\n", color
);
8027 if(infoPtr
->clrBk
!= color
) {
8028 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8029 infoPtr
->clrBk
= color
;
8030 if (color
== CLR_NONE
)
8031 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8034 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8035 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8042 /* LISTVIEW_SetBkImage */
8044 /*** Helper for {Insert,Set}ColumnT *only* */
8045 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8046 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8048 if (lpColumn
->mask
& LVCF_FMT
)
8050 /* format member is valid */
8051 lphdi
->mask
|= HDI_FORMAT
;
8053 /* set text alignment (leftmost column must be left-aligned) */
8054 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8055 lphdi
->fmt
|= HDF_LEFT
;
8056 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8057 lphdi
->fmt
|= HDF_RIGHT
;
8058 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8059 lphdi
->fmt
|= HDF_CENTER
;
8061 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8062 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8064 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8066 lphdi
->fmt
|= HDF_IMAGE
;
8067 lphdi
->iImage
= I_IMAGECALLBACK
;
8070 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8071 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8074 if (lpColumn
->mask
& LVCF_WIDTH
)
8076 lphdi
->mask
|= HDI_WIDTH
;
8077 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8079 /* make it fill the remainder of the controls width */
8083 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8085 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8086 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8089 /* retrieve the layout of the header */
8090 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8091 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8093 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8096 lphdi
->cxy
= lpColumn
->cx
;
8099 if (lpColumn
->mask
& LVCF_TEXT
)
8101 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8102 lphdi
->fmt
|= HDF_STRING
;
8103 lphdi
->pszText
= lpColumn
->pszText
;
8104 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8107 if (lpColumn
->mask
& LVCF_IMAGE
)
8109 lphdi
->mask
|= HDI_IMAGE
;
8110 lphdi
->iImage
= lpColumn
->iImage
;
8113 if (lpColumn
->mask
& LVCF_ORDER
)
8115 lphdi
->mask
|= HDI_ORDER
;
8116 lphdi
->iOrder
= lpColumn
->iOrder
;
8123 * Inserts a new column.
8126 * [I] infoPtr : valid pointer to the listview structure
8127 * [I] nColumn : column index
8128 * [I] lpColumn : column information
8129 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8132 * SUCCESS : new column index
8135 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8136 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8138 COLUMN_INFO
*lpColumnInfo
;
8142 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8144 if (!lpColumn
|| nColumn
< 0) return -1;
8145 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8147 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8148 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8151 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8152 * (can be seen in SPY) otherwise column never gets added.
8154 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8155 hdi
.mask
|= HDI_WIDTH
;
8160 * when the iSubItem is available Windows copies it to the header lParam. It seems
8161 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8163 if (lpColumn
->mask
& LVCF_SUBITEM
)
8165 hdi
.mask
|= HDI_LPARAM
;
8166 hdi
.lParam
= lpColumn
->iSubItem
;
8169 /* create header if not present */
8170 LISTVIEW_CreateHeader(infoPtr
);
8171 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8172 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8174 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8177 /* insert item in header control */
8178 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8179 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8180 nColumn
, (LPARAM
)&hdi
);
8181 if (nNewColumn
== -1) return -1;
8182 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8184 /* create our own column info */
8185 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8186 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8188 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8189 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8190 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8193 /* now we have to actually adjust the data */
8194 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8196 SUBITEM_INFO
*lpSubItem
;
8202 item
.iSubItem
= nNewColumn
;
8203 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8204 item
.iImage
= I_IMAGECALLBACK
;
8205 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8207 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8209 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8210 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8212 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8213 if (lpSubItem
->iSubItem
>= nNewColumn
)
8214 lpSubItem
->iSubItem
++;
8217 /* add new subitem for each item */
8219 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8223 /* make space for the new column */
8224 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8225 LISTVIEW_UpdateItemSize(infoPtr
);
8230 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8233 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8241 * Sets the attributes of a header item.
8244 * [I] infoPtr : valid pointer to the listview structure
8245 * [I] nColumn : column index
8246 * [I] lpColumn : column attributes
8247 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8253 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8254 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8256 HDITEMW hdi
, hdiget
;
8259 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8261 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8263 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8264 if (lpColumn
->mask
& LVCF_FMT
)
8266 hdi
.mask
|= HDI_FORMAT
;
8267 hdiget
.mask
= HDI_FORMAT
;
8268 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8269 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8271 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8273 /* set header item attributes */
8274 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8275 if (!bResult
) return FALSE
;
8277 if (lpColumn
->mask
& LVCF_FMT
)
8279 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8280 INT oldFmt
= lpColumnInfo
->fmt
;
8282 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8283 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8285 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8289 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8290 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8297 * Sets the column order array
8300 * [I] infoPtr : valid pointer to the listview structure
8301 * [I] iCount : number of elements in column order array
8302 * [I] lpiArray : pointer to column order array
8308 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8310 if (!infoPtr
->hwndHeader
) return FALSE
;
8311 infoPtr
->colRectsDirty
= TRUE
;
8312 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8317 * Sets the width of a column
8320 * [I] infoPtr : valid pointer to the listview structure
8321 * [I] nColumn : column index
8322 * [I] cx : column width
8328 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8330 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8334 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8336 /* set column width only if in report or list mode */
8337 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8339 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8340 with _USEHEADER being the lowest */
8341 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8342 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8344 /* resize all columns if in LV_VIEW_LIST mode */
8345 if(infoPtr
->uView
== LV_VIEW_LIST
)
8347 infoPtr
->nItemWidth
= cx
;
8348 LISTVIEW_InvalidateList(infoPtr
);
8352 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8354 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8359 lvItem
.mask
= LVIF_TEXT
;
8361 lvItem
.iSubItem
= nColumn
;
8362 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8363 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8365 lvItem
.pszText
= szDispText
;
8366 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8367 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8368 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8370 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8371 max_cx
+= infoPtr
->iconSize
.cx
;
8372 max_cx
+= TRAILING_LABEL_PADDING
;
8375 /* autosize based on listview items width */
8376 if(cx
== LVSCW_AUTOSIZE
)
8378 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8380 /* if iCol is the last column make it fill the remainder of the controls width */
8381 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8386 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8387 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8389 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8393 /* Despite what the MS docs say, if this is not the last
8394 column, then MS resizes the column to the width of the
8395 largest text string in the column, including headers
8396 and items. This is different from LVSCW_AUTOSIZE in that
8397 LVSCW_AUTOSIZE ignores the header string length. */
8400 /* retrieve header text */
8401 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8402 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8403 hdi
.pszText
= szDispText
;
8404 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8406 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8407 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8408 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8409 INT bitmap_margin
= 0;
8412 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8413 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8415 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8416 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8418 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8420 INT icon_cx
, icon_cy
;
8422 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8423 cx
+= icon_cx
+ 2*bitmap_margin
;
8425 else if (hdi
.fmt
& HDF_BITMAP
)
8429 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8430 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8433 SelectObject(hdc
, old_font
);
8434 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8436 cx
= max (cx
, max_cx
);
8440 if (cx
< 0) return FALSE
;
8442 /* call header to update the column change */
8443 hdi
.mask
= HDI_WIDTH
;
8444 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8445 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8446 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8450 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8453 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8456 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8458 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8459 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8462 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8463 ILC_COLOR
| ILC_MASK
, 2, 2);
8464 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8465 hdc
= CreateCompatibleDC(hdc_wnd
);
8466 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8467 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8468 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8470 rc
.left
= rc
.top
= 0;
8471 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
8472 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
8474 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8475 FillRect(hdc
, &rc
, hbr_white
);
8476 InflateRect(&rc
, -2, -2);
8477 FillRect(hdc
, &rc
, hbr_black
);
8479 SelectObject(hdc
, hbm_im
);
8480 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8481 SelectObject(hdc
, hbm_orig
);
8482 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8484 SelectObject(hdc
, hbm_im
);
8485 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8486 SelectObject(hdc
, hbm_orig
);
8487 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8489 DeleteObject(hbm_mask
);
8490 DeleteObject(hbm_im
);
8498 * Sets the extended listview style.
8501 * [I] infoPtr : valid pointer to the listview structure
8503 * [I] dwStyle : style
8506 * SUCCESS : previous style
8509 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8511 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8513 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8517 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8519 infoPtr
->dwLvExStyle
= ex_style
;
8521 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8523 HIMAGELIST himl
= 0;
8524 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8527 item
.mask
= LVIF_STATE
;
8528 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8529 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8530 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8532 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8533 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8534 ImageList_Destroy(infoPtr
->himlState
);
8536 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8537 /* checkbox list replaces previous custom list or... */
8538 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8539 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8540 /* ...previous was checkbox list */
8541 (old_ex_style
& LVS_EX_CHECKBOXES
))
8542 ImageList_Destroy(himl
);
8545 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8549 /* if not already created */
8550 LISTVIEW_CreateHeader(infoPtr
);
8552 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8553 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8554 style
|= HDS_DRAGDROP
;
8556 style
&= ~HDS_DRAGDROP
;
8557 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8560 /* GRIDLINES adds decoration at top so changes sizes */
8561 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8563 LISTVIEW_CreateHeader(infoPtr
);
8564 LISTVIEW_UpdateSize(infoPtr
);
8567 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8569 LISTVIEW_CreateHeader(infoPtr
);
8572 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8574 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8575 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8578 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8580 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8581 LISTVIEW_CreateHeader(infoPtr
);
8583 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8584 LISTVIEW_UpdateSize(infoPtr
);
8585 LISTVIEW_UpdateScroll(infoPtr
);
8588 LISTVIEW_InvalidateList(infoPtr
);
8589 return old_ex_style
;
8594 * Sets the new hot cursor used during hot tracking and hover selection.
8597 * [I] infoPtr : valid pointer to the listview structure
8598 * [I] hCursor : the new hot cursor handle
8601 * Returns the previous hot cursor
8603 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8605 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8607 infoPtr
->hHotCursor
= hCursor
;
8615 * Sets the hot item index.
8618 * [I] infoPtr : valid pointer to the listview structure
8619 * [I] iIndex : index
8622 * SUCCESS : previous hot item index
8623 * FAILURE : -1 (no hot item)
8625 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8627 INT iOldIndex
= infoPtr
->nHotItem
;
8629 infoPtr
->nHotItem
= iIndex
;
8637 * Sets the amount of time the cursor must hover over an item before it is selected.
8640 * [I] infoPtr : valid pointer to the listview structure
8641 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8644 * Returns the previous hover time
8646 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8648 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8650 infoPtr
->dwHoverTime
= dwHoverTime
;
8652 return oldHoverTime
;
8657 * Sets spacing for icons of LVS_ICON style.
8660 * [I] infoPtr : valid pointer to the listview structure
8661 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8662 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8665 * MAKELONG(oldcx, oldcy)
8667 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8669 INT iconWidth
= 0, iconHeight
= 0;
8670 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8672 TRACE("requested=(%d,%d)\n", cx
, cy
);
8674 /* set to defaults, if instructed to */
8675 if (cx
== -1 && cy
== -1)
8677 infoPtr
->autoSpacing
= TRUE
;
8678 if (infoPtr
->himlNormal
)
8679 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8680 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8681 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8684 infoPtr
->autoSpacing
= FALSE
;
8686 /* if 0 then keep width */
8688 infoPtr
->iconSpacing
.cx
= cx
;
8690 /* if 0 then keep height */
8692 infoPtr
->iconSpacing
.cy
= cy
;
8694 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8695 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8696 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8697 infoPtr
->ntmHeight
);
8699 /* these depend on the iconSpacing */
8700 LISTVIEW_UpdateItemSize(infoPtr
);
8705 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8709 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8716 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8717 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8726 * [I] infoPtr : valid pointer to the listview structure
8727 * [I] nType : image list type
8728 * [I] himl : image list handle
8731 * SUCCESS : old image list
8734 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8736 INT oldHeight
= infoPtr
->nItemHeight
;
8737 HIMAGELIST himlOld
= 0;
8739 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8744 himlOld
= infoPtr
->himlNormal
;
8745 infoPtr
->himlNormal
= himl
;
8746 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8747 if (infoPtr
->autoSpacing
)
8748 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8752 himlOld
= infoPtr
->himlSmall
;
8753 infoPtr
->himlSmall
= himl
;
8754 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8755 if (infoPtr
->hwndHeader
)
8756 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8760 himlOld
= infoPtr
->himlState
;
8761 infoPtr
->himlState
= himl
;
8762 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8763 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8767 ERR("Unknown icon type=%d\n", nType
);
8771 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8772 if (infoPtr
->nItemHeight
!= oldHeight
)
8773 LISTVIEW_UpdateScroll(infoPtr
);
8780 * Preallocates memory (does *not* set the actual count of items !)
8783 * [I] infoPtr : valid pointer to the listview structure
8784 * [I] nItems : item count (projected number of items to allocate)
8785 * [I] dwFlags : update flags
8791 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8793 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8795 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8797 INT nOldCount
= infoPtr
->nItemCount
;
8799 if (nItems
< nOldCount
)
8801 RANGE range
= { nItems
, nOldCount
};
8802 ranges_del(infoPtr
->selectionRanges
, range
);
8803 if (infoPtr
->nFocusedItem
>= nItems
)
8805 LISTVIEW_SetItemFocus(infoPtr
, -1);
8806 SetRectEmpty(&infoPtr
->rcFocus
);
8810 infoPtr
->nItemCount
= nItems
;
8811 LISTVIEW_UpdateScroll(infoPtr
);
8813 /* the flags are valid only in ownerdata report and list modes */
8814 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8816 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8817 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8819 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8820 LISTVIEW_InvalidateList(infoPtr
);
8827 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8828 nFrom
= min(nOldCount
, nItems
);
8829 nTo
= max(nOldCount
, nItems
);
8831 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8834 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8835 rcErase
.right
= infoPtr
->nItemWidth
;
8836 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8837 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8838 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8839 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8841 else /* LV_VIEW_LIST */
8843 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8845 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8846 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8847 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8848 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8849 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8850 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8851 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8853 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8855 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8856 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8857 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8858 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8859 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8865 /* According to MSDN for non-LVS_OWNERDATA this is just
8866 * a performance issue. The control allocates its internal
8867 * data structures for the number of items specified. It
8868 * cuts down on the number of memory allocations. Therefore
8869 * we will just issue a WARN here
8871 WARN("for non-ownerdata performance option not implemented.\n");
8879 * Sets the position of an item.
8882 * [I] infoPtr : valid pointer to the listview structure
8883 * [I] nItem : item index
8884 * [I] pt : coordinate
8890 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8894 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8896 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8897 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8900 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8902 /* This point value seems to be an undocumented feature.
8903 * The best guess is that it means either at the origin,
8904 * or at true beginning of the list. I will assume the origin. */
8905 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8908 if (infoPtr
->uView
== LV_VIEW_ICON
)
8910 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8911 Pt
.y
-= ICON_TOP_PADDING
;
8916 infoPtr
->bAutoarrange
= FALSE
;
8918 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8923 * Sets the state of one or many items.
8926 * [I] infoPtr : valid pointer to the listview structure
8927 * [I] nItem : item index
8928 * [I] item : item or subitem info
8934 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8939 if (!item
) return FALSE
;
8941 lvItem
.iItem
= nItem
;
8942 lvItem
.iSubItem
= 0;
8943 lvItem
.mask
= LVIF_STATE
;
8944 lvItem
.state
= item
->state
;
8945 lvItem
.stateMask
= item
->stateMask
;
8946 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8953 /* special case optimization for recurring attempt to deselect all */
8954 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8957 /* select all isn't allowed in LVS_SINGLESEL */
8958 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8961 /* focus all isn't allowed */
8962 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8964 notify
= infoPtr
->bDoChangeNotify
;
8965 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8967 infoPtr
->bDoChangeNotify
= FALSE
;
8968 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8969 oldstate
|= LVIS_SELECTED
;
8970 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
8973 /* apply to all items */
8974 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8975 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
8977 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8981 infoPtr
->bDoChangeNotify
= notify
;
8985 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
8986 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
8987 nmlv
.uChanged
= LVIF_STATE
;
8988 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
8991 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
8995 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9002 * Sets the text of an item or subitem.
9005 * [I] hwnd : window handle
9006 * [I] nItem : item index
9007 * [I] lpLVItem : item or subitem info
9008 * [I] isW : TRUE if input is Unicode
9014 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9018 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9019 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9021 lvItem
.iItem
= nItem
;
9022 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9023 lvItem
.mask
= LVIF_TEXT
;
9024 lvItem
.pszText
= lpLVItem
->pszText
;
9025 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9027 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9029 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9034 * Set item index that marks the start of a multiple selection.
9037 * [I] infoPtr : valid pointer to the listview structure
9038 * [I] nIndex : index
9041 * Index number or -1 if there is no selection mark.
9043 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9045 INT nOldIndex
= infoPtr
->nSelectionMark
;
9047 TRACE("(nIndex=%d)\n", nIndex
);
9049 infoPtr
->nSelectionMark
= nIndex
;
9056 * Sets the text background color.
9059 * [I] infoPtr : valid pointer to the listview structure
9060 * [I] color : text background color
9066 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9068 TRACE("(color=%x)\n", color
);
9070 infoPtr
->clrTextBk
= color
;
9076 * Sets the text foreground color.
9079 * [I] infoPtr : valid pointer to the listview structure
9080 * [I] color : text color
9086 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9088 TRACE("(color=%x)\n", color
);
9090 infoPtr
->clrText
= color
;
9096 * Sets new ToolTip window to ListView control.
9099 * [I] infoPtr : valid pointer to the listview structure
9100 * [I] hwndNewToolTip : handle to new ToolTip
9105 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9107 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9108 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9109 return hwndOldToolTip
;
9114 * sets the Unicode character format flag for the control
9116 * [I] infoPtr :valid pointer to the listview structure
9117 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9120 * Old Unicode Format
9122 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9124 SHORT rc
= infoPtr
->notifyFormat
;
9125 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9126 return rc
== NFR_UNICODE
;
9131 * sets the control view mode
9133 * [I] infoPtr :valid pointer to the listview structure
9134 * [I] nView :new view mode value
9140 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9144 if (infoPtr
->uView
== nView
) return 1;
9146 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9147 if (nView
== LV_VIEW_TILE
)
9149 FIXME("View LV_VIEW_TILE unimplemented\n");
9153 infoPtr
->uView
= nView
;
9155 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9156 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9158 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9159 SetRectEmpty(&infoPtr
->rcFocus
);
9161 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9162 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9167 case LV_VIEW_SMALLICON
:
9168 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9170 case LV_VIEW_DETAILS
:
9175 LISTVIEW_CreateHeader( infoPtr
);
9177 hl
.prc
= &infoPtr
->rcList
;
9179 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9180 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9181 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9188 LISTVIEW_UpdateItemSize(infoPtr
);
9189 LISTVIEW_UpdateSize(infoPtr
);
9190 LISTVIEW_UpdateScroll(infoPtr
);
9191 LISTVIEW_InvalidateList(infoPtr
);
9193 TRACE("nView=%d\n", nView
);
9198 /* LISTVIEW_SetWorkAreas */
9202 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9205 * [I] first : pointer to first ITEM_INFO to compare
9206 * [I] second : pointer to second ITEM_INFO to compare
9207 * [I] lParam : HWND of control
9210 * if first comes before second : negative
9211 * if first comes after second : positive
9212 * if first and second are equivalent : zero
9214 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9216 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9217 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9218 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9220 /* Forward the call to the client defined callback */
9221 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9226 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9229 * [I] first : pointer to first ITEM_INFO to compare
9230 * [I] second : pointer to second ITEM_INFO to compare
9231 * [I] lParam : HWND of control
9234 * if first comes before second : negative
9235 * if first comes after second : positive
9236 * if first and second are equivalent : zero
9238 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9240 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9241 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9242 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9244 /* Forward the call to the client defined callback */
9245 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9250 * Sorts the listview items.
9253 * [I] infoPtr : valid pointer to the listview structure
9254 * [I] pfnCompare : application-defined value
9255 * [I] lParamSort : pointer to comparison callback
9256 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9262 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9263 LPARAM lParamSort
, BOOL IsEx
)
9267 LPVOID selectionMarkItem
= NULL
;
9268 LPVOID focusedItem
= NULL
;
9271 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9273 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9275 if (!pfnCompare
) return FALSE
;
9276 if (!infoPtr
->hdpaItems
) return FALSE
;
9278 /* if there are 0 or 1 items, there is no need to sort */
9279 if (infoPtr
->nItemCount
< 2) return TRUE
;
9281 /* clear selection */
9282 ranges_clear(infoPtr
->selectionRanges
);
9284 /* save selection mark and focused item */
9285 if (infoPtr
->nSelectionMark
>= 0)
9286 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9287 if (infoPtr
->nFocusedItem
>= 0)
9288 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9290 infoPtr
->pfnCompare
= pfnCompare
;
9291 infoPtr
->lParamSort
= lParamSort
;
9293 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9295 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9297 /* restore selection ranges */
9298 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9300 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9301 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9303 if (lpItem
->state
& LVIS_SELECTED
)
9304 ranges_additem(infoPtr
->selectionRanges
, i
);
9306 /* restore selection mark and focused item */
9307 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9308 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9310 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9312 /* refresh the display */
9313 LISTVIEW_InvalidateList(infoPtr
);
9319 * Update theme handle after a theme change.
9322 * [I] infoPtr : valid pointer to the listview structure
9326 * FAILURE : something else
9328 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9330 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9331 CloseThemeData(theme
);
9332 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9338 * Updates an items or rearranges the listview control.
9341 * [I] infoPtr : valid pointer to the listview structure
9342 * [I] nItem : item index
9348 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9350 TRACE("(nItem=%d)\n", nItem
);
9352 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9354 /* rearrange with default alignment style */
9355 if (is_autoarrange(infoPtr
))
9356 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9358 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9365 * Draw the track line at the place defined in the infoPtr structure.
9366 * The line is drawn with a XOR pen so drawing the line for the second time
9367 * in the same place erases the line.
9370 * [I] infoPtr : valid pointer to the listview structure
9376 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9380 if (infoPtr
->xTrackLine
== -1)
9383 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9385 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9386 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9387 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9393 * Called when an edit control should be displayed. This function is called after
9394 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9397 * [I] hwnd : Handle to the listview
9398 * [I] uMsg : WM_TIMER (ignored)
9399 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9400 * [I] dwTimer : The elapsed time (ignored)
9405 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9407 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9408 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9410 KillTimer(hwnd
, idEvent
);
9411 editItem
->fEnabled
= FALSE
;
9412 /* check if the item is still selected */
9413 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9414 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9419 * Creates the listview control - the WM_NCCREATE phase.
9422 * [I] hwnd : window handle
9423 * [I] lpcs : the create parameters
9429 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9431 LISTVIEW_INFO
*infoPtr
;
9434 TRACE("(lpcs=%p)\n", lpcs
);
9436 /* initialize info pointer */
9437 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9438 if (!infoPtr
) return FALSE
;
9440 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9442 infoPtr
->hwndSelf
= hwnd
;
9443 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9444 map_style_view(infoPtr
);
9445 /* determine the type of structures to use */
9446 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9447 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9449 /* initialize color information */
9450 infoPtr
->clrBk
= CLR_NONE
;
9451 infoPtr
->clrText
= CLR_DEFAULT
;
9452 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9453 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9455 /* set default values */
9456 infoPtr
->nFocusedItem
= -1;
9457 infoPtr
->nSelectionMark
= -1;
9458 infoPtr
->nHotItem
= -1;
9459 infoPtr
->bRedraw
= TRUE
;
9460 infoPtr
->bNoItemMetrics
= TRUE
;
9461 infoPtr
->bDoChangeNotify
= TRUE
;
9462 infoPtr
->autoSpacing
= TRUE
;
9463 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9464 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9465 infoPtr
->nEditLabelItem
= -1;
9466 infoPtr
->nLButtonDownItem
= -1;
9467 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9468 infoPtr
->cWheelRemainder
= 0;
9469 infoPtr
->nMeasureItemHeight
= 0;
9470 infoPtr
->xTrackLine
= -1; /* no track line */
9471 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9472 infoPtr
->iVersion
= COMCTL32_VERSION
;
9473 infoPtr
->colRectsDirty
= FALSE
;
9475 /* get default font (icon title) */
9476 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9477 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9478 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9479 LISTVIEW_SaveTextMetrics(infoPtr
);
9481 /* allocate memory for the data structure */
9482 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9483 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9484 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9485 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9486 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9487 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9491 DestroyWindow(infoPtr
->hwndHeader
);
9492 ranges_destroy(infoPtr
->selectionRanges
);
9493 DPA_Destroy(infoPtr
->hdpaItems
);
9494 DPA_Destroy(infoPtr
->hdpaItemIds
);
9495 DPA_Destroy(infoPtr
->hdpaPosX
);
9496 DPA_Destroy(infoPtr
->hdpaPosY
);
9497 DPA_Destroy(infoPtr
->hdpaColumns
);
9504 * Creates the listview control - the WM_CREATE phase. Most of the data is
9505 * already set up in LISTVIEW_NCCreate
9508 * [I] hwnd : window handle
9509 * [I] lpcs : the create parameters
9515 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9517 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9519 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9521 infoPtr
->dwStyle
= lpcs
->style
;
9522 map_style_view(infoPtr
);
9524 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9525 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9526 /* on error defaulting to ANSI notifications */
9527 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9528 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9530 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9532 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9535 infoPtr
->hwndHeader
= 0;
9537 /* init item size to avoid division by 0 */
9538 LISTVIEW_UpdateItemSize (infoPtr
);
9539 LISTVIEW_UpdateSize (infoPtr
);
9541 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9543 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9545 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9547 LISTVIEW_UpdateScroll(infoPtr
);
9548 /* send WM_MEASUREITEM notification */
9549 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9552 OpenThemeData(hwnd
, themeClass
);
9554 /* initialize the icon sizes */
9555 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9556 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9562 * Destroys the listview control.
9565 * [I] infoPtr : valid pointer to the listview structure
9571 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9573 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9574 CloseThemeData(theme
);
9576 /* delete all items */
9577 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9584 * Enables the listview control.
9587 * [I] infoPtr : valid pointer to the listview structure
9588 * [I] bEnable : specifies whether to enable or disable the window
9594 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9596 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9597 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9603 * Erases the background of the listview control.
9606 * [I] infoPtr : valid pointer to the listview structure
9607 * [I] hdc : device context handle
9613 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9617 TRACE("(hdc=%p)\n", hdc
);
9619 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9621 if (infoPtr
->clrBk
== CLR_NONE
)
9623 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9624 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9625 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9627 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9630 /* for double buffered controls we need to do this during refresh */
9631 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9633 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9639 * Helper function for LISTVIEW_[HV]Scroll *only*.
9640 * Performs vertical/horizontal scrolling by a give amount.
9643 * [I] infoPtr : valid pointer to the listview structure
9644 * [I] dx : amount of horizontal scroll
9645 * [I] dy : amount of vertical scroll
9647 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9649 /* now we can scroll the list */
9650 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9651 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9652 /* if we have focus, adjust rect */
9653 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9654 UpdateWindow(infoPtr
->hwndSelf
);
9659 * Performs vertical scrolling.
9662 * [I] infoPtr : valid pointer to the listview structure
9663 * [I] nScrollCode : scroll code
9664 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9665 * [I] hScrollWnd : scrollbar control window handle
9671 * SB_LINEUP/SB_LINEDOWN:
9672 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9673 * for LVS_REPORT is 1 line
9674 * for LVS_LIST cannot occur
9677 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9680 INT nOldScrollPos
, nNewScrollPos
;
9681 SCROLLINFO scrollInfo
;
9684 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9685 debugscrollcode(nScrollCode
), nScrollDiff
);
9687 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9689 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9690 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9692 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9694 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9696 nOldScrollPos
= scrollInfo
.nPos
;
9697 switch (nScrollCode
)
9703 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9707 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9711 nScrollDiff
= -scrollInfo
.nPage
;
9715 nScrollDiff
= scrollInfo
.nPage
;
9718 case SB_THUMBPOSITION
:
9720 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9727 /* quit right away if pos isn't changing */
9728 if (nScrollDiff
== 0) return 0;
9730 /* calculate new position, and handle overflows */
9731 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9732 if (nScrollDiff
> 0) {
9733 if (nNewScrollPos
< nOldScrollPos
||
9734 nNewScrollPos
> scrollInfo
.nMax
)
9735 nNewScrollPos
= scrollInfo
.nMax
;
9737 if (nNewScrollPos
> nOldScrollPos
||
9738 nNewScrollPos
< scrollInfo
.nMin
)
9739 nNewScrollPos
= scrollInfo
.nMin
;
9742 /* set the new position, and reread in case it changed */
9743 scrollInfo
.fMask
= SIF_POS
;
9744 scrollInfo
.nPos
= nNewScrollPos
;
9745 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9747 /* carry on only if it really changed */
9748 if (nNewScrollPos
== nOldScrollPos
) return 0;
9750 /* now adjust to client coordinates */
9751 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9752 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9754 /* and scroll the window */
9755 scroll_list(infoPtr
, 0, nScrollDiff
);
9762 * Performs horizontal scrolling.
9765 * [I] infoPtr : valid pointer to the listview structure
9766 * [I] nScrollCode : scroll code
9767 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9768 * [I] hScrollWnd : scrollbar control window handle
9774 * SB_LINELEFT/SB_LINERIGHT:
9775 * for LVS_ICON, LVS_SMALLICON 1 pixel
9776 * for LVS_REPORT is 1 pixel
9777 * for LVS_LIST is 1 column --> which is a 1 because the
9778 * scroll is based on columns not pixels
9781 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9784 INT nOldScrollPos
, nNewScrollPos
;
9785 SCROLLINFO scrollInfo
;
9788 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9789 debugscrollcode(nScrollCode
), nScrollDiff
);
9791 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9793 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9794 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9796 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9798 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9800 nOldScrollPos
= scrollInfo
.nPos
;
9802 switch (nScrollCode
)
9808 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9812 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9816 nScrollDiff
= -scrollInfo
.nPage
;
9820 nScrollDiff
= scrollInfo
.nPage
;
9823 case SB_THUMBPOSITION
:
9825 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9832 /* quit right away if pos isn't changing */
9833 if (nScrollDiff
== 0) return 0;
9835 /* calculate new position, and handle overflows */
9836 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9837 if (nScrollDiff
> 0) {
9838 if (nNewScrollPos
< nOldScrollPos
||
9839 nNewScrollPos
> scrollInfo
.nMax
)
9840 nNewScrollPos
= scrollInfo
.nMax
;
9842 if (nNewScrollPos
> nOldScrollPos
||
9843 nNewScrollPos
< scrollInfo
.nMin
)
9844 nNewScrollPos
= scrollInfo
.nMin
;
9847 /* set the new position, and reread in case it changed */
9848 scrollInfo
.fMask
= SIF_POS
;
9849 scrollInfo
.nPos
= nNewScrollPos
;
9850 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9852 /* carry on only if it really changed */
9853 if (nNewScrollPos
== nOldScrollPos
) return 0;
9855 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9857 /* now adjust to client coordinates */
9858 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9859 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9861 /* and scroll the window */
9862 scroll_list(infoPtr
, nScrollDiff
, 0);
9867 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9869 UINT pulScrollLines
= 3;
9871 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9873 switch(infoPtr
->uView
)
9876 case LV_VIEW_SMALLICON
:
9878 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9879 * should be fixed in the future.
9881 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9882 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9885 case LV_VIEW_DETAILS
:
9886 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9888 /* if scrolling changes direction, ignore left overs */
9889 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9890 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9891 infoPtr
->cWheelRemainder
+= wheelDelta
;
9893 infoPtr
->cWheelRemainder
= wheelDelta
;
9894 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9897 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9898 cLineScroll
= pulScrollLines
* (float)infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9899 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
9900 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9905 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9916 * [I] infoPtr : valid pointer to the listview structure
9917 * [I] nVirtualKey : virtual key
9918 * [I] lKeyData : key data
9923 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9925 HWND hwndSelf
= infoPtr
->hwndSelf
;
9927 NMLVKEYDOWN nmKeyDown
;
9929 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9931 /* send LVN_KEYDOWN notification */
9932 nmKeyDown
.wVKey
= nVirtualKey
;
9933 nmKeyDown
.flags
= 0;
9934 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9935 if (!IsWindow(hwndSelf
))
9938 switch (nVirtualKey
)
9941 nItem
= infoPtr
->nFocusedItem
;
9942 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9943 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9947 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9949 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9950 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9955 if (infoPtr
->nItemCount
> 0)
9960 if (infoPtr
->nItemCount
> 0)
9961 nItem
= infoPtr
->nItemCount
- 1;
9965 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9969 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9973 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9977 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9981 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9983 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9984 if (infoPtr
->nFocusedItem
== topidx
)
9985 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9990 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9991 * LISTVIEW_GetCountPerRow(infoPtr
);
9992 if(nItem
< 0) nItem
= 0;
9996 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9998 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9999 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10000 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10001 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10003 nItem
= topidx
+ cnt
- 1;
10006 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10007 * LISTVIEW_GetCountPerRow(infoPtr
);
10008 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10012 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10013 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10023 * [I] infoPtr : valid pointer to the listview structure
10028 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10032 /* drop any left over scroll amount */
10033 infoPtr
->cWheelRemainder
= 0;
10035 /* if we did not have the focus, there's nothing more to do */
10036 if (!infoPtr
->bFocus
) return 0;
10038 /* send NM_KILLFOCUS notification */
10039 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10041 /* if we have a focus rectangle, get rid of it */
10042 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10044 /* if have a marquee selection, stop it */
10045 if (infoPtr
->bMarqueeSelect
)
10047 /* Remove the marquee rectangle and release our mouse capture */
10048 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10051 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10053 infoPtr
->bMarqueeSelect
= FALSE
;
10054 infoPtr
->bScrolling
= FALSE
;
10055 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10058 /* set window focus flag */
10059 infoPtr
->bFocus
= FALSE
;
10061 /* invalidate the selected items before resetting focus flag */
10062 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10069 * Processes double click messages (left mouse button).
10072 * [I] infoPtr : valid pointer to the listview structure
10073 * [I] wKey : key flag
10074 * [I] x,y : mouse coordinate
10079 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10081 LVHITTESTINFO htInfo
;
10083 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10085 /* Cancel the item edition if any */
10086 if (infoPtr
->itemEdit
.fEnabled
)
10088 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10089 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10092 /* send NM_RELEASEDCAPTURE notification */
10093 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10098 /* send NM_DBLCLK notification */
10099 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10100 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10102 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10103 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10108 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10113 r
.top
= r
.bottom
= pt
.y
;
10114 r
.left
= r
.right
= pt
.x
;
10116 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10118 SetCapture(infoPtr
->hwndSelf
);
10122 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10124 if (msg
.message
== WM_MOUSEMOVE
)
10126 pt
.x
= (short)LOWORD(msg
.lParam
);
10127 pt
.y
= (short)HIWORD(msg
.lParam
);
10128 if (PtInRect(&r
, pt
))
10136 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10137 msg
.message
<= WM_RBUTTONDBLCLK
)
10142 DispatchMessageW(&msg
);
10145 if (GetCapture() != infoPtr
->hwndSelf
)
10156 * Processes mouse down messages (left mouse button).
10159 * infoPtr [I ] valid pointer to the listview structure
10160 * wKey [I ] key flag
10161 * x,y [I ] mouse coordinate
10166 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10168 LVHITTESTINFO lvHitTestInfo
;
10169 static BOOL bGroupSelect
= TRUE
;
10170 POINT pt
= { x
, y
};
10173 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10175 /* send NM_RELEASEDCAPTURE notification */
10176 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10178 /* set left button down flag and record the click position */
10179 infoPtr
->bLButtonDown
= TRUE
;
10180 infoPtr
->ptClickPos
= pt
;
10181 infoPtr
->bDragging
= FALSE
;
10182 infoPtr
->bMarqueeSelect
= FALSE
;
10183 infoPtr
->bScrolling
= FALSE
;
10185 lvHitTestInfo
.pt
.x
= x
;
10186 lvHitTestInfo
.pt
.y
= y
;
10188 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10189 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10190 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10192 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10194 toggle_checkbox_state(infoPtr
, nItem
);
10198 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10200 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10201 infoPtr
->nEditLabelItem
= nItem
;
10203 LISTVIEW_SetSelection(infoPtr
, nItem
);
10207 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10211 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10212 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10213 infoPtr
->nSelectionMark
= nItem
;
10219 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10220 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10222 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10223 infoPtr
->nSelectionMark
= nItem
;
10226 else if (wKey
& MK_CONTROL
)
10230 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10232 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10233 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10234 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10235 infoPtr
->nSelectionMark
= nItem
;
10237 else if (wKey
& MK_SHIFT
)
10239 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10243 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10245 infoPtr
->nEditLabelItem
= nItem
;
10246 infoPtr
->nLButtonDownItem
= nItem
;
10248 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10251 /* set selection (clears other pre-existing selections) */
10252 LISTVIEW_SetSelection(infoPtr
, nItem
);
10256 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10257 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10261 if (!infoPtr
->bFocus
)
10262 SetFocus(infoPtr
->hwndSelf
);
10264 /* remove all selections */
10265 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10266 LISTVIEW_DeselectAll(infoPtr
);
10275 * Processes mouse up messages (left mouse button).
10278 * infoPtr [I ] valid pointer to the listview structure
10279 * wKey [I ] key flag
10280 * x,y [I ] mouse coordinate
10285 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10287 LVHITTESTINFO lvHitTestInfo
;
10289 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10291 if (!infoPtr
->bLButtonDown
) return 0;
10293 lvHitTestInfo
.pt
.x
= x
;
10294 lvHitTestInfo
.pt
.y
= y
;
10296 /* send NM_CLICK notification */
10297 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10298 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10300 /* set left button flag */
10301 infoPtr
->bLButtonDown
= FALSE
;
10303 /* set a single selection, reset others */
10304 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10305 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10306 infoPtr
->nLButtonDownItem
= -1;
10308 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10310 /* Remove the marquee rectangle and release our mouse capture */
10311 if (infoPtr
->bMarqueeSelect
)
10313 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10317 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10318 SetRect(&infoPtr
->marqueeDrawRect
, 0, 0, 0, 0);
10320 infoPtr
->bDragging
= FALSE
;
10321 infoPtr
->bMarqueeSelect
= FALSE
;
10322 infoPtr
->bScrolling
= FALSE
;
10324 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10328 /* if we clicked on a selected item, edit the label */
10329 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10331 /* we want to make sure the user doesn't want to do a double click. So we will
10332 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10334 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10335 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10336 SetTimer(infoPtr
->hwndSelf
,
10337 (UINT_PTR
)&infoPtr
->itemEdit
,
10338 GetDoubleClickTime(),
10339 LISTVIEW_DelayedEditItem
);
10342 if (!infoPtr
->bFocus
)
10343 SetFocus(infoPtr
->hwndSelf
);
10350 * Destroys the listview control (called after WM_DESTROY).
10353 * [I] infoPtr : valid pointer to the listview structure
10358 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10364 /* destroy data structure */
10365 DPA_Destroy(infoPtr
->hdpaItems
);
10366 DPA_Destroy(infoPtr
->hdpaItemIds
);
10367 DPA_Destroy(infoPtr
->hdpaPosX
);
10368 DPA_Destroy(infoPtr
->hdpaPosY
);
10370 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10371 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10372 DPA_Destroy(infoPtr
->hdpaColumns
);
10373 ranges_destroy(infoPtr
->selectionRanges
);
10375 /* destroy image lists */
10376 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10378 ImageList_Destroy(infoPtr
->himlNormal
);
10379 ImageList_Destroy(infoPtr
->himlSmall
);
10380 ImageList_Destroy(infoPtr
->himlState
);
10383 /* destroy font, bkgnd brush */
10384 infoPtr
->hFont
= 0;
10385 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10386 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10388 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10390 /* free listview info pointer*/
10398 * Handles notifications.
10401 * [I] infoPtr : valid pointer to the listview structure
10402 * [I] lpnmhdr : notification information
10407 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10411 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10413 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10415 /* remember: HDN_LAST < HDN_FIRST */
10416 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10417 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10419 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10421 switch (lpnmhdr
->code
)
10426 COLUMN_INFO
*lpColumnInfo
;
10430 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10433 /* remove the old line (if any) */
10434 LISTVIEW_DrawTrackLine(infoPtr
);
10436 /* compute & draw the new line */
10437 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10438 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10439 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10440 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10441 LISTVIEW_DrawTrackLine(infoPtr
);
10442 return notify_forward_header(infoPtr
, lpnmh
);
10445 case HDN_ENDTRACKA
:
10446 case HDN_ENDTRACKW
:
10447 /* remove the track line (if any) */
10448 LISTVIEW_DrawTrackLine(infoPtr
);
10449 infoPtr
->xTrackLine
= -1;
10450 return notify_forward_header(infoPtr
, lpnmh
);
10452 case HDN_BEGINDRAG
:
10453 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10454 return notify_forward_header(infoPtr
, lpnmh
);
10457 infoPtr
->colRectsDirty
= TRUE
;
10458 LISTVIEW_InvalidateList(infoPtr
);
10459 return notify_forward_header(infoPtr
, lpnmh
);
10461 case HDN_ITEMCHANGEDW
:
10462 case HDN_ITEMCHANGEDA
:
10464 COLUMN_INFO
*lpColumnInfo
;
10468 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10470 hdi
.mask
= HDI_WIDTH
;
10471 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10475 cxy
= lpnmh
->pitem
->cxy
;
10477 /* determine how much we change since the last know position */
10478 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10479 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10482 lpColumnInfo
->rcHeader
.right
+= dx
;
10484 hdi
.mask
= HDI_ORDER
;
10485 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10487 /* not the rightmost one */
10488 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10490 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10491 hdi
.iOrder
+ 1, 0);
10492 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10496 /* only needs to update the scrolls */
10497 infoPtr
->nItemWidth
+= dx
;
10498 LISTVIEW_UpdateScroll(infoPtr
);
10500 LISTVIEW_UpdateItemSize(infoPtr
);
10501 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10504 RECT rcCol
= lpColumnInfo
->rcHeader
;
10506 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10507 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10509 rcCol
.top
= infoPtr
->rcList
.top
;
10510 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10512 /* resizing left-aligned columns leaves most of the left side untouched */
10513 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10515 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10518 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10521 /* when shrinking the last column clear the now unused field */
10522 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10528 /* deal with right from rightmost column area */
10529 right
.left
= rcCol
.right
;
10530 right
.top
= rcCol
.top
;
10531 right
.bottom
= rcCol
.bottom
;
10532 right
.right
= infoPtr
->rcList
.right
;
10534 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10537 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10543 case HDN_ITEMCLICKW
:
10544 case HDN_ITEMCLICKA
:
10546 /* Handle sorting by Header Column */
10549 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10551 nmlv
.iSubItem
= lpnmh
->iItem
;
10552 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10553 return notify_forward_header(infoPtr
, lpnmh
);
10556 case HDN_DIVIDERDBLCLICKW
:
10557 case HDN_DIVIDERDBLCLICKA
:
10558 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10559 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10560 split needed for that */
10561 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10562 return notify_forward_header(infoPtr
, lpnmh
);
10569 * Paint non-client area of control.
10572 * [I] infoPtr : valid pointer to the listview structureof the sender
10573 * [I] region : update region
10576 * TRUE - frame was painted
10577 * FALSE - call default window proc
10579 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10581 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10585 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10586 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10589 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10591 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10593 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10594 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10595 if (region
!= (HRGN
)1)
10596 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10597 OffsetRect(&r
, -r
.left
, -r
.top
);
10599 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10600 OffsetRect(&r
, -r
.left
, -r
.top
);
10602 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10603 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10604 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10605 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10607 /* Call default proc to get the scrollbars etc. painted */
10608 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10615 * Determines the type of structure to use.
10618 * [I] infoPtr : valid pointer to the listview structureof the sender
10619 * [I] hwndFrom : listview window handle
10620 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10625 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10627 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10629 if (nCommand
== NF_REQUERY
)
10630 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10632 return infoPtr
->notifyFormat
;
10637 * Paints/Repaints the listview control. Internal use.
10640 * [I] infoPtr : valid pointer to the listview structure
10641 * [I] hdc : device context handle
10646 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10648 TRACE("(hdc=%p)\n", hdc
);
10650 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10652 infoPtr
->bNoItemMetrics
= FALSE
;
10653 LISTVIEW_UpdateItemSize(infoPtr
);
10654 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10655 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10656 LISTVIEW_UpdateScroll(infoPtr
);
10659 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10662 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10667 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10668 if (!hdc
) return 1;
10669 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10670 EndPaint(infoPtr
->hwndSelf
, &ps
);
10678 * Paints/Repaints the listview control, WM_PAINT handler.
10681 * [I] infoPtr : valid pointer to the listview structure
10682 * [I] hdc : device context handle
10687 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10689 TRACE("(hdc=%p)\n", hdc
);
10691 if (!is_redrawing(infoPtr
))
10692 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10694 return LISTVIEW_Paint(infoPtr
, hdc
);
10699 * Paints/Repaints the listview control.
10702 * [I] infoPtr : valid pointer to the listview structure
10703 * [I] hdc : device context handle
10704 * [I] options : drawing options
10709 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10711 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10713 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10716 if (options
& PRF_ERASEBKGND
)
10717 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10719 if (options
& PRF_CLIENT
)
10720 LISTVIEW_Paint(infoPtr
, hdc
);
10728 * Processes double click messages (right mouse button).
10731 * [I] infoPtr : valid pointer to the listview structure
10732 * [I] wKey : key flag
10733 * [I] x,y : mouse coordinate
10738 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10740 LVHITTESTINFO lvHitTestInfo
;
10742 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10744 /* send NM_RELEASEDCAPTURE notification */
10745 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10747 /* send NM_RDBLCLK notification */
10748 lvHitTestInfo
.pt
.x
= x
;
10749 lvHitTestInfo
.pt
.y
= y
;
10750 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10751 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10758 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10761 * [I] infoPtr : valid pointer to the listview structure
10762 * [I] wKey : key flag
10763 * [I] x, y : mouse coordinate
10768 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10773 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10775 /* send NM_RELEASEDCAPTURE notification */
10776 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10778 /* determine the index of the selected item */
10781 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10783 /* make sure the listview control window has the focus */
10784 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10786 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10788 LISTVIEW_SetItemFocus(infoPtr
, item
);
10789 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10790 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10791 LISTVIEW_SetSelection(infoPtr
, item
);
10794 LISTVIEW_DeselectAll(infoPtr
);
10796 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10798 if (ht
.iItem
!= -1)
10802 memset(&nmlv
, 0, sizeof(nmlv
));
10803 nmlv
.iItem
= ht
.iItem
;
10804 nmlv
.ptAction
= ht
.pt
;
10806 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10811 SetFocus(infoPtr
->hwndSelf
);
10815 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10817 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10819 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10820 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10821 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10833 * [I] infoPtr : valid pointer to the listview structure
10834 * [I] hwnd : window handle of window containing the cursor
10835 * [I] nHittest : hit-test code
10836 * [I] wMouseMsg : ideintifier of the mouse message
10839 * TRUE if cursor is set
10842 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10844 LVHITTESTINFO lvHitTestInfo
;
10846 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10848 if (!infoPtr
->hHotCursor
) goto forward
;
10850 GetCursorPos(&lvHitTestInfo
.pt
);
10851 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10853 SetCursor(infoPtr
->hHotCursor
);
10859 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10867 * [I] infoPtr : valid pointer to the listview structure
10868 * [I] hwndLoseFocus : handle of previously focused window
10873 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10875 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10877 /* if we have the focus already, there's nothing to do */
10878 if (infoPtr
->bFocus
) return 0;
10880 /* send NM_SETFOCUS notification */
10881 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10883 /* set window focus flag */
10884 infoPtr
->bFocus
= TRUE
;
10886 /* put the focus rect back on */
10887 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10889 /* redraw all visible selected items */
10890 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10900 * [I] infoPtr : valid pointer to the listview structure
10901 * [I] fRedraw : font handle
10902 * [I] fRedraw : redraw flag
10907 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10909 HFONT oldFont
= infoPtr
->hFont
;
10910 INT oldHeight
= infoPtr
->nItemHeight
;
10912 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10914 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10915 if (infoPtr
->hFont
== oldFont
) return 0;
10917 LISTVIEW_SaveTextMetrics(infoPtr
);
10919 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10921 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10923 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10924 LISTVIEW_UpdateSize(infoPtr
);
10925 LISTVIEW_UpdateScroll(infoPtr
);
10927 else if (infoPtr
->nItemHeight
!= oldHeight
)
10928 LISTVIEW_UpdateScroll(infoPtr
);
10930 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10937 * Message handling for WM_SETREDRAW.
10938 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10941 * [I] infoPtr : valid pointer to the listview structure
10942 * [I] bRedraw: state of redraw flag
10945 * DefWinProc return value
10947 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10949 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10951 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10952 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10954 infoPtr
->bRedraw
= bRedraw
;
10956 if(!bRedraw
) return 0;
10958 if (is_autoarrange(infoPtr
))
10959 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10960 LISTVIEW_UpdateScroll(infoPtr
);
10962 /* despite what the WM_SETREDRAW docs says, apps expect us
10963 * to invalidate the listview here... stupid! */
10964 LISTVIEW_InvalidateList(infoPtr
);
10971 * Resizes the listview control. This function processes WM_SIZE
10972 * messages. At this time, the width and height are not used.
10975 * [I] infoPtr : valid pointer to the listview structure
10976 * [I] Width : new width
10977 * [I] Height : new height
10982 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10984 RECT rcOld
= infoPtr
->rcList
;
10986 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10988 LISTVIEW_UpdateSize(infoPtr
);
10989 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10991 /* do not bother with display related stuff if we're not redrawing */
10992 if (!is_redrawing(infoPtr
)) return 0;
10994 if (is_autoarrange(infoPtr
))
10995 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10997 LISTVIEW_UpdateScroll(infoPtr
);
10999 /* refresh all only for lists whose height changed significantly */
11000 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11001 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11002 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11003 LISTVIEW_InvalidateList(infoPtr
);
11010 * Sets the size information.
11013 * [I] infoPtr : valid pointer to the listview structure
11018 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11020 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11022 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11024 if (infoPtr
->uView
== LV_VIEW_LIST
)
11026 /* Apparently the "LIST" style is supposed to have the same
11027 * number of items in a column even if there is no scroll bar.
11028 * Since if a scroll bar already exists then the bottom is already
11029 * reduced, only reduce if the scroll bar does not currently exist.
11030 * The "2" is there to mimic the native control. I think it may be
11031 * related to either padding or edges. (GLA 7/2002)
11033 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11034 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11035 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11038 /* if control created invisible header isn't created */
11039 if (infoPtr
->hwndHeader
)
11044 hl
.prc
= &infoPtr
->rcList
;
11046 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11047 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11049 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11050 wp
.flags
|= SWP_SHOWWINDOW
;
11053 wp
.flags
|= SWP_HIDEWINDOW
;
11057 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11058 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11060 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11062 /* extra padding for grid */
11063 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11064 infoPtr
->rcList
.top
+= 2;
11066 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11071 * Processes WM_STYLECHANGED messages.
11074 * [I] infoPtr : valid pointer to the listview structure
11075 * [I] wStyleType : window style type (normal or extended)
11076 * [I] lpss : window style information
11081 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11082 const STYLESTRUCT
*lpss
)
11084 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11085 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11088 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11089 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11091 if (wStyleType
!= GWL_STYLE
) return 0;
11093 infoPtr
->dwStyle
= lpss
->styleNew
;
11095 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11096 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11097 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11099 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11100 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11101 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11103 if (uNewView
!= uOldView
)
11107 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11108 changing style updates current view only when view bits change. */
11109 map_style_view(infoPtr
);
11110 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11111 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11113 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11114 SetRectEmpty(&infoPtr
->rcFocus
);
11116 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11117 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11119 if (uNewView
== LVS_REPORT
)
11124 LISTVIEW_CreateHeader( infoPtr
);
11126 hl
.prc
= &infoPtr
->rcList
;
11128 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11129 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11130 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11131 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11134 LISTVIEW_UpdateItemSize(infoPtr
);
11137 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11139 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11141 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11143 /* Turn off the header control */
11144 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11145 TRACE("Hide header control, was 0x%08x\n", style
);
11146 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11148 /* Turn on the header control */
11149 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11151 TRACE("Show header control, was 0x%08x\n", style
);
11152 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11158 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11159 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11160 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11162 /* update the size of the client area */
11163 LISTVIEW_UpdateSize(infoPtr
);
11165 /* add scrollbars if needed */
11166 LISTVIEW_UpdateScroll(infoPtr
);
11168 /* invalidate client area + erase background */
11169 LISTVIEW_InvalidateList(infoPtr
);
11176 * Processes WM_STYLECHANGING messages.
11179 * [I] wStyleType : window style type (normal or extended)
11180 * [I0] lpss : window style information
11185 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11188 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11189 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11191 /* don't forward LVS_OWNERDATA only if not already set to */
11192 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11194 if (lpss
->styleOld
& LVS_OWNERDATA
)
11195 lpss
->styleNew
|= LVS_OWNERDATA
;
11197 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11205 * Processes WM_SHOWWINDOW messages.
11208 * [I] infoPtr : valid pointer to the listview structure
11209 * [I] bShown : window is being shown (FALSE when hidden)
11210 * [I] iStatus : window show status
11215 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11217 /* header delayed creation */
11218 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11220 LISTVIEW_CreateHeader(infoPtr
);
11222 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11223 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11226 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11231 * Processes CCM_GETVERSION messages.
11234 * [I] infoPtr : valid pointer to the listview structure
11239 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11241 return infoPtr
->iVersion
;
11246 * Processes CCM_SETVERSION messages.
11249 * [I] infoPtr : valid pointer to the listview structure
11250 * [I] iVersion : version to be set
11253 * -1 when requested version is greater than DLL version;
11254 * previous version otherwise
11256 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11258 INT iOldVersion
= infoPtr
->iVersion
;
11260 if (iVersion
> COMCTL32_VERSION
)
11263 infoPtr
->iVersion
= iVersion
;
11265 TRACE("new version %d\n", iVersion
);
11267 return iOldVersion
;
11272 * Window procedure of the listview control.
11275 static LRESULT WINAPI
11276 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11278 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11280 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11282 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11283 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11287 case LVM_APPROXIMATEVIEWRECT
:
11288 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11289 LOWORD(lParam
), HIWORD(lParam
));
11291 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11293 case LVM_CANCELEDITLABEL
:
11294 return LISTVIEW_CancelEditLabel(infoPtr
);
11296 case LVM_CREATEDRAGIMAGE
:
11297 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11299 case LVM_DELETEALLITEMS
:
11300 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11302 case LVM_DELETECOLUMN
:
11303 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11305 case LVM_DELETEITEM
:
11306 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11308 case LVM_EDITLABELA
:
11309 case LVM_EDITLABELW
:
11310 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11311 uMsg
== LVM_EDITLABELW
);
11312 /* case LVM_ENABLEGROUPVIEW: */
11314 case LVM_ENSUREVISIBLE
:
11315 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11317 case LVM_FINDITEMW
:
11318 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11320 case LVM_FINDITEMA
:
11321 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11323 case LVM_GETBKCOLOR
:
11324 return infoPtr
->clrBk
;
11326 /* case LVM_GETBKIMAGE: */
11328 case LVM_GETCALLBACKMASK
:
11329 return infoPtr
->uCallbackMask
;
11331 case LVM_GETCOLUMNA
:
11332 case LVM_GETCOLUMNW
:
11333 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11334 uMsg
== LVM_GETCOLUMNW
);
11336 case LVM_GETCOLUMNORDERARRAY
:
11337 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11339 case LVM_GETCOLUMNWIDTH
:
11340 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11342 case LVM_GETCOUNTPERPAGE
:
11343 return LISTVIEW_GetCountPerPage(infoPtr
);
11345 case LVM_GETEDITCONTROL
:
11346 return (LRESULT
)infoPtr
->hwndEdit
;
11348 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11349 return infoPtr
->dwLvExStyle
;
11351 /* case LVM_GETGROUPINFO: */
11353 /* case LVM_GETGROUPMETRICS: */
11355 case LVM_GETHEADER
:
11356 return (LRESULT
)infoPtr
->hwndHeader
;
11358 case LVM_GETHOTCURSOR
:
11359 return (LRESULT
)infoPtr
->hHotCursor
;
11361 case LVM_GETHOTITEM
:
11362 return infoPtr
->nHotItem
;
11364 case LVM_GETHOVERTIME
:
11365 return infoPtr
->dwHoverTime
;
11367 case LVM_GETIMAGELIST
:
11368 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11370 /* case LVM_GETINSERTMARK: */
11372 /* case LVM_GETINSERTMARKCOLOR: */
11374 /* case LVM_GETINSERTMARKRECT: */
11376 case LVM_GETISEARCHSTRINGA
:
11377 case LVM_GETISEARCHSTRINGW
:
11378 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11383 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11385 case LVM_GETITEMCOUNT
:
11386 return infoPtr
->nItemCount
;
11388 case LVM_GETITEMPOSITION
:
11389 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11391 case LVM_GETITEMRECT
:
11392 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11394 case LVM_GETITEMSPACING
:
11395 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11397 case LVM_GETITEMSTATE
:
11398 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11400 case LVM_GETITEMTEXTA
:
11401 case LVM_GETITEMTEXTW
:
11402 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11403 uMsg
== LVM_GETITEMTEXTW
);
11405 case LVM_GETNEXTITEM
:
11406 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11408 case LVM_GETNUMBEROFWORKAREAS
:
11409 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11412 case LVM_GETORIGIN
:
11413 if (!lParam
) return FALSE
;
11414 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11415 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11416 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11419 /* case LVM_GETOUTLINECOLOR: */
11421 /* case LVM_GETSELECTEDCOLUMN: */
11423 case LVM_GETSELECTEDCOUNT
:
11424 return LISTVIEW_GetSelectedCount(infoPtr
);
11426 case LVM_GETSELECTIONMARK
:
11427 return infoPtr
->nSelectionMark
;
11429 case LVM_GETSTRINGWIDTHA
:
11430 case LVM_GETSTRINGWIDTHW
:
11431 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11432 uMsg
== LVM_GETSTRINGWIDTHW
);
11434 case LVM_GETSUBITEMRECT
:
11435 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11437 case LVM_GETTEXTBKCOLOR
:
11438 return infoPtr
->clrTextBk
;
11440 case LVM_GETTEXTCOLOR
:
11441 return infoPtr
->clrText
;
11443 /* case LVM_GETTILEINFO: */
11445 /* case LVM_GETTILEVIEWINFO: */
11447 case LVM_GETTOOLTIPS
:
11448 if( !infoPtr
->hwndToolTip
)
11449 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11450 return (LRESULT
)infoPtr
->hwndToolTip
;
11452 case LVM_GETTOPINDEX
:
11453 return LISTVIEW_GetTopIndex(infoPtr
);
11455 case LVM_GETUNICODEFORMAT
:
11456 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11459 return infoPtr
->uView
;
11461 case LVM_GETVIEWRECT
:
11462 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11464 case LVM_GETWORKAREAS
:
11465 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11468 /* case LVM_HASGROUP: */
11471 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11473 case LVM_INSERTCOLUMNA
:
11474 case LVM_INSERTCOLUMNW
:
11475 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11476 uMsg
== LVM_INSERTCOLUMNW
);
11478 /* case LVM_INSERTGROUP: */
11480 /* case LVM_INSERTGROUPSORTED: */
11482 case LVM_INSERTITEMA
:
11483 case LVM_INSERTITEMW
:
11484 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11486 /* case LVM_INSERTMARKHITTEST: */
11488 /* case LVM_ISGROUPVIEWENABLED: */
11490 case LVM_ISITEMVISIBLE
:
11491 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11493 case LVM_MAPIDTOINDEX
:
11494 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11496 case LVM_MAPINDEXTOID
:
11497 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11499 /* case LVM_MOVEGROUP: */
11501 /* case LVM_MOVEITEMTOGROUP: */
11503 case LVM_REDRAWITEMS
:
11504 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11506 /* case LVM_REMOVEALLGROUPS: */
11508 /* case LVM_REMOVEGROUP: */
11511 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11513 case LVM_SETBKCOLOR
:
11514 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11516 /* case LVM_SETBKIMAGE: */
11518 case LVM_SETCALLBACKMASK
:
11519 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11522 case LVM_SETCOLUMNA
:
11523 case LVM_SETCOLUMNW
:
11524 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11525 uMsg
== LVM_SETCOLUMNW
);
11527 case LVM_SETCOLUMNORDERARRAY
:
11528 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11530 case LVM_SETCOLUMNWIDTH
:
11531 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11533 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11534 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11536 /* case LVM_SETGROUPINFO: */
11538 /* case LVM_SETGROUPMETRICS: */
11540 case LVM_SETHOTCURSOR
:
11541 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11543 case LVM_SETHOTITEM
:
11544 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11546 case LVM_SETHOVERTIME
:
11547 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11549 case LVM_SETICONSPACING
:
11551 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11552 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11554 case LVM_SETIMAGELIST
:
11555 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11557 /* case LVM_SETINFOTIP: */
11559 /* case LVM_SETINSERTMARK: */
11561 /* case LVM_SETINSERTMARKCOLOR: */
11566 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11567 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11570 case LVM_SETITEMCOUNT
:
11571 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11573 case LVM_SETITEMPOSITION
:
11576 pt
.x
= (short)LOWORD(lParam
);
11577 pt
.y
= (short)HIWORD(lParam
);
11578 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11581 case LVM_SETITEMPOSITION32
:
11582 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11584 case LVM_SETITEMSTATE
:
11585 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11587 case LVM_SETITEMTEXTA
:
11588 case LVM_SETITEMTEXTW
:
11589 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11590 uMsg
== LVM_SETITEMTEXTW
);
11592 /* case LVM_SETOUTLINECOLOR: */
11594 /* case LVM_SETSELECTEDCOLUMN: */
11596 case LVM_SETSELECTIONMARK
:
11597 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11599 case LVM_SETTEXTBKCOLOR
:
11600 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11602 case LVM_SETTEXTCOLOR
:
11603 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11605 /* case LVM_SETTILEINFO: */
11607 /* case LVM_SETTILEVIEWINFO: */
11609 /* case LVM_SETTILEWIDTH: */
11611 case LVM_SETTOOLTIPS
:
11612 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11614 case LVM_SETUNICODEFORMAT
:
11615 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11618 return LISTVIEW_SetView(infoPtr
, wParam
);
11620 /* case LVM_SETWORKAREAS: */
11622 /* case LVM_SORTGROUPS: */
11624 case LVM_SORTITEMS
:
11625 case LVM_SORTITEMSEX
:
11626 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11627 uMsg
== LVM_SORTITEMSEX
);
11628 case LVM_SUBITEMHITTEST
:
11629 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11632 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11634 case CCM_GETVERSION
:
11635 return LISTVIEW_GetVersion(infoPtr
);
11637 case CCM_SETVERSION
:
11638 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11641 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11644 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11647 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11650 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11653 return LISTVIEW_Destroy(infoPtr
);
11656 return LISTVIEW_Enable(infoPtr
);
11658 case WM_ERASEBKGND
:
11659 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11661 case WM_GETDLGCODE
:
11662 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11665 return (LRESULT
)infoPtr
->hFont
;
11668 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11671 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11674 return LISTVIEW_KillFocus(infoPtr
);
11676 case WM_LBUTTONDBLCLK
:
11677 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11679 case WM_LBUTTONDOWN
:
11680 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11683 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11686 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11688 case WM_MOUSEHOVER
:
11689 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11692 return LISTVIEW_NCDestroy(infoPtr
);
11695 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11698 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11700 case WM_NOTIFYFORMAT
:
11701 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11703 case WM_PRINTCLIENT
:
11704 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11707 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11709 case WM_RBUTTONDBLCLK
:
11710 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11712 case WM_RBUTTONDOWN
:
11713 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11716 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11719 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11722 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11725 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11727 case WM_SHOWWINDOW
:
11728 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11730 case WM_STYLECHANGED
:
11731 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11733 case WM_STYLECHANGING
:
11734 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11736 case WM_SYSCOLORCHANGE
:
11737 COMCTL32_RefreshSysColors();
11740 /* case WM_TIMER: */
11741 case WM_THEMECHANGED
:
11742 return LISTVIEW_ThemeChanged(infoPtr
);
11745 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11747 case WM_MOUSEWHEEL
:
11748 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11749 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11750 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11752 case WM_WINDOWPOSCHANGED
:
11753 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11755 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11756 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11758 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11760 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11762 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11764 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11766 /* case WM_WININICHANGE: */
11769 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11770 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11772 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11779 * Registers the window class.
11787 void LISTVIEW_Register(void)
11789 WNDCLASSW wndClass
;
11791 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11792 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11793 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11794 wndClass
.cbClsExtra
= 0;
11795 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11796 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11797 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11798 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11799 RegisterClassW(&wndClass
);
11804 * Unregisters the window class.
11812 void LISTVIEW_Unregister(void)
11814 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11819 * Handle any WM_COMMAND messages
11822 * [I] infoPtr : valid pointer to the listview structure
11823 * [I] wParam : the first message parameter
11824 * [I] lParam : the second message parameter
11829 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11832 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11834 if (!infoPtr
->hwndEdit
) return 0;
11836 switch (HIWORD(wParam
))
11841 * Adjust the edit window size
11843 WCHAR buffer
[1024];
11844 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11845 HFONT hFont
, hOldFont
= 0;
11849 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11850 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11851 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11853 /* Select font to get the right dimension of the string */
11854 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11857 hOldFont
= SelectObject(hdc
, hFont
);
11860 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11862 TEXTMETRICW textMetric
;
11864 /* Add Extra spacing for the next character */
11865 GetTextMetricsW(hdc
, &textMetric
);
11866 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11868 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11869 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11872 SelectObject(hdc
, hOldFont
);
11874 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11880 LISTVIEW_CancelEditLabel(infoPtr
);
11885 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);