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 framing items (iterator_frameditems),
68 * and finding the 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 redraw
; /* 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=%u, ", 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
)
852 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
853 item
.iItem
= htInfo
->iItem
;
855 item
.stateMask
= (UINT
)-1;
856 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
857 nmia
.lParam
= item
.lParam
;
858 nmia
.uOldState
= item
.state
;
859 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
860 nmia
.uChanged
= LVIF_STATE
;
863 nmia
.iItem
= htInfo
->iItem
;
864 nmia
.iSubItem
= htInfo
->iSubItem
;
865 nmia
.ptAction
= htInfo
->pt
;
867 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
868 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
869 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
871 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
874 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
876 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
877 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
880 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
881 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
885 HWND hwnd
= infoPtr
->hwndSelf
;
888 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
889 ZeroMemory(&nmia
, sizeof(nmia
));
890 nmia
.iItem
= lvht
->iItem
;
891 nmia
.iSubItem
= lvht
->iSubItem
;
892 nmia
.ptAction
= lvht
->pt
;
893 item
.mask
= LVIF_PARAM
;
894 item
.iItem
= lvht
->iItem
;
896 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
897 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
898 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
901 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
905 HWND hwnd
= infoPtr
->hwndSelf
;
907 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
909 item
.mask
= LVIF_PARAM
;
912 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
913 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
914 return IsWindow(hwnd
);
918 Send notification. depends on dispinfoW having same
919 structure as dispinfoA.
920 infoPtr : listview struct
921 code : *Unicode* notification code
922 pdi : dispinfo structure (can be unicode or ansi)
923 isW : TRUE if dispinfo is Unicode
925 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
927 INT length
= 0, ret_length
;
928 LPWSTR buffer
= NULL
, ret_text
;
929 BOOL return_ansi
= FALSE
;
930 BOOL return_unicode
= FALSE
;
933 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
935 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
936 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
939 ret_length
= pdi
->item
.cchTextMax
;
940 ret_text
= pdi
->item
.pszText
;
942 if (return_unicode
|| return_ansi
)
944 if (code
!= LVN_GETDISPINFOW
)
946 length
= return_ansi
?
947 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
948 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
952 length
= pdi
->item
.cchTextMax
;
953 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
956 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
957 if (!buffer
) return FALSE
;
960 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
963 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
966 pdi
->item
.pszText
= buffer
;
967 pdi
->item
.cchTextMax
= length
;
970 if (infoPtr
->notifyFormat
== NFR_ANSI
)
971 code
= get_ansi_notification(code
);
973 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
974 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
975 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
977 if (return_ansi
|| return_unicode
)
979 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
981 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
983 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
985 strcpyW(ret_text
, pdi
->item
.pszText
);
987 else if (return_ansi
) /* note : pointer can be changed by app ! */
989 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
990 ret_length
, NULL
, NULL
);
993 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
994 ret_text
, ret_length
);
996 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
997 pdi
->item
.cchTextMax
= ret_length
;
1003 /* if dipsinfo holder changed notification code then convert */
1004 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1006 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1008 buffer
= Alloc(length
* sizeof(CHAR
));
1009 if (!buffer
) return FALSE
;
1011 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1012 ret_length
, NULL
, NULL
);
1014 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1021 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1022 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1024 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1025 lpnmlvcd
->nmcd
.hdc
= hdc
;
1026 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1027 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1028 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1029 if (!lplvItem
) return;
1030 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1031 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1032 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1033 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1034 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1035 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1038 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1040 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1043 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1044 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1045 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1046 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1047 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1048 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1052 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1054 COLORREF backcolor
, textcolor
;
1056 /* apparently, for selected items, we have to override the returned values */
1059 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1061 if (infoPtr
->bFocus
)
1063 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1064 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1066 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1068 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1069 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1074 backcolor
= lpnmlvcd
->clrTextBk
;
1075 textcolor
= lpnmlvcd
->clrText
;
1077 if (backcolor
== CLR_DEFAULT
)
1078 backcolor
= comctl32_color
.clrWindow
;
1079 if (textcolor
== CLR_DEFAULT
)
1080 textcolor
= comctl32_color
.clrWindowText
;
1082 /* Set the text attributes */
1083 if (backcolor
!= CLR_NONE
)
1085 SetBkMode(hdc
, OPAQUE
);
1086 SetBkColor(hdc
, backcolor
);
1089 SetBkMode(hdc
, TRANSPARENT
);
1090 SetTextColor(hdc
, textcolor
);
1093 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1095 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1098 /* returns TRUE when repaint needed, FALSE otherwise */
1099 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1101 MEASUREITEMSTRUCT mis
;
1102 mis
.CtlType
= ODT_LISTVIEW
;
1103 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1107 mis
.itemHeight
= infoPtr
->nItemHeight
;
1108 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1109 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1111 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1117 /******** Item iterator functions **********************************/
1119 static RANGES
ranges_create(int count
);
1120 static void ranges_destroy(RANGES ranges
);
1121 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1122 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1123 static void ranges_dump(RANGES ranges
);
1125 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1127 RANGE range
= { nItem
, nItem
+ 1 };
1129 return ranges_add(ranges
, range
);
1132 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1134 RANGE range
= { nItem
, nItem
+ 1 };
1136 return ranges_del(ranges
, range
);
1140 * ITERATOR DOCUMENTATION
1142 * The iterator functions allow for easy, and convenient iteration
1143 * over items of interest in the list. Typically, you create an
1144 * iterator, use it, and destroy it, as such:
1147 * iterator_xxxitems(&i, ...);
1148 * while (iterator_{prev,next}(&i)
1150 * //code which uses i.nItem
1152 * iterator_destroy(&i);
1154 * where xxx is either: framed, or visible.
1155 * Note that it is important that the code destroys the iterator
1156 * after it's done with it, as the creation of the iterator may
1157 * allocate memory, which thus needs to be freed.
1159 * You can iterate both forwards, and backwards through the list,
1160 * by using iterator_next or iterator_prev respectively.
1162 * Lower numbered items are draw on top of higher number items in
1163 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1164 * items may overlap). So, to test items, you should use
1166 * which lists the items top to bottom (in Z-order).
1167 * For drawing items, you should use
1169 * which lists the items bottom to top (in Z-order).
1170 * If you keep iterating over the items after the end-of-items
1171 * marker (-1) is returned, the iterator will start from the
1172 * beginning. Typically, you don't need to test for -1,
1173 * because iterator_{next,prev} will return TRUE if more items
1174 * are to be iterated over, or FALSE otherwise.
1176 * Note: the iterator is defined to be bidirectional. That is,
1177 * any number of prev followed by any number of next, or
1178 * five versa, should leave the iterator at the same item:
1179 * prev * n, next * n = next * n, prev * n
1181 * The iterator has a notion of an out-of-order, special item,
1182 * which sits at the start of the list. This is used in
1183 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1184 * which needs to be first, as it may overlap other items.
1186 * The code is a bit messy because we have:
1187 * - a special item to deal with
1188 * - simple range, or composite range
1190 * If you find bugs, or want to add features, please make sure you
1191 * always check/modify *both* iterator_prev, and iterator_next.
1195 * This function iterates through the items in increasing order,
1196 * but prefixed by the special item, then -1. That is:
1197 * special, 1, 2, 3, ..., n, -1.
1198 * Each item is listed only once.
1200 static inline BOOL
iterator_next(ITERATOR
* i
)
1204 i
->nItem
= i
->nSpecial
;
1205 if (i
->nItem
!= -1) return TRUE
;
1207 if (i
->nItem
== i
->nSpecial
)
1209 if (i
->ranges
) i
->index
= 0;
1215 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1216 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1221 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1222 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1225 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1227 i
->nItem
= i
->range
.lower
;
1228 if (i
->nItem
>= 0) goto testitem
;
1235 * This function iterates through the items in decreasing order,
1236 * followed by the special item, then -1. That is:
1237 * n, n-1, ..., 3, 2, 1, special, -1.
1238 * Each item is listed only once.
1240 static inline BOOL
iterator_prev(ITERATOR
* i
)
1247 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1250 if (i
->nItem
== i
->nSpecial
)
1258 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1259 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1265 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1268 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1270 i
->nItem
= i
->range
.upper
;
1271 if (i
->nItem
> 0) goto testitem
;
1273 return (i
->nItem
= i
->nSpecial
) != -1;
1276 static RANGE
iterator_range(const ITERATOR
*i
)
1280 if (!i
->ranges
) return i
->range
;
1282 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1284 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1285 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1287 else range
.lower
= range
.upper
= 0;
1293 * Releases resources associated with this iterator.
1295 static inline void iterator_destroy(const ITERATOR
*i
)
1297 ranges_destroy(i
->ranges
);
1301 * Create an empty iterator.
1303 static inline BOOL
iterator_empty(ITERATOR
* i
)
1305 ZeroMemory(i
, sizeof(*i
));
1306 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1311 * Create an iterator over a range.
1313 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1321 * Create an iterator over a bunch of ranges.
1322 * Please note that the iterator will take ownership of the ranges,
1323 * and will free them upon destruction.
1325 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1333 * Creates an iterator over the items which intersect frame.
1334 * Uses absolute coordinates rather than compensating for the current offset.
1336 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1338 RECT rcItem
, rcTemp
;
1340 /* in case we fail, we want to return an empty iterator */
1341 if (!iterator_empty(i
)) return FALSE
;
1343 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1345 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1349 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1351 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1352 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1353 i
->nSpecial
= infoPtr
->nFocusedItem
;
1355 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1356 /* to do better here, we need to have PosX, and PosY sorted */
1357 TRACE("building icon ranges:\n");
1358 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1360 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1361 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1362 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1363 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1364 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1365 ranges_additem(i
->ranges
, nItem
);
1369 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1373 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1374 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1376 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1377 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1378 if (range
.upper
<= range
.lower
) return TRUE
;
1379 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1380 TRACE(" report=%s\n", debugrange(&i
->range
));
1384 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1385 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1386 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1393 if (infoPtr
->nItemWidth
)
1395 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1396 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1400 nFirstCol
= max(frame
->left
, 0);
1401 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1404 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1406 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1407 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1409 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1411 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1412 TRACE("building list ranges:\n");
1413 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1415 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1416 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1417 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1418 TRACE(" list=%s\n", debugrange(&item_range
));
1419 ranges_add(i
->ranges
, item_range
);
1427 * Creates an iterator over the items which intersect lprc.
1429 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1434 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1436 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1437 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1439 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1443 * Creates an iterator over the items which intersect the visible region of hdc.
1445 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1447 POINT Origin
, Position
;
1448 RECT rcItem
, rcClip
;
1451 rgntype
= GetClipBox(hdc
, &rcClip
);
1452 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1453 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1454 if (rgntype
== SIMPLEREGION
) return TRUE
;
1456 /* first deal with the special item */
1457 if (i
->nSpecial
!= -1)
1459 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1460 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1463 /* if we can't deal with the region, we'll just go with the simple range */
1464 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1465 TRACE("building visible range:\n");
1466 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1468 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1469 if (!ranges_add(i
->ranges
, i
->range
))
1471 ranges_destroy(i
->ranges
);
1477 /* now delete the invisible items from the list */
1478 while(iterator_next(i
))
1480 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1481 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1482 rcItem
.top
= Position
.y
+ Origin
.y
;
1483 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1484 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1485 if (!RectVisible(hdc
, &rcItem
))
1486 ranges_delitem(i
->ranges
, i
->nItem
);
1488 /* the iterator should restart on the next iterator_next */
1494 /* Remove common elements from two iterators */
1495 /* Passed iterators have to point on the first elements */
1496 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1498 if(!iter1
->ranges
|| !iter2
->ranges
) {
1501 if(iter1
->ranges
|| iter2
->ranges
||
1502 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1503 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1504 ERR("result is not a one range iterator\n");
1508 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1511 lower
= iter1
->range
.lower
;
1512 upper
= iter1
->range
.upper
;
1514 if(lower
< iter2
->range
.lower
)
1515 iter1
->range
.upper
= iter2
->range
.lower
;
1516 else if(upper
> iter2
->range
.upper
)
1517 iter1
->range
.lower
= iter2
->range
.upper
;
1519 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1521 if(iter2
->range
.lower
< lower
)
1522 iter2
->range
.upper
= lower
;
1523 else if(iter2
->range
.upper
> upper
)
1524 iter2
->range
.lower
= upper
;
1526 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1531 iterator_next(iter1
);
1532 iterator_next(iter2
);
1535 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1538 if(iter1
->nItem
== iter2
->nItem
) {
1539 int delete = iter1
->nItem
;
1541 iterator_prev(iter1
);
1542 iterator_prev(iter2
);
1543 ranges_delitem(iter1
->ranges
, delete);
1544 ranges_delitem(iter2
->ranges
, delete);
1545 iterator_next(iter1
);
1546 iterator_next(iter2
);
1547 } else if(iter1
->nItem
> iter2
->nItem
)
1548 iterator_next(iter2
);
1550 iterator_next(iter1
);
1553 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1554 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1558 /******** Misc helper functions ************************************/
1560 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1561 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1563 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1564 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1567 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1569 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1570 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1573 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1575 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1576 if(state
== 1 || state
== 2)
1580 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1581 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1582 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1586 /* this should be called after window style got updated,
1587 it used to reset view state to match current window style */
1588 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1590 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1593 infoPtr
->uView
= LV_VIEW_ICON
;
1596 infoPtr
->uView
= LV_VIEW_DETAILS
;
1599 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1602 infoPtr
->uView
= LV_VIEW_LIST
;
1606 /* computes next item id value */
1607 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1609 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1613 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1614 return lpID
->id
+ 1;
1619 /******** Internal API functions ************************************/
1621 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1623 static COLUMN_INFO mainItem
;
1625 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1626 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1628 /* update cached column rectangles */
1629 if (infoPtr
->colRectsDirty
)
1632 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1635 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1636 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1637 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1639 Ptr
->colRectsDirty
= FALSE
;
1642 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1645 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1647 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1650 if (infoPtr
->hwndHeader
) return 0;
1652 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1654 /* setup creation flags */
1655 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1656 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1658 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1661 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1662 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1663 if (!infoPtr
->hwndHeader
) return -1;
1665 /* set header unicode format */
1666 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1668 /* set header font */
1669 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1671 /* set header image list */
1672 if (infoPtr
->himlSmall
)
1673 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1675 LISTVIEW_UpdateSize(infoPtr
);
1680 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1682 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1685 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1687 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1688 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1689 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1692 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1694 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1697 /* used to handle collapse main item column case */
1698 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1700 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1701 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1704 /* Listview invalidation functions: use _only_ these functions to invalidate */
1706 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1708 return infoPtr
->redraw
;
1711 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1713 if(!is_redrawing(infoPtr
)) return;
1714 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1715 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1718 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1722 if(!is_redrawing(infoPtr
)) return;
1723 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1724 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1727 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1729 POINT Origin
, Position
;
1732 if(!is_redrawing(infoPtr
)) return;
1733 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1734 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1735 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1736 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1738 rcBox
.bottom
= infoPtr
->nItemHeight
;
1739 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1740 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1743 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1745 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1748 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1752 if(!is_redrawing(infoPtr
)) return;
1753 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1754 rcCol
.top
= infoPtr
->rcList
.top
;
1755 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1756 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1761 * Retrieves the number of items that can fit vertically in the client area.
1764 * [I] infoPtr : valid pointer to the listview structure
1767 * Number of items per row.
1769 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1771 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1773 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1778 * Retrieves the number of items that can fit horizontally in the client
1782 * [I] infoPtr : valid pointer to the listview structure
1785 * Number of items per column.
1787 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1789 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1791 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1795 /*************************************************************************
1796 * LISTVIEW_ProcessLetterKeys
1798 * Processes keyboard messages generated by pressing the letter keys
1800 * What this does is perform a case insensitive search from the
1801 * current position with the following quirks:
1802 * - If two chars or more are pressed in quick succession we search
1803 * for the corresponding string (e.g. 'abc').
1804 * - If there is a delay we wipe away the current search string and
1805 * restart with just that char.
1806 * - If the user keeps pressing the same character, whether slowly or
1807 * fast, so that the search string is entirely composed of this
1808 * character ('aaaaa' for instance), then we search for first item
1809 * that starting with that character.
1810 * - If the user types the above character in quick succession, then
1811 * we must also search for the corresponding string ('aaaaa'), and
1812 * go to that string if there is a match.
1815 * [I] hwnd : handle to the window
1816 * [I] charCode : the character code, the actual character
1817 * [I] keyData : key data
1825 * - The current implementation has a list of characters it will
1826 * accept and it ignores everything else. In particular it will
1827 * ignore accentuated characters which seems to match what
1828 * Windows does. But I'm not sure it makes sense to follow
1830 * - We don't sound a beep when the search fails.
1834 * TREEVIEW_ProcessLetterKeys
1836 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1838 WCHAR buffer
[MAX_PATH
];
1845 /* simple parameter checking */
1846 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1848 /* only allow the valid WM_CHARs through */
1849 if (!isalnumW(charCode
) &&
1850 charCode
!= '.' && charCode
!= '`' && 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
!= '~')
1861 /* update the search parameters */
1862 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1863 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1864 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1866 if (diff
>= 0 && diff
< KEY_DELAY
)
1868 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1869 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1871 if (infoPtr
->charCode
!= charCode
)
1872 infoPtr
->charCode
= charCode
= 0;
1876 infoPtr
->charCode
= charCode
;
1877 infoPtr
->szSearchParam
[0] = charCode
;
1878 infoPtr
->nSearchParamLength
= 1;
1881 /* should start from next after focused item, so next item that matches
1882 will be selected, if there isn't any and focused matches it will be selected
1883 on second search stage from beginning of the list */
1884 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1886 /* with some accumulated search data available start with current focus, otherwise
1887 it's excluded from search */
1888 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1889 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1894 /* let application handle this for virtual listview */
1895 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1899 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1900 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1901 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1902 nmlv
.iStart
= startidx
;
1904 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1906 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1910 int i
= startidx
, endidx
;
1912 /* and search from the current position */
1914 endidx
= infoPtr
->nItemCount
;
1916 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1919 /* start from first item if not found with >= startidx */
1920 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1926 for (i
= startidx
; i
< endidx
; i
++)
1929 item
.mask
= LVIF_TEXT
;
1932 item
.pszText
= buffer
;
1933 item
.cchTextMax
= MAX_PATH
;
1934 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1936 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1941 /* this is used to find first char match when search string is not available yet,
1942 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1943 already waiting for user to complete a string */
1944 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1946 /* this would work but we must keep looking for a longer match */
1951 if ( nItem
!= -1 || /* found something */
1952 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1953 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1959 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1964 /*************************************************************************
1965 * LISTVIEW_UpdateHeaderSize [Internal]
1967 * Function to resize the header control
1970 * [I] hwnd : handle to a window
1971 * [I] nNewScrollPos : scroll pos to set
1976 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1981 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1983 if (!infoPtr
->hwndHeader
) return;
1985 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1986 point
[0].x
= winRect
.left
;
1987 point
[0].y
= winRect
.top
;
1988 point
[1].x
= winRect
.right
;
1989 point
[1].y
= winRect
.bottom
;
1991 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1992 point
[0].x
= -nNewScrollPos
;
1993 point
[1].x
+= nNewScrollPos
;
1995 SetWindowPos(infoPtr
->hwndHeader
,0,
1996 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1997 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1998 SWP_NOZORDER
| SWP_NOACTIVATE
);
2003 * Update the scrollbars. This functions should be called whenever
2004 * the content, size or view changes.
2007 * [I] infoPtr : valid pointer to the listview structure
2012 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2014 SCROLLINFO horzInfo
, vertInfo
;
2017 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2019 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2020 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2021 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2023 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2024 if (infoPtr
->uView
== LV_VIEW_LIST
)
2026 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2027 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2029 /* scroll by at least one column per page */
2030 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2031 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2033 if (infoPtr
->nItemWidth
)
2034 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2036 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2038 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2040 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2044 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2047 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2049 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2054 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2055 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2057 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2058 horzInfo
.nMax
= rcHeader
.right
;
2059 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2063 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2064 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2065 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2066 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2067 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2069 /* Setting the horizontal scroll can change the listview size
2070 * (and potentially everything else) so we need to recompute
2071 * everything again for the vertical scroll
2074 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2075 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2076 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2078 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2080 vertInfo
.nMax
= infoPtr
->nItemCount
;
2082 /* scroll by at least one page */
2083 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2084 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2086 if (infoPtr
->nItemHeight
> 0)
2087 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2089 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2093 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2096 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2097 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2098 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2099 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2100 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2102 /* Change of the range may have changed the scroll pos. If so move the content */
2103 if (dx
!= 0 || dy
!= 0)
2106 listRect
= infoPtr
->rcList
;
2107 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2108 SW_ERASE
| SW_INVALIDATE
);
2111 /* Update the Header Control */
2112 if (infoPtr
->hwndHeader
)
2114 horzInfo
.fMask
= SIF_POS
;
2115 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2116 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2123 * Shows/hides the focus rectangle.
2126 * [I] infoPtr : valid pointer to the listview structure
2127 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2132 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2136 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2138 if (infoPtr
->nFocusedItem
< 0) return;
2140 /* we need some gymnastics in ICON mode to handle large items */
2141 if (infoPtr
->uView
== LV_VIEW_ICON
)
2145 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2146 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2148 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2153 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2155 /* for some reason, owner draw should work only in report mode */
2156 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2161 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2162 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2164 item
.iItem
= infoPtr
->nFocusedItem
;
2166 item
.mask
= LVIF_PARAM
;
2167 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2169 ZeroMemory(&dis
, sizeof(dis
));
2170 dis
.CtlType
= ODT_LISTVIEW
;
2171 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2172 dis
.itemID
= item
.iItem
;
2173 dis
.itemAction
= ODA_FOCUS
;
2174 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2175 dis
.hwndItem
= infoPtr
->hwndSelf
;
2177 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2178 dis
.itemData
= item
.lParam
;
2180 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2182 SelectObject(hdc
, hOldFont
);
2186 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2189 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2193 * Invalidates all visible selected items.
2195 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2199 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2200 while(iterator_next(&i
))
2202 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2203 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2205 iterator_destroy(&i
);
2210 * DESCRIPTION: [INTERNAL]
2211 * Computes an item's (left,top) corner, relative to rcView.
2212 * That is, the position has NOT been made relative to the Origin.
2213 * This is deliberate, to avoid computing the Origin over, and
2214 * over again, when this function is called in a loop. Instead,
2215 * one can factor the computation of the Origin before the loop,
2216 * and offset the value returned by this function, on every iteration.
2219 * [I] infoPtr : valid pointer to the listview structure
2220 * [I] nItem : item number
2221 * [O] lpptOrig : item top, left corner
2226 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2228 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2230 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2232 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2233 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2235 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2237 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2238 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2239 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2241 else /* LV_VIEW_DETAILS */
2243 lpptPosition
->x
= REPORT_MARGINX
;
2244 /* item is always at zero indexed column */
2245 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2246 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2247 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2252 * DESCRIPTION: [INTERNAL]
2253 * Compute the rectangles of an item. This is to localize all
2254 * the computations in one place. If you are not interested in some
2255 * of these values, simply pass in a NULL -- the function is smart
2256 * enough to compute only what's necessary. The function computes
2257 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2258 * one, the BOX rectangle. This rectangle is very cheap to compute,
2259 * and is guaranteed to contain all the other rectangles. Computing
2260 * the ICON rect is also cheap, but all the others are potentially
2261 * expensive. This gives an easy and effective optimization when
2262 * searching (like point inclusion, or rectangle intersection):
2263 * first test against the BOX, and if TRUE, test against the desired
2265 * If the function does not have all the necessary information
2266 * to computed the requested rectangles, will crash with a
2267 * failed assertion. This is done so we catch all programming
2268 * errors, given that the function is called only from our code.
2270 * We have the following 'special' meanings for a few fields:
2271 * * If LVIS_FOCUSED is set, we assume the item has the focus
2272 * This is important in ICON mode, where it might get a larger
2273 * then usual rectangle
2275 * Please note that subitem support works only in REPORT mode.
2278 * [I] infoPtr : valid pointer to the listview structure
2279 * [I] lpLVItem : item to compute the measures for
2280 * [O] lprcBox : ptr to Box rectangle
2281 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2282 * [0] lprcSelectBox : ptr to select box rectangle
2283 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2284 * [O] lprcIcon : ptr to Icon rectangle
2285 * Same as LVM_GETITEMRECT with LVIR_ICON
2286 * [O] lprcStateIcon: ptr to State Icon rectangle
2287 * [O] lprcLabel : ptr to Label rectangle
2288 * Same as LVM_GETITEMRECT with LVIR_LABEL
2293 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2294 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2295 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2297 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2298 RECT Box
, SelectBox
, Icon
, Label
;
2299 COLUMN_INFO
*lpColumnInfo
= NULL
;
2300 SIZE labelSize
= { 0, 0 };
2302 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2304 /* Be smart and try to figure out the minimum we have to do */
2305 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2306 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2308 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2309 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2311 if (lprcSelectBox
) doSelectBox
= TRUE
;
2312 if (lprcLabel
) doLabel
= TRUE
;
2313 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2320 /************************************************************/
2321 /* compute the box rectangle (it should be cheap to do) */
2322 /************************************************************/
2323 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2324 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2326 if (lpLVItem
->iSubItem
)
2328 Box
= lpColumnInfo
->rcHeader
;
2333 Box
.right
= infoPtr
->nItemWidth
;
2336 Box
.bottom
= infoPtr
->nItemHeight
;
2338 /******************************************************************/
2339 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2340 /******************************************************************/
2343 LONG state_width
= 0;
2345 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2346 state_width
= infoPtr
->iconStateSize
.cx
;
2348 if (infoPtr
->uView
== LV_VIEW_ICON
)
2350 Icon
.left
= Box
.left
+ state_width
;
2351 if (infoPtr
->himlNormal
)
2352 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2353 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2354 Icon
.right
= Icon
.left
;
2355 Icon
.bottom
= Icon
.top
;
2356 if (infoPtr
->himlNormal
)
2358 Icon
.right
+= infoPtr
->iconSize
.cx
;
2359 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2362 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2364 Icon
.left
= Box
.left
+ state_width
;
2366 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2368 /* we need the indent in report mode */
2369 assert(lpLVItem
->mask
& LVIF_INDENT
);
2370 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2374 Icon
.right
= Icon
.left
;
2375 if (infoPtr
->himlSmall
&&
2376 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2377 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2378 Icon
.right
+= infoPtr
->iconSize
.cx
;
2379 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2381 if(lprcIcon
) *lprcIcon
= Icon
;
2382 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2384 /* TODO: is this correct? */
2387 lprcStateIcon
->left
= Icon
.left
- state_width
;
2388 lprcStateIcon
->right
= Icon
.left
;
2389 lprcStateIcon
->top
= Icon
.top
;
2390 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2391 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2394 else Icon
.right
= 0;
2396 /************************************************************/
2397 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2398 /************************************************************/
2401 /* calculate how far to the right can the label stretch */
2402 Label
.right
= Box
.right
;
2403 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2405 if (lpLVItem
->iSubItem
== 0)
2407 /* we need a zero based rect here */
2408 Label
= lpColumnInfo
->rcHeader
;
2409 OffsetRect(&Label
, -Label
.left
, 0);
2413 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2415 labelSize
.cx
= infoPtr
->nItemWidth
;
2416 labelSize
.cy
= infoPtr
->nItemHeight
;
2420 /* we need the text in non owner draw mode */
2421 assert(lpLVItem
->mask
& LVIF_TEXT
);
2422 if (is_text(lpLVItem
->pszText
))
2424 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2425 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2426 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2430 /* compute rough rectangle where the label will go */
2431 SetRectEmpty(&rcText
);
2432 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2433 rcText
.bottom
= infoPtr
->nItemHeight
;
2434 if (infoPtr
->uView
== LV_VIEW_ICON
)
2435 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2437 /* now figure out the flags */
2438 if (infoPtr
->uView
== LV_VIEW_ICON
)
2439 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2441 uFormat
= LV_SL_DT_FLAGS
;
2443 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2445 if (rcText
.right
!= rcText
.left
)
2446 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2448 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2450 SelectObject(hdc
, hOldFont
);
2451 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2455 if (infoPtr
->uView
== LV_VIEW_ICON
)
2457 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2458 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2459 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2460 Label
.right
= Label
.left
+ labelSize
.cx
;
2461 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2462 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2464 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2465 labelSize
.cy
/= infoPtr
->ntmHeight
;
2466 labelSize
.cy
= max(labelSize
.cy
, 1);
2467 labelSize
.cy
*= infoPtr
->ntmHeight
;
2469 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2471 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2473 Label
.left
= Icon
.right
;
2474 Label
.top
= Box
.top
;
2475 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2476 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2477 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2479 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2481 Label
.left
= Icon
.right
;
2482 Label
.top
= Box
.top
;
2483 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2484 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2487 if (lprcLabel
) *lprcLabel
= Label
;
2488 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2491 /************************************************************/
2492 /* compute SELECT bounding box */
2493 /************************************************************/
2496 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2498 SelectBox
.left
= Icon
.left
;
2499 SelectBox
.top
= Box
.top
;
2500 SelectBox
.bottom
= Box
.bottom
;
2503 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2505 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2509 UnionRect(&SelectBox
, &Icon
, &Label
);
2511 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2512 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2515 /* Fix the Box if necessary */
2518 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2519 else *lprcBox
= Box
;
2521 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2525 * DESCRIPTION: [INTERNAL]
2528 * [I] infoPtr : valid pointer to the listview structure
2529 * [I] nItem : item number
2530 * [O] lprcBox : ptr to Box rectangle
2535 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2537 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2538 POINT Position
, Origin
;
2541 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2542 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2544 /* Be smart and try to figure out the minimum we have to do */
2546 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2547 lvItem
.mask
|= LVIF_TEXT
;
2548 lvItem
.iItem
= nItem
;
2549 lvItem
.iSubItem
= 0;
2550 lvItem
.pszText
= szDispText
;
2551 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2552 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2553 if (infoPtr
->uView
== LV_VIEW_ICON
)
2555 lvItem
.mask
|= LVIF_STATE
;
2556 lvItem
.stateMask
= LVIS_FOCUSED
;
2557 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2559 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2561 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2562 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2564 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2567 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2570 /* LISTVIEW_MapIdToIndex helper */
2571 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2573 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2574 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2576 if (id1
->id
== id2
->id
) return 0;
2578 return (id1
->id
< id2
->id
) ? -1 : 1;
2583 * Returns the item index for id specified.
2586 * [I] infoPtr : valid pointer to the listview structure
2587 * [I] iID : item id to get index for
2590 * Item index, or -1 on failure.
2592 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2597 TRACE("iID=%d\n", iID
);
2599 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2600 if (infoPtr
->nItemCount
== 0) return -1;
2603 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2607 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2608 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2616 * Returns the item id for index given.
2619 * [I] infoPtr : valid pointer to the listview structure
2620 * [I] iItem : item index to get id for
2625 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2630 TRACE("iItem=%d\n", iItem
);
2632 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2633 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2635 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2636 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2638 return lpItem
->id
->id
;
2643 * Returns the current icon position, and advances it along the top.
2644 * The returned position is not offset by Origin.
2647 * [I] infoPtr : valid pointer to the listview structure
2648 * [O] lpPos : will get the current icon position
2653 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2655 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2657 *lpPos
= infoPtr
->currIconPos
;
2659 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2660 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2662 infoPtr
->currIconPos
.x
= 0;
2663 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2669 * Returns the current icon position, and advances it down the left edge.
2670 * The returned position is not offset by Origin.
2673 * [I] infoPtr : valid pointer to the listview structure
2674 * [O] lpPos : will get the current icon position
2679 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2681 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2683 *lpPos
= infoPtr
->currIconPos
;
2685 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2686 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2688 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2689 infoPtr
->currIconPos
.y
= 0;
2695 * Moves an icon to the specified position.
2696 * It takes care of invalidating the item, etc.
2699 * [I] infoPtr : valid pointer to the listview structure
2700 * [I] nItem : the item to move
2701 * [I] lpPos : the new icon position
2702 * [I] isNew : flags the item as being new
2708 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2714 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2715 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2717 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2718 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2721 /* Allocating a POINTER for every item is too resource intensive,
2722 * so we'll keep the (x,y) in different arrays */
2723 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2724 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2726 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2733 * Arranges listview items in icon display mode.
2736 * [I] infoPtr : valid pointer to the listview structure
2737 * [I] nAlignCode : alignment code
2743 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2745 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2749 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2751 TRACE("nAlignCode=%d\n", nAlignCode
);
2753 if (nAlignCode
== LVA_DEFAULT
)
2755 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2756 else nAlignCode
= LVA_ALIGNTOP
;
2761 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2762 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2763 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2764 default: return FALSE
;
2767 infoPtr
->bAutoarrange
= TRUE
;
2768 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2769 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2771 next_pos(infoPtr
, &pos
);
2772 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2780 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2781 * For LVS_REPORT always returns empty rectangle.
2784 * [I] infoPtr : valid pointer to the listview structure
2785 * [O] lprcView : bounding rectangle
2791 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2795 SetRectEmpty(lprcView
);
2797 switch (infoPtr
->uView
)
2800 case LV_VIEW_SMALLICON
:
2801 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2803 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2804 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2805 lprcView
->right
= max(lprcView
->right
, x
);
2806 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2808 if (infoPtr
->nItemCount
> 0)
2810 lprcView
->right
+= infoPtr
->nItemWidth
;
2811 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2816 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2817 x
= infoPtr
->nItemCount
/ y
;
2818 if (infoPtr
->nItemCount
% y
) x
++;
2819 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2820 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2827 * Retrieves the bounding rectangle of all the items.
2830 * [I] infoPtr : valid pointer to the listview structure
2831 * [O] lprcView : bounding rectangle
2837 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2841 TRACE("(lprcView=%p)\n", lprcView
);
2843 if (!lprcView
) return FALSE
;
2845 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2847 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2849 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2850 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2853 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2860 * Retrieves the subitem pointer associated with the subitem index.
2863 * [I] hdpaSubItems : DPA handle for a specific item
2864 * [I] nSubItem : index of subitem
2867 * SUCCESS : subitem pointer
2870 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2872 SUBITEM_INFO
*lpSubItem
;
2875 /* we should binary search here if need be */
2876 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2878 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2879 if (lpSubItem
->iSubItem
== nSubItem
)
2889 * Calculates the desired item width.
2892 * [I] infoPtr : valid pointer to the listview structure
2895 * The desired item width.
2897 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2901 TRACE("uView=%d\n", infoPtr
->uView
);
2903 if (infoPtr
->uView
== LV_VIEW_ICON
)
2904 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2905 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2907 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2912 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2913 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2915 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2916 nItemWidth
= rcHeader
.right
;
2919 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2921 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2925 lvItem
.mask
= LVIF_TEXT
;
2926 lvItem
.iSubItem
= 0;
2928 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2931 lvItem
.pszText
= szDispText
;
2932 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2933 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2934 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2938 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2939 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2941 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2949 * Calculates the desired item height.
2952 * [I] infoPtr : valid pointer to the listview structure
2955 * The desired item height.
2957 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2961 TRACE("uView=%d\n", infoPtr
->uView
);
2963 if (infoPtr
->uView
== LV_VIEW_ICON
)
2964 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2967 nItemHeight
= infoPtr
->ntmHeight
;
2968 if (infoPtr
->himlState
)
2969 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2970 if (infoPtr
->himlSmall
)
2971 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2972 nItemHeight
+= HEIGHT_PADDING
;
2973 if (infoPtr
->nMeasureItemHeight
> 0)
2974 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2977 return max(nItemHeight
, 1);
2982 * Updates the width, and height of an item.
2985 * [I] infoPtr : valid pointer to the listview structure
2990 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2992 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2993 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2999 * Retrieves and saves important text metrics info for the current
3003 * [I] infoPtr : valid pointer to the listview structure
3006 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3008 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3009 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3010 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3014 if (GetTextMetricsW(hdc
, &tm
))
3016 infoPtr
->ntmHeight
= tm
.tmHeight
;
3017 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3020 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3021 infoPtr
->nEllipsisWidth
= sz
.cx
;
3023 SelectObject(hdc
, hOldFont
);
3024 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3026 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3031 * A compare function for ranges
3034 * [I] range1 : pointer to range 1;
3035 * [I] range2 : pointer to range 2;
3039 * > 0 : if range 1 > range 2
3040 * < 0 : if range 2 > range 1
3041 * = 0 : if range intersects range 2
3043 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3047 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3049 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3054 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3059 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3061 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3066 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3068 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3069 ranges_dump(ranges
);
3070 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3072 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3073 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3074 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3076 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3077 assert (prev
->upper
<= curr
->lower
);
3078 assert (curr
->lower
< curr
->upper
);
3082 TRACE("--- Done checking---\n");
3085 static RANGES
ranges_create(int count
)
3087 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3088 if (!ranges
) return NULL
;
3089 ranges
->hdpa
= DPA_Create(count
);
3090 if (ranges
->hdpa
) return ranges
;
3095 static void ranges_clear(RANGES ranges
)
3099 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3100 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3101 DPA_DeleteAllPtrs(ranges
->hdpa
);
3105 static void ranges_destroy(RANGES ranges
)
3107 if (!ranges
) return;
3108 ranges_clear(ranges
);
3109 DPA_Destroy(ranges
->hdpa
);
3113 static RANGES
ranges_clone(RANGES ranges
)
3118 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3120 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3122 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3123 if (!newrng
) goto fail
;
3124 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3125 if (!DPA_SetPtr(clone
->hdpa
, i
, newrng
))
3134 TRACE ("clone failed\n");
3135 ranges_destroy(clone
);
3139 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3143 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3144 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3149 static void ranges_dump(RANGES ranges
)
3153 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3154 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3157 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3159 RANGE srchrng
= { nItem
, nItem
+ 1 };
3161 TRACE("(nItem=%d)\n", nItem
);
3162 ranges_check(ranges
, "before contain");
3163 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3166 static INT
ranges_itemcount(RANGES ranges
)
3170 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3172 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3173 count
+= sel
->upper
- sel
->lower
;
3179 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3181 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3184 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3185 if (index
== -1) return TRUE
;
3187 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3189 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3190 if (chkrng
->lower
>= nItem
)
3191 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3192 if (chkrng
->upper
> nItem
)
3193 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3198 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3203 TRACE("(%s)\n", debugrange(&range
));
3204 ranges_check(ranges
, "before add");
3206 /* try find overlapping regions first */
3207 srchrgn
.lower
= range
.lower
- 1;
3208 srchrgn
.upper
= range
.upper
+ 1;
3209 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3215 TRACE("Adding new range\n");
3217 /* create the brand new range to insert */
3218 newrgn
= Alloc(sizeof(RANGE
));
3219 if(!newrgn
) goto fail
;
3222 /* figure out where to insert it */
3223 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3224 TRACE("index=%d\n", index
);
3225 if (index
== -1) index
= 0;
3227 /* and get it over with */
3228 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3236 RANGE
*chkrgn
, *mrgrgn
;
3237 INT fromindex
, mergeindex
;
3239 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3240 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3242 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3243 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3245 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3247 /* merge now common ranges */
3249 srchrgn
.lower
= chkrgn
->lower
- 1;
3250 srchrgn
.upper
= chkrgn
->upper
+ 1;
3254 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3255 if (mergeindex
== -1) break;
3256 if (mergeindex
== index
)
3258 fromindex
= index
+ 1;
3262 TRACE("Merge with index %i\n", mergeindex
);
3264 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3265 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3266 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3268 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3269 if (mergeindex
< index
) index
--;
3273 ranges_check(ranges
, "after add");
3277 ranges_check(ranges
, "failed add");
3281 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3286 TRACE("(%s)\n", debugrange(&range
));
3287 ranges_check(ranges
, "before del");
3289 /* we don't use DPAS_SORTED here, since we need *
3290 * to find the first overlapping range */
3291 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3294 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3296 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3298 /* case 1: Same range */
3299 if ( (chkrgn
->upper
== range
.upper
) &&
3300 (chkrgn
->lower
== range
.lower
) )
3302 DPA_DeletePtr(ranges
->hdpa
, index
);
3306 /* case 2: engulf */
3307 else if ( (chkrgn
->upper
<= range
.upper
) &&
3308 (chkrgn
->lower
>= range
.lower
) )
3310 DPA_DeletePtr(ranges
->hdpa
, index
);
3313 /* case 3: overlap upper */
3314 else if ( (chkrgn
->upper
<= range
.upper
) &&
3315 (chkrgn
->lower
< range
.lower
) )
3317 chkrgn
->upper
= range
.lower
;
3319 /* case 4: overlap lower */
3320 else if ( (chkrgn
->upper
> range
.upper
) &&
3321 (chkrgn
->lower
>= range
.lower
) )
3323 chkrgn
->lower
= range
.upper
;
3326 /* case 5: fully internal */
3331 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3332 newrgn
->lower
= chkrgn
->lower
;
3333 newrgn
->upper
= range
.lower
;
3334 chkrgn
->lower
= range
.upper
;
3335 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3343 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3346 ranges_check(ranges
, "after del");
3350 ranges_check(ranges
, "failed del");
3356 * Removes all selection ranges
3359 * [I] infoPtr : valid pointer to the listview structure
3360 * [I] toSkip : item range to skip removing the selection
3366 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3375 lvItem
.stateMask
= LVIS_SELECTED
;
3377 /* need to clone the DPA because callbacks can change it */
3378 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3379 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3380 while(iterator_next(&i
))
3381 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3382 /* note that the iterator destructor will free the cloned range */
3383 iterator_destroy(&i
);
3388 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3392 if (!(toSkip
= ranges_create(1))) return FALSE
;
3393 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3394 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3395 ranges_destroy(toSkip
);
3399 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3401 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3406 * Retrieves the number of items that are marked as selected.
3409 * [I] infoPtr : valid pointer to the listview structure
3412 * Number of items selected.
3414 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3416 INT nSelectedCount
= 0;
3418 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3421 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3423 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3428 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3430 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3431 return nSelectedCount
;
3436 * Manages the item focus.
3439 * [I] infoPtr : valid pointer to the listview structure
3440 * [I] nItem : item index
3443 * TRUE : focused item changed
3444 * FALSE : focused item has NOT changed
3446 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3448 INT oldFocus
= infoPtr
->nFocusedItem
;
3451 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3453 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3454 lvItem
.stateMask
= LVIS_FOCUSED
;
3455 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3457 return oldFocus
!= infoPtr
->nFocusedItem
;
3460 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3462 if (nShiftItem
< nItem
) return nShiftItem
;
3464 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3466 if (direction
> 0) return nShiftItem
+ direction
;
3468 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3471 /* This function updates focus index.
3474 focus : current focus index
3475 item : index of item to be added/removed
3476 direction : add/remove flag
3478 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3480 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3482 infoPtr
->bDoChangeNotify
= FALSE
;
3483 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3484 if (focus
!= infoPtr
->nFocusedItem
)
3485 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3486 infoPtr
->bDoChangeNotify
= old_change
;
3491 * Updates the various indices after an item has been inserted or deleted.
3494 * [I] infoPtr : valid pointer to the listview structure
3495 * [I] nItem : item index
3496 * [I] direction : Direction of shift, +1 or -1.
3501 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3503 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3505 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3506 assert(abs(direction
) == 1);
3507 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3509 /* But we are not supposed to modify nHotItem! */
3514 * Adds a block of selections.
3517 * [I] infoPtr : valid pointer to the listview structure
3518 * [I] nItem : item index
3521 * Whether the window is still valid.
3523 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3525 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3526 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3527 HWND hwndSelf
= infoPtr
->hwndSelf
;
3528 NMLVODSTATECHANGE nmlv
;
3533 /* Temporarily disable change notification
3534 * If the control is LVS_OWNERDATA, we need to send
3535 * only one LVN_ODSTATECHANGED notification.
3536 * See MSDN documentation for LVN_ITEMCHANGED.
3538 bOldChange
= infoPtr
->bDoChangeNotify
;
3539 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3541 if (nFirst
== -1) nFirst
= nItem
;
3543 item
.state
= LVIS_SELECTED
;
3544 item
.stateMask
= LVIS_SELECTED
;
3546 for (i
= nFirst
; i
<= nLast
; i
++)
3547 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3549 ZeroMemory(&nmlv
, sizeof(nmlv
));
3550 nmlv
.iFrom
= nFirst
;
3553 nmlv
.uNewState
= item
.state
;
3555 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3556 if (!IsWindow(hwndSelf
))
3558 infoPtr
->bDoChangeNotify
= bOldChange
;
3565 * Sets a single group selection.
3568 * [I] infoPtr : valid pointer to the listview structure
3569 * [I] nItem : item index
3574 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3581 if (!(selection
= ranges_create(100))) return;
3583 item
.state
= LVIS_SELECTED
;
3584 item
.stateMask
= LVIS_SELECTED
;
3586 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3588 if (infoPtr
->nSelectionMark
== -1)
3590 infoPtr
->nSelectionMark
= nItem
;
3591 ranges_additem(selection
, nItem
);
3597 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3598 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3599 ranges_add(selection
, sel
);
3604 RECT rcItem
, rcSel
, rcSelMark
;
3607 rcItem
.left
= LVIR_BOUNDS
;
3608 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3609 ranges_destroy (selection
);
3612 rcSelMark
.left
= LVIR_BOUNDS
;
3613 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3614 ranges_destroy (selection
);
3617 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3618 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3619 while(iterator_next(&i
))
3621 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3622 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3624 iterator_destroy(&i
);
3627 /* disable per item notifications on LVS_OWNERDATA style
3628 FIXME: single LVN_ODSTATECHANGED should be used */
3629 bOldChange
= infoPtr
->bDoChangeNotify
;
3630 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3632 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3635 iterator_rangesitems(&i
, selection
);
3636 while(iterator_next(&i
))
3637 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3638 /* this will also destroy the selection */
3639 iterator_destroy(&i
);
3641 infoPtr
->bDoChangeNotify
= bOldChange
;
3643 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3648 * Sets a single selection.
3651 * [I] infoPtr : valid pointer to the listview structure
3652 * [I] nItem : item index
3657 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3661 TRACE("nItem=%d\n", nItem
);
3663 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3665 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3666 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3667 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3669 infoPtr
->nSelectionMark
= nItem
;
3674 * Set selection(s) with keyboard.
3677 * [I] infoPtr : valid pointer to the listview structure
3678 * [I] nItem : item index
3679 * [I] space : VK_SPACE code sent
3682 * SUCCESS : TRUE (needs to be repainted)
3683 * FAILURE : FALSE (nothing has changed)
3685 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3687 /* FIXME: pass in the state */
3688 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3689 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3690 BOOL bResult
= FALSE
;
3692 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3693 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3697 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3698 LISTVIEW_SetSelection(infoPtr
, nItem
);
3702 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3706 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3707 lvItem
.stateMask
= LVIS_SELECTED
;
3710 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3711 if (lvItem
.state
& LVIS_SELECTED
)
3712 infoPtr
->nSelectionMark
= nItem
;
3714 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3717 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3720 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3724 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3726 LVHITTESTINFO lvHitTestInfo
;
3728 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3729 lvHitTestInfo
.pt
.x
= pt
.x
;
3730 lvHitTestInfo
.pt
.y
= pt
.y
;
3732 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3734 lpLVItem
->mask
= LVIF_PARAM
;
3735 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3736 lpLVItem
->iSubItem
= 0;
3738 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3741 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3743 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3744 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3745 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3750 * Called when the mouse is being actively tracked and has hovered for a specified
3754 * [I] infoPtr : valid pointer to the listview structure
3755 * [I] fwKeys : key indicator
3756 * [I] x,y : mouse position
3759 * 0 if the message was processed, non-zero if there was an error
3762 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3763 * over the item for a certain period of time.
3766 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3770 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3772 if (LISTVIEW_IsHotTracking(infoPtr
))
3780 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3781 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3783 SetFocus(infoPtr
->hwndSelf
);
3789 #define SCROLL_LEFT 0x1
3790 #define SCROLL_RIGHT 0x2
3791 #define SCROLL_UP 0x4
3792 #define SCROLL_DOWN 0x8
3796 * Utility routine to draw and highlight items within a marquee selection rectangle.
3799 * [I] infoPtr : valid pointer to the listview structure
3800 * [I] coords_orig : original co-ordinates of the cursor
3801 * [I] coords_offs : offsetted coordinates of the cursor
3802 * [I] offset : offset amount
3803 * [I] scroll : Bitmask of which directions we should scroll, if at all
3808 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3809 const POINT
*coords_offs
, const POINT
*offset
,
3812 BOOL controlDown
= FALSE
;
3814 ITERATOR old_elems
, new_elems
;
3817 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3819 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3820 rect
.right
= coords_offs
->x
;
3824 rect
.left
= coords_offs
->x
;
3825 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3828 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3830 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3831 rect
.bottom
= coords_offs
->y
;
3835 rect
.top
= coords_offs
->y
;
3836 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3839 /* Cancel out the old marquee rectangle and draw the new one */
3840 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3842 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3843 the cursor is further away */
3845 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3846 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3848 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3849 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3851 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3852 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3854 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3855 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3857 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3859 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3861 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3862 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3864 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3865 iterator_remove_common_items(&old_elems
, &new_elems
);
3867 /* Iterate over no longer selected items */
3868 while (iterator_next(&old_elems
))
3870 if (old_elems
.nItem
> -1)
3872 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3875 item
.state
= LVIS_SELECTED
;
3877 item
.stateMask
= LVIS_SELECTED
;
3879 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3882 iterator_destroy(&old_elems
);
3885 /* Iterate over newly selected items */
3886 if (GetKeyState(VK_CONTROL
) & 0x8000)
3889 while (iterator_next(&new_elems
))
3891 if (new_elems
.nItem
> -1)
3893 /* If CTRL is pressed, invert. If not, always select the item. */
3894 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3897 item
.state
= LVIS_SELECTED
;
3899 item
.stateMask
= LVIS_SELECTED
;
3901 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3904 iterator_destroy(&new_elems
);
3906 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3911 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3912 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3915 * [I] hwnd : Handle to the listview
3916 * [I] uMsg : WM_TIMER (ignored)
3917 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3918 * [I] dwTimer : The elapsed time (ignored)
3923 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3925 LISTVIEW_INFO
*infoPtr
;
3926 SCROLLINFO scrollInfo
;
3932 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3937 /* Get the current cursor position and convert to client coordinates */
3938 GetCursorPos(&coords_orig
);
3939 ScreenToClient(hWnd
, &coords_orig
);
3941 /* Ensure coordinates are within client bounds */
3942 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3943 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3946 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3948 /* Offset coordinates by the appropriate amount */
3949 coords_offs
.x
-= offset
.x
;
3950 coords_offs
.y
-= offset
.y
;
3952 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3953 scrollInfo
.fMask
= SIF_ALL
;
3955 /* Work out in which directions we can scroll */
3956 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3958 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3959 scroll
|= SCROLL_UP
;
3961 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3962 scroll
|= SCROLL_DOWN
;
3965 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3967 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3968 scroll
|= SCROLL_LEFT
;
3970 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3971 scroll
|= SCROLL_RIGHT
;
3974 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3975 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3976 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3977 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3979 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3985 * Called whenever WM_MOUSEMOVE is received.
3988 * [I] infoPtr : valid pointer to the listview structure
3989 * [I] fwKeys : key indicator
3990 * [I] x,y : mouse position
3993 * 0 if the message is processed, non-zero if there was an error
3995 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4001 if (!(fwKeys
& MK_LBUTTON
))
4002 infoPtr
->bLButtonDown
= FALSE
;
4004 if (infoPtr
->bLButtonDown
)
4006 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4007 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4009 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4011 if (infoPtr
->bMarqueeSelect
)
4021 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4023 /* Ensure coordinates are within client bounds */
4024 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4025 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4027 /* Offset coordinates by the appropriate amount */
4028 coords_offs
.x
-= offset
.x
;
4029 coords_offs
.y
-= offset
.y
;
4031 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4032 move the mouse again */
4034 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4035 (y
>= infoPtr
->rcList
.bottom
))
4037 if (!infoPtr
->bScrolling
)
4039 infoPtr
->bScrolling
= TRUE
;
4040 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4045 infoPtr
->bScrolling
= FALSE
;
4046 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4049 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4057 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4059 /* reset item marker */
4060 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4061 infoPtr
->nLButtonDownItem
= -1;
4063 if (!PtInRect(&rect
, pt
))
4065 /* this path covers the following:
4066 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4067 2. change focus with keys
4068 3. move mouse over item from step 1 selects it and moves focus on it */
4069 if (infoPtr
->nLButtonDownItem
!= -1 &&
4070 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4074 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4075 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4077 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4078 infoPtr
->nLButtonDownItem
= -1;
4081 if (!infoPtr
->bDragging
)
4083 ht
.pt
= infoPtr
->ptClickPos
;
4084 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4086 /* If the click is outside the range of an item, begin a
4087 highlight. If not, begin an item drag. */
4092 /* If we're allowing multiple selections, send notification.
4093 If return value is non-zero, cancel. */
4094 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4096 /* Store the absolute coordinates of the click */
4098 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4100 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4101 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4103 /* Begin selection and capture mouse */
4104 infoPtr
->bMarqueeSelect
= TRUE
;
4105 SetCapture(infoPtr
->hwndSelf
);
4112 ZeroMemory(&nmlv
, sizeof(nmlv
));
4113 nmlv
.iItem
= ht
.iItem
;
4114 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4116 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4117 infoPtr
->bDragging
= TRUE
;
4125 /* see if we are supposed to be tracking mouse hovering */
4126 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4127 TRACKMOUSEEVENT trackinfo
;
4130 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4131 trackinfo
.dwFlags
= TME_QUERY
;
4133 /* see if we are already tracking this hwnd */
4134 _TrackMouseEvent(&trackinfo
);
4137 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
4140 if((trackinfo
.dwFlags
& flags
) != flags
|| trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4141 trackinfo
.dwFlags
= flags
;
4142 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4143 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4145 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4146 _TrackMouseEvent(&trackinfo
);
4155 * Tests whether the item is assignable to a list with style lStyle
4157 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4159 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4160 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4161 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4169 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4172 * [I] infoPtr : valid pointer to the listview structure
4173 * [I] lpLVItem : valid pointer to new item attributes
4174 * [I] isNew : the item being set is being inserted
4175 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4176 * [O] bChanged : will be set to TRUE if the item really changed
4182 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4188 /* stateMask is ignored for LVM_INSERTITEM */
4189 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4193 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4195 if (lpLVItem
->mask
== 0) return TRUE
;
4197 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4199 /* a virtual listview only stores selection and focus */
4200 if (lpLVItem
->mask
& ~LVIF_STATE
)
4206 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4207 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4211 /* we need to get the lParam and state of the item */
4212 item
.iItem
= lpLVItem
->iItem
;
4213 item
.iSubItem
= lpLVItem
->iSubItem
;
4214 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4215 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4219 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4221 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4222 /* determine what fields will change */
4223 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4224 uChanged
|= LVIF_STATE
;
4226 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4227 uChanged
|= LVIF_IMAGE
;
4229 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4230 uChanged
|= LVIF_PARAM
;
4232 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4233 uChanged
|= LVIF_INDENT
;
4235 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4236 uChanged
|= LVIF_TEXT
;
4238 TRACE("change mask=0x%x\n", uChanged
);
4240 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4241 nmlv
.iItem
= lpLVItem
->iItem
;
4242 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4243 nmlv
.uOldState
= item
.state
;
4244 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4245 nmlv
.lParam
= item
.lParam
;
4247 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4248 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4249 are enabled. Even nothing really changed we still need to send this,
4250 in this case uChanged mask is just set to passed item mask. */
4251 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4253 HWND hwndSelf
= infoPtr
->hwndSelf
;
4255 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4257 if (!IsWindow(hwndSelf
))
4261 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4262 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4263 /* this means we won't hit a focus change path later */
4264 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4266 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4267 infoPtr
->nFocusedItem
++;
4270 if (!uChanged
) return TRUE
;
4273 /* copy information */
4274 if (lpLVItem
->mask
& LVIF_TEXT
)
4275 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4277 if (lpLVItem
->mask
& LVIF_IMAGE
)
4278 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4280 if (lpLVItem
->mask
& LVIF_PARAM
)
4281 lpItem
->lParam
= lpLVItem
->lParam
;
4283 if (lpLVItem
->mask
& LVIF_INDENT
)
4284 lpItem
->iIndent
= lpLVItem
->iIndent
;
4286 if (uChanged
& LVIF_STATE
)
4288 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4290 lpItem
->state
&= ~stateMask
;
4291 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4293 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4295 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4296 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4298 else if (stateMask
& LVIS_SELECTED
)
4300 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4302 /* If we are asked to change focus, and we manage it, do it.
4303 It's important to have all new item data stored at this point,
4304 because changing existing focus could result in a redrawing operation,
4305 which in turn could ask for disp data, application should see all data
4306 for inserted item when processing LVN_GETDISPINFO.
4308 The way this works application will see nested item change notifications -
4309 changed item notifications interrupted by ones from item losing focus. */
4310 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4312 if (lpLVItem
->state
& LVIS_FOCUSED
)
4314 /* update selection mark */
4315 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4316 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4318 if (infoPtr
->nFocusedItem
!= -1)
4320 /* remove current focus */
4321 item
.mask
= LVIF_STATE
;
4323 item
.stateMask
= LVIS_FOCUSED
;
4325 /* recurse with redrawing an item */
4326 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4329 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4330 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4332 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4334 infoPtr
->nFocusedItem
= -1;
4339 /* if we're inserting the item, we're done */
4340 if (isNew
) return TRUE
;
4342 /* send LVN_ITEMCHANGED notification */
4343 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4344 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4351 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4354 * [I] infoPtr : valid pointer to the listview structure
4355 * [I] lpLVItem : valid pointer to new subitem attributes
4356 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4357 * [O] bChanged : will be set to TRUE if the item really changed
4363 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4366 SUBITEM_INFO
*lpSubItem
;
4368 /* we do not support subitems for virtual listviews */
4369 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4371 /* set subitem only if column is present */
4372 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4374 /* First do some sanity checks */
4375 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4376 particularly useful. We currently do not actually do anything with
4377 the flag on subitems.
4379 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4380 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4382 /* get the subitem structure, and create it if not there */
4383 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4384 assert (hdpaSubItems
);
4386 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4389 SUBITEM_INFO
*tmpSubItem
;
4392 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4393 if (!lpSubItem
) return FALSE
;
4394 /* we could binary search here, if need be...*/
4395 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4397 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4398 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4400 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4405 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4406 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4410 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4412 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4416 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4418 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4427 * Sets item attributes.
4430 * [I] infoPtr : valid pointer to the listview structure
4431 * [I] lpLVItem : new item attributes
4432 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4438 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4440 HWND hwndSelf
= infoPtr
->hwndSelf
;
4441 LPWSTR pszText
= NULL
;
4442 BOOL bResult
, bChanged
= FALSE
;
4445 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4447 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4450 /* Store old item area */
4451 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4453 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4454 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4456 pszText
= lpLVItem
->pszText
;
4457 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4460 /* actually set the fields */
4461 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4463 if (lpLVItem
->iSubItem
)
4464 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4466 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4467 if (!IsWindow(hwndSelf
))
4470 /* redraw item, if necessary */
4471 if (bChanged
&& !infoPtr
->bIsDrawing
)
4473 /* this little optimization eliminates some nasty flicker */
4474 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4475 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4476 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4477 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4480 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4481 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4487 textfreeT(lpLVItem
->pszText
, isW
);
4488 lpLVItem
->pszText
= pszText
;
4496 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4499 * [I] infoPtr : valid pointer to the listview structure
4504 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4507 SCROLLINFO scrollInfo
;
4509 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4510 scrollInfo
.fMask
= SIF_POS
;
4512 if (infoPtr
->uView
== LV_VIEW_LIST
)
4514 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4515 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4517 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4519 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4520 nItem
= scrollInfo
.nPos
;
4524 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4525 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4528 TRACE("nItem=%d\n", nItem
);
4536 * Erases the background of the given rectangle
4539 * [I] infoPtr : valid pointer to the listview structure
4540 * [I] hdc : device context handle
4541 * [I] lprcBox : clipping rectangle
4547 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4549 if (!infoPtr
->hBkBrush
) return FALSE
;
4551 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4553 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4556 /* Draw main item or subitem */
4557 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4559 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4560 const RECT
*background
;
4565 /* now check if we need to update the focus rectangle */
4566 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4567 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4569 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4570 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4571 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4572 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4573 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4574 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4575 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4576 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4577 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4579 /* FIXME: temporary hack */
4580 rcSelect
.left
= rcLabel
.left
;
4582 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4584 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4585 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4586 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4587 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4588 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4591 /* in icon mode, the label rect is really what we want to draw the
4593 /* in detail mode, we want to paint background for label rect when
4594 * item is not selected or listview has full row select; otherwise paint
4595 * background for text only */
4596 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4597 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4598 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4599 background
= &rcLabel
;
4601 background
= &rcSelect
;
4603 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4604 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4606 if (item
->state
& LVIS_FOCUSED
)
4608 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4610 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4612 /* we have to update left focus bound too if item isn't in leftmost column
4613 and reduce right box bound */
4614 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4618 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4620 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4621 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4622 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4624 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4625 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4628 rcSelect
.right
= rcBox
.right
;
4630 infoPtr
->rcFocus
= rcSelect
;
4633 infoPtr
->rcFocus
= rcLabel
;
4637 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4639 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4642 TRACE("stateimage=%d\n", stateimage
);
4643 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4648 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4649 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4653 TRACE("iImage=%d\n", item
->iImage
);
4655 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4656 style
= ILD_SELECTED
;
4660 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4661 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4662 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4663 style
| (item
->state
& LVIS_OVERLAYMASK
));
4666 /* Don't bother painting item being edited */
4667 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4669 /* figure out the text drawing flags */
4670 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4671 if (infoPtr
->uView
== LV_VIEW_ICON
)
4672 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4673 else if (item
->iSubItem
)
4675 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4677 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4678 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4679 default: format
|= DT_LEFT
;
4682 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4684 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4685 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4687 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4689 /* for GRIDLINES reduce the bottom so the text formats correctly */
4690 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4693 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4701 * [I] infoPtr : valid pointer to the listview structure
4702 * [I] hdc : device context handle
4703 * [I] nItem : item index
4704 * [I] nSubItem : subitem index
4705 * [I] pos : item position in client coordinates
4706 * [I] cdmode : custom draw mode
4712 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4714 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4715 static WCHAR callbackW
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4716 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4718 NMLVCUSTOMDRAW nmlvcd
;
4721 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4723 /* get information needed for drawing the item */
4724 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4725 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4726 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4727 lvItem
.iItem
= nItem
;
4728 lvItem
.iSubItem
= 0;
4731 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4732 lvItem
.pszText
= szDispText
;
4733 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4734 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4735 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4737 /* now check if we need to update the focus rectangle */
4738 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4739 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4741 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4742 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4744 /* Full custom draw stage sequence looks like this:
4749 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4750 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item iself
4751 - CDDS_ITEMPOSTPAINT
4756 - CDDS_ITEMPOSTPAINT
4759 /* fill in the custom draw structure */
4760 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4761 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4762 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4763 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4767 while (iterator_next(subitems
))
4769 DWORD subitemstage
= CDRF_DODEFAULT
;
4771 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4772 if (subitems
->nItem
)
4774 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4775 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4776 lvItem
.iItem
= nItem
;
4777 lvItem
.iSubItem
= subitems
->nItem
;
4780 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4781 lvItem
.pszText
= szDispText
;
4782 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4783 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4784 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4785 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4786 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4788 /* update custom draw data */
4789 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4790 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4791 nmlvcd
.iSubItem
= subitems
->nItem
;
4794 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4795 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4798 nmlvcd
.clrTextBk
= infoPtr
->clrTextBk
;
4799 nmlvcd
.clrText
= infoPtr
->clrText
;
4802 if (subitems
->nItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4803 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4804 else if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4805 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4807 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4808 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4810 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4811 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4816 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4817 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4821 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4823 nmlvcd
.iSubItem
= 0;
4824 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4832 * Draws listview items when in owner draw mode.
4835 * [I] infoPtr : valid pointer to the listview structure
4836 * [I] hdc : device context handle
4841 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4843 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4844 DWORD cditemmode
= CDRF_DODEFAULT
;
4845 NMLVCUSTOMDRAW nmlvcd
;
4846 POINT Origin
, Position
;
4852 ZeroMemory(&dis
, sizeof(dis
));
4854 /* Get scroll info once before loop */
4855 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4857 /* iterate through the invalidated rows */
4858 while(iterator_next(i
))
4860 item
.iItem
= i
->nItem
;
4862 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4863 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4864 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4866 dis
.CtlType
= ODT_LISTVIEW
;
4868 dis
.itemID
= item
.iItem
;
4869 dis
.itemAction
= ODA_DRAWENTIRE
;
4871 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4872 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4873 dis
.hwndItem
= infoPtr
->hwndSelf
;
4875 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4876 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4877 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4878 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4879 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4880 dis
.itemData
= item
.lParam
;
4882 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4885 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4886 * structure for the rest. of the paint cycle
4888 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4889 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4890 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4892 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4894 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4895 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4898 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4899 notify_postpaint(infoPtr
, &nmlvcd
);
4905 * Draws listview items when in report display mode.
4908 * [I] infoPtr : valid pointer to the listview structure
4909 * [I] hdc : device context handle
4910 * [I] cdmode : custom draw mode
4915 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4918 RECT rcClip
, rcItem
;
4926 /* figure out what to draw */
4927 rgntype
= GetClipBox(hdc
, &rcClip
);
4928 if (rgntype
== NULLREGION
) return;
4930 /* Get scroll info once before loop */
4931 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4933 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4935 /* narrow down the columns we need to paint */
4936 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4938 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4940 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4941 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4942 ranges_additem(colRanges
, index
);
4944 iterator_rangesitems(&j
, colRanges
);
4946 /* in full row select, we _have_ to draw the main item */
4947 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4950 /* iterate through the invalidated rows */
4951 while(iterator_next(i
))
4957 SelectObject(hdc
, infoPtr
->hFont
);
4958 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4959 Position
.x
= Origin
.x
;
4960 Position
.y
+= Origin
.y
;
4962 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4964 /* iterate through the invalidated columns */
4965 while(iterator_next(&j
))
4967 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4969 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4972 rcItem
.bottom
= infoPtr
->nItemHeight
;
4973 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4974 if (!RectVisible(hdc
, &rcItem
)) continue;
4977 ranges_additem(subitems
, j
.nItem
);
4980 iterator_rangesitems(&k
, subitems
);
4981 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
4982 iterator_destroy(&k
);
4984 iterator_destroy(&j
);
4989 * Draws the gridlines if necessary when in report display mode.
4992 * [I] infoPtr : valid pointer to the listview structure
4993 * [I] hdc : device context handle
4998 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
5004 RECT rcClip
, rcItem
= {0};
5012 /* figure out what to draw */
5013 rgntype
= GetClipBox(hdc
, &rcClip
);
5014 if (rgntype
== NULLREGION
) return;
5016 /* Get scroll info once before loop */
5017 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5019 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5021 /* narrow down the columns we need to paint */
5022 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5024 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5026 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5027 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5028 ranges_additem(colRanges
, index
);
5031 /* is right most vertical line visible? */
5032 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5034 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5035 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5036 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5039 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5041 hOldPen
= SelectObject ( hdc
, hPen
);
5043 /* draw the vertical lines for the columns */
5044 iterator_rangesitems(&j
, colRanges
);
5045 while(iterator_next(&j
))
5047 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5048 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5049 rcItem
.left
+= Origin
.x
;
5050 rcItem
.right
+= Origin
.x
;
5051 rcItem
.top
= infoPtr
->rcList
.top
;
5052 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5053 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5054 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5055 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5057 iterator_destroy(&j
);
5058 /* draw rightmost grid line if visible */
5061 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5062 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5063 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5065 rcItem
.right
+= Origin
.x
;
5067 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5068 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5071 /* draw the horizontal lines for the rows */
5072 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5073 rcItem
.left
= infoPtr
->rcList
.left
;
5074 rcItem
.right
= infoPtr
->rcList
.right
;
5075 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5077 rcItem
.bottom
= rcItem
.top
= y
;
5078 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5079 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5080 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5083 SelectObject( hdc
, hOldPen
);
5084 DeleteObject( hPen
);
5087 ranges_destroy(colRanges
);
5092 * Draws listview items when in list display mode.
5095 * [I] infoPtr : valid pointer to the listview structure
5096 * [I] hdc : device context handle
5097 * [I] cdmode : custom draw mode
5102 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5104 POINT Origin
, Position
;
5106 /* Get scroll info once before loop */
5107 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5109 while(iterator_prev(i
))
5111 SelectObject(hdc
, infoPtr
->hFont
);
5112 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5113 Position
.x
+= Origin
.x
;
5114 Position
.y
+= Origin
.y
;
5116 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5123 * Draws listview items.
5126 * [I] infoPtr : valid pointer to the listview structure
5127 * [I] hdc : device context handle
5128 * [I] prcErase : rect to be erased before refresh (may be NULL)
5133 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5135 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5136 NMLVCUSTOMDRAW nmlvcd
;
5143 HBITMAP hbmp
= NULL
;
5146 LISTVIEW_DUMP(infoPtr
);
5148 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5149 TRACE("double buffering\n");
5151 hdc
= CreateCompatibleDC(hdcOrig
);
5153 ERR("Failed to create DC for backbuffer\n");
5156 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5157 infoPtr
->rcList
.bottom
);
5159 ERR("Failed to create bitmap for backbuffer\n");
5164 SelectObject(hdc
, hbmp
);
5165 SelectObject(hdc
, infoPtr
->hFont
);
5167 if(GetClipBox(hdcOrig
, &rcClient
))
5168 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5170 /* Save dc values we're gonna trash while drawing
5171 * FIXME: Should be done in LISTVIEW_DrawItem() */
5172 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5173 oldBkMode
= GetBkMode(hdc
);
5174 oldBkColor
= GetBkColor(hdc
);
5175 oldTextColor
= GetTextColor(hdc
);
5178 infoPtr
->bIsDrawing
= TRUE
;
5181 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5182 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5183 /* If no erasing was done (usually because RedrawWindow was called
5184 * with RDW_INVALIDATE only) we need to copy the old contents into
5185 * the backbuffer before continuing. */
5186 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5187 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5188 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5189 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5192 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5193 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5194 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5195 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5197 /* nothing to draw */
5198 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5200 /* figure out what we need to draw */
5201 iterator_visibleitems(&i
, infoPtr
, hdc
);
5202 range
= iterator_range(&i
);
5204 /* send cache hint notification */
5205 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5209 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5210 nmlv
.iFrom
= range
.lower
;
5211 nmlv
.iTo
= range
.upper
- 1;
5212 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5215 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5216 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5219 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5220 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5221 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5222 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5224 /* if we have a focus rect and it's visible, draw it */
5225 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5226 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5227 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5229 iterator_destroy(&i
);
5232 /* For LVS_EX_GRIDLINES go and draw lines */
5233 /* This includes the case where there were *no* items */
5234 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5235 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5237 /* Draw marquee rectangle if appropriate */
5238 if (infoPtr
->bMarqueeSelect
)
5239 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5241 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5242 notify_postpaint(infoPtr
, &nmlvcd
);
5245 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5246 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5247 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5248 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5253 SelectObject(hdc
, hOldFont
);
5254 SetBkMode(hdc
, oldBkMode
);
5255 SetBkColor(hdc
, oldBkColor
);
5256 SetTextColor(hdc
, oldTextColor
);
5259 infoPtr
->bIsDrawing
= FALSE
;
5265 * Calculates the approximate width and height of a given number of items.
5268 * [I] infoPtr : valid pointer to the listview structure
5269 * [I] nItemCount : number of items
5270 * [I] wWidth : width
5271 * [I] wHeight : height
5274 * Returns a DWORD. The width in the low word and the height in high word.
5276 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5277 WORD wWidth
, WORD wHeight
)
5279 DWORD dwViewRect
= 0;
5281 if (nItemCount
== -1)
5282 nItemCount
= infoPtr
->nItemCount
;
5284 if (infoPtr
->uView
== LV_VIEW_LIST
)
5286 INT nItemCountPerColumn
= 1;
5287 INT nColumnCount
= 0;
5289 if (wHeight
== 0xFFFF)
5291 /* use current height */
5292 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5295 if (wHeight
< infoPtr
->nItemHeight
)
5296 wHeight
= infoPtr
->nItemHeight
;
5300 if (infoPtr
->nItemHeight
> 0)
5302 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5303 if (nItemCountPerColumn
== 0)
5304 nItemCountPerColumn
= 1;
5306 if (nItemCount
% nItemCountPerColumn
!= 0)
5307 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5309 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5313 /* Microsoft padding magic */
5314 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5315 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5317 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5319 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5323 if (infoPtr
->nItemCount
> 0)
5325 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5326 wWidth
= rcBox
.right
- rcBox
.left
;
5327 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5331 /* use current height and width */
5332 if (wHeight
== 0xffff)
5333 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5334 if (wWidth
== 0xffff)
5335 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5338 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5340 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5346 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5347 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5349 if (wWidth
== 0xffff)
5350 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5352 if (wWidth
< nItemWidth
)
5353 wWidth
= nItemWidth
;
5355 cols
= wWidth
/ nItemWidth
;
5356 if (cols
> nItemCount
)
5363 rows
= nItemCount
/ cols
;
5364 if (nItemCount
% cols
)
5370 wHeight
= (nItemHeight
* rows
)+2;
5371 wWidth
= (nItemWidth
* cols
)+2;
5373 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5375 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5376 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5383 * Cancel edit label with saving item text.
5386 * [I] infoPtr : valid pointer to the listview structure
5389 * Always returns TRUE.
5391 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5393 if (infoPtr
->hwndEdit
)
5395 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5396 HWND edit
= infoPtr
->hwndEdit
;
5398 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5399 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5407 * Create a drag image list for the specified item.
5410 * [I] infoPtr : valid pointer to the listview structure
5411 * [I] iItem : index of item
5412 * [O] lppt : Upper-left corner of the image
5415 * Returns a handle to the image list if successful, NULL otherwise.
5417 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5423 HBITMAP hbmp
, hOldbmp
;
5425 HIMAGELIST dragList
= 0;
5426 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5428 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5431 rcItem
.left
= LVIR_BOUNDS
;
5432 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5435 lppt
->x
= rcItem
.left
;
5436 lppt
->y
= rcItem
.top
;
5438 size
.cx
= rcItem
.right
- rcItem
.left
;
5439 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5441 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5442 hdc
= CreateCompatibleDC(hdcOrig
);
5443 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5444 hOldbmp
= SelectObject(hdc
, hbmp
);
5445 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5447 SetRect(&rcItem
, 0, 0, size
.cx
, size
.cy
);
5448 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5451 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5453 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5454 SelectObject(hdc
, hOldbmp
);
5455 ImageList_Add(dragList
, hbmp
, 0);
5458 SelectObject(hdc
, hOldbmp
);
5460 SelectObject(hdc
, hOldFont
);
5463 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5465 TRACE("ret=%p\n", dragList
);
5473 * Removes all listview items and subitems.
5476 * [I] infoPtr : valid pointer to the listview structure
5482 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5484 HDPA hdpaSubItems
= NULL
;
5485 BOOL suppress
= FALSE
;
5493 /* we do it directly, to avoid notifications */
5494 ranges_clear(infoPtr
->selectionRanges
);
5495 infoPtr
->nSelectionMark
= -1;
5496 infoPtr
->nFocusedItem
= -1;
5497 SetRectEmpty(&infoPtr
->rcFocus
);
5498 /* But we are supposed to leave nHotItem as is! */
5500 /* send LVN_DELETEALLITEMS notification */
5501 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5505 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5507 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5510 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5512 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5514 /* send LVN_DELETEITEM notification, if not suppressed
5515 and if it is not a virtual listview */
5516 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5517 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5518 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5519 /* free id struct */
5520 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5521 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5522 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5524 /* both item and subitem start with ITEMHDR header */
5525 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5527 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5528 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5531 DPA_Destroy(hdpaSubItems
);
5532 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5534 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5535 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5536 infoPtr
->nItemCount
--;
5541 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5542 LISTVIEW_UpdateScroll(infoPtr
);
5544 LISTVIEW_InvalidateList(infoPtr
);
5551 * Scrolls, and updates the columns, when a column is changing width.
5554 * [I] infoPtr : valid pointer to the listview structure
5555 * [I] nColumn : column to scroll
5556 * [I] dx : amount of scroll, in pixels
5561 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5563 COLUMN_INFO
*lpColumnInfo
;
5569 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5570 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5571 rcCol
= lpColumnInfo
->rcHeader
;
5572 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5573 rcCol
.left
= rcCol
.right
;
5575 /* adjust the other columns */
5576 hdi
.mask
= HDI_ORDER
;
5577 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5579 INT nOrder
= hdi
.iOrder
;
5580 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5582 hdi
.mask
= HDI_ORDER
;
5583 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5584 if (hdi
.iOrder
>= nOrder
) {
5585 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5586 lpColumnInfo
->rcHeader
.left
+= dx
;
5587 lpColumnInfo
->rcHeader
.right
+= dx
;
5592 /* do not update screen if not in report mode */
5593 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5595 /* Need to reset the item width when inserting a new column */
5596 infoPtr
->nItemWidth
+= dx
;
5598 LISTVIEW_UpdateScroll(infoPtr
);
5599 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5601 /* scroll to cover the deleted column, and invalidate for redraw */
5602 rcOld
= infoPtr
->rcList
;
5603 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5604 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5609 * Removes a column from the listview control.
5612 * [I] infoPtr : valid pointer to the listview structure
5613 * [I] nColumn : column index
5619 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5623 TRACE("nColumn=%d\n", nColumn
);
5625 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5626 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5628 /* While the MSDN specifically says that column zero should not be deleted,
5629 what actually happens is that the column itself is deleted but no items or subitems
5633 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5635 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5638 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5639 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5641 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5643 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5645 INT nItem
, nSubItem
, i
;
5647 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5649 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5652 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5654 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5655 if (lpSubItem
->iSubItem
== nColumn
)
5658 lpDelItem
= lpSubItem
;
5660 else if (lpSubItem
->iSubItem
> nColumn
)
5662 lpSubItem
->iSubItem
--;
5666 /* if we found our subitem, zap it */
5670 if (is_text(lpDelItem
->hdr
.pszText
))
5671 Free(lpDelItem
->hdr
.pszText
);
5676 /* free dpa memory */
5677 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5682 /* update the other column info */
5683 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5684 LISTVIEW_InvalidateList(infoPtr
);
5686 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5687 LISTVIEW_UpdateItemSize(infoPtr
);
5694 * Invalidates the listview after an item's insertion or deletion.
5697 * [I] infoPtr : valid pointer to the listview structure
5698 * [I] nItem : item index
5699 * [I] dir : -1 if deleting, 1 if inserting
5704 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5706 INT nPerCol
, nItemCol
, nItemRow
;
5710 /* if we don't refresh, what's the point of scrolling? */
5711 if (!is_redrawing(infoPtr
)) return;
5713 assert (abs(dir
) == 1);
5715 /* arrange icons if autoarrange is on */
5716 if (is_autoarrange(infoPtr
))
5718 BOOL arrange
= TRUE
;
5719 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5720 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5721 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5724 /* scrollbars need updating */
5725 LISTVIEW_UpdateScroll(infoPtr
);
5727 /* figure out the item's position */
5728 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5729 nPerCol
= infoPtr
->nItemCount
+ 1;
5730 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5731 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5732 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5735 nItemCol
= nItem
/ nPerCol
;
5736 nItemRow
= nItem
% nPerCol
;
5737 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5739 /* move the items below up a slot */
5740 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5741 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5742 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5743 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5744 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5745 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5746 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5748 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5749 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5752 /* report has only that column, so we're done */
5753 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5755 /* now for LISTs, we have to deal with the columns to the right */
5756 SetRect(&rcScroll
, (nItemCol
+ 1) * infoPtr
->nItemWidth
, 0,
5757 (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
,
5758 nPerCol
* infoPtr
->nItemHeight
);
5759 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5760 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5761 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5766 * Removes an item from the listview control.
5769 * [I] infoPtr : valid pointer to the listview structure
5770 * [I] nItem : item index
5776 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5779 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5780 INT focus
= infoPtr
->nFocusedItem
;
5782 TRACE("(nItem=%d)\n", nItem
);
5784 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5786 /* remove selection, and focus */
5788 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5789 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5791 /* send LVN_DELETEITEM notification. */
5792 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5794 /* we need to do this here, because we'll be deleting stuff */
5796 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5798 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5806 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5807 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5809 /* free id struct */
5810 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5811 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5812 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5814 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5816 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5817 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5820 DPA_Destroy(hdpaSubItems
);
5825 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5826 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5829 infoPtr
->nItemCount
--;
5830 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5831 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5833 /* now is the invalidation fun */
5835 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5842 * Callback implementation for editlabel control
5845 * [I] infoPtr : valid pointer to the listview structure
5846 * [I] storeText : store edit box text as item text
5847 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5853 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5855 HWND hwndSelf
= infoPtr
->hwndSelf
;
5856 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5857 NMLVDISPINFOW dispInfo
;
5858 INT editedItem
= infoPtr
->nEditLabelItem
;
5860 WCHAR
*pszText
= NULL
;
5865 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5869 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5871 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5872 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5877 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5879 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5880 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5881 dispInfo
.item
.iItem
= editedItem
;
5882 dispInfo
.item
.iSubItem
= 0;
5883 dispInfo
.item
.stateMask
= ~0;
5884 dispInfo
.item
.pszText
= szDispText
;
5885 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5886 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5893 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5896 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5897 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5898 textfreeT(tmp
, FALSE
);
5901 /* add the text from the edit in */
5902 dispInfo
.item
.mask
|= LVIF_TEXT
;
5903 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5904 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5906 /* Do we need to update the Item Text */
5907 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5909 infoPtr
->nEditLabelItem
= -1;
5910 infoPtr
->hwndEdit
= 0;
5912 if (!res
) goto cleanup
;
5914 if (!IsWindow(hwndSelf
))
5919 if (!pszText
) return TRUE
;
5926 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5928 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5929 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5930 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5932 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5938 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5939 dispInfo
.item
.mask
= LVIF_TEXT
;
5940 dispInfo
.item
.iItem
= editedItem
;
5941 dispInfo
.item
.iSubItem
= 0;
5942 dispInfo
.item
.pszText
= pszText
;
5943 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5944 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5954 * Subclassed edit control windproc function
5957 * [I] hwnd : the edit window handle
5958 * [I] uMsg : the message that is to be processed
5959 * [I] wParam : first message parameter
5960 * [I] lParam : second message parameter
5961 * [I] isW : TRUE if input is Unicode
5966 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5968 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5971 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5972 hwnd
, uMsg
, wParam
, lParam
, isW
);
5977 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5981 WNDPROC editProc
= infoPtr
->EditWndProc
;
5982 infoPtr
->EditWndProc
= 0;
5983 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5984 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5988 if (VK_ESCAPE
== (INT
)wParam
)
5993 else if (VK_RETURN
== (INT
)wParam
)
5997 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6001 if (infoPtr
->hwndEdit
)
6002 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
6004 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6010 * Subclassed edit control Unicode windproc function
6013 * [I] hwnd : the edit window handle
6014 * [I] uMsg : the message that is to be processed
6015 * [I] wParam : first message parameter
6016 * [I] lParam : second message parameter
6020 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6022 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6027 * Subclassed edit control ANSI windproc function
6030 * [I] hwnd : the edit window handle
6031 * [I] uMsg : the message that is to be processed
6032 * [I] wParam : first message parameter
6033 * [I] lParam : second message parameter
6037 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6039 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6044 * Creates a subclassed edit control
6047 * [I] infoPtr : valid pointer to the listview structure
6048 * [I] text : initial text for the edit
6049 * [I] style : the window style
6050 * [I] isW : TRUE if input is Unicode
6054 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6056 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6057 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6060 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6062 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6064 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6066 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6068 if (!hedit
) return 0;
6070 infoPtr
->EditWndProc
= (WNDPROC
)
6071 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6072 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6074 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6075 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6082 * Begin in place editing of specified list view item
6085 * [I] infoPtr : valid pointer to the listview structure
6086 * [I] nItem : item index
6087 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6093 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6095 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6096 HWND hwndSelf
= infoPtr
->hwndSelf
;
6097 NMLVDISPINFOW dispInfo
;
6098 HFONT hOldFont
= NULL
;
6104 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6106 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6108 /* remove existing edit box */
6109 if (infoPtr
->hwndEdit
)
6111 SetFocus(infoPtr
->hwndSelf
);
6112 infoPtr
->hwndEdit
= 0;
6115 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6117 infoPtr
->nEditLabelItem
= nItem
;
6119 LISTVIEW_SetSelection(infoPtr
, nItem
);
6120 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6121 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6123 rect
.left
= LVIR_LABEL
;
6124 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6126 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6127 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6128 dispInfo
.item
.iItem
= nItem
;
6129 dispInfo
.item
.iSubItem
= 0;
6130 dispInfo
.item
.stateMask
= ~0;
6131 dispInfo
.item
.pszText
= disptextW
;
6132 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6133 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6135 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6136 if (!infoPtr
->hwndEdit
) return 0;
6138 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6140 if (!IsWindow(hwndSelf
))
6142 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6143 infoPtr
->hwndEdit
= 0;
6147 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6149 /* position and display edit box */
6150 hdc
= GetDC(infoPtr
->hwndSelf
);
6152 /* select the font to get appropriate metric dimensions */
6154 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6156 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6157 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6158 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6160 /* get string length in pixels */
6161 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6163 /* add extra spacing for the next character */
6164 GetTextMetricsW(hdc
, &tm
);
6165 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6168 SelectObject(hdc
, hOldFont
);
6170 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6172 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6175 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6176 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6177 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6178 SetFocus(infoPtr
->hwndEdit
);
6179 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6180 return infoPtr
->hwndEdit
;
6186 * Ensures the specified item is visible, scrolling into view if necessary.
6189 * [I] infoPtr : valid pointer to the listview structure
6190 * [I] nItem : item index
6191 * [I] bPartial : partially or entirely visible
6197 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6199 INT nScrollPosHeight
= 0;
6200 INT nScrollPosWidth
= 0;
6201 INT nHorzAdjust
= 0;
6202 INT nVertAdjust
= 0;
6205 RECT rcItem
, rcTemp
;
6207 rcItem
.left
= LVIR_BOUNDS
;
6208 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6210 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6212 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6214 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6215 if (infoPtr
->uView
== LV_VIEW_LIST
)
6216 nScrollPosWidth
= infoPtr
->nItemWidth
;
6217 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6218 nScrollPosWidth
= 1;
6220 if (rcItem
.left
< infoPtr
->rcList
.left
)
6223 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6228 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6232 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6234 /* scroll up/down, but not in LVS_LIST mode */
6235 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6236 nScrollPosHeight
= infoPtr
->nItemHeight
;
6237 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6238 nScrollPosHeight
= 1;
6240 if (rcItem
.top
< infoPtr
->rcList
.top
)
6243 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6248 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6252 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6254 if (nScrollPosWidth
)
6256 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6257 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6258 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6261 if (nScrollPosHeight
)
6263 INT diff
= nVertDiff
/ nScrollPosHeight
;
6264 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6265 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6273 * Searches for an item with specific characteristics.
6276 * [I] hwnd : window handle
6277 * [I] nStart : base item index
6278 * [I] lpFindInfo : item information to look for
6281 * SUCCESS : index of item
6284 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6285 const LVFINDINFOW
*lpFindInfo
)
6287 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6288 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6289 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6290 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6291 POINT Position
, Destination
;
6294 /* Search in virtual listviews should be done by application, not by
6295 listview control, so we just send LVN_ODFINDITEMW and return the result */
6296 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6300 nmlv
.iStart
= nStart
;
6301 nmlv
.lvfi
= *lpFindInfo
;
6302 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6305 if (!lpFindInfo
|| nItem
< 0) return -1;
6308 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6309 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6311 lvItem
.mask
|= LVIF_TEXT
;
6312 lvItem
.pszText
= szDispText
;
6313 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6316 if (lpFindInfo
->flags
& LVFI_WRAP
)
6319 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6320 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6325 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6326 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6327 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6328 switch(lpFindInfo
->vkDirection
)
6330 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6331 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6332 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6333 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6334 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6335 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6336 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6338 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6339 Destination
.x
= rcArea
.right
;
6340 Destination
.y
= rcArea
.bottom
;
6342 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6346 else Destination
.x
= Destination
.y
= 0;
6348 /* if LVFI_PARAM is specified, all other flags are ignored */
6349 if (lpFindInfo
->flags
& LVFI_PARAM
)
6351 lvItem
.mask
|= LVIF_PARAM
;
6353 lvItem
.mask
&= ~LVIF_TEXT
;
6357 for (; nItem
< nLast
; nItem
++)
6359 lvItem
.iItem
= nItem
;
6360 lvItem
.iSubItem
= 0;
6361 lvItem
.pszText
= szDispText
;
6362 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6364 if (lvItem
.mask
& LVIF_PARAM
)
6366 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6372 if (lvItem
.mask
& LVIF_TEXT
)
6374 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6376 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6377 if (!p
|| p
!= lvItem
.pszText
) continue;
6381 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6385 if (!bNearest
) return nItem
;
6387 /* This is very inefficient. To do a good job here,
6388 * we need a sorted array of (x,y) item positions */
6389 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6391 /* compute the distance^2 to the destination */
6392 xdist
= Destination
.x
- Position
.x
;
6393 ydist
= Destination
.y
- Position
.y
;
6394 dist
= xdist
* xdist
+ ydist
* ydist
;
6396 /* remember the distance, and item if it's closer */
6400 nNearestItem
= nItem
;
6407 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6412 return nNearestItem
;
6417 * Searches for an item with specific characteristics.
6420 * [I] hwnd : window handle
6421 * [I] nStart : base item index
6422 * [I] lpFindInfo : item information to look for
6425 * SUCCESS : index of item
6428 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6429 const LVFINDINFOA
*lpFindInfo
)
6431 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6432 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6437 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6438 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6439 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6440 textfreeT(strW
, FALSE
);
6446 * Retrieves column attributes.
6449 * [I] infoPtr : valid pointer to the listview structure
6450 * [I] nColumn : column index
6451 * [IO] lpColumn : column information
6452 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6453 * otherwise it is in fact a LPLVCOLUMNA
6459 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6461 COLUMN_INFO
*lpColumnInfo
;
6464 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6465 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6467 /* initialize memory */
6468 ZeroMemory(&hdi
, sizeof(hdi
));
6470 if (lpColumn
->mask
& LVCF_TEXT
)
6472 hdi
.mask
|= HDI_TEXT
;
6473 hdi
.pszText
= lpColumn
->pszText
;
6474 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6477 if (lpColumn
->mask
& LVCF_IMAGE
)
6478 hdi
.mask
|= HDI_IMAGE
;
6480 if (lpColumn
->mask
& LVCF_ORDER
)
6481 hdi
.mask
|= HDI_ORDER
;
6483 if (lpColumn
->mask
& LVCF_SUBITEM
)
6484 hdi
.mask
|= HDI_LPARAM
;
6486 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6488 if (lpColumn
->mask
& LVCF_FMT
)
6489 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6491 if (lpColumn
->mask
& LVCF_WIDTH
)
6492 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6494 if (lpColumn
->mask
& LVCF_IMAGE
)
6495 lpColumn
->iImage
= hdi
.iImage
;
6497 if (lpColumn
->mask
& LVCF_ORDER
)
6498 lpColumn
->iOrder
= hdi
.iOrder
;
6500 if (lpColumn
->mask
& LVCF_SUBITEM
)
6501 lpColumn
->iSubItem
= hdi
.lParam
;
6503 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6504 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6509 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6511 if (!infoPtr
->hwndHeader
) return FALSE
;
6512 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6517 * Retrieves the column width.
6520 * [I] infoPtr : valid pointer to the listview structure
6521 * [I] int : column index
6524 * SUCCESS : column width
6527 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6529 INT nColumnWidth
= 0;
6532 TRACE("nColumn=%d\n", nColumn
);
6534 /* we have a 'column' in LIST and REPORT mode only */
6535 switch(infoPtr
->uView
)
6538 nColumnWidth
= infoPtr
->nItemWidth
;
6540 case LV_VIEW_DETAILS
:
6541 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6542 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6543 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6545 hdItem
.mask
= HDI_WIDTH
;
6546 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6548 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6551 nColumnWidth
= hdItem
.cxy
;
6555 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6556 return nColumnWidth
;
6561 * In list or report display mode, retrieves the number of items that can fit
6562 * vertically in the visible area. In icon or small icon display mode,
6563 * retrieves the total number of visible items.
6566 * [I] infoPtr : valid pointer to the listview structure
6569 * Number of fully visible items.
6571 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6573 switch (infoPtr
->uView
)
6576 case LV_VIEW_SMALLICON
:
6577 return infoPtr
->nItemCount
;
6578 case LV_VIEW_DETAILS
:
6579 return LISTVIEW_GetCountPerColumn(infoPtr
);
6581 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6589 * Retrieves an image list handle.
6592 * [I] infoPtr : valid pointer to the listview structure
6593 * [I] nImageList : image list identifier
6596 * SUCCESS : image list handle
6599 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6603 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6604 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6605 case LVSIL_STATE
: return infoPtr
->himlState
;
6606 case LVSIL_GROUPHEADER
:
6607 FIXME("LVSIL_GROUPHEADER not supported\n");
6610 WARN("got unknown imagelist index - %d\n", nImageList
);
6615 /* LISTVIEW_GetISearchString */
6619 * Retrieves item attributes.
6622 * [I] hwnd : window handle
6623 * [IO] lpLVItem : item info
6624 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6625 * if FALSE, then lpLVItem is a LPLVITEMA.
6628 * This is the internal 'GetItem' interface -- it tries to
6629 * be smart and avoid text copies, if possible, by modifying
6630 * lpLVItem->pszText to point to the text string. Please note
6631 * that this is not always possible (e.g. OWNERDATA), so on
6632 * entry you *must* supply valid values for pszText, and cchTextMax.
6633 * The only difference to the documented interface is that upon
6634 * return, you should use *only* the lpLVItem->pszText, rather than
6635 * the buffer pointer you provided on input. Most code already does
6636 * that, so it's not a problem.
6637 * For the two cases when the text must be copied (that is,
6638 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6644 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6646 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6647 NMLVDISPINFOW dispInfo
;
6653 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6655 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6658 if (lpLVItem
->mask
== 0) return TRUE
;
6659 TRACE("mask=%x\n", lpLVItem
->mask
);
6661 /* make a local copy */
6662 isubitem
= lpLVItem
->iSubItem
;
6664 /* a quick optimization if all we're asked is the focus state
6665 * these queries are worth optimising since they are common,
6666 * and can be answered in constant time, without the heavy accesses */
6667 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6668 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6670 lpLVItem
->state
= 0;
6671 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6672 lpLVItem
->state
|= LVIS_FOCUSED
;
6676 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6678 /* if the app stores all the data, handle it separately */
6679 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6681 dispInfo
.item
.state
= 0;
6683 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6684 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6685 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6687 UINT mask
= lpLVItem
->mask
;
6689 /* NOTE: copy only fields which we _know_ are initialized, some apps
6690 * depend on the uninitialized fields being 0 */
6691 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6692 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6693 dispInfo
.item
.iSubItem
= isubitem
;
6694 if (lpLVItem
->mask
& LVIF_TEXT
)
6696 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6698 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6701 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6702 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6705 if (lpLVItem
->mask
& LVIF_STATE
)
6706 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6707 /* could be zeroed on LVIF_NORECOMPUTE case */
6708 if (dispInfo
.item
.mask
)
6710 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6711 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6712 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6714 /* full size structure expected - _WIN32IE >= 0x560 */
6715 *lpLVItem
= dispInfo
.item
;
6717 else if (lpLVItem
->mask
& LVIF_INDENT
)
6719 /* indent member expected - _WIN32IE >= 0x300 */
6720 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6724 /* minimal structure expected */
6725 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6727 lpLVItem
->mask
= mask
;
6728 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6732 /* make sure lParam is zeroed out */
6733 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6735 /* callback marked pointer required here */
6736 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6737 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6739 /* we store only a little state, so if we're not asked, we're done */
6740 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6742 /* if focus is handled by us, report it */
6743 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6745 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6746 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6747 lpLVItem
->state
|= LVIS_FOCUSED
;
6750 /* and do the same for selection, if we handle it */
6751 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6753 lpLVItem
->state
&= ~LVIS_SELECTED
;
6754 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6755 lpLVItem
->state
|= LVIS_SELECTED
;
6761 /* find the item and subitem structures before we proceed */
6762 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6763 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6768 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6769 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6772 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6777 pItemHdr
= &lpItem
->hdr
;
6779 /* Do we need to query the state from the app? */
6780 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6782 dispInfo
.item
.mask
|= LVIF_STATE
;
6783 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6786 /* Do we need to enquire about the image? */
6787 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6788 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6790 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6791 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6794 /* Only items support indentation */
6795 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6798 dispInfo
.item
.mask
|= LVIF_INDENT
;
6799 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6802 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6803 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6804 !is_text(pItemHdr
->pszText
))
6806 dispInfo
.item
.mask
|= LVIF_TEXT
;
6807 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6808 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6809 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6810 *dispInfo
.item
.pszText
= '\0';
6813 /* If we don't have all the requested info, query the application */
6814 if (dispInfo
.item
.mask
)
6816 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6817 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6818 dispInfo
.item
.lParam
= lpItem
->lParam
;
6819 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6820 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6823 /* we should not store values for subitems */
6824 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6826 /* Now, handle the iImage field */
6827 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6829 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6830 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6831 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6833 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6835 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6836 lpLVItem
->iImage
= pItemHdr
->iImage
;
6838 lpLVItem
->iImage
= 0;
6841 /* The pszText field */
6842 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6844 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6845 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6847 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6849 else if (lpLVItem
->mask
& LVIF_TEXT
)
6851 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6852 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6853 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6856 /* Next is the lParam field */
6857 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6859 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6860 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6861 lpItem
->lParam
= dispInfo
.item
.lParam
;
6863 else if (lpLVItem
->mask
& LVIF_PARAM
)
6864 lpLVItem
->lParam
= lpItem
->lParam
;
6866 /* if this is a subitem, we're done */
6867 if (isubitem
) return TRUE
;
6869 /* ... the state field (this one is different due to uCallbackmask) */
6870 if (lpLVItem
->mask
& LVIF_STATE
)
6872 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6873 if (dispInfo
.item
.mask
& LVIF_STATE
)
6875 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6876 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6878 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6880 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6881 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6882 lpLVItem
->state
|= LVIS_FOCUSED
;
6884 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6886 lpLVItem
->state
&= ~LVIS_SELECTED
;
6887 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6888 lpLVItem
->state
|= LVIS_SELECTED
;
6892 /* and last, but not least, the indent field */
6893 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6895 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6896 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6897 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6899 else if (lpLVItem
->mask
& LVIF_INDENT
)
6901 lpLVItem
->iIndent
= lpItem
->iIndent
;
6909 * Retrieves item attributes.
6912 * [I] hwnd : window handle
6913 * [IO] lpLVItem : item info
6914 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6915 * if FALSE, then lpLVItem is a LPLVITEMA.
6918 * This is the external 'GetItem' interface -- it properly copies
6919 * the text in the provided buffer.
6925 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6930 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6933 pszText
= lpLVItem
->pszText
;
6934 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6935 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6937 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6938 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6940 pszText
= LPSTR_TEXTCALLBACKW
;
6942 lpLVItem
->pszText
= pszText
;
6950 * Retrieves the position (upper-left) of the listview control item.
6951 * Note that for LVS_ICON style, the upper-left is that of the icon
6952 * and not the bounding box.
6955 * [I] infoPtr : valid pointer to the listview structure
6956 * [I] nItem : item index
6957 * [O] lpptPosition : coordinate information
6963 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6967 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6969 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6971 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6972 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6974 if (infoPtr
->uView
== LV_VIEW_ICON
)
6976 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6977 lpptPosition
->y
+= ICON_TOP_PADDING
;
6979 lpptPosition
->x
+= Origin
.x
;
6980 lpptPosition
->y
+= Origin
.y
;
6982 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6989 * Retrieves the bounding rectangle for a listview control item.
6992 * [I] infoPtr : valid pointer to the listview structure
6993 * [I] nItem : item index
6994 * [IO] lprc : bounding rectangle coordinates
6995 * lprc->left specifies the portion of the item for which the bounding
6996 * rectangle will be retrieved.
6998 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6999 * including the icon and label.
7002 * * Experiment shows that native control returns:
7003 * * width = min (48, length of text line)
7004 * * .left = position.x - (width - iconsize.cx)/2
7005 * * .right = .left + width
7006 * * height = #lines of text * ntmHeight + icon height + 8
7007 * * .top = position.y - 2
7008 * * .bottom = .top + height
7009 * * separation between items .y = itemSpacing.cy - height
7010 * * .x = itemSpacing.cx - width
7011 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7014 * * Experiment shows that native control returns:
7015 * * width = iconSize.cx + 16
7016 * * .left = position.x - (width - iconsize.cx)/2
7017 * * .right = .left + width
7018 * * height = iconSize.cy + 4
7019 * * .top = position.y - 2
7020 * * .bottom = .top + height
7021 * * separation between items .y = itemSpacing.cy - height
7022 * * .x = itemSpacing.cx - width
7023 * LVIR_LABEL Returns the bounding rectangle of the item text.
7026 * * Experiment shows that native control returns:
7027 * * width = text length
7028 * * .left = position.x - width/2
7029 * * .right = .left + width
7030 * * height = ntmH * linecount + 2
7031 * * .top = position.y + iconSize.cy + 6
7032 * * .bottom = .top + height
7033 * * separation between items .y = itemSpacing.cy - height
7034 * * .x = itemSpacing.cx - width
7035 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7036 * rectangles, but excludes columns in report view.
7043 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7044 * upon whether the window has the focus currently and on whether the item
7045 * is the one with the focus. Ensure that the control's record of which
7046 * item has the focus agrees with the items' records.
7048 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7050 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7051 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7052 POINT Position
, Origin
;
7056 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7058 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7060 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7061 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7063 /* Be smart and try to figure out the minimum we have to do */
7064 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7065 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7066 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7067 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7068 oversizedBox
= TRUE
;
7070 /* get what we need from the item before hand, so we make
7071 * only one request. This can speed up things, if data
7072 * is stored on the app side */
7074 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7075 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7076 lvItem
.iItem
= nItem
;
7077 lvItem
.iSubItem
= 0;
7078 lvItem
.pszText
= szDispText
;
7079 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7080 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7081 /* we got the state already up, simulate it here, to avoid a reget */
7082 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7084 lvItem
.mask
|= LVIF_STATE
;
7085 lvItem
.stateMask
= LVIS_FOCUSED
;
7086 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7089 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7090 lprc
->left
= LVIR_BOUNDS
;
7096 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7100 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7104 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7107 case LVIR_SELECTBOUNDS
:
7108 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7112 WARN("Unknown value: %d\n", lprc
->left
);
7116 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7118 if (mode
!= LVIR_BOUNDS
)
7119 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7120 Position
.y
+ Origin
.y
);
7122 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7125 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7127 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7134 * Retrieves the spacing between listview control items.
7137 * [I] infoPtr : valid pointer to the listview structure
7138 * [IO] lprc : rectangle to receive the output
7139 * on input, lprc->top = nSubItem
7140 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7142 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7143 * not only those of the first column.
7149 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7151 RECT rect
= { 0, 0, 0, 0 };
7155 if (!lprc
) return FALSE
;
7157 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7158 /* Subitem of '0' means item itself, and this works for all control view modes */
7160 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7162 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7164 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7165 /* this works for any item index, no matter if it exists or not */
7166 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7168 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7171 rect
.bottom
= infoPtr
->nItemHeight
;
7175 /* Native implementation is broken for this case and garbage is left for left and right fields,
7176 we zero them to get predictable output */
7177 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7178 lprc
->bottom
= infoPtr
->nItemHeight
;
7179 OffsetRect(lprc
, origin
.x
, y
);
7180 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7188 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7189 if (infoPtr
->himlSmall
)
7190 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7192 rect
.right
= rect
.left
;
7194 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7202 ERR("Unknown bounds=%d\n", lprc
->left
);
7206 OffsetRect(&rect
, origin
.x
, y
);
7208 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7215 * Retrieves the spacing between listview control items.
7218 * [I] infoPtr : valid pointer to the listview structure
7219 * [I] bSmall : flag for small or large icon
7222 * Horizontal + vertical spacing
7224 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7230 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7234 if (infoPtr
->uView
== LV_VIEW_ICON
)
7235 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7237 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7244 * Retrieves the state of a listview control item.
7247 * [I] infoPtr : valid pointer to the listview structure
7248 * [I] nItem : item index
7249 * [I] uMask : state mask
7252 * State specified by the mask.
7254 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7258 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7260 lvItem
.iItem
= nItem
;
7261 lvItem
.iSubItem
= 0;
7262 lvItem
.mask
= LVIF_STATE
;
7263 lvItem
.stateMask
= uMask
;
7264 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7266 return lvItem
.state
& uMask
;
7271 * Retrieves the text of a listview control item or subitem.
7274 * [I] hwnd : window handle
7275 * [I] nItem : item index
7276 * [IO] lpLVItem : item information
7277 * [I] isW : TRUE if lpLVItem is Unicode
7280 * SUCCESS : string length
7283 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7285 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7287 lpLVItem
->mask
= LVIF_TEXT
;
7288 lpLVItem
->iItem
= nItem
;
7289 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7291 return textlenT(lpLVItem
->pszText
, isW
);
7296 * Searches for an item based on properties + relationships.
7299 * [I] infoPtr : valid pointer to the listview structure
7300 * [I] nItem : item index
7301 * [I] uFlags : relationship flag
7304 * SUCCESS : item index
7307 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7310 LVFINDINFOW lvFindInfo
;
7311 INT nCountPerColumn
;
7315 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7316 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7318 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7320 if (uFlags
& LVNI_CUT
)
7323 if (uFlags
& LVNI_DROPHILITED
)
7324 uMask
|= LVIS_DROPHILITED
;
7326 if (uFlags
& LVNI_FOCUSED
)
7327 uMask
|= LVIS_FOCUSED
;
7329 if (uFlags
& LVNI_SELECTED
)
7330 uMask
|= LVIS_SELECTED
;
7332 /* if we're asked for the focused item, that's only one,
7333 * so it's worth optimizing */
7334 if (uFlags
& LVNI_FOCUSED
)
7336 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7337 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7340 if (uFlags
& LVNI_ABOVE
)
7342 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7347 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7353 /* Special case for autoarrange - move 'til the top of a list */
7354 if (is_autoarrange(infoPtr
))
7356 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7357 while (nItem
- nCountPerRow
>= 0)
7359 nItem
-= nCountPerRow
;
7360 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7365 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7366 lvFindInfo
.vkDirection
= VK_UP
;
7367 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7368 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7370 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7375 else if (uFlags
& LVNI_BELOW
)
7377 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7379 while (nItem
< infoPtr
->nItemCount
)
7382 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7388 /* Special case for autoarrange - move 'til the bottom of a list */
7389 if (is_autoarrange(infoPtr
))
7391 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7392 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7394 nItem
+= nCountPerRow
;
7395 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7400 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7401 lvFindInfo
.vkDirection
= VK_DOWN
;
7402 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7403 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7405 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7410 else if (uFlags
& LVNI_TOLEFT
)
7412 if (infoPtr
->uView
== LV_VIEW_LIST
)
7414 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7415 while (nItem
- nCountPerColumn
>= 0)
7417 nItem
-= nCountPerColumn
;
7418 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7422 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7424 /* Special case for autoarrange - move 'til the beginning of a row */
7425 if (is_autoarrange(infoPtr
))
7427 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7428 while (nItem
% nCountPerRow
> 0)
7431 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7436 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7437 lvFindInfo
.vkDirection
= VK_LEFT
;
7438 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7439 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7441 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7446 else if (uFlags
& LVNI_TORIGHT
)
7448 if (infoPtr
->uView
== LV_VIEW_LIST
)
7450 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7451 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7453 nItem
+= nCountPerColumn
;
7454 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7458 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7460 /* Special case for autoarrange - move 'til the end of a row */
7461 if (is_autoarrange(infoPtr
))
7463 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7464 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7467 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7472 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7473 lvFindInfo
.vkDirection
= VK_RIGHT
;
7474 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7475 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7477 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7486 /* search by index */
7487 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7489 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7497 /* LISTVIEW_GetNumberOfWorkAreas */
7501 * Retrieves the origin coordinates when in icon or small icon display mode.
7504 * [I] infoPtr : valid pointer to the listview structure
7505 * [O] lpptOrigin : coordinate information
7510 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7512 INT nHorzPos
= 0, nVertPos
= 0;
7513 SCROLLINFO scrollInfo
;
7515 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7516 scrollInfo
.fMask
= SIF_POS
;
7518 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7519 nHorzPos
= scrollInfo
.nPos
;
7520 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7521 nVertPos
= scrollInfo
.nPos
;
7523 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7525 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7526 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7527 if (infoPtr
->uView
== LV_VIEW_LIST
)
7528 nHorzPos
*= infoPtr
->nItemWidth
;
7529 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7530 nVertPos
*= infoPtr
->nItemHeight
;
7532 lpptOrigin
->x
-= nHorzPos
;
7533 lpptOrigin
->y
-= nVertPos
;
7535 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7540 * Retrieves the width of a string.
7543 * [I] hwnd : window handle
7544 * [I] lpszText : text string to process
7545 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7548 * SUCCESS : string width (in pixels)
7551 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7556 if (is_text(lpszText
))
7558 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7559 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7560 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7563 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7565 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7566 SelectObject(hdc
, hOldFont
);
7567 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7569 return stringSize
.cx
;
7574 * Determines which listview item is located at the specified position.
7577 * [I] infoPtr : valid pointer to the listview structure
7578 * [IO] lpht : hit test information
7579 * [I] subitem : fill out iSubItem.
7580 * [I] select : return the index only if the hit selects the item
7583 * (mm 20001022): We must not allow iSubItem to be touched, for
7584 * an app might pass only a structure with space up to iItem!
7585 * (MS Office 97 does that for instance in the file open dialog)
7588 * SUCCESS : item index
7591 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7593 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7594 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7595 POINT Origin
, Position
, opt
;
7601 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7605 if (subitem
) lpht
->iSubItem
= 0;
7607 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7609 /* set whole list relation flags */
7610 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7612 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7613 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7614 lpht
->flags
|= LVHT_TOLEFT
;
7616 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7617 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7621 if (infoPtr
->rcList
.bottom
< opt
.y
)
7622 lpht
->flags
|= LVHT_BELOW
;
7626 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7627 lpht
->flags
|= LVHT_TOLEFT
;
7628 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7629 lpht
->flags
|= LVHT_TORIGHT
;
7631 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7632 lpht
->flags
|= LVHT_ABOVE
;
7633 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7634 lpht
->flags
|= LVHT_BELOW
;
7637 /* even if item is invalid try to find subitem */
7638 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7643 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7645 lpht
->iSubItem
= -1;
7646 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7648 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7650 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7656 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7658 /* if we're outside horizontal columns bounds there's nothing to test further */
7659 if (lpht
->iSubItem
== -1)
7662 lpht
->flags
= LVHT_NOWHERE
;
7667 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7668 if (lpht
->flags
) return -1;
7670 lpht
->flags
|= LVHT_NOWHERE
;
7672 /* first deal with the large items */
7673 rcSearch
.left
= lpht
->pt
.x
;
7674 rcSearch
.top
= lpht
->pt
.y
;
7675 rcSearch
.right
= rcSearch
.left
+ 1;
7676 rcSearch
.bottom
= rcSearch
.top
+ 1;
7678 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7679 iterator_next(&i
); /* go to first item in the sequence */
7681 iterator_destroy(&i
);
7683 TRACE("lpht->iItem=%d\n", iItem
);
7684 if (iItem
== -1) return -1;
7686 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7687 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7688 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7689 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7690 lvItem
.iItem
= iItem
;
7691 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7692 lvItem
.pszText
= szDispText
;
7693 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7694 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7695 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7697 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7698 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7699 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7701 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7702 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7704 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7706 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7709 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7710 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7714 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7715 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7717 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7718 if (!PtInRect(&rcBounds
, opt
)) return -1;
7720 /* That's a special case - row rectangle is used as item rectangle and
7721 returned flags contain all item parts. */
7722 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7724 if (PtInRect(&rcIcon
, opt
))
7725 lpht
->flags
|= LVHT_ONITEMICON
;
7726 else if (PtInRect(&rcLabel
, opt
))
7727 lpht
->flags
|= LVHT_ONITEMLABEL
;
7728 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7729 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7730 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7732 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7734 if (lpht
->flags
& LVHT_ONITEM
)
7735 lpht
->flags
&= ~LVHT_NOWHERE
;
7736 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7738 if (select
&& !is_fullrow
)
7740 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7742 /* get main item bounds */
7743 lvItem
.iSubItem
= 0;
7744 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7745 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7746 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7748 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7750 return lpht
->iItem
= iItem
;
7755 * Inserts a new item in the listview control.
7758 * [I] infoPtr : valid pointer to the listview structure
7759 * [I] lpLVItem : item information
7760 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7763 * SUCCESS : new item index
7766 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7773 BOOL is_sorted
, has_changed
;
7775 HWND hwndSelf
= infoPtr
->hwndSelf
;
7777 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7779 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7781 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7782 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7784 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7786 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7788 /* insert item in listview control data structure */
7789 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7790 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7792 /* link with id struct */
7793 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7795 lpID
->item
= hdpaSubItems
;
7796 lpID
->id
= get_next_itemid(infoPtr
);
7797 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7799 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7800 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7802 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7804 /* calculate new item index */
7811 while (i
< infoPtr
->nItemCount
)
7813 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7814 item_s
= DPA_GetPtr(hItem
, 0);
7816 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7817 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7819 if (cmpv
>= 0) break;
7825 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7827 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7828 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7829 if (nItem
== -1) goto fail
;
7830 infoPtr
->nItemCount
++;
7832 /* shift indices first so they don't get tangled */
7833 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7835 /* set the item attributes */
7836 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7838 /* full size structure expected - _WIN32IE >= 0x560 */
7841 else if (lpLVItem
->mask
& LVIF_INDENT
)
7843 /* indent member expected - _WIN32IE >= 0x300 */
7844 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7848 /* minimal structure expected */
7849 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7852 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7854 if (item
.mask
& LVIF_STATE
)
7856 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7857 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7858 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7862 item
.mask
|= LVIF_STATE
;
7863 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7864 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7868 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7870 /* make room for the position, if we are in the right mode */
7871 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7873 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7875 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7877 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7882 /* send LVN_INSERTITEM notification */
7883 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7885 nmlv
.lParam
= lpItem
->lParam
;
7886 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7887 if (!IsWindow(hwndSelf
))
7890 /* align items (set position of each item) */
7891 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7895 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7896 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7898 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7900 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7903 /* now is the invalidation fun */
7904 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7908 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7909 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7910 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7911 infoPtr
->nItemCount
--;
7913 DPA_DeletePtr(hdpaSubItems
, 0);
7914 DPA_Destroy (hdpaSubItems
);
7921 * Checks item visibility.
7924 * [I] infoPtr : valid pointer to the listview structure
7925 * [I] nFirst : item index to check for
7928 * Item visible : TRUE
7929 * Item invisible or failure : FALSE
7931 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7933 POINT Origin
, Position
;
7938 TRACE("nItem=%d\n", nItem
);
7940 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7942 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7943 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7944 rcItem
.left
= Position
.x
+ Origin
.x
;
7945 rcItem
.top
= Position
.y
+ Origin
.y
;
7946 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7947 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7949 hdc
= GetDC(infoPtr
->hwndSelf
);
7950 if (!hdc
) return FALSE
;
7951 ret
= RectVisible(hdc
, &rcItem
);
7952 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7959 * Redraws a range of items.
7962 * [I] infoPtr : valid pointer to the listview structure
7963 * [I] nFirst : first item
7964 * [I] nLast : last item
7970 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7974 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7975 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7978 for (i
= nFirst
; i
<= nLast
; i
++)
7979 LISTVIEW_InvalidateItem(infoPtr
, i
);
7986 * Scroll the content of a listview.
7989 * [I] infoPtr : valid pointer to the listview structure
7990 * [I] dx : horizontal scroll amount in pixels
7991 * [I] dy : vertical scroll amount in pixels
7998 * If the control is in report view (LV_VIEW_DETAILS) the control can
7999 * be scrolled only in line increments. "dy" will be rounded to the
8000 * nearest number of pixels that are a whole line. Ex: if line height
8001 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
8002 * is passed, then the scroll will be 0. (per MSDN 7/2002)
8004 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8006 switch(infoPtr
->uView
) {
8007 case LV_VIEW_DETAILS
:
8008 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
8009 dy
/= infoPtr
->nItemHeight
;
8012 if (dy
!= 0) return FALSE
;
8018 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8019 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8026 * Sets the background color.
8029 * [I] infoPtr : valid pointer to the listview structure
8030 * [I] color : background color
8036 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8038 TRACE("(color=%x)\n", color
);
8040 if(infoPtr
->clrBk
!= color
) {
8041 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8042 infoPtr
->clrBk
= color
;
8043 if (color
== CLR_NONE
)
8044 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8047 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8048 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8055 /* LISTVIEW_SetBkImage */
8057 /*** Helper for {Insert,Set}ColumnT *only* */
8058 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8059 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8061 if (lpColumn
->mask
& LVCF_FMT
)
8063 /* format member is valid */
8064 lphdi
->mask
|= HDI_FORMAT
;
8066 /* set text alignment (leftmost column must be left-aligned) */
8067 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8068 lphdi
->fmt
|= HDF_LEFT
;
8069 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8070 lphdi
->fmt
|= HDF_RIGHT
;
8071 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8072 lphdi
->fmt
|= HDF_CENTER
;
8074 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8075 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8077 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8079 lphdi
->fmt
|= HDF_IMAGE
;
8080 lphdi
->iImage
= I_IMAGECALLBACK
;
8083 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8084 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8087 if (lpColumn
->mask
& LVCF_WIDTH
)
8089 lphdi
->mask
|= HDI_WIDTH
;
8090 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8092 /* make it fill the remainder of the controls width */
8096 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8098 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8099 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8102 /* retrieve the layout of the header */
8103 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8104 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8106 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8109 lphdi
->cxy
= lpColumn
->cx
;
8112 if (lpColumn
->mask
& LVCF_TEXT
)
8114 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8115 lphdi
->fmt
|= HDF_STRING
;
8116 lphdi
->pszText
= lpColumn
->pszText
;
8117 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8120 if (lpColumn
->mask
& LVCF_IMAGE
)
8122 lphdi
->mask
|= HDI_IMAGE
;
8123 lphdi
->iImage
= lpColumn
->iImage
;
8126 if (lpColumn
->mask
& LVCF_ORDER
)
8128 lphdi
->mask
|= HDI_ORDER
;
8129 lphdi
->iOrder
= lpColumn
->iOrder
;
8136 * Inserts a new column.
8139 * [I] infoPtr : valid pointer to the listview structure
8140 * [I] nColumn : column index
8141 * [I] lpColumn : column information
8142 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8145 * SUCCESS : new column index
8148 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8149 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8151 COLUMN_INFO
*lpColumnInfo
;
8155 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8157 if (!lpColumn
|| nColumn
< 0) return -1;
8158 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8160 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8161 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8164 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8165 * (can be seen in SPY) otherwise column never gets added.
8167 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8168 hdi
.mask
|= HDI_WIDTH
;
8173 * when the iSubItem is available Windows copies it to the header lParam. It seems
8174 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8176 if (lpColumn
->mask
& LVCF_SUBITEM
)
8178 hdi
.mask
|= HDI_LPARAM
;
8179 hdi
.lParam
= lpColumn
->iSubItem
;
8182 /* create header if not present */
8183 LISTVIEW_CreateHeader(infoPtr
);
8184 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8185 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8187 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8190 /* insert item in header control */
8191 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8192 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8193 nColumn
, (LPARAM
)&hdi
);
8194 if (nNewColumn
== -1) return -1;
8195 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8197 /* create our own column info */
8198 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8199 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8201 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8202 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8203 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8206 /* now we have to actually adjust the data */
8207 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8209 SUBITEM_INFO
*lpSubItem
;
8215 item
.iSubItem
= nNewColumn
;
8216 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8217 item
.iImage
= I_IMAGECALLBACK
;
8218 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8220 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8222 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8223 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8225 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8226 if (lpSubItem
->iSubItem
>= nNewColumn
)
8227 lpSubItem
->iSubItem
++;
8230 /* add new subitem for each item */
8232 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8236 /* make space for the new column */
8237 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8238 LISTVIEW_UpdateItemSize(infoPtr
);
8243 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8246 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8254 * Sets the attributes of a header item.
8257 * [I] infoPtr : valid pointer to the listview structure
8258 * [I] nColumn : column index
8259 * [I] lpColumn : column attributes
8260 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8266 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8267 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8269 HDITEMW hdi
, hdiget
;
8272 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8274 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8276 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8277 if (lpColumn
->mask
& LVCF_FMT
)
8279 hdi
.mask
|= HDI_FORMAT
;
8280 hdiget
.mask
= HDI_FORMAT
;
8281 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8282 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8284 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8286 /* set header item attributes */
8287 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8288 if (!bResult
) return FALSE
;
8290 if (lpColumn
->mask
& LVCF_FMT
)
8292 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8293 INT oldFmt
= lpColumnInfo
->fmt
;
8295 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8296 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8298 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8302 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8303 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8310 * Sets the column order array
8313 * [I] infoPtr : valid pointer to the listview structure
8314 * [I] iCount : number of elements in column order array
8315 * [I] lpiArray : pointer to column order array
8321 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8323 if (!infoPtr
->hwndHeader
) return FALSE
;
8324 infoPtr
->colRectsDirty
= TRUE
;
8325 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8330 * Sets the width of a column
8333 * [I] infoPtr : valid pointer to the listview structure
8334 * [I] nColumn : column index
8335 * [I] cx : column width
8341 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8343 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8347 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8349 /* set column width only if in report or list mode */
8350 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8352 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8353 with _USEHEADER being the lowest */
8354 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8355 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8357 /* resize all columns if in LV_VIEW_LIST mode */
8358 if(infoPtr
->uView
== LV_VIEW_LIST
)
8360 infoPtr
->nItemWidth
= cx
;
8361 LISTVIEW_InvalidateList(infoPtr
);
8365 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8367 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8372 lvItem
.mask
= LVIF_TEXT
;
8374 lvItem
.iSubItem
= nColumn
;
8375 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8376 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8378 lvItem
.pszText
= szDispText
;
8379 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8380 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8381 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8383 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8384 max_cx
+= infoPtr
->iconSize
.cx
;
8385 max_cx
+= TRAILING_LABEL_PADDING
;
8388 /* autosize based on listview items width */
8389 if(cx
== LVSCW_AUTOSIZE
)
8391 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8393 /* if iCol is the last column make it fill the remainder of the controls width */
8394 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8399 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8400 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8402 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8406 /* Despite what the MS docs say, if this is not the last
8407 column, then MS resizes the column to the width of the
8408 largest text string in the column, including headers
8409 and items. This is different from LVSCW_AUTOSIZE in that
8410 LVSCW_AUTOSIZE ignores the header string length. */
8413 /* retrieve header text */
8414 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8415 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8416 hdi
.pszText
= szDispText
;
8417 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8419 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8420 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8421 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8422 INT bitmap_margin
= 0;
8425 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8426 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8428 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8429 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8431 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8433 INT icon_cx
, icon_cy
;
8435 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8436 cx
+= icon_cx
+ 2*bitmap_margin
;
8438 else if (hdi
.fmt
& HDF_BITMAP
)
8442 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8443 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8446 SelectObject(hdc
, old_font
);
8447 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8449 cx
= max (cx
, max_cx
);
8453 if (cx
< 0) return FALSE
;
8455 /* call header to update the column change */
8456 hdi
.mask
= HDI_WIDTH
;
8457 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8458 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8459 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8463 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8466 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8469 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8471 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8472 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8475 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8476 ILC_COLOR
| ILC_MASK
, 2, 2);
8477 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8478 hdc
= CreateCompatibleDC(hdc_wnd
);
8479 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8480 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8481 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8483 SetRect(&rc
, 0, 0, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8484 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8485 FillRect(hdc
, &rc
, hbr_white
);
8486 InflateRect(&rc
, -2, -2);
8487 FillRect(hdc
, &rc
, hbr_black
);
8489 SelectObject(hdc
, hbm_im
);
8490 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8491 SelectObject(hdc
, hbm_orig
);
8492 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8494 SelectObject(hdc
, hbm_im
);
8495 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8496 SelectObject(hdc
, hbm_orig
);
8497 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8499 DeleteObject(hbm_mask
);
8500 DeleteObject(hbm_im
);
8508 * Sets the extended listview style.
8511 * [I] infoPtr : valid pointer to the listview structure
8513 * [I] dwStyle : style
8516 * SUCCESS : previous style
8519 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8521 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8523 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8527 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8529 infoPtr
->dwLvExStyle
= ex_style
;
8531 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8533 HIMAGELIST himl
= 0;
8534 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8537 item
.mask
= LVIF_STATE
;
8538 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8539 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8540 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8542 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8543 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8544 ImageList_Destroy(infoPtr
->himlState
);
8546 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8547 /* checkbox list replaces previous custom list or... */
8548 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8549 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8550 /* ...previous was checkbox list */
8551 (old_ex_style
& LVS_EX_CHECKBOXES
))
8552 ImageList_Destroy(himl
);
8555 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8559 /* if not already created */
8560 LISTVIEW_CreateHeader(infoPtr
);
8562 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8563 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8564 style
|= HDS_DRAGDROP
;
8566 style
&= ~HDS_DRAGDROP
;
8567 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8570 /* GRIDLINES adds decoration at top so changes sizes */
8571 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8573 LISTVIEW_CreateHeader(infoPtr
);
8574 LISTVIEW_UpdateSize(infoPtr
);
8577 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8579 LISTVIEW_CreateHeader(infoPtr
);
8582 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8584 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8585 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8588 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8590 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8591 LISTVIEW_CreateHeader(infoPtr
);
8593 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8594 LISTVIEW_UpdateSize(infoPtr
);
8595 LISTVIEW_UpdateScroll(infoPtr
);
8598 LISTVIEW_InvalidateList(infoPtr
);
8599 return old_ex_style
;
8604 * Sets the new hot cursor used during hot tracking and hover selection.
8607 * [I] infoPtr : valid pointer to the listview structure
8608 * [I] hCursor : the new hot cursor handle
8611 * Returns the previous hot cursor
8613 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8615 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8617 infoPtr
->hHotCursor
= hCursor
;
8625 * Sets the hot item index.
8628 * [I] infoPtr : valid pointer to the listview structure
8629 * [I] iIndex : index
8632 * SUCCESS : previous hot item index
8633 * FAILURE : -1 (no hot item)
8635 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8637 INT iOldIndex
= infoPtr
->nHotItem
;
8639 infoPtr
->nHotItem
= iIndex
;
8647 * Sets the amount of time the cursor must hover over an item before it is selected.
8650 * [I] infoPtr : valid pointer to the listview structure
8651 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8654 * Returns the previous hover time
8656 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8658 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8660 infoPtr
->dwHoverTime
= dwHoverTime
;
8662 return oldHoverTime
;
8667 * Sets spacing for icons of LVS_ICON style.
8670 * [I] infoPtr : valid pointer to the listview structure
8671 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8672 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8675 * MAKELONG(oldcx, oldcy)
8677 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8679 INT iconWidth
= 0, iconHeight
= 0;
8680 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8682 TRACE("requested=(%d,%d)\n", cx
, cy
);
8684 /* set to defaults, if instructed to */
8685 if (cx
== -1 && cy
== -1)
8687 infoPtr
->autoSpacing
= TRUE
;
8688 if (infoPtr
->himlNormal
)
8689 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8690 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8691 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8694 infoPtr
->autoSpacing
= FALSE
;
8696 /* if 0 then keep width */
8698 infoPtr
->iconSpacing
.cx
= cx
;
8700 /* if 0 then keep height */
8702 infoPtr
->iconSpacing
.cy
= cy
;
8704 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8705 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8706 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8707 infoPtr
->ntmHeight
);
8709 /* these depend on the iconSpacing */
8710 LISTVIEW_UpdateItemSize(infoPtr
);
8715 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8719 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8726 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8727 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8736 * [I] infoPtr : valid pointer to the listview structure
8737 * [I] nType : image list type
8738 * [I] himl : image list handle
8741 * SUCCESS : old image list
8744 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8746 INT oldHeight
= infoPtr
->nItemHeight
;
8747 HIMAGELIST himlOld
= 0;
8749 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8754 himlOld
= infoPtr
->himlNormal
;
8755 infoPtr
->himlNormal
= himl
;
8756 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8757 if (infoPtr
->autoSpacing
)
8758 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8762 himlOld
= infoPtr
->himlSmall
;
8763 infoPtr
->himlSmall
= himl
;
8764 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8765 if (infoPtr
->hwndHeader
)
8766 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8770 himlOld
= infoPtr
->himlState
;
8771 infoPtr
->himlState
= himl
;
8772 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8773 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8777 ERR("Unknown icon type=%d\n", nType
);
8781 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8782 if (infoPtr
->nItemHeight
!= oldHeight
)
8783 LISTVIEW_UpdateScroll(infoPtr
);
8790 * Preallocates memory (does *not* set the actual count of items !)
8793 * [I] infoPtr : valid pointer to the listview structure
8794 * [I] nItems : item count (projected number of items to allocate)
8795 * [I] dwFlags : update flags
8801 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8803 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8805 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8807 INT nOldCount
= infoPtr
->nItemCount
;
8808 infoPtr
->nItemCount
= nItems
;
8810 if (nItems
< nOldCount
)
8812 RANGE range
= { nItems
, nOldCount
};
8813 ranges_del(infoPtr
->selectionRanges
, range
);
8814 if (infoPtr
->nFocusedItem
>= nItems
)
8816 LISTVIEW_SetItemFocus(infoPtr
, -1);
8817 SetRectEmpty(&infoPtr
->rcFocus
);
8821 LISTVIEW_UpdateScroll(infoPtr
);
8823 /* the flags are valid only in ownerdata report and list modes */
8824 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8826 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8827 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8829 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8830 LISTVIEW_InvalidateList(infoPtr
);
8837 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8838 nFrom
= min(nOldCount
, nItems
);
8839 nTo
= max(nOldCount
, nItems
);
8841 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8843 SetRect(&rcErase
, 0, nFrom
* infoPtr
->nItemHeight
, infoPtr
->nItemWidth
,
8844 nTo
* infoPtr
->nItemHeight
);
8845 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8846 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8847 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8849 else /* LV_VIEW_LIST */
8851 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8853 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8854 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8855 rcErase
.right
= rcErase
.left
+ 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
);
8861 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8863 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8864 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8865 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8866 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8867 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8873 /* According to MSDN for non-LVS_OWNERDATA this is just
8874 * a performance issue. The control allocates its internal
8875 * data structures for the number of items specified. It
8876 * cuts down on the number of memory allocations. Therefore
8877 * we will just issue a WARN here
8879 WARN("for non-ownerdata performance option not implemented.\n");
8887 * Sets the position of an item.
8890 * [I] infoPtr : valid pointer to the listview structure
8891 * [I] nItem : item index
8892 * [I] pt : coordinate
8898 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8902 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8904 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8905 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8908 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8910 /* This point value seems to be an undocumented feature.
8911 * The best guess is that it means either at the origin,
8912 * or at true beginning of the list. I will assume the origin. */
8913 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8916 if (infoPtr
->uView
== LV_VIEW_ICON
)
8918 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8919 Pt
.y
-= ICON_TOP_PADDING
;
8924 infoPtr
->bAutoarrange
= FALSE
;
8926 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8931 * Sets the state of one or many items.
8934 * [I] infoPtr : valid pointer to the listview structure
8935 * [I] nItem : item index
8936 * [I] item : item or subitem info
8942 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8947 if (!item
) return FALSE
;
8949 lvItem
.iItem
= nItem
;
8950 lvItem
.iSubItem
= 0;
8951 lvItem
.mask
= LVIF_STATE
;
8952 lvItem
.state
= item
->state
;
8953 lvItem
.stateMask
= item
->stateMask
;
8954 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8961 /* special case optimization for recurring attempt to deselect all */
8962 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8965 /* select all isn't allowed in LVS_SINGLESEL */
8966 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8969 /* focus all isn't allowed */
8970 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8972 notify
= infoPtr
->bDoChangeNotify
;
8973 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8975 infoPtr
->bDoChangeNotify
= FALSE
;
8976 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8977 oldstate
|= LVIS_SELECTED
;
8978 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
8981 /* apply to all items */
8982 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8983 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
8985 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8989 infoPtr
->bDoChangeNotify
= notify
;
8993 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
8994 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
8995 nmlv
.uChanged
= LVIF_STATE
;
8996 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
8999 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
9003 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9010 * Sets the text of an item or subitem.
9013 * [I] hwnd : window handle
9014 * [I] nItem : item index
9015 * [I] lpLVItem : item or subitem info
9016 * [I] isW : TRUE if input is Unicode
9022 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9026 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9027 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9029 lvItem
.iItem
= nItem
;
9030 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9031 lvItem
.mask
= LVIF_TEXT
;
9032 lvItem
.pszText
= lpLVItem
->pszText
;
9033 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9035 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9037 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9042 * Set item index that marks the start of a multiple selection.
9045 * [I] infoPtr : valid pointer to the listview structure
9046 * [I] nIndex : index
9049 * Index number or -1 if there is no selection mark.
9051 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9053 INT nOldIndex
= infoPtr
->nSelectionMark
;
9055 TRACE("(nIndex=%d)\n", nIndex
);
9057 infoPtr
->nSelectionMark
= nIndex
;
9064 * Sets the text background color.
9067 * [I] infoPtr : valid pointer to the listview structure
9068 * [I] color : text background color
9074 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9076 TRACE("(color=%x)\n", color
);
9078 infoPtr
->clrTextBk
= color
;
9084 * Sets the text foreground color.
9087 * [I] infoPtr : valid pointer to the listview structure
9088 * [I] color : text color
9094 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9096 TRACE("(color=%x)\n", color
);
9098 infoPtr
->clrText
= color
;
9104 * Sets new ToolTip window to ListView control.
9107 * [I] infoPtr : valid pointer to the listview structure
9108 * [I] hwndNewToolTip : handle to new ToolTip
9113 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9115 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9116 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9117 return hwndOldToolTip
;
9122 * sets the Unicode character format flag for the control
9124 * [I] infoPtr :valid pointer to the listview structure
9125 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9128 * Old Unicode Format
9130 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9132 SHORT rc
= infoPtr
->notifyFormat
;
9133 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9134 return rc
== NFR_UNICODE
;
9139 * sets the control view mode
9141 * [I] infoPtr :valid pointer to the listview structure
9142 * [I] nView :new view mode value
9148 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9152 if (infoPtr
->uView
== nView
) return 1;
9154 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9155 if (nView
== LV_VIEW_TILE
)
9157 FIXME("View LV_VIEW_TILE unimplemented\n");
9161 infoPtr
->uView
= nView
;
9163 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9164 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9166 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9167 SetRectEmpty(&infoPtr
->rcFocus
);
9169 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9170 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9175 case LV_VIEW_SMALLICON
:
9176 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9178 case LV_VIEW_DETAILS
:
9183 LISTVIEW_CreateHeader( infoPtr
);
9185 hl
.prc
= &infoPtr
->rcList
;
9187 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9188 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9189 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9196 LISTVIEW_UpdateItemSize(infoPtr
);
9197 LISTVIEW_UpdateSize(infoPtr
);
9198 LISTVIEW_UpdateScroll(infoPtr
);
9199 LISTVIEW_InvalidateList(infoPtr
);
9201 TRACE("nView=%d\n", nView
);
9206 /* LISTVIEW_SetWorkAreas */
9210 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9213 * [I] first : pointer to first ITEM_INFO to compare
9214 * [I] second : pointer to second ITEM_INFO to compare
9215 * [I] lParam : HWND of control
9218 * if first comes before second : negative
9219 * if first comes after second : positive
9220 * if first and second are equivalent : zero
9222 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9224 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9225 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9226 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9228 /* Forward the call to the client defined callback */
9229 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9234 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9237 * [I] first : pointer to first ITEM_INFO to compare
9238 * [I] second : pointer to second ITEM_INFO to compare
9239 * [I] lParam : HWND of control
9242 * if first comes before second : negative
9243 * if first comes after second : positive
9244 * if first and second are equivalent : zero
9246 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9248 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9249 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9250 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9252 /* Forward the call to the client defined callback */
9253 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9258 * Sorts the listview items.
9261 * [I] infoPtr : valid pointer to the listview structure
9262 * [I] pfnCompare : application-defined value
9263 * [I] lParamSort : pointer to comparison callback
9264 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9270 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9271 LPARAM lParamSort
, BOOL IsEx
)
9275 LPVOID selectionMarkItem
= NULL
;
9276 LPVOID focusedItem
= NULL
;
9279 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9281 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9283 if (!pfnCompare
) return FALSE
;
9284 if (!infoPtr
->hdpaItems
) return FALSE
;
9286 /* if there are 0 or 1 items, there is no need to sort */
9287 if (infoPtr
->nItemCount
< 2) return TRUE
;
9289 /* clear selection */
9290 ranges_clear(infoPtr
->selectionRanges
);
9292 /* save selection mark and focused item */
9293 if (infoPtr
->nSelectionMark
>= 0)
9294 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9295 if (infoPtr
->nFocusedItem
>= 0)
9296 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9298 infoPtr
->pfnCompare
= pfnCompare
;
9299 infoPtr
->lParamSort
= lParamSort
;
9301 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9303 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9305 /* restore selection ranges */
9306 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9308 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9309 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9311 if (lpItem
->state
& LVIS_SELECTED
)
9312 ranges_additem(infoPtr
->selectionRanges
, i
);
9314 /* restore selection mark and focused item */
9315 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9316 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9318 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9320 /* refresh the display */
9321 LISTVIEW_InvalidateList(infoPtr
);
9327 * Update theme handle after a theme change.
9330 * [I] infoPtr : valid pointer to the listview structure
9334 * FAILURE : something else
9336 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9338 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9339 CloseThemeData(theme
);
9340 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9346 * Updates an items or rearranges the listview control.
9349 * [I] infoPtr : valid pointer to the listview structure
9350 * [I] nItem : item index
9356 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9358 TRACE("(nItem=%d)\n", nItem
);
9360 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9362 /* rearrange with default alignment style */
9363 if (is_autoarrange(infoPtr
))
9364 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9366 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9373 * Draw the track line at the place defined in the infoPtr structure.
9374 * The line is drawn with a XOR pen so drawing the line for the second time
9375 * in the same place erases the line.
9378 * [I] infoPtr : valid pointer to the listview structure
9384 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9388 if (infoPtr
->xTrackLine
== -1)
9391 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9393 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9394 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9395 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9401 * Called when an edit control should be displayed. This function is called after
9402 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9405 * [I] hwnd : Handle to the listview
9406 * [I] uMsg : WM_TIMER (ignored)
9407 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9408 * [I] dwTimer : The elapsed time (ignored)
9413 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9415 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9416 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9418 KillTimer(hwnd
, idEvent
);
9419 editItem
->fEnabled
= FALSE
;
9420 /* check if the item is still selected */
9421 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9422 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9427 * Creates the listview control - the WM_NCCREATE phase.
9430 * [I] hwnd : window handle
9431 * [I] lpcs : the create parameters
9437 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9439 LISTVIEW_INFO
*infoPtr
;
9442 TRACE("(lpcs=%p)\n", lpcs
);
9444 /* initialize info pointer */
9445 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9446 if (!infoPtr
) return FALSE
;
9448 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9450 infoPtr
->hwndSelf
= hwnd
;
9451 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9452 map_style_view(infoPtr
);
9453 /* determine the type of structures to use */
9454 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9455 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9457 /* initialize color information */
9458 infoPtr
->clrBk
= CLR_NONE
;
9459 infoPtr
->clrText
= CLR_DEFAULT
;
9460 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9461 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9463 /* set default values */
9464 infoPtr
->nFocusedItem
= -1;
9465 infoPtr
->nSelectionMark
= -1;
9466 infoPtr
->nHotItem
= -1;
9467 infoPtr
->redraw
= TRUE
;
9468 infoPtr
->bNoItemMetrics
= TRUE
;
9469 infoPtr
->bDoChangeNotify
= TRUE
;
9470 infoPtr
->autoSpacing
= TRUE
;
9471 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9472 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9473 infoPtr
->nEditLabelItem
= -1;
9474 infoPtr
->nLButtonDownItem
= -1;
9475 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9476 infoPtr
->cWheelRemainder
= 0;
9477 infoPtr
->nMeasureItemHeight
= 0;
9478 infoPtr
->xTrackLine
= -1; /* no track line */
9479 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9480 infoPtr
->iVersion
= COMCTL32_VERSION
;
9481 infoPtr
->colRectsDirty
= FALSE
;
9483 /* get default font (icon title) */
9484 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9485 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9486 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9487 LISTVIEW_SaveTextMetrics(infoPtr
);
9489 /* allocate memory for the data structure */
9490 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9491 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9492 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9493 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9494 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9495 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9499 DestroyWindow(infoPtr
->hwndHeader
);
9500 ranges_destroy(infoPtr
->selectionRanges
);
9501 DPA_Destroy(infoPtr
->hdpaItems
);
9502 DPA_Destroy(infoPtr
->hdpaItemIds
);
9503 DPA_Destroy(infoPtr
->hdpaPosX
);
9504 DPA_Destroy(infoPtr
->hdpaPosY
);
9505 DPA_Destroy(infoPtr
->hdpaColumns
);
9512 * Creates the listview control - the WM_CREATE phase. Most of the data is
9513 * already set up in LISTVIEW_NCCreate
9516 * [I] hwnd : window handle
9517 * [I] lpcs : the create parameters
9523 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9525 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9527 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9529 infoPtr
->dwStyle
= lpcs
->style
;
9530 map_style_view(infoPtr
);
9532 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9533 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9534 /* on error defaulting to ANSI notifications */
9535 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9536 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9538 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9540 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9543 infoPtr
->hwndHeader
= 0;
9545 /* init item size to avoid division by 0 */
9546 LISTVIEW_UpdateItemSize (infoPtr
);
9547 LISTVIEW_UpdateSize (infoPtr
);
9549 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9551 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9553 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9555 LISTVIEW_UpdateScroll(infoPtr
);
9556 /* send WM_MEASUREITEM notification */
9557 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9560 OpenThemeData(hwnd
, themeClass
);
9562 /* initialize the icon sizes */
9563 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9564 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9570 * Destroys the listview control.
9573 * [I] infoPtr : valid pointer to the listview structure
9579 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9581 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9582 CloseThemeData(theme
);
9584 /* delete all items */
9585 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9592 * Enables the listview control.
9595 * [I] infoPtr : valid pointer to the listview structure
9596 * [I] bEnable : specifies whether to enable or disable the window
9602 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9604 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9605 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9611 * Erases the background of the listview control.
9614 * [I] infoPtr : valid pointer to the listview structure
9615 * [I] hdc : device context handle
9621 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9625 TRACE("(hdc=%p)\n", hdc
);
9627 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9629 if (infoPtr
->clrBk
== CLR_NONE
)
9631 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9632 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9633 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9635 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9638 /* for double buffered controls we need to do this during refresh */
9639 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9641 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9647 * Helper function for LISTVIEW_[HV]Scroll *only*.
9648 * Performs vertical/horizontal scrolling by a give amount.
9651 * [I] infoPtr : valid pointer to the listview structure
9652 * [I] dx : amount of horizontal scroll
9653 * [I] dy : amount of vertical scroll
9655 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9657 /* now we can scroll the list */
9658 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9659 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9660 /* if we have focus, adjust rect */
9661 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9662 UpdateWindow(infoPtr
->hwndSelf
);
9667 * Performs vertical scrolling.
9670 * [I] infoPtr : valid pointer to the listview structure
9671 * [I] nScrollCode : scroll code
9672 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9673 * [I] hScrollWnd : scrollbar control window handle
9679 * SB_LINEUP/SB_LINEDOWN:
9680 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9681 * for LVS_REPORT is 1 line
9682 * for LVS_LIST cannot occur
9685 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9688 INT nOldScrollPos
, nNewScrollPos
;
9689 SCROLLINFO scrollInfo
;
9692 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9693 debugscrollcode(nScrollCode
), nScrollDiff
);
9695 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9697 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9698 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9700 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9702 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9704 nOldScrollPos
= scrollInfo
.nPos
;
9705 switch (nScrollCode
)
9711 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9715 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9719 nScrollDiff
= -scrollInfo
.nPage
;
9723 nScrollDiff
= scrollInfo
.nPage
;
9726 case SB_THUMBPOSITION
:
9728 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9735 /* quit right away if pos isn't changing */
9736 if (nScrollDiff
== 0) return 0;
9738 /* calculate new position, and handle overflows */
9739 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9740 if (nScrollDiff
> 0) {
9741 if (nNewScrollPos
< nOldScrollPos
||
9742 nNewScrollPos
> scrollInfo
.nMax
)
9743 nNewScrollPos
= scrollInfo
.nMax
;
9745 if (nNewScrollPos
> nOldScrollPos
||
9746 nNewScrollPos
< scrollInfo
.nMin
)
9747 nNewScrollPos
= scrollInfo
.nMin
;
9750 /* set the new position, and reread in case it changed */
9751 scrollInfo
.fMask
= SIF_POS
;
9752 scrollInfo
.nPos
= nNewScrollPos
;
9753 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9755 /* carry on only if it really changed */
9756 if (nNewScrollPos
== nOldScrollPos
) return 0;
9758 /* now adjust to client coordinates */
9759 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9760 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9762 /* and scroll the window */
9763 scroll_list(infoPtr
, 0, nScrollDiff
);
9770 * Performs horizontal scrolling.
9773 * [I] infoPtr : valid pointer to the listview structure
9774 * [I] nScrollCode : scroll code
9775 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9776 * [I] hScrollWnd : scrollbar control window handle
9782 * SB_LINELEFT/SB_LINERIGHT:
9783 * for LVS_ICON, LVS_SMALLICON 1 pixel
9784 * for LVS_REPORT is 1 pixel
9785 * for LVS_LIST is 1 column --> which is a 1 because the
9786 * scroll is based on columns not pixels
9789 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9792 INT nOldScrollPos
, nNewScrollPos
;
9793 SCROLLINFO scrollInfo
;
9796 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9797 debugscrollcode(nScrollCode
), nScrollDiff
);
9799 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9801 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9802 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9804 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9806 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9808 nOldScrollPos
= scrollInfo
.nPos
;
9810 switch (nScrollCode
)
9816 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9820 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9824 nScrollDiff
= -scrollInfo
.nPage
;
9828 nScrollDiff
= scrollInfo
.nPage
;
9831 case SB_THUMBPOSITION
:
9833 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9840 /* quit right away if pos isn't changing */
9841 if (nScrollDiff
== 0) return 0;
9843 /* calculate new position, and handle overflows */
9844 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9845 if (nScrollDiff
> 0) {
9846 if (nNewScrollPos
< nOldScrollPos
||
9847 nNewScrollPos
> scrollInfo
.nMax
)
9848 nNewScrollPos
= scrollInfo
.nMax
;
9850 if (nNewScrollPos
> nOldScrollPos
||
9851 nNewScrollPos
< scrollInfo
.nMin
)
9852 nNewScrollPos
= scrollInfo
.nMin
;
9855 /* set the new position, and reread in case it changed */
9856 scrollInfo
.fMask
= SIF_POS
;
9857 scrollInfo
.nPos
= nNewScrollPos
;
9858 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9860 /* carry on only if it really changed */
9861 if (nNewScrollPos
== nOldScrollPos
) return 0;
9863 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9865 /* now adjust to client coordinates */
9866 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9867 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9869 /* and scroll the window */
9870 scroll_list(infoPtr
, nScrollDiff
, 0);
9875 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9877 UINT pulScrollLines
= 3;
9879 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9881 switch(infoPtr
->uView
)
9884 case LV_VIEW_SMALLICON
:
9886 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9887 * should be fixed in the future.
9889 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9890 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9893 case LV_VIEW_DETAILS
:
9894 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9896 /* if scrolling changes direction, ignore left overs */
9897 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9898 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9899 infoPtr
->cWheelRemainder
+= wheelDelta
;
9901 infoPtr
->cWheelRemainder
= wheelDelta
;
9902 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9905 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9906 cLineScroll
= pulScrollLines
* (float)infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9907 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
9908 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9913 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9924 * [I] infoPtr : valid pointer to the listview structure
9925 * [I] nVirtualKey : virtual key
9926 * [I] lKeyData : key data
9931 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9933 HWND hwndSelf
= infoPtr
->hwndSelf
;
9935 NMLVKEYDOWN nmKeyDown
;
9937 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9939 /* send LVN_KEYDOWN notification */
9940 nmKeyDown
.wVKey
= nVirtualKey
;
9941 nmKeyDown
.flags
= 0;
9942 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9943 if (!IsWindow(hwndSelf
))
9946 switch (nVirtualKey
)
9949 nItem
= infoPtr
->nFocusedItem
;
9950 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9951 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9955 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9957 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9958 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9963 if (infoPtr
->nItemCount
> 0)
9968 if (infoPtr
->nItemCount
> 0)
9969 nItem
= infoPtr
->nItemCount
- 1;
9973 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9977 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9981 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9985 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9989 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9991 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9992 if (infoPtr
->nFocusedItem
== topidx
)
9993 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9998 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9999 * LISTVIEW_GetCountPerRow(infoPtr
);
10000 if(nItem
< 0) nItem
= 0;
10004 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10006 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10007 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10008 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10009 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10011 nItem
= topidx
+ cnt
- 1;
10014 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10015 * LISTVIEW_GetCountPerRow(infoPtr
);
10016 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10020 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10021 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10031 * [I] infoPtr : valid pointer to the listview structure
10036 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10040 /* drop any left over scroll amount */
10041 infoPtr
->cWheelRemainder
= 0;
10043 /* if we did not have the focus, there's nothing more to do */
10044 if (!infoPtr
->bFocus
) return 0;
10046 /* send NM_KILLFOCUS notification */
10047 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10049 /* if we have a focus rectangle, get rid of it */
10050 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10052 /* if have a marquee selection, stop it */
10053 if (infoPtr
->bMarqueeSelect
)
10055 /* Remove the marquee rectangle and release our mouse capture */
10056 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10059 SetRectEmpty(&infoPtr
->marqueeRect
);
10061 infoPtr
->bMarqueeSelect
= FALSE
;
10062 infoPtr
->bScrolling
= FALSE
;
10063 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10066 /* set window focus flag */
10067 infoPtr
->bFocus
= FALSE
;
10069 /* invalidate the selected items before resetting focus flag */
10070 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10077 * Processes double click messages (left mouse button).
10080 * [I] infoPtr : valid pointer to the listview structure
10081 * [I] wKey : key flag
10082 * [I] x,y : mouse coordinate
10087 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10089 LVHITTESTINFO htInfo
;
10091 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10093 /* Cancel the item edition if any */
10094 if (infoPtr
->itemEdit
.fEnabled
)
10096 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10097 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10100 /* send NM_RELEASEDCAPTURE notification */
10101 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10106 /* send NM_DBLCLK notification */
10107 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10108 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10110 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10111 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10116 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10121 r
.top
= r
.bottom
= pt
.y
;
10122 r
.left
= r
.right
= pt
.x
;
10124 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10126 SetCapture(infoPtr
->hwndSelf
);
10130 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10132 if (msg
.message
== WM_MOUSEMOVE
)
10134 pt
.x
= (short)LOWORD(msg
.lParam
);
10135 pt
.y
= (short)HIWORD(msg
.lParam
);
10136 if (PtInRect(&r
, pt
))
10144 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10145 msg
.message
<= WM_RBUTTONDBLCLK
)
10150 DispatchMessageW(&msg
);
10153 if (GetCapture() != infoPtr
->hwndSelf
)
10164 * Processes mouse down messages (left mouse button).
10167 * infoPtr [I ] valid pointer to the listview structure
10168 * wKey [I ] key flag
10169 * x,y [I ] mouse coordinate
10174 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10176 LVHITTESTINFO lvHitTestInfo
;
10177 static BOOL bGroupSelect
= TRUE
;
10178 POINT pt
= { x
, y
};
10181 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10183 /* send NM_RELEASEDCAPTURE notification */
10184 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10186 /* set left button down flag and record the click position */
10187 infoPtr
->bLButtonDown
= TRUE
;
10188 infoPtr
->ptClickPos
= pt
;
10189 infoPtr
->bDragging
= FALSE
;
10190 infoPtr
->bMarqueeSelect
= FALSE
;
10191 infoPtr
->bScrolling
= FALSE
;
10193 lvHitTestInfo
.pt
.x
= x
;
10194 lvHitTestInfo
.pt
.y
= y
;
10196 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10197 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10198 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10200 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10202 toggle_checkbox_state(infoPtr
, nItem
);
10206 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10208 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10209 infoPtr
->nEditLabelItem
= nItem
;
10211 LISTVIEW_SetSelection(infoPtr
, nItem
);
10215 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10219 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10220 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10221 infoPtr
->nSelectionMark
= nItem
;
10227 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10228 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10230 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10231 infoPtr
->nSelectionMark
= nItem
;
10234 else if (wKey
& MK_CONTROL
)
10238 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10240 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10241 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10242 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10243 infoPtr
->nSelectionMark
= nItem
;
10245 else if (wKey
& MK_SHIFT
)
10247 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10251 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10253 infoPtr
->nEditLabelItem
= nItem
;
10254 infoPtr
->nLButtonDownItem
= nItem
;
10256 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10259 /* set selection (clears other pre-existing selections) */
10260 LISTVIEW_SetSelection(infoPtr
, nItem
);
10264 if (!infoPtr
->bFocus
)
10265 SetFocus(infoPtr
->hwndSelf
);
10267 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10268 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10272 if (!infoPtr
->bFocus
)
10273 SetFocus(infoPtr
->hwndSelf
);
10275 /* remove all selections */
10276 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10277 LISTVIEW_DeselectAll(infoPtr
);
10286 * Processes mouse up messages (left mouse button).
10289 * infoPtr [I ] valid pointer to the listview structure
10290 * wKey [I ] key flag
10291 * x,y [I ] mouse coordinate
10296 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10298 LVHITTESTINFO lvHitTestInfo
;
10300 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10302 if (!infoPtr
->bLButtonDown
) return 0;
10304 lvHitTestInfo
.pt
.x
= x
;
10305 lvHitTestInfo
.pt
.y
= y
;
10307 /* send NM_CLICK notification */
10308 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10309 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10311 /* set left button flag */
10312 infoPtr
->bLButtonDown
= FALSE
;
10314 /* set a single selection, reset others */
10315 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10316 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10317 infoPtr
->nLButtonDownItem
= -1;
10319 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10321 /* Remove the marquee rectangle and release our mouse capture */
10322 if (infoPtr
->bMarqueeSelect
)
10324 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10328 SetRectEmpty(&infoPtr
->marqueeRect
);
10329 SetRectEmpty(&infoPtr
->marqueeDrawRect
);
10331 infoPtr
->bDragging
= FALSE
;
10332 infoPtr
->bMarqueeSelect
= FALSE
;
10333 infoPtr
->bScrolling
= FALSE
;
10335 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10339 /* if we clicked on a selected item, edit the label */
10340 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10342 /* we want to make sure the user doesn't want to do a double click. So we will
10343 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10345 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10346 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10347 SetTimer(infoPtr
->hwndSelf
,
10348 (UINT_PTR
)&infoPtr
->itemEdit
,
10349 GetDoubleClickTime(),
10350 LISTVIEW_DelayedEditItem
);
10358 * Destroys the listview control (called after WM_DESTROY).
10361 * [I] infoPtr : valid pointer to the listview structure
10366 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10372 /* destroy data structure */
10373 DPA_Destroy(infoPtr
->hdpaItems
);
10374 DPA_Destroy(infoPtr
->hdpaItemIds
);
10375 DPA_Destroy(infoPtr
->hdpaPosX
);
10376 DPA_Destroy(infoPtr
->hdpaPosY
);
10378 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10379 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10380 DPA_Destroy(infoPtr
->hdpaColumns
);
10381 ranges_destroy(infoPtr
->selectionRanges
);
10383 /* destroy image lists */
10384 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10386 ImageList_Destroy(infoPtr
->himlNormal
);
10387 ImageList_Destroy(infoPtr
->himlSmall
);
10388 ImageList_Destroy(infoPtr
->himlState
);
10391 /* destroy font, bkgnd brush */
10392 infoPtr
->hFont
= 0;
10393 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10394 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10396 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10398 /* free listview info pointer*/
10406 * Handles notifications.
10409 * [I] infoPtr : valid pointer to the listview structure
10410 * [I] lpnmhdr : notification information
10415 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10419 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10421 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10423 /* remember: HDN_LAST < HDN_FIRST */
10424 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10425 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10427 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10429 switch (lpnmhdr
->code
)
10434 COLUMN_INFO
*lpColumnInfo
;
10438 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10441 /* remove the old line (if any) */
10442 LISTVIEW_DrawTrackLine(infoPtr
);
10444 /* compute & draw the new line */
10445 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10446 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10447 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10448 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10449 LISTVIEW_DrawTrackLine(infoPtr
);
10450 return notify_forward_header(infoPtr
, lpnmh
);
10453 case HDN_ENDTRACKA
:
10454 case HDN_ENDTRACKW
:
10455 /* remove the track line (if any) */
10456 LISTVIEW_DrawTrackLine(infoPtr
);
10457 infoPtr
->xTrackLine
= -1;
10458 return notify_forward_header(infoPtr
, lpnmh
);
10460 case HDN_BEGINDRAG
:
10461 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10462 return notify_forward_header(infoPtr
, lpnmh
);
10465 infoPtr
->colRectsDirty
= TRUE
;
10466 LISTVIEW_InvalidateList(infoPtr
);
10467 return notify_forward_header(infoPtr
, lpnmh
);
10469 case HDN_ITEMCHANGEDW
:
10470 case HDN_ITEMCHANGEDA
:
10472 COLUMN_INFO
*lpColumnInfo
;
10476 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10478 hdi
.mask
= HDI_WIDTH
;
10479 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10483 cxy
= lpnmh
->pitem
->cxy
;
10485 /* determine how much we change since the last know position */
10486 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10487 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10490 lpColumnInfo
->rcHeader
.right
+= dx
;
10492 hdi
.mask
= HDI_ORDER
;
10493 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10495 /* not the rightmost one */
10496 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10498 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10499 hdi
.iOrder
+ 1, 0);
10500 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10504 /* only needs to update the scrolls */
10505 infoPtr
->nItemWidth
+= dx
;
10506 LISTVIEW_UpdateScroll(infoPtr
);
10508 LISTVIEW_UpdateItemSize(infoPtr
);
10509 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10512 RECT rcCol
= lpColumnInfo
->rcHeader
;
10514 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10515 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10517 rcCol
.top
= infoPtr
->rcList
.top
;
10518 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10520 /* resizing left-aligned columns leaves most of the left side untouched */
10521 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10523 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10526 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10529 /* when shrinking the last column clear the now unused field */
10530 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10536 /* deal with right from rightmost column area */
10537 right
.left
= rcCol
.right
;
10538 right
.top
= rcCol
.top
;
10539 right
.bottom
= rcCol
.bottom
;
10540 right
.right
= infoPtr
->rcList
.right
;
10542 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10545 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10551 case HDN_ITEMCLICKW
:
10552 case HDN_ITEMCLICKA
:
10554 /* Handle sorting by Header Column */
10557 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10559 nmlv
.iSubItem
= lpnmh
->iItem
;
10560 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10561 return notify_forward_header(infoPtr
, lpnmh
);
10564 case HDN_DIVIDERDBLCLICKW
:
10565 case HDN_DIVIDERDBLCLICKA
:
10566 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10567 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10568 split needed for that */
10569 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10570 return notify_forward_header(infoPtr
, lpnmh
);
10577 * Paint non-client area of control.
10580 * [I] infoPtr : valid pointer to the listview structureof the sender
10581 * [I] region : update region
10584 * TRUE - frame was painted
10585 * FALSE - call default window proc
10587 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10589 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10593 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10594 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10597 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10599 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10601 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10602 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10603 if (region
!= (HRGN
)1)
10604 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10605 OffsetRect(&r
, -r
.left
, -r
.top
);
10607 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10608 OffsetRect(&r
, -r
.left
, -r
.top
);
10610 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10611 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10612 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10613 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10615 /* Call default proc to get the scrollbars etc. painted */
10616 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10623 * Determines the type of structure to use.
10626 * [I] infoPtr : valid pointer to the listview structureof the sender
10627 * [I] hwndFrom : listview window handle
10628 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10633 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10635 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10637 if (nCommand
== NF_REQUERY
)
10638 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10640 return infoPtr
->notifyFormat
;
10645 * Paints/Repaints the listview control. Internal use.
10648 * [I] infoPtr : valid pointer to the listview structure
10649 * [I] hdc : device context handle
10654 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10656 TRACE("(hdc=%p)\n", hdc
);
10658 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10660 infoPtr
->bNoItemMetrics
= FALSE
;
10661 LISTVIEW_UpdateItemSize(infoPtr
);
10662 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10663 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10664 LISTVIEW_UpdateScroll(infoPtr
);
10667 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10670 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10675 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10676 if (!hdc
) return 1;
10677 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10678 EndPaint(infoPtr
->hwndSelf
, &ps
);
10686 * Paints/Repaints the listview control, WM_PAINT handler.
10689 * [I] infoPtr : valid pointer to the listview structure
10690 * [I] hdc : device context handle
10695 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10697 TRACE("(hdc=%p)\n", hdc
);
10699 if (!is_redrawing(infoPtr
))
10700 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10702 return LISTVIEW_Paint(infoPtr
, hdc
);
10707 * Paints/Repaints the listview control.
10710 * [I] infoPtr : valid pointer to the listview structure
10711 * [I] hdc : device context handle
10712 * [I] options : drawing options
10717 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10719 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10721 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10724 if (options
& PRF_ERASEBKGND
)
10725 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10727 if (options
& PRF_CLIENT
)
10728 LISTVIEW_Paint(infoPtr
, hdc
);
10736 * Processes double click messages (right mouse button).
10739 * [I] infoPtr : valid pointer to the listview structure
10740 * [I] wKey : key flag
10741 * [I] x,y : mouse coordinate
10746 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10748 LVHITTESTINFO lvHitTestInfo
;
10750 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10752 /* send NM_RELEASEDCAPTURE notification */
10753 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10755 /* send NM_RDBLCLK notification */
10756 lvHitTestInfo
.pt
.x
= x
;
10757 lvHitTestInfo
.pt
.y
= y
;
10758 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10759 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10766 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10769 * [I] infoPtr : valid pointer to the listview structure
10770 * [I] wKey : key flag
10771 * [I] x, y : mouse coordinate
10776 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10781 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10783 /* send NM_RELEASEDCAPTURE notification */
10784 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10786 /* determine the index of the selected item */
10789 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10791 /* make sure the listview control window has the focus */
10792 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10794 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10796 LISTVIEW_SetItemFocus(infoPtr
, item
);
10797 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10798 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10799 LISTVIEW_SetSelection(infoPtr
, item
);
10802 LISTVIEW_DeselectAll(infoPtr
);
10804 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10806 if (ht
.iItem
!= -1)
10810 memset(&nmlv
, 0, sizeof(nmlv
));
10811 nmlv
.iItem
= ht
.iItem
;
10812 nmlv
.ptAction
= ht
.pt
;
10814 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10819 SetFocus(infoPtr
->hwndSelf
);
10823 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10825 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10827 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10828 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10829 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10841 * [I] infoPtr : valid pointer to the listview structure
10842 * [I] hwnd : window handle of window containing the cursor
10843 * [I] nHittest : hit-test code
10844 * [I] wMouseMsg : ideintifier of the mouse message
10847 * TRUE if cursor is set
10850 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10852 LVHITTESTINFO lvHitTestInfo
;
10854 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10856 if (!infoPtr
->hHotCursor
) goto forward
;
10858 GetCursorPos(&lvHitTestInfo
.pt
);
10859 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10861 SetCursor(infoPtr
->hHotCursor
);
10867 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10875 * [I] infoPtr : valid pointer to the listview structure
10876 * [I] hwndLoseFocus : handle of previously focused window
10881 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10883 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10885 /* if we have the focus already, there's nothing to do */
10886 if (infoPtr
->bFocus
) return 0;
10888 /* send NM_SETFOCUS notification */
10889 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10891 /* set window focus flag */
10892 infoPtr
->bFocus
= TRUE
;
10894 /* put the focus rect back on */
10895 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10897 /* redraw all visible selected items */
10898 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10908 * [I] infoPtr : valid pointer to the listview structure
10909 * [I] fRedraw : font handle
10910 * [I] fRedraw : redraw flag
10915 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10917 HFONT oldFont
= infoPtr
->hFont
;
10918 INT oldHeight
= infoPtr
->nItemHeight
;
10920 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10922 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10923 if (infoPtr
->hFont
== oldFont
) return 0;
10925 LISTVIEW_SaveTextMetrics(infoPtr
);
10927 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10929 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10931 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10932 LISTVIEW_UpdateSize(infoPtr
);
10933 LISTVIEW_UpdateScroll(infoPtr
);
10935 else if (infoPtr
->nItemHeight
!= oldHeight
)
10936 LISTVIEW_UpdateScroll(infoPtr
);
10938 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10945 * Message handling for WM_SETREDRAW.
10946 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10949 * [I] infoPtr : valid pointer to the listview structure
10950 * [I] redraw: state of redraw flag
10955 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL redraw
)
10957 TRACE("old=%d, new=%d\n", infoPtr
->redraw
, redraw
);
10959 if (infoPtr
->redraw
== !!redraw
)
10962 if (!(infoPtr
->redraw
= !!redraw
))
10965 if (is_autoarrange(infoPtr
))
10966 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10967 LISTVIEW_UpdateScroll(infoPtr
);
10969 /* despite what the WM_SETREDRAW docs says, apps expect us
10970 * to invalidate the listview here... stupid! */
10971 LISTVIEW_InvalidateList(infoPtr
);
10978 * Resizes the listview control. This function processes WM_SIZE
10979 * messages. At this time, the width and height are not used.
10982 * [I] infoPtr : valid pointer to the listview structure
10983 * [I] Width : new width
10984 * [I] Height : new height
10989 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10991 RECT rcOld
= infoPtr
->rcList
;
10993 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10995 LISTVIEW_UpdateSize(infoPtr
);
10996 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10998 /* do not bother with display related stuff if we're not redrawing */
10999 if (!is_redrawing(infoPtr
)) return 0;
11001 if (is_autoarrange(infoPtr
))
11002 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11004 LISTVIEW_UpdateScroll(infoPtr
);
11006 /* refresh all only for lists whose height changed significantly */
11007 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11008 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11009 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11010 LISTVIEW_InvalidateList(infoPtr
);
11017 * Sets the size information.
11020 * [I] infoPtr : valid pointer to the listview structure
11025 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11027 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11029 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11031 if (infoPtr
->uView
== LV_VIEW_LIST
)
11033 /* Apparently the "LIST" style is supposed to have the same
11034 * number of items in a column even if there is no scroll bar.
11035 * Since if a scroll bar already exists then the bottom is already
11036 * reduced, only reduce if the scroll bar does not currently exist.
11037 * The "2" is there to mimic the native control. I think it may be
11038 * related to either padding or edges. (GLA 7/2002)
11040 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11041 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11042 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11045 /* if control created invisible header isn't created */
11046 if (infoPtr
->hwndHeader
)
11051 hl
.prc
= &infoPtr
->rcList
;
11053 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11054 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11056 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11057 wp
.flags
|= SWP_SHOWWINDOW
;
11060 wp
.flags
|= SWP_HIDEWINDOW
;
11064 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11065 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11067 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11069 /* extra padding for grid */
11070 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11071 infoPtr
->rcList
.top
+= 2;
11073 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11078 * Processes WM_STYLECHANGED messages.
11081 * [I] infoPtr : valid pointer to the listview structure
11082 * [I] wStyleType : window style type (normal or extended)
11083 * [I] lpss : window style information
11088 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11089 const STYLESTRUCT
*lpss
)
11091 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11092 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11095 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11096 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11098 if (wStyleType
!= GWL_STYLE
) return 0;
11100 infoPtr
->dwStyle
= lpss
->styleNew
;
11102 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11103 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11104 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11106 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11107 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11108 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11110 if (uNewView
!= uOldView
)
11114 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11115 changing style updates current view only when view bits change. */
11116 map_style_view(infoPtr
);
11117 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11118 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11120 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11121 SetRectEmpty(&infoPtr
->rcFocus
);
11123 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11124 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11126 if (uNewView
== LVS_REPORT
)
11131 LISTVIEW_CreateHeader( infoPtr
);
11133 hl
.prc
= &infoPtr
->rcList
;
11135 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11136 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11137 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11138 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11141 LISTVIEW_UpdateItemSize(infoPtr
);
11144 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11146 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11148 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11150 /* Turn off the header control */
11151 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11152 TRACE("Hide header control, was 0x%08x\n", style
);
11153 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11155 /* Turn on the header control */
11156 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11158 TRACE("Show header control, was 0x%08x\n", style
);
11159 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11165 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11166 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11167 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11169 /* update the size of the client area */
11170 LISTVIEW_UpdateSize(infoPtr
);
11172 /* add scrollbars if needed */
11173 LISTVIEW_UpdateScroll(infoPtr
);
11175 /* invalidate client area + erase background */
11176 LISTVIEW_InvalidateList(infoPtr
);
11183 * Processes WM_STYLECHANGING messages.
11186 * [I] wStyleType : window style type (normal or extended)
11187 * [I0] lpss : window style information
11192 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11195 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11196 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11198 /* don't forward LVS_OWNERDATA only if not already set to */
11199 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11201 if (lpss
->styleOld
& LVS_OWNERDATA
)
11202 lpss
->styleNew
|= LVS_OWNERDATA
;
11204 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11212 * Processes WM_SHOWWINDOW messages.
11215 * [I] infoPtr : valid pointer to the listview structure
11216 * [I] bShown : window is being shown (FALSE when hidden)
11217 * [I] iStatus : window show status
11222 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11224 /* header delayed creation */
11225 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11227 LISTVIEW_CreateHeader(infoPtr
);
11229 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11230 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11233 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11238 * Processes CCM_GETVERSION messages.
11241 * [I] infoPtr : valid pointer to the listview structure
11246 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11248 return infoPtr
->iVersion
;
11253 * Processes CCM_SETVERSION messages.
11256 * [I] infoPtr : valid pointer to the listview structure
11257 * [I] iVersion : version to be set
11260 * -1 when requested version is greater than DLL version;
11261 * previous version otherwise
11263 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11265 INT iOldVersion
= infoPtr
->iVersion
;
11267 if (iVersion
> COMCTL32_VERSION
)
11270 infoPtr
->iVersion
= iVersion
;
11272 TRACE("new version %d\n", iVersion
);
11274 return iOldVersion
;
11279 * Window procedure of the listview control.
11282 static LRESULT WINAPI
11283 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11285 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11287 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11289 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11290 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11294 case LVM_APPROXIMATEVIEWRECT
:
11295 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11296 LOWORD(lParam
), HIWORD(lParam
));
11298 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11300 case LVM_CANCELEDITLABEL
:
11301 return LISTVIEW_CancelEditLabel(infoPtr
);
11303 case LVM_CREATEDRAGIMAGE
:
11304 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11306 case LVM_DELETEALLITEMS
:
11307 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11309 case LVM_DELETECOLUMN
:
11310 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11312 case LVM_DELETEITEM
:
11313 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11315 case LVM_EDITLABELA
:
11316 case LVM_EDITLABELW
:
11317 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11318 uMsg
== LVM_EDITLABELW
);
11319 /* case LVM_ENABLEGROUPVIEW: */
11321 case LVM_ENSUREVISIBLE
:
11322 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11324 case LVM_FINDITEMW
:
11325 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11327 case LVM_FINDITEMA
:
11328 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11330 case LVM_GETBKCOLOR
:
11331 return infoPtr
->clrBk
;
11333 /* case LVM_GETBKIMAGE: */
11335 case LVM_GETCALLBACKMASK
:
11336 return infoPtr
->uCallbackMask
;
11338 case LVM_GETCOLUMNA
:
11339 case LVM_GETCOLUMNW
:
11340 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11341 uMsg
== LVM_GETCOLUMNW
);
11343 case LVM_GETCOLUMNORDERARRAY
:
11344 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11346 case LVM_GETCOLUMNWIDTH
:
11347 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11349 case LVM_GETCOUNTPERPAGE
:
11350 return LISTVIEW_GetCountPerPage(infoPtr
);
11352 case LVM_GETEDITCONTROL
:
11353 return (LRESULT
)infoPtr
->hwndEdit
;
11355 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11356 return infoPtr
->dwLvExStyle
;
11358 /* case LVM_GETGROUPINFO: */
11360 /* case LVM_GETGROUPMETRICS: */
11362 case LVM_GETHEADER
:
11363 return (LRESULT
)infoPtr
->hwndHeader
;
11365 case LVM_GETHOTCURSOR
:
11366 return (LRESULT
)infoPtr
->hHotCursor
;
11368 case LVM_GETHOTITEM
:
11369 return infoPtr
->nHotItem
;
11371 case LVM_GETHOVERTIME
:
11372 return infoPtr
->dwHoverTime
;
11374 case LVM_GETIMAGELIST
:
11375 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11377 /* case LVM_GETINSERTMARK: */
11379 /* case LVM_GETINSERTMARKCOLOR: */
11381 /* case LVM_GETINSERTMARKRECT: */
11383 case LVM_GETISEARCHSTRINGA
:
11384 case LVM_GETISEARCHSTRINGW
:
11385 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11390 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11392 case LVM_GETITEMCOUNT
:
11393 return infoPtr
->nItemCount
;
11395 case LVM_GETITEMPOSITION
:
11396 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11398 case LVM_GETITEMRECT
:
11399 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11401 case LVM_GETITEMSPACING
:
11402 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11404 case LVM_GETITEMSTATE
:
11405 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11407 case LVM_GETITEMTEXTA
:
11408 case LVM_GETITEMTEXTW
:
11409 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11410 uMsg
== LVM_GETITEMTEXTW
);
11412 case LVM_GETNEXTITEM
:
11413 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11415 case LVM_GETNUMBEROFWORKAREAS
:
11416 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11419 case LVM_GETORIGIN
:
11420 if (!lParam
) return FALSE
;
11421 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11422 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11423 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11426 /* case LVM_GETOUTLINECOLOR: */
11428 /* case LVM_GETSELECTEDCOLUMN: */
11430 case LVM_GETSELECTEDCOUNT
:
11431 return LISTVIEW_GetSelectedCount(infoPtr
);
11433 case LVM_GETSELECTIONMARK
:
11434 return infoPtr
->nSelectionMark
;
11436 case LVM_GETSTRINGWIDTHA
:
11437 case LVM_GETSTRINGWIDTHW
:
11438 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11439 uMsg
== LVM_GETSTRINGWIDTHW
);
11441 case LVM_GETSUBITEMRECT
:
11442 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11444 case LVM_GETTEXTBKCOLOR
:
11445 return infoPtr
->clrTextBk
;
11447 case LVM_GETTEXTCOLOR
:
11448 return infoPtr
->clrText
;
11450 /* case LVM_GETTILEINFO: */
11452 /* case LVM_GETTILEVIEWINFO: */
11454 case LVM_GETTOOLTIPS
:
11455 if( !infoPtr
->hwndToolTip
)
11456 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11457 return (LRESULT
)infoPtr
->hwndToolTip
;
11459 case LVM_GETTOPINDEX
:
11460 return LISTVIEW_GetTopIndex(infoPtr
);
11462 case LVM_GETUNICODEFORMAT
:
11463 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11466 return infoPtr
->uView
;
11468 case LVM_GETVIEWRECT
:
11469 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11471 case LVM_GETWORKAREAS
:
11472 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11475 /* case LVM_HASGROUP: */
11478 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11480 case LVM_INSERTCOLUMNA
:
11481 case LVM_INSERTCOLUMNW
:
11482 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11483 uMsg
== LVM_INSERTCOLUMNW
);
11485 /* case LVM_INSERTGROUP: */
11487 /* case LVM_INSERTGROUPSORTED: */
11489 case LVM_INSERTITEMA
:
11490 case LVM_INSERTITEMW
:
11491 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11493 /* case LVM_INSERTMARKHITTEST: */
11495 /* case LVM_ISGROUPVIEWENABLED: */
11497 case LVM_ISITEMVISIBLE
:
11498 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11500 case LVM_MAPIDTOINDEX
:
11501 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11503 case LVM_MAPINDEXTOID
:
11504 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11506 /* case LVM_MOVEGROUP: */
11508 /* case LVM_MOVEITEMTOGROUP: */
11510 case LVM_REDRAWITEMS
:
11511 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11513 /* case LVM_REMOVEALLGROUPS: */
11515 /* case LVM_REMOVEGROUP: */
11518 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11520 case LVM_SETBKCOLOR
:
11521 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11523 /* case LVM_SETBKIMAGE: */
11525 case LVM_SETCALLBACKMASK
:
11526 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11529 case LVM_SETCOLUMNA
:
11530 case LVM_SETCOLUMNW
:
11531 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11532 uMsg
== LVM_SETCOLUMNW
);
11534 case LVM_SETCOLUMNORDERARRAY
:
11535 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11537 case LVM_SETCOLUMNWIDTH
:
11538 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11540 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11541 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11543 /* case LVM_SETGROUPINFO: */
11545 /* case LVM_SETGROUPMETRICS: */
11547 case LVM_SETHOTCURSOR
:
11548 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11550 case LVM_SETHOTITEM
:
11551 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11553 case LVM_SETHOVERTIME
:
11554 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11556 case LVM_SETICONSPACING
:
11558 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11559 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11561 case LVM_SETIMAGELIST
:
11562 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11564 /* case LVM_SETINFOTIP: */
11566 /* case LVM_SETINSERTMARK: */
11568 /* case LVM_SETINSERTMARKCOLOR: */
11573 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11574 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11577 case LVM_SETITEMCOUNT
:
11578 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11580 case LVM_SETITEMPOSITION
:
11583 pt
.x
= (short)LOWORD(lParam
);
11584 pt
.y
= (short)HIWORD(lParam
);
11585 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11588 case LVM_SETITEMPOSITION32
:
11589 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11591 case LVM_SETITEMSTATE
:
11592 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11594 case LVM_SETITEMTEXTA
:
11595 case LVM_SETITEMTEXTW
:
11596 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11597 uMsg
== LVM_SETITEMTEXTW
);
11599 /* case LVM_SETOUTLINECOLOR: */
11601 /* case LVM_SETSELECTEDCOLUMN: */
11603 case LVM_SETSELECTIONMARK
:
11604 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11606 case LVM_SETTEXTBKCOLOR
:
11607 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11609 case LVM_SETTEXTCOLOR
:
11610 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11612 /* case LVM_SETTILEINFO: */
11614 /* case LVM_SETTILEVIEWINFO: */
11616 /* case LVM_SETTILEWIDTH: */
11618 case LVM_SETTOOLTIPS
:
11619 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11621 case LVM_SETUNICODEFORMAT
:
11622 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11625 return LISTVIEW_SetView(infoPtr
, wParam
);
11627 /* case LVM_SETWORKAREAS: */
11629 /* case LVM_SORTGROUPS: */
11631 case LVM_SORTITEMS
:
11632 case LVM_SORTITEMSEX
:
11633 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11634 uMsg
== LVM_SORTITEMSEX
);
11635 case LVM_SUBITEMHITTEST
:
11636 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11639 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11641 case CCM_GETVERSION
:
11642 return LISTVIEW_GetVersion(infoPtr
);
11644 case CCM_SETVERSION
:
11645 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11648 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11651 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11654 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11657 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11660 return LISTVIEW_Destroy(infoPtr
);
11663 return LISTVIEW_Enable(infoPtr
);
11665 case WM_ERASEBKGND
:
11666 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11668 case WM_GETDLGCODE
:
11669 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11672 return (LRESULT
)infoPtr
->hFont
;
11675 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11678 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11681 return LISTVIEW_KillFocus(infoPtr
);
11683 case WM_LBUTTONDBLCLK
:
11684 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11686 case WM_LBUTTONDOWN
:
11687 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11690 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11693 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11695 case WM_MOUSEHOVER
:
11696 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11699 return LISTVIEW_NCDestroy(infoPtr
);
11702 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11705 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11707 case WM_NOTIFYFORMAT
:
11708 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11710 case WM_PRINTCLIENT
:
11711 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11714 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11716 case WM_RBUTTONDBLCLK
:
11717 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11719 case WM_RBUTTONDOWN
:
11720 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11723 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11726 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11729 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11732 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11734 case WM_SHOWWINDOW
:
11735 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11737 case WM_STYLECHANGED
:
11738 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11740 case WM_STYLECHANGING
:
11741 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11743 case WM_SYSCOLORCHANGE
:
11744 COMCTL32_RefreshSysColors();
11747 /* case WM_TIMER: */
11748 case WM_THEMECHANGED
:
11749 return LISTVIEW_ThemeChanged(infoPtr
);
11752 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11754 case WM_MOUSEWHEEL
:
11755 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11756 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11757 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11759 case WM_WINDOWPOSCHANGED
:
11760 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11762 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11763 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11765 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11767 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11769 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11771 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11773 /* case WM_WININICHANGE: */
11776 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11777 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11779 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11786 * Registers the window class.
11794 void LISTVIEW_Register(void)
11796 WNDCLASSW wndClass
;
11798 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11799 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11800 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11801 wndClass
.cbClsExtra
= 0;
11802 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11803 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11804 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11805 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11806 RegisterClassW(&wndClass
);
11811 * Unregisters the window class.
11819 void LISTVIEW_Unregister(void)
11821 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11826 * Handle any WM_COMMAND messages
11829 * [I] infoPtr : valid pointer to the listview structure
11830 * [I] wParam : the first message parameter
11831 * [I] lParam : the second message parameter
11836 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11839 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11841 if (!infoPtr
->hwndEdit
) return 0;
11843 switch (HIWORD(wParam
))
11848 * Adjust the edit window size
11850 WCHAR buffer
[1024];
11851 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11852 HFONT hFont
, hOldFont
= 0;
11856 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11857 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11858 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11860 /* Select font to get the right dimension of the string */
11861 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11864 hOldFont
= SelectObject(hdc
, hFont
);
11867 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11869 TEXTMETRICW textMetric
;
11871 /* Add Extra spacing for the next character */
11872 GetTextMetricsW(hdc
, &textMetric
);
11873 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11875 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11876 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11879 SelectObject(hdc
, hOldFont
);
11881 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11887 LISTVIEW_CancelEditLabel(infoPtr
);
11892 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);