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
)
853 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
854 item
.iItem
= htInfo
->iItem
;
856 item
.stateMask
= (UINT
)-1;
857 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
858 nmia
.lParam
= item
.lParam
;
859 nmia
.uOldState
= item
.state
;
860 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
861 nmia
.uChanged
= LVIF_STATE
;
864 nmia
.iItem
= htInfo
->iItem
;
865 nmia
.iSubItem
= htInfo
->iSubItem
;
866 nmia
.ptAction
= htInfo
->pt
;
868 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
869 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
870 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
872 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
875 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
877 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
878 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
881 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
882 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
886 HWND hwnd
= infoPtr
->hwndSelf
;
889 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
890 ZeroMemory(&nmia
, sizeof(nmia
));
891 nmia
.iItem
= lvht
->iItem
;
892 nmia
.iSubItem
= lvht
->iSubItem
;
893 nmia
.ptAction
= lvht
->pt
;
894 item
.mask
= LVIF_PARAM
;
895 item
.iItem
= lvht
->iItem
;
897 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
898 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
899 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
902 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
906 HWND hwnd
= infoPtr
->hwndSelf
;
908 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
910 item
.mask
= LVIF_PARAM
;
913 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
914 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
915 return IsWindow(hwnd
);
919 Send notification. depends on dispinfoW having same
920 structure as dispinfoA.
921 infoPtr : listview struct
922 code : *Unicode* notification code
923 pdi : dispinfo structure (can be unicode or ansi)
924 isW : TRUE if dispinfo is Unicode
926 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
928 INT length
= 0, ret_length
;
929 LPWSTR buffer
= NULL
, ret_text
;
930 BOOL return_ansi
= FALSE
;
931 BOOL return_unicode
= FALSE
;
934 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
936 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
937 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
940 ret_length
= pdi
->item
.cchTextMax
;
941 ret_text
= pdi
->item
.pszText
;
943 if (return_unicode
|| return_ansi
)
945 if (code
!= LVN_GETDISPINFOW
)
947 length
= return_ansi
?
948 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
949 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
953 length
= pdi
->item
.cchTextMax
;
954 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
957 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
958 if (!buffer
) return FALSE
;
961 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
964 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
967 pdi
->item
.pszText
= buffer
;
968 pdi
->item
.cchTextMax
= length
;
971 if (infoPtr
->notifyFormat
== NFR_ANSI
)
972 code
= get_ansi_notification(code
);
974 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
975 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
976 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
978 if (return_ansi
|| return_unicode
)
980 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
982 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
984 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
986 strcpyW(ret_text
, pdi
->item
.pszText
);
988 else if (return_ansi
) /* note : pointer can be changed by app ! */
990 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
991 ret_length
, NULL
, NULL
);
994 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
995 ret_text
, ret_length
);
997 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
998 pdi
->item
.cchTextMax
= ret_length
;
1004 /* if dipsinfo holder changed notification code then convert */
1005 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1007 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1009 buffer
= Alloc(length
* sizeof(CHAR
));
1010 if (!buffer
) return FALSE
;
1012 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1013 ret_length
, NULL
, NULL
);
1015 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1022 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1023 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1025 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1026 lpnmlvcd
->nmcd
.hdc
= hdc
;
1027 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1028 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1029 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1030 if (!lplvItem
) return;
1031 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1032 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1033 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1034 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1035 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1036 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1039 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1041 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1044 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1045 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1046 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1047 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1048 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1049 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1053 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1055 COLORREF backcolor
, textcolor
;
1057 /* apparently, for selected items, we have to override the returned values */
1060 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1062 if (infoPtr
->bFocus
)
1064 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1065 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1067 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1069 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1070 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1075 backcolor
= lpnmlvcd
->clrTextBk
;
1076 textcolor
= lpnmlvcd
->clrText
;
1078 if (backcolor
== CLR_DEFAULT
)
1079 backcolor
= comctl32_color
.clrWindow
;
1080 if (textcolor
== CLR_DEFAULT
)
1081 textcolor
= comctl32_color
.clrWindowText
;
1083 /* Set the text attributes */
1084 if (backcolor
!= CLR_NONE
)
1086 SetBkMode(hdc
, OPAQUE
);
1087 SetBkColor(hdc
, backcolor
);
1090 SetBkMode(hdc
, TRANSPARENT
);
1091 SetTextColor(hdc
, textcolor
);
1094 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1096 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1099 /* returns TRUE when repaint needed, FALSE otherwise */
1100 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1102 MEASUREITEMSTRUCT mis
;
1103 mis
.CtlType
= ODT_LISTVIEW
;
1104 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1108 mis
.itemHeight
= infoPtr
->nItemHeight
;
1109 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1110 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1112 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1118 /******** Item iterator functions **********************************/
1120 static RANGES
ranges_create(int count
);
1121 static void ranges_destroy(RANGES ranges
);
1122 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1123 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1124 static void ranges_dump(RANGES ranges
);
1126 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1128 RANGE range
= { nItem
, nItem
+ 1 };
1130 return ranges_add(ranges
, range
);
1133 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1135 RANGE range
= { nItem
, nItem
+ 1 };
1137 return ranges_del(ranges
, range
);
1141 * ITERATOR DOCUMENTATION
1143 * The iterator functions allow for easy, and convenient iteration
1144 * over items of interest in the list. Typically, you create an
1145 * iterator, use it, and destroy it, as such:
1148 * iterator_xxxitems(&i, ...);
1149 * while (iterator_{prev,next}(&i)
1151 * //code which uses i.nItem
1153 * iterator_destroy(&i);
1155 * where xxx is either: framed, or visible.
1156 * Note that it is important that the code destroys the iterator
1157 * after it's done with it, as the creation of the iterator may
1158 * allocate memory, which thus needs to be freed.
1160 * You can iterate both forwards, and backwards through the list,
1161 * by using iterator_next or iterator_prev respectively.
1163 * Lower numbered items are draw on top of higher number items in
1164 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1165 * items may overlap). So, to test items, you should use
1167 * which lists the items top to bottom (in Z-order).
1168 * For drawing items, you should use
1170 * which lists the items bottom to top (in Z-order).
1171 * If you keep iterating over the items after the end-of-items
1172 * marker (-1) is returned, the iterator will start from the
1173 * beginning. Typically, you don't need to test for -1,
1174 * because iterator_{next,prev} will return TRUE if more items
1175 * are to be iterated over, or FALSE otherwise.
1177 * Note: the iterator is defined to be bidirectional. That is,
1178 * any number of prev followed by any number of next, or
1179 * five versa, should leave the iterator at the same item:
1180 * prev * n, next * n = next * n, prev * n
1182 * The iterator has a notion of an out-of-order, special item,
1183 * which sits at the start of the list. This is used in
1184 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1185 * which needs to be first, as it may overlap other items.
1187 * The code is a bit messy because we have:
1188 * - a special item to deal with
1189 * - simple range, or composite range
1191 * If you find bugs, or want to add features, please make sure you
1192 * always check/modify *both* iterator_prev, and iterator_next.
1196 * This function iterates through the items in increasing order,
1197 * but prefixed by the special item, then -1. That is:
1198 * special, 1, 2, 3, ..., n, -1.
1199 * Each item is listed only once.
1201 static inline BOOL
iterator_next(ITERATOR
* i
)
1205 i
->nItem
= i
->nSpecial
;
1206 if (i
->nItem
!= -1) return TRUE
;
1208 if (i
->nItem
== i
->nSpecial
)
1210 if (i
->ranges
) i
->index
= 0;
1216 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1217 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1222 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1223 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1226 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1228 i
->nItem
= i
->range
.lower
;
1229 if (i
->nItem
>= 0) goto testitem
;
1236 * This function iterates through the items in decreasing order,
1237 * followed by the special item, then -1. That is:
1238 * n, n-1, ..., 3, 2, 1, special, -1.
1239 * Each item is listed only once.
1241 static inline BOOL
iterator_prev(ITERATOR
* i
)
1248 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1251 if (i
->nItem
== i
->nSpecial
)
1259 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1260 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1266 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1269 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1271 i
->nItem
= i
->range
.upper
;
1272 if (i
->nItem
> 0) goto testitem
;
1274 return (i
->nItem
= i
->nSpecial
) != -1;
1277 static RANGE
iterator_range(const ITERATOR
*i
)
1281 if (!i
->ranges
) return i
->range
;
1283 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1285 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1286 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1288 else range
.lower
= range
.upper
= 0;
1294 * Releases resources associated with this iterator.
1296 static inline void iterator_destroy(const ITERATOR
*i
)
1298 ranges_destroy(i
->ranges
);
1302 * Create an empty iterator.
1304 static inline BOOL
iterator_empty(ITERATOR
* i
)
1306 ZeroMemory(i
, sizeof(*i
));
1307 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1312 * Create an iterator over a range.
1314 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1322 * Create an iterator over a bunch of ranges.
1323 * Please note that the iterator will take ownership of the ranges,
1324 * and will free them upon destruction.
1326 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1334 * Creates an iterator over the items which intersect frame.
1335 * Uses absolute coordinates rather than compensating for the current offset.
1337 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1339 RECT rcItem
, rcTemp
;
1341 /* in case we fail, we want to return an empty iterator */
1342 if (!iterator_empty(i
)) return FALSE
;
1344 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1346 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1350 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1352 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1353 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1354 i
->nSpecial
= infoPtr
->nFocusedItem
;
1356 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1357 /* to do better here, we need to have PosX, and PosY sorted */
1358 TRACE("building icon ranges:\n");
1359 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1361 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1362 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1363 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1364 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1365 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1366 ranges_additem(i
->ranges
, nItem
);
1370 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1374 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1375 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1377 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1378 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1379 if (range
.upper
<= range
.lower
) return TRUE
;
1380 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1381 TRACE(" report=%s\n", debugrange(&i
->range
));
1385 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1386 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1387 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1394 if (infoPtr
->nItemWidth
)
1396 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1397 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1401 nFirstCol
= max(frame
->left
, 0);
1402 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1405 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1407 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1408 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1410 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1412 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1413 TRACE("building list ranges:\n");
1414 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1416 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1417 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1418 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1419 TRACE(" list=%s\n", debugrange(&item_range
));
1420 ranges_add(i
->ranges
, item_range
);
1428 * Creates an iterator over the items which intersect lprc.
1430 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1435 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1437 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1438 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1440 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1444 * Creates an iterator over the items which intersect the visible region of hdc.
1446 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1448 POINT Origin
, Position
;
1449 RECT rcItem
, rcClip
;
1452 rgntype
= GetClipBox(hdc
, &rcClip
);
1453 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1454 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1455 if (rgntype
== SIMPLEREGION
) return TRUE
;
1457 /* first deal with the special item */
1458 if (i
->nSpecial
!= -1)
1460 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1461 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1464 /* if we can't deal with the region, we'll just go with the simple range */
1465 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1466 TRACE("building visible range:\n");
1467 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1469 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1470 if (!ranges_add(i
->ranges
, i
->range
))
1472 ranges_destroy(i
->ranges
);
1478 /* now delete the invisible items from the list */
1479 while(iterator_next(i
))
1481 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1482 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1483 rcItem
.top
= Position
.y
+ Origin
.y
;
1484 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1485 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1486 if (!RectVisible(hdc
, &rcItem
))
1487 ranges_delitem(i
->ranges
, i
->nItem
);
1489 /* the iterator should restart on the next iterator_next */
1495 /* Remove common elements from two iterators */
1496 /* Passed iterators have to point on the first elements */
1497 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1499 if(!iter1
->ranges
|| !iter2
->ranges
) {
1502 if(iter1
->ranges
|| iter2
->ranges
||
1503 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1504 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1505 ERR("result is not a one range iterator\n");
1509 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1512 lower
= iter1
->range
.lower
;
1513 upper
= iter1
->range
.upper
;
1515 if(lower
< iter2
->range
.lower
)
1516 iter1
->range
.upper
= iter2
->range
.lower
;
1517 else if(upper
> iter2
->range
.upper
)
1518 iter1
->range
.lower
= iter2
->range
.upper
;
1520 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1522 if(iter2
->range
.lower
< lower
)
1523 iter2
->range
.upper
= lower
;
1524 else if(iter2
->range
.upper
> upper
)
1525 iter2
->range
.lower
= upper
;
1527 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1532 iterator_next(iter1
);
1533 iterator_next(iter2
);
1536 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1539 if(iter1
->nItem
== iter2
->nItem
) {
1540 int delete = iter1
->nItem
;
1542 iterator_prev(iter1
);
1543 iterator_prev(iter2
);
1544 ranges_delitem(iter1
->ranges
, delete);
1545 ranges_delitem(iter2
->ranges
, delete);
1546 iterator_next(iter1
);
1547 iterator_next(iter2
);
1548 } else if(iter1
->nItem
> iter2
->nItem
)
1549 iterator_next(iter2
);
1551 iterator_next(iter1
);
1554 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1555 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1559 /******** Misc helper functions ************************************/
1561 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1562 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1564 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1565 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1568 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1570 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1571 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1574 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1576 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1577 if(state
== 1 || state
== 2)
1581 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1582 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1583 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1587 /* this should be called after window style got updated,
1588 it used to reset view state to match current window style */
1589 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1591 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1594 infoPtr
->uView
= LV_VIEW_ICON
;
1597 infoPtr
->uView
= LV_VIEW_DETAILS
;
1600 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1603 infoPtr
->uView
= LV_VIEW_LIST
;
1607 /* computes next item id value */
1608 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1610 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1614 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1615 return lpID
->id
+ 1;
1620 /******** Internal API functions ************************************/
1622 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1624 static COLUMN_INFO mainItem
;
1626 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1627 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1629 /* update cached column rectangles */
1630 if (infoPtr
->colRectsDirty
)
1633 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1636 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1637 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1638 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1640 Ptr
->colRectsDirty
= FALSE
;
1643 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1646 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1648 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1651 if (infoPtr
->hwndHeader
) return 0;
1653 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1655 /* setup creation flags */
1656 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1657 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1659 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1662 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1663 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1664 if (!infoPtr
->hwndHeader
) return -1;
1666 /* set header unicode format */
1667 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1669 /* set header font */
1670 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1672 /* set header image list */
1673 if (infoPtr
->himlSmall
)
1674 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1676 LISTVIEW_UpdateSize(infoPtr
);
1681 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1683 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1686 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1688 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1689 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1690 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1693 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1695 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1698 /* used to handle collapse main item column case */
1699 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1701 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1702 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1705 /* Listview invalidation functions: use _only_ these functions to invalidate */
1707 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1709 return infoPtr
->redraw
;
1712 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1714 if(!is_redrawing(infoPtr
)) return;
1715 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1716 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1719 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1723 if(!is_redrawing(infoPtr
)) return;
1724 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1725 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1728 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1730 POINT Origin
, Position
;
1733 if(!is_redrawing(infoPtr
)) return;
1734 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1735 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1736 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1737 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1739 rcBox
.bottom
= infoPtr
->nItemHeight
;
1740 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1741 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1744 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1746 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1749 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1753 if(!is_redrawing(infoPtr
)) return;
1754 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1755 rcCol
.top
= infoPtr
->rcList
.top
;
1756 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1757 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1762 * Retrieves the number of items that can fit vertically in the client area.
1765 * [I] infoPtr : valid pointer to the listview structure
1768 * Number of items per row.
1770 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1772 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1774 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1779 * Retrieves the number of items that can fit horizontally in the client
1783 * [I] infoPtr : valid pointer to the listview structure
1786 * Number of items per column.
1788 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1790 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1792 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1796 /*************************************************************************
1797 * LISTVIEW_ProcessLetterKeys
1799 * Processes keyboard messages generated by pressing the letter keys
1801 * What this does is perform a case insensitive search from the
1802 * current position with the following quirks:
1803 * - If two chars or more are pressed in quick succession we search
1804 * for the corresponding string (e.g. 'abc').
1805 * - If there is a delay we wipe away the current search string and
1806 * restart with just that char.
1807 * - If the user keeps pressing the same character, whether slowly or
1808 * fast, so that the search string is entirely composed of this
1809 * character ('aaaaa' for instance), then we search for first item
1810 * that starting with that character.
1811 * - If the user types the above character in quick succession, then
1812 * we must also search for the corresponding string ('aaaaa'), and
1813 * go to that string if there is a match.
1816 * [I] hwnd : handle to the window
1817 * [I] charCode : the character code, the actual character
1818 * [I] keyData : key data
1826 * - The current implementation has a list of characters it will
1827 * accept and it ignores everything else. In particular it will
1828 * ignore accentuated characters which seems to match what
1829 * Windows does. But I'm not sure it makes sense to follow
1831 * - We don't sound a beep when the search fails.
1835 * TREEVIEW_ProcessLetterKeys
1837 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1839 WCHAR buffer
[MAX_PATH
];
1846 /* simple parameter checking */
1847 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1849 /* only allow the valid WM_CHARs through */
1850 if (!isalnumW(charCode
) &&
1851 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1852 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1853 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1854 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1855 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1856 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1857 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1858 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1859 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1862 /* update the search parameters */
1863 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1864 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1865 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1867 if (diff
>= 0 && diff
< KEY_DELAY
)
1869 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1870 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1872 if (infoPtr
->charCode
!= charCode
)
1873 infoPtr
->charCode
= charCode
= 0;
1877 infoPtr
->charCode
= charCode
;
1878 infoPtr
->szSearchParam
[0] = charCode
;
1879 infoPtr
->nSearchParamLength
= 1;
1882 /* should start from next after focused item, so next item that matches
1883 will be selected, if there isn't any and focused matches it will be selected
1884 on second search stage from beginning of the list */
1885 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1887 /* with some accumulated search data available start with current focus, otherwise
1888 it's excluded from search */
1889 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1890 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1895 /* let application handle this for virtual listview */
1896 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1900 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1901 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1902 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1903 nmlv
.iStart
= startidx
;
1905 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1907 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1911 int i
= startidx
, endidx
;
1913 /* and search from the current position */
1915 endidx
= infoPtr
->nItemCount
;
1917 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1920 /* start from first item if not found with >= startidx */
1921 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1927 for (i
= startidx
; i
< endidx
; i
++)
1930 item
.mask
= LVIF_TEXT
;
1933 item
.pszText
= buffer
;
1934 item
.cchTextMax
= MAX_PATH
;
1935 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1937 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1942 /* this is used to find first char match when search string is not available yet,
1943 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1944 already waiting for user to complete a string */
1945 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1947 /* this would work but we must keep looking for a longer match */
1952 if ( nItem
!= -1 || /* found something */
1953 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1954 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1960 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1965 /*************************************************************************
1966 * LISTVIEW_UpdateHeaderSize [Internal]
1968 * Function to resize the header control
1971 * [I] hwnd : handle to a window
1972 * [I] nNewScrollPos : scroll pos to set
1977 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1982 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1984 if (!infoPtr
->hwndHeader
) return;
1986 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1987 point
[0].x
= winRect
.left
;
1988 point
[0].y
= winRect
.top
;
1989 point
[1].x
= winRect
.right
;
1990 point
[1].y
= winRect
.bottom
;
1992 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1993 point
[0].x
= -nNewScrollPos
;
1994 point
[1].x
+= nNewScrollPos
;
1996 SetWindowPos(infoPtr
->hwndHeader
,0,
1997 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1998 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1999 SWP_NOZORDER
| SWP_NOACTIVATE
);
2004 * Update the scrollbars. This functions should be called whenever
2005 * the content, size or view changes.
2008 * [I] infoPtr : valid pointer to the listview structure
2013 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2015 SCROLLINFO horzInfo
, vertInfo
;
2018 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2020 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2021 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2022 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2024 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2025 if (infoPtr
->uView
== LV_VIEW_LIST
)
2027 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2028 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2030 /* scroll by at least one column per page */
2031 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2032 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2034 if (infoPtr
->nItemWidth
)
2035 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2037 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2039 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2041 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2045 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2048 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2050 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2055 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2056 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2058 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2059 horzInfo
.nMax
= rcHeader
.right
;
2060 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2064 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2065 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2066 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2067 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2068 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2070 /* Setting the horizontal scroll can change the listview size
2071 * (and potentially everything else) so we need to recompute
2072 * everything again for the vertical scroll
2075 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2076 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2077 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2079 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2081 vertInfo
.nMax
= infoPtr
->nItemCount
;
2083 /* scroll by at least one page */
2084 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2085 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2087 if (infoPtr
->nItemHeight
> 0)
2088 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2090 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2094 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2097 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2098 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2099 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2100 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2101 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2103 /* Change of the range may have changed the scroll pos. If so move the content */
2104 if (dx
!= 0 || dy
!= 0)
2107 listRect
= infoPtr
->rcList
;
2108 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2109 SW_ERASE
| SW_INVALIDATE
);
2112 /* Update the Header Control */
2113 if (infoPtr
->hwndHeader
)
2115 horzInfo
.fMask
= SIF_POS
;
2116 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2117 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2124 * Shows/hides the focus rectangle.
2127 * [I] infoPtr : valid pointer to the listview structure
2128 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2133 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2137 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2139 if (infoPtr
->nFocusedItem
< 0) return;
2141 /* we need some gymnastics in ICON mode to handle large items */
2142 if (infoPtr
->uView
== LV_VIEW_ICON
)
2146 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2147 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2149 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2154 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2156 /* for some reason, owner draw should work only in report mode */
2157 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2162 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2163 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2165 item
.iItem
= infoPtr
->nFocusedItem
;
2167 item
.mask
= LVIF_PARAM
;
2168 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2170 ZeroMemory(&dis
, sizeof(dis
));
2171 dis
.CtlType
= ODT_LISTVIEW
;
2172 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2173 dis
.itemID
= item
.iItem
;
2174 dis
.itemAction
= ODA_FOCUS
;
2175 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2176 dis
.hwndItem
= infoPtr
->hwndSelf
;
2178 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2179 dis
.itemData
= item
.lParam
;
2181 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2183 SelectObject(hdc
, hOldFont
);
2187 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2190 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2194 * Invalidates all visible selected items.
2196 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2200 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2201 while(iterator_next(&i
))
2203 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2204 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2206 iterator_destroy(&i
);
2211 * DESCRIPTION: [INTERNAL]
2212 * Computes an item's (left,top) corner, relative to rcView.
2213 * That is, the position has NOT been made relative to the Origin.
2214 * This is deliberate, to avoid computing the Origin over, and
2215 * over again, when this function is called in a loop. Instead,
2216 * one can factor the computation of the Origin before the loop,
2217 * and offset the value returned by this function, on every iteration.
2220 * [I] infoPtr : valid pointer to the listview structure
2221 * [I] nItem : item number
2222 * [O] lpptOrig : item top, left corner
2227 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2229 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2231 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2233 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2234 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2236 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2238 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2239 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2240 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2242 else /* LV_VIEW_DETAILS */
2244 lpptPosition
->x
= REPORT_MARGINX
;
2245 /* item is always at zero indexed column */
2246 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2247 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2248 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2253 * DESCRIPTION: [INTERNAL]
2254 * Compute the rectangles of an item. This is to localize all
2255 * the computations in one place. If you are not interested in some
2256 * of these values, simply pass in a NULL -- the function is smart
2257 * enough to compute only what's necessary. The function computes
2258 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2259 * one, the BOX rectangle. This rectangle is very cheap to compute,
2260 * and is guaranteed to contain all the other rectangles. Computing
2261 * the ICON rect is also cheap, but all the others are potentially
2262 * expensive. This gives an easy and effective optimization when
2263 * searching (like point inclusion, or rectangle intersection):
2264 * first test against the BOX, and if TRUE, test against the desired
2266 * If the function does not have all the necessary information
2267 * to computed the requested rectangles, will crash with a
2268 * failed assertion. This is done so we catch all programming
2269 * errors, given that the function is called only from our code.
2271 * We have the following 'special' meanings for a few fields:
2272 * * If LVIS_FOCUSED is set, we assume the item has the focus
2273 * This is important in ICON mode, where it might get a larger
2274 * then usual rectangle
2276 * Please note that subitem support works only in REPORT mode.
2279 * [I] infoPtr : valid pointer to the listview structure
2280 * [I] lpLVItem : item to compute the measures for
2281 * [O] lprcBox : ptr to Box rectangle
2282 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2283 * [0] lprcSelectBox : ptr to select box rectangle
2284 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2285 * [O] lprcIcon : ptr to Icon rectangle
2286 * Same as LVM_GETITEMRECT with LVIR_ICON
2287 * [O] lprcStateIcon: ptr to State Icon rectangle
2288 * [O] lprcLabel : ptr to Label rectangle
2289 * Same as LVM_GETITEMRECT with LVIR_LABEL
2294 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2295 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2296 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2298 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2299 RECT Box
, SelectBox
, Icon
, Label
;
2300 COLUMN_INFO
*lpColumnInfo
= NULL
;
2301 SIZE labelSize
= { 0, 0 };
2303 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2305 /* Be smart and try to figure out the minimum we have to do */
2306 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2307 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2309 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2310 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2312 if (lprcSelectBox
) doSelectBox
= TRUE
;
2313 if (lprcLabel
) doLabel
= TRUE
;
2314 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2321 /************************************************************/
2322 /* compute the box rectangle (it should be cheap to do) */
2323 /************************************************************/
2324 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2325 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2327 if (lpLVItem
->iSubItem
)
2329 Box
= lpColumnInfo
->rcHeader
;
2334 Box
.right
= infoPtr
->nItemWidth
;
2337 Box
.bottom
= infoPtr
->nItemHeight
;
2339 /******************************************************************/
2340 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2341 /******************************************************************/
2344 LONG state_width
= 0;
2346 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2347 state_width
= infoPtr
->iconStateSize
.cx
;
2349 if (infoPtr
->uView
== LV_VIEW_ICON
)
2351 Icon
.left
= Box
.left
+ state_width
;
2352 if (infoPtr
->himlNormal
)
2353 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2354 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2355 Icon
.right
= Icon
.left
;
2356 Icon
.bottom
= Icon
.top
;
2357 if (infoPtr
->himlNormal
)
2359 Icon
.right
+= infoPtr
->iconSize
.cx
;
2360 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2363 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2365 Icon
.left
= Box
.left
+ state_width
;
2367 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2369 /* we need the indent in report mode */
2370 assert(lpLVItem
->mask
& LVIF_INDENT
);
2371 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2375 Icon
.right
= Icon
.left
;
2376 if (infoPtr
->himlSmall
&&
2377 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2378 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2379 Icon
.right
+= infoPtr
->iconSize
.cx
;
2380 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2382 if(lprcIcon
) *lprcIcon
= Icon
;
2383 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2385 /* TODO: is this correct? */
2388 lprcStateIcon
->left
= Icon
.left
- state_width
;
2389 lprcStateIcon
->right
= Icon
.left
;
2390 lprcStateIcon
->top
= Icon
.top
;
2391 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2392 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2395 else Icon
.right
= 0;
2397 /************************************************************/
2398 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2399 /************************************************************/
2402 /* calculate how far to the right can the label stretch */
2403 Label
.right
= Box
.right
;
2404 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2406 if (lpLVItem
->iSubItem
== 0)
2408 /* we need a zero based rect here */
2409 Label
= lpColumnInfo
->rcHeader
;
2410 OffsetRect(&Label
, -Label
.left
, 0);
2414 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2416 labelSize
.cx
= infoPtr
->nItemWidth
;
2417 labelSize
.cy
= infoPtr
->nItemHeight
;
2421 /* we need the text in non owner draw mode */
2422 assert(lpLVItem
->mask
& LVIF_TEXT
);
2423 if (is_text(lpLVItem
->pszText
))
2425 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2426 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2427 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2431 /* compute rough rectangle where the label will go */
2432 SetRectEmpty(&rcText
);
2433 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2434 rcText
.bottom
= infoPtr
->nItemHeight
;
2435 if (infoPtr
->uView
== LV_VIEW_ICON
)
2436 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2438 /* now figure out the flags */
2439 if (infoPtr
->uView
== LV_VIEW_ICON
)
2440 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2442 uFormat
= LV_SL_DT_FLAGS
;
2444 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2446 if (rcText
.right
!= rcText
.left
)
2447 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2449 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2451 SelectObject(hdc
, hOldFont
);
2452 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2456 if (infoPtr
->uView
== LV_VIEW_ICON
)
2458 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2459 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2460 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2461 Label
.right
= Label
.left
+ labelSize
.cx
;
2462 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2463 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2465 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2466 labelSize
.cy
/= infoPtr
->ntmHeight
;
2467 labelSize
.cy
= max(labelSize
.cy
, 1);
2468 labelSize
.cy
*= infoPtr
->ntmHeight
;
2470 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2472 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2474 Label
.left
= Icon
.right
;
2475 Label
.top
= Box
.top
;
2476 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2477 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2478 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2480 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2482 Label
.left
= Icon
.right
;
2483 Label
.top
= Box
.top
;
2484 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2485 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2488 if (lprcLabel
) *lprcLabel
= Label
;
2489 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2492 /************************************************************/
2493 /* compute SELECT bounding box */
2494 /************************************************************/
2497 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2499 SelectBox
.left
= Icon
.left
;
2500 SelectBox
.top
= Box
.top
;
2501 SelectBox
.bottom
= Box
.bottom
;
2504 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2506 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2510 UnionRect(&SelectBox
, &Icon
, &Label
);
2512 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2513 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2516 /* Fix the Box if necessary */
2519 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2520 else *lprcBox
= Box
;
2522 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2526 * DESCRIPTION: [INTERNAL]
2529 * [I] infoPtr : valid pointer to the listview structure
2530 * [I] nItem : item number
2531 * [O] lprcBox : ptr to Box rectangle
2536 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2538 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2539 POINT Position
, Origin
;
2542 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2543 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2545 /* Be smart and try to figure out the minimum we have to do */
2547 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2548 lvItem
.mask
|= LVIF_TEXT
;
2549 lvItem
.iItem
= nItem
;
2550 lvItem
.iSubItem
= 0;
2551 lvItem
.pszText
= szDispText
;
2552 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2553 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2554 if (infoPtr
->uView
== LV_VIEW_ICON
)
2556 lvItem
.mask
|= LVIF_STATE
;
2557 lvItem
.stateMask
= LVIS_FOCUSED
;
2558 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2560 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2562 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2563 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2565 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2568 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2571 /* LISTVIEW_MapIdToIndex helper */
2572 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2574 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2575 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2577 if (id1
->id
== id2
->id
) return 0;
2579 return (id1
->id
< id2
->id
) ? -1 : 1;
2584 * Returns the item index for id specified.
2587 * [I] infoPtr : valid pointer to the listview structure
2588 * [I] iID : item id to get index for
2591 * Item index, or -1 on failure.
2593 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2598 TRACE("iID=%d\n", iID
);
2600 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2601 if (infoPtr
->nItemCount
== 0) return -1;
2604 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2608 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2609 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2617 * Returns the item id for index given.
2620 * [I] infoPtr : valid pointer to the listview structure
2621 * [I] iItem : item index to get id for
2626 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2631 TRACE("iItem=%d\n", iItem
);
2633 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2634 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2636 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2637 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2639 return lpItem
->id
->id
;
2644 * Returns the current icon position, and advances it along the top.
2645 * The returned position is not offset by Origin.
2648 * [I] infoPtr : valid pointer to the listview structure
2649 * [O] lpPos : will get the current icon position
2654 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2656 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2658 *lpPos
= infoPtr
->currIconPos
;
2660 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2661 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2663 infoPtr
->currIconPos
.x
= 0;
2664 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2670 * Returns the current icon position, and advances it down the left edge.
2671 * The returned position is not offset by Origin.
2674 * [I] infoPtr : valid pointer to the listview structure
2675 * [O] lpPos : will get the current icon position
2680 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2682 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2684 *lpPos
= infoPtr
->currIconPos
;
2686 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2687 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2689 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2690 infoPtr
->currIconPos
.y
= 0;
2696 * Moves an icon to the specified position.
2697 * It takes care of invalidating the item, etc.
2700 * [I] infoPtr : valid pointer to the listview structure
2701 * [I] nItem : the item to move
2702 * [I] lpPos : the new icon position
2703 * [I] isNew : flags the item as being new
2709 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2715 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2716 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2718 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2719 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2722 /* Allocating a POINTER for every item is too resource intensive,
2723 * so we'll keep the (x,y) in different arrays */
2724 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2725 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2727 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2734 * Arranges listview items in icon display mode.
2737 * [I] infoPtr : valid pointer to the listview structure
2738 * [I] nAlignCode : alignment code
2744 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2746 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2750 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2752 TRACE("nAlignCode=%d\n", nAlignCode
);
2754 if (nAlignCode
== LVA_DEFAULT
)
2756 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2757 else nAlignCode
= LVA_ALIGNTOP
;
2762 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2763 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2764 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2765 default: return FALSE
;
2768 infoPtr
->bAutoarrange
= TRUE
;
2769 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2770 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2772 next_pos(infoPtr
, &pos
);
2773 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2781 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2782 * For LVS_REPORT always returns empty rectangle.
2785 * [I] infoPtr : valid pointer to the listview structure
2786 * [O] lprcView : bounding rectangle
2792 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2796 SetRectEmpty(lprcView
);
2798 switch (infoPtr
->uView
)
2801 case LV_VIEW_SMALLICON
:
2802 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2804 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2805 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2806 lprcView
->right
= max(lprcView
->right
, x
);
2807 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2809 if (infoPtr
->nItemCount
> 0)
2811 lprcView
->right
+= infoPtr
->nItemWidth
;
2812 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2817 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2818 x
= infoPtr
->nItemCount
/ y
;
2819 if (infoPtr
->nItemCount
% y
) x
++;
2820 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2821 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2828 * Retrieves the bounding rectangle of all the items.
2831 * [I] infoPtr : valid pointer to the listview structure
2832 * [O] lprcView : bounding rectangle
2838 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2842 TRACE("(lprcView=%p)\n", lprcView
);
2844 if (!lprcView
) return FALSE
;
2846 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2848 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2850 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2851 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2854 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2861 * Retrieves the subitem pointer associated with the subitem index.
2864 * [I] hdpaSubItems : DPA handle for a specific item
2865 * [I] nSubItem : index of subitem
2868 * SUCCESS : subitem pointer
2871 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2873 SUBITEM_INFO
*lpSubItem
;
2876 /* we should binary search here if need be */
2877 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2879 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2880 if (lpSubItem
->iSubItem
== nSubItem
)
2890 * Calculates the desired item width.
2893 * [I] infoPtr : valid pointer to the listview structure
2896 * The desired item width.
2898 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2902 TRACE("uView=%d\n", infoPtr
->uView
);
2904 if (infoPtr
->uView
== LV_VIEW_ICON
)
2905 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2906 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2908 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2913 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2914 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2916 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2917 nItemWidth
= rcHeader
.right
;
2920 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2922 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2926 lvItem
.mask
= LVIF_TEXT
;
2927 lvItem
.iSubItem
= 0;
2929 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2932 lvItem
.pszText
= szDispText
;
2933 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2934 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2935 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2939 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2940 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2942 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2950 * Calculates the desired item height.
2953 * [I] infoPtr : valid pointer to the listview structure
2956 * The desired item height.
2958 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2962 TRACE("uView=%d\n", infoPtr
->uView
);
2964 if (infoPtr
->uView
== LV_VIEW_ICON
)
2965 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2968 nItemHeight
= infoPtr
->ntmHeight
;
2969 if (infoPtr
->himlState
)
2970 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2971 if (infoPtr
->himlSmall
)
2972 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2973 nItemHeight
+= HEIGHT_PADDING
;
2974 if (infoPtr
->nMeasureItemHeight
> 0)
2975 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2978 return max(nItemHeight
, 1);
2983 * Updates the width, and height of an item.
2986 * [I] infoPtr : valid pointer to the listview structure
2991 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2993 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2994 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3000 * Retrieves and saves important text metrics info for the current
3004 * [I] infoPtr : valid pointer to the listview structure
3007 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3009 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3010 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3011 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3015 if (GetTextMetricsW(hdc
, &tm
))
3017 infoPtr
->ntmHeight
= tm
.tmHeight
;
3018 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3021 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3022 infoPtr
->nEllipsisWidth
= sz
.cx
;
3024 SelectObject(hdc
, hOldFont
);
3025 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3027 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3032 * A compare function for ranges
3035 * [I] range1 : pointer to range 1;
3036 * [I] range2 : pointer to range 2;
3040 * > 0 : if range 1 > range 2
3041 * < 0 : if range 2 > range 1
3042 * = 0 : if range intersects range 2
3044 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3048 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3050 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3055 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3060 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3062 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3067 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3069 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3070 ranges_dump(ranges
);
3071 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3073 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3074 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3075 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3077 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3078 assert (prev
->upper
<= curr
->lower
);
3079 assert (curr
->lower
< curr
->upper
);
3083 TRACE("--- Done checking---\n");
3086 static RANGES
ranges_create(int count
)
3088 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3089 if (!ranges
) return NULL
;
3090 ranges
->hdpa
= DPA_Create(count
);
3091 if (ranges
->hdpa
) return ranges
;
3096 static void ranges_clear(RANGES ranges
)
3100 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3101 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3102 DPA_DeleteAllPtrs(ranges
->hdpa
);
3106 static void ranges_destroy(RANGES ranges
)
3108 if (!ranges
) return;
3109 ranges_clear(ranges
);
3110 DPA_Destroy(ranges
->hdpa
);
3114 static RANGES
ranges_clone(RANGES ranges
)
3119 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3121 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3123 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3124 if (!newrng
) goto fail
;
3125 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3126 if (!DPA_SetPtr(clone
->hdpa
, i
, newrng
))
3135 TRACE ("clone failed\n");
3136 ranges_destroy(clone
);
3140 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3144 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3145 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3150 static void ranges_dump(RANGES ranges
)
3154 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3155 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3158 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3160 RANGE srchrng
= { nItem
, nItem
+ 1 };
3162 TRACE("(nItem=%d)\n", nItem
);
3163 ranges_check(ranges
, "before contain");
3164 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3167 static INT
ranges_itemcount(RANGES ranges
)
3171 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3173 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3174 count
+= sel
->upper
- sel
->lower
;
3180 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3182 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3185 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3186 if (index
== -1) return TRUE
;
3188 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3190 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3191 if (chkrng
->lower
>= nItem
)
3192 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3193 if (chkrng
->upper
> nItem
)
3194 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3199 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3204 TRACE("(%s)\n", debugrange(&range
));
3205 ranges_check(ranges
, "before add");
3207 /* try find overlapping regions first */
3208 srchrgn
.lower
= range
.lower
- 1;
3209 srchrgn
.upper
= range
.upper
+ 1;
3210 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3216 TRACE("Adding new range\n");
3218 /* create the brand new range to insert */
3219 newrgn
= Alloc(sizeof(RANGE
));
3220 if(!newrgn
) goto fail
;
3223 /* figure out where to insert it */
3224 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3225 TRACE("index=%d\n", index
);
3226 if (index
== -1) index
= 0;
3228 /* and get it over with */
3229 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3237 RANGE
*chkrgn
, *mrgrgn
;
3238 INT fromindex
, mergeindex
;
3240 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3241 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3243 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3244 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3246 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3248 /* merge now common ranges */
3250 srchrgn
.lower
= chkrgn
->lower
- 1;
3251 srchrgn
.upper
= chkrgn
->upper
+ 1;
3255 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3256 if (mergeindex
== -1) break;
3257 if (mergeindex
== index
)
3259 fromindex
= index
+ 1;
3263 TRACE("Merge with index %i\n", mergeindex
);
3265 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3266 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3267 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3269 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3270 if (mergeindex
< index
) index
--;
3274 ranges_check(ranges
, "after add");
3278 ranges_check(ranges
, "failed add");
3282 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3287 TRACE("(%s)\n", debugrange(&range
));
3288 ranges_check(ranges
, "before del");
3290 /* we don't use DPAS_SORTED here, since we need *
3291 * to find the first overlapping range */
3292 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3295 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3297 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3299 /* case 1: Same range */
3300 if ( (chkrgn
->upper
== range
.upper
) &&
3301 (chkrgn
->lower
== range
.lower
) )
3303 DPA_DeletePtr(ranges
->hdpa
, index
);
3307 /* case 2: engulf */
3308 else if ( (chkrgn
->upper
<= range
.upper
) &&
3309 (chkrgn
->lower
>= range
.lower
) )
3311 DPA_DeletePtr(ranges
->hdpa
, index
);
3314 /* case 3: overlap upper */
3315 else if ( (chkrgn
->upper
<= range
.upper
) &&
3316 (chkrgn
->lower
< range
.lower
) )
3318 chkrgn
->upper
= range
.lower
;
3320 /* case 4: overlap lower */
3321 else if ( (chkrgn
->upper
> range
.upper
) &&
3322 (chkrgn
->lower
>= range
.lower
) )
3324 chkrgn
->lower
= range
.upper
;
3327 /* case 5: fully internal */
3332 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3333 newrgn
->lower
= chkrgn
->lower
;
3334 newrgn
->upper
= range
.lower
;
3335 chkrgn
->lower
= range
.upper
;
3336 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3344 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3347 ranges_check(ranges
, "after del");
3351 ranges_check(ranges
, "failed del");
3357 * Removes all selection ranges
3360 * [I] infoPtr : valid pointer to the listview structure
3361 * [I] toSkip : item range to skip removing the selection
3367 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3376 lvItem
.stateMask
= LVIS_SELECTED
;
3378 /* need to clone the DPA because callbacks can change it */
3379 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3380 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3381 while(iterator_next(&i
))
3382 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3383 /* note that the iterator destructor will free the cloned range */
3384 iterator_destroy(&i
);
3389 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3393 if (!(toSkip
= ranges_create(1))) return FALSE
;
3394 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3395 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3396 ranges_destroy(toSkip
);
3400 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3402 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3407 * Retrieves the number of items that are marked as selected.
3410 * [I] infoPtr : valid pointer to the listview structure
3413 * Number of items selected.
3415 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3417 INT nSelectedCount
= 0;
3419 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3422 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3424 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3429 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3431 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3432 return nSelectedCount
;
3437 * Manages the item focus.
3440 * [I] infoPtr : valid pointer to the listview structure
3441 * [I] nItem : item index
3444 * TRUE : focused item changed
3445 * FALSE : focused item has NOT changed
3447 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3449 INT oldFocus
= infoPtr
->nFocusedItem
;
3452 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3454 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3455 lvItem
.stateMask
= LVIS_FOCUSED
;
3456 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3458 return oldFocus
!= infoPtr
->nFocusedItem
;
3461 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3463 if (nShiftItem
< nItem
) return nShiftItem
;
3465 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3467 if (direction
> 0) return nShiftItem
+ direction
;
3469 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3472 /* This function updates focus index.
3475 focus : current focus index
3476 item : index of item to be added/removed
3477 direction : add/remove flag
3479 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3481 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3483 infoPtr
->bDoChangeNotify
= FALSE
;
3484 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3485 if (focus
!= infoPtr
->nFocusedItem
)
3486 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3487 infoPtr
->bDoChangeNotify
= old_change
;
3492 * Updates the various indices after an item has been inserted or deleted.
3495 * [I] infoPtr : valid pointer to the listview structure
3496 * [I] nItem : item index
3497 * [I] direction : Direction of shift, +1 or -1.
3502 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3504 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3506 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3507 assert(abs(direction
) == 1);
3508 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3510 /* But we are not supposed to modify nHotItem! */
3515 * Adds a block of selections.
3518 * [I] infoPtr : valid pointer to the listview structure
3519 * [I] nItem : item index
3522 * Whether the window is still valid.
3524 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3526 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3527 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3528 HWND hwndSelf
= infoPtr
->hwndSelf
;
3529 NMLVODSTATECHANGE nmlv
;
3534 /* Temporarily disable change notification
3535 * If the control is LVS_OWNERDATA, we need to send
3536 * only one LVN_ODSTATECHANGED notification.
3537 * See MSDN documentation for LVN_ITEMCHANGED.
3539 bOldChange
= infoPtr
->bDoChangeNotify
;
3540 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3542 if (nFirst
== -1) nFirst
= nItem
;
3544 item
.state
= LVIS_SELECTED
;
3545 item
.stateMask
= LVIS_SELECTED
;
3547 for (i
= nFirst
; i
<= nLast
; i
++)
3548 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3550 ZeroMemory(&nmlv
, sizeof(nmlv
));
3551 nmlv
.iFrom
= nFirst
;
3554 nmlv
.uNewState
= item
.state
;
3556 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3557 if (!IsWindow(hwndSelf
))
3559 infoPtr
->bDoChangeNotify
= bOldChange
;
3566 * Sets a single group selection.
3569 * [I] infoPtr : valid pointer to the listview structure
3570 * [I] nItem : item index
3575 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3582 if (!(selection
= ranges_create(100))) return;
3584 item
.state
= LVIS_SELECTED
;
3585 item
.stateMask
= LVIS_SELECTED
;
3587 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3589 if (infoPtr
->nSelectionMark
== -1)
3591 infoPtr
->nSelectionMark
= nItem
;
3592 ranges_additem(selection
, nItem
);
3598 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3599 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3600 ranges_add(selection
, sel
);
3605 RECT rcItem
, rcSel
, rcSelMark
;
3608 rcItem
.left
= LVIR_BOUNDS
;
3609 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3610 ranges_destroy (selection
);
3613 rcSelMark
.left
= LVIR_BOUNDS
;
3614 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3615 ranges_destroy (selection
);
3618 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3619 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3620 while(iterator_next(&i
))
3622 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3623 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3625 iterator_destroy(&i
);
3628 /* disable per item notifications on LVS_OWNERDATA style
3629 FIXME: single LVN_ODSTATECHANGED should be used */
3630 bOldChange
= infoPtr
->bDoChangeNotify
;
3631 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3633 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3636 iterator_rangesitems(&i
, selection
);
3637 while(iterator_next(&i
))
3638 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3639 /* this will also destroy the selection */
3640 iterator_destroy(&i
);
3642 infoPtr
->bDoChangeNotify
= bOldChange
;
3644 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3649 * Sets a single selection.
3652 * [I] infoPtr : valid pointer to the listview structure
3653 * [I] nItem : item index
3658 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3662 TRACE("nItem=%d\n", nItem
);
3664 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3666 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3667 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3668 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3670 infoPtr
->nSelectionMark
= nItem
;
3675 * Set selection(s) with keyboard.
3678 * [I] infoPtr : valid pointer to the listview structure
3679 * [I] nItem : item index
3680 * [I] space : VK_SPACE code sent
3683 * SUCCESS : TRUE (needs to be repainted)
3684 * FAILURE : FALSE (nothing has changed)
3686 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3688 /* FIXME: pass in the state */
3689 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3690 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3691 BOOL bResult
= FALSE
;
3693 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3694 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3698 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3699 LISTVIEW_SetSelection(infoPtr
, nItem
);
3703 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3707 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3708 lvItem
.stateMask
= LVIS_SELECTED
;
3711 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3712 if (lvItem
.state
& LVIS_SELECTED
)
3713 infoPtr
->nSelectionMark
= nItem
;
3715 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3718 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3721 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3725 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3727 LVHITTESTINFO lvHitTestInfo
;
3729 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3730 lvHitTestInfo
.pt
.x
= pt
.x
;
3731 lvHitTestInfo
.pt
.y
= pt
.y
;
3733 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3735 lpLVItem
->mask
= LVIF_PARAM
;
3736 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3737 lpLVItem
->iSubItem
= 0;
3739 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3742 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3744 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3745 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3746 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3751 * Called when the mouse is being actively tracked and has hovered for a specified
3755 * [I] infoPtr : valid pointer to the listview structure
3756 * [I] fwKeys : key indicator
3757 * [I] x,y : mouse position
3760 * 0 if the message was processed, non-zero if there was an error
3763 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3764 * over the item for a certain period of time.
3767 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3771 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3773 if (LISTVIEW_IsHotTracking(infoPtr
))
3781 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3782 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3784 SetFocus(infoPtr
->hwndSelf
);
3790 #define SCROLL_LEFT 0x1
3791 #define SCROLL_RIGHT 0x2
3792 #define SCROLL_UP 0x4
3793 #define SCROLL_DOWN 0x8
3797 * Utility routine to draw and highlight items within a marquee selection rectangle.
3800 * [I] infoPtr : valid pointer to the listview structure
3801 * [I] coords_orig : original co-ordinates of the cursor
3802 * [I] coords_offs : offsetted coordinates of the cursor
3803 * [I] offset : offset amount
3804 * [I] scroll : Bitmask of which directions we should scroll, if at all
3809 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3810 const POINT
*coords_offs
, const POINT
*offset
,
3813 BOOL controlDown
= FALSE
;
3815 ITERATOR old_elems
, new_elems
;
3818 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3820 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3821 rect
.right
= coords_offs
->x
;
3825 rect
.left
= coords_offs
->x
;
3826 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3829 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3831 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3832 rect
.bottom
= coords_offs
->y
;
3836 rect
.top
= coords_offs
->y
;
3837 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3840 /* Cancel out the old marquee rectangle and draw the new one */
3841 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3843 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3844 the cursor is further away */
3846 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3847 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3849 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3850 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3852 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3853 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3855 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3856 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3858 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3860 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3862 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3863 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3865 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3866 iterator_remove_common_items(&old_elems
, &new_elems
);
3868 /* Iterate over no longer selected items */
3869 while (iterator_next(&old_elems
))
3871 if (old_elems
.nItem
> -1)
3873 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3876 item
.state
= LVIS_SELECTED
;
3878 item
.stateMask
= LVIS_SELECTED
;
3880 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3883 iterator_destroy(&old_elems
);
3886 /* Iterate over newly selected items */
3887 if (GetKeyState(VK_CONTROL
) & 0x8000)
3890 while (iterator_next(&new_elems
))
3892 if (new_elems
.nItem
> -1)
3894 /* If CTRL is pressed, invert. If not, always select the item. */
3895 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3898 item
.state
= LVIS_SELECTED
;
3900 item
.stateMask
= LVIS_SELECTED
;
3902 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3905 iterator_destroy(&new_elems
);
3907 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3912 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3913 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3916 * [I] hwnd : Handle to the listview
3917 * [I] uMsg : WM_TIMER (ignored)
3918 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3919 * [I] dwTimer : The elapsed time (ignored)
3924 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3926 LISTVIEW_INFO
*infoPtr
;
3927 SCROLLINFO scrollInfo
;
3933 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3938 /* Get the current cursor position and convert to client coordinates */
3939 GetCursorPos(&coords_orig
);
3940 ScreenToClient(hWnd
, &coords_orig
);
3942 /* Ensure coordinates are within client bounds */
3943 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3944 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3947 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3949 /* Offset coordinates by the appropriate amount */
3950 coords_offs
.x
-= offset
.x
;
3951 coords_offs
.y
-= offset
.y
;
3953 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3954 scrollInfo
.fMask
= SIF_ALL
;
3956 /* Work out in which directions we can scroll */
3957 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3959 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3960 scroll
|= SCROLL_UP
;
3962 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3963 scroll
|= SCROLL_DOWN
;
3966 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3968 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3969 scroll
|= SCROLL_LEFT
;
3971 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3972 scroll
|= SCROLL_RIGHT
;
3975 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3976 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3977 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3978 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3980 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3986 * Called whenever WM_MOUSEMOVE is received.
3989 * [I] infoPtr : valid pointer to the listview structure
3990 * [I] fwKeys : key indicator
3991 * [I] x,y : mouse position
3994 * 0 if the message is processed, non-zero if there was an error
3996 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4002 if (!(fwKeys
& MK_LBUTTON
))
4003 infoPtr
->bLButtonDown
= FALSE
;
4005 if (infoPtr
->bLButtonDown
)
4007 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4008 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4010 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4012 if (infoPtr
->bMarqueeSelect
)
4022 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4024 /* Ensure coordinates are within client bounds */
4025 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4026 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4028 /* Offset coordinates by the appropriate amount */
4029 coords_offs
.x
-= offset
.x
;
4030 coords_offs
.y
-= offset
.y
;
4032 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4033 move the mouse again */
4035 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4036 (y
>= infoPtr
->rcList
.bottom
))
4038 if (!infoPtr
->bScrolling
)
4040 infoPtr
->bScrolling
= TRUE
;
4041 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4046 infoPtr
->bScrolling
= FALSE
;
4047 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4050 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4058 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4060 /* reset item marker */
4061 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4062 infoPtr
->nLButtonDownItem
= -1;
4064 if (!PtInRect(&rect
, pt
))
4066 /* this path covers the following:
4067 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4068 2. change focus with keys
4069 3. move mouse over item from step 1 selects it and moves focus on it */
4070 if (infoPtr
->nLButtonDownItem
!= -1 &&
4071 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4075 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4076 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4078 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4079 infoPtr
->nLButtonDownItem
= -1;
4082 if (!infoPtr
->bDragging
)
4084 ht
.pt
= infoPtr
->ptClickPos
;
4085 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4087 /* If the click is outside the range of an item, begin a
4088 highlight. If not, begin an item drag. */
4093 /* If we're allowing multiple selections, send notification.
4094 If return value is non-zero, cancel. */
4095 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4097 /* Store the absolute coordinates of the click */
4099 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4101 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4102 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4104 /* Begin selection and capture mouse */
4105 infoPtr
->bMarqueeSelect
= TRUE
;
4106 SetCapture(infoPtr
->hwndSelf
);
4113 ZeroMemory(&nmlv
, sizeof(nmlv
));
4114 nmlv
.iItem
= ht
.iItem
;
4115 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4117 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4118 infoPtr
->bDragging
= TRUE
;
4126 /* see if we are supposed to be tracking mouse hovering */
4127 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4128 TRACKMOUSEEVENT trackinfo
;
4131 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4132 trackinfo
.dwFlags
= TME_QUERY
;
4134 /* see if we are already tracking this hwnd */
4135 _TrackMouseEvent(&trackinfo
);
4138 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
4141 if((trackinfo
.dwFlags
& flags
) != flags
|| trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4142 trackinfo
.dwFlags
= flags
;
4143 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4144 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4146 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4147 _TrackMouseEvent(&trackinfo
);
4156 * Tests whether the item is assignable to a list with style lStyle
4158 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4160 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4161 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4162 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4170 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4173 * [I] infoPtr : valid pointer to the listview structure
4174 * [I] lpLVItem : valid pointer to new item attributes
4175 * [I] isNew : the item being set is being inserted
4176 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4177 * [O] bChanged : will be set to TRUE if the item really changed
4183 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4189 /* stateMask is ignored for LVM_INSERTITEM */
4190 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4194 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4196 if (lpLVItem
->mask
== 0) return TRUE
;
4198 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4200 /* a virtual listview only stores selection and focus */
4201 if (lpLVItem
->mask
& ~LVIF_STATE
)
4207 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4208 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4212 /* we need to get the lParam and state of the item */
4213 item
.iItem
= lpLVItem
->iItem
;
4214 item
.iSubItem
= lpLVItem
->iSubItem
;
4215 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4216 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4220 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4222 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4223 /* determine what fields will change */
4224 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4225 uChanged
|= LVIF_STATE
;
4227 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4228 uChanged
|= LVIF_IMAGE
;
4230 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4231 uChanged
|= LVIF_PARAM
;
4233 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4234 uChanged
|= LVIF_INDENT
;
4236 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4237 uChanged
|= LVIF_TEXT
;
4239 TRACE("change mask=0x%x\n", uChanged
);
4241 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4242 nmlv
.iItem
= lpLVItem
->iItem
;
4243 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4244 nmlv
.uOldState
= item
.state
;
4245 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4246 nmlv
.lParam
= item
.lParam
;
4248 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4249 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4250 are enabled. Even nothing really changed we still need to send this,
4251 in this case uChanged mask is just set to passed item mask. */
4252 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4254 HWND hwndSelf
= infoPtr
->hwndSelf
;
4256 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4258 if (!IsWindow(hwndSelf
))
4262 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4263 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4264 /* this means we won't hit a focus change path later */
4265 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4267 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4268 infoPtr
->nFocusedItem
++;
4271 if (!uChanged
) return TRUE
;
4274 /* copy information */
4275 if (lpLVItem
->mask
& LVIF_TEXT
)
4276 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4278 if (lpLVItem
->mask
& LVIF_IMAGE
)
4279 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4281 if (lpLVItem
->mask
& LVIF_PARAM
)
4282 lpItem
->lParam
= lpLVItem
->lParam
;
4284 if (lpLVItem
->mask
& LVIF_INDENT
)
4285 lpItem
->iIndent
= lpLVItem
->iIndent
;
4287 if (uChanged
& LVIF_STATE
)
4289 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4291 lpItem
->state
&= ~stateMask
;
4292 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4294 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4296 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4297 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4299 else if (stateMask
& LVIS_SELECTED
)
4301 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4303 /* If we are asked to change focus, and we manage it, do it.
4304 It's important to have all new item data stored at this point,
4305 because changing existing focus could result in a redrawing operation,
4306 which in turn could ask for disp data, application should see all data
4307 for inserted item when processing LVN_GETDISPINFO.
4309 The way this works application will see nested item change notifications -
4310 changed item notifications interrupted by ones from item losing focus. */
4311 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4313 if (lpLVItem
->state
& LVIS_FOCUSED
)
4315 /* update selection mark */
4316 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4317 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4319 if (infoPtr
->nFocusedItem
!= -1)
4321 /* remove current focus */
4322 item
.mask
= LVIF_STATE
;
4324 item
.stateMask
= LVIS_FOCUSED
;
4326 /* recurse with redrawing an item */
4327 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4330 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4331 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4333 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4335 infoPtr
->nFocusedItem
= -1;
4340 /* if we're inserting the item, we're done */
4341 if (isNew
) return TRUE
;
4343 /* send LVN_ITEMCHANGED notification */
4344 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4345 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4352 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4355 * [I] infoPtr : valid pointer to the listview structure
4356 * [I] lpLVItem : valid pointer to new subitem attributes
4357 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4358 * [O] bChanged : will be set to TRUE if the item really changed
4364 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4367 SUBITEM_INFO
*lpSubItem
;
4369 /* we do not support subitems for virtual listviews */
4370 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4372 /* set subitem only if column is present */
4373 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4375 /* First do some sanity checks */
4376 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4377 particularly useful. We currently do not actually do anything with
4378 the flag on subitems.
4380 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4381 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4383 /* get the subitem structure, and create it if not there */
4384 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4385 assert (hdpaSubItems
);
4387 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4390 SUBITEM_INFO
*tmpSubItem
;
4393 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4394 if (!lpSubItem
) return FALSE
;
4395 /* we could binary search here, if need be...*/
4396 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4398 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4399 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4401 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4406 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4407 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4411 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4413 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4417 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4419 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4428 * Sets item attributes.
4431 * [I] infoPtr : valid pointer to the listview structure
4432 * [I] lpLVItem : new item attributes
4433 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4439 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4441 HWND hwndSelf
= infoPtr
->hwndSelf
;
4442 LPWSTR pszText
= NULL
;
4443 BOOL bResult
, bChanged
= FALSE
;
4446 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4448 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4451 /* Store old item area */
4452 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4454 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4455 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4457 pszText
= lpLVItem
->pszText
;
4458 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4461 /* actually set the fields */
4462 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4464 if (lpLVItem
->iSubItem
)
4465 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4467 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4468 if (!IsWindow(hwndSelf
))
4471 /* redraw item, if necessary */
4472 if (bChanged
&& !infoPtr
->bIsDrawing
)
4474 /* this little optimization eliminates some nasty flicker */
4475 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4476 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4477 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4478 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4481 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4482 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4488 textfreeT(lpLVItem
->pszText
, isW
);
4489 lpLVItem
->pszText
= pszText
;
4497 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4500 * [I] infoPtr : valid pointer to the listview structure
4505 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4508 SCROLLINFO scrollInfo
;
4510 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4511 scrollInfo
.fMask
= SIF_POS
;
4513 if (infoPtr
->uView
== LV_VIEW_LIST
)
4515 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4516 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4518 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4520 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4521 nItem
= scrollInfo
.nPos
;
4525 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4526 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4529 TRACE("nItem=%d\n", nItem
);
4537 * Erases the background of the given rectangle
4540 * [I] infoPtr : valid pointer to the listview structure
4541 * [I] hdc : device context handle
4542 * [I] lprcBox : clipping rectangle
4548 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4550 if (!infoPtr
->hBkBrush
) return FALSE
;
4552 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4554 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4557 /* Draw main item or subitem */
4558 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4560 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4561 const RECT
*background
;
4566 /* now check if we need to update the focus rectangle */
4567 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4568 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4570 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4571 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4572 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4573 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4574 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4575 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4576 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4577 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4578 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4580 /* FIXME: temporary hack */
4581 rcSelect
.left
= rcLabel
.left
;
4583 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4585 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4586 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4587 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4588 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4589 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4592 /* in icon mode, the label rect is really what we want to draw the
4594 /* in detail mode, we want to paint background for label rect when
4595 * item is not selected or listview has full row select; otherwise paint
4596 * background for text only */
4597 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4598 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4599 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4600 background
= &rcLabel
;
4602 background
= &rcSelect
;
4604 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4605 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4607 if (item
->state
& LVIS_FOCUSED
)
4609 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4611 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4613 /* we have to update left focus bound too if item isn't in leftmost column
4614 and reduce right box bound */
4615 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4619 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4621 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4622 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4623 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4625 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4626 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4629 rcSelect
.right
= rcBox
.right
;
4631 infoPtr
->rcFocus
= rcSelect
;
4634 infoPtr
->rcFocus
= rcLabel
;
4638 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4640 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4643 TRACE("stateimage=%d\n", stateimage
);
4644 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4649 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4650 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4654 TRACE("iImage=%d\n", item
->iImage
);
4656 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4657 style
= ILD_SELECTED
;
4661 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4662 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4663 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4664 style
| (item
->state
& LVIS_OVERLAYMASK
));
4667 /* Don't bother painting item being edited */
4668 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4670 /* figure out the text drawing flags */
4671 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4672 if (infoPtr
->uView
== LV_VIEW_ICON
)
4673 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4674 else if (item
->iSubItem
)
4676 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4678 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4679 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4680 default: format
|= DT_LEFT
;
4683 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4685 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4686 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4688 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4690 /* for GRIDLINES reduce the bottom so the text formats correctly */
4691 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4694 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4702 * [I] infoPtr : valid pointer to the listview structure
4703 * [I] hdc : device context handle
4704 * [I] nItem : item index
4705 * [I] nSubItem : subitem index
4706 * [I] pos : item position in client coordinates
4707 * [I] cdmode : custom draw mode
4713 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4715 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4716 static WCHAR callbackW
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4717 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4719 NMLVCUSTOMDRAW nmlvcd
;
4722 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4724 /* get information needed for drawing the item */
4725 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4726 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4727 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4728 lvItem
.iItem
= nItem
;
4729 lvItem
.iSubItem
= 0;
4732 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4733 lvItem
.pszText
= szDispText
;
4734 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4735 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4736 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4738 /* now check if we need to update the focus rectangle */
4739 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4740 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4742 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4743 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4745 /* Full custom draw stage sequence looks like this:
4750 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4751 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item iself
4752 - CDDS_ITEMPOSTPAINT
4757 - CDDS_ITEMPOSTPAINT
4760 /* fill in the custom draw structure */
4761 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4762 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4763 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4764 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4768 while (iterator_next(subitems
))
4770 DWORD subitemstage
= CDRF_DODEFAULT
;
4772 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4773 if (subitems
->nItem
)
4775 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4776 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4777 lvItem
.iItem
= nItem
;
4778 lvItem
.iSubItem
= subitems
->nItem
;
4781 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4782 lvItem
.pszText
= szDispText
;
4783 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4784 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4785 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4786 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4787 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4789 /* update custom draw data */
4790 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4791 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4792 nmlvcd
.iSubItem
= subitems
->nItem
;
4795 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4796 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4799 nmlvcd
.clrTextBk
= infoPtr
->clrTextBk
;
4800 nmlvcd
.clrText
= infoPtr
->clrText
;
4803 if (subitems
->nItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4804 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4805 else if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4806 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4808 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4809 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4811 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4812 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4817 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4818 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4822 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4824 nmlvcd
.iSubItem
= 0;
4825 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4833 * Draws listview items when in owner draw mode.
4836 * [I] infoPtr : valid pointer to the listview structure
4837 * [I] hdc : device context handle
4842 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4844 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4845 DWORD cditemmode
= CDRF_DODEFAULT
;
4846 NMLVCUSTOMDRAW nmlvcd
;
4847 POINT Origin
, Position
;
4853 ZeroMemory(&dis
, sizeof(dis
));
4855 /* Get scroll info once before loop */
4856 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4858 /* iterate through the invalidated rows */
4859 while(iterator_next(i
))
4861 item
.iItem
= i
->nItem
;
4863 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4864 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4865 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4867 dis
.CtlType
= ODT_LISTVIEW
;
4869 dis
.itemID
= item
.iItem
;
4870 dis
.itemAction
= ODA_DRAWENTIRE
;
4872 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4873 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4874 dis
.hwndItem
= infoPtr
->hwndSelf
;
4876 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4877 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4878 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4879 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4880 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4881 dis
.itemData
= item
.lParam
;
4883 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4886 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4887 * structure for the rest. of the paint cycle
4889 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4890 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4891 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4893 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4895 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4896 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4899 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4900 notify_postpaint(infoPtr
, &nmlvcd
);
4906 * Draws listview items when in report display mode.
4909 * [I] infoPtr : valid pointer to the listview structure
4910 * [I] hdc : device context handle
4911 * [I] cdmode : custom draw mode
4916 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4919 RECT rcClip
, rcItem
;
4927 /* figure out what to draw */
4928 rgntype
= GetClipBox(hdc
, &rcClip
);
4929 if (rgntype
== NULLREGION
) return;
4931 /* Get scroll info once before loop */
4932 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4934 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4936 /* narrow down the columns we need to paint */
4937 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4939 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4941 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4942 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4943 ranges_additem(colRanges
, index
);
4945 iterator_rangesitems(&j
, colRanges
);
4947 /* in full row select, we _have_ to draw the main item */
4948 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4951 /* iterate through the invalidated rows */
4952 while(iterator_next(i
))
4958 SelectObject(hdc
, infoPtr
->hFont
);
4959 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4960 Position
.x
= Origin
.x
;
4961 Position
.y
+= Origin
.y
;
4963 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4965 /* iterate through the invalidated columns */
4966 while(iterator_next(&j
))
4968 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4970 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4973 rcItem
.bottom
= infoPtr
->nItemHeight
;
4974 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4975 if (!RectVisible(hdc
, &rcItem
)) continue;
4978 ranges_additem(subitems
, j
.nItem
);
4981 iterator_rangesitems(&k
, subitems
);
4982 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
4983 iterator_destroy(&k
);
4985 iterator_destroy(&j
);
4990 * Draws the gridlines if necessary when in report display mode.
4993 * [I] infoPtr : valid pointer to the listview structure
4994 * [I] hdc : device context handle
4999 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
5005 RECT rcClip
, rcItem
= {0};
5013 /* figure out what to draw */
5014 rgntype
= GetClipBox(hdc
, &rcClip
);
5015 if (rgntype
== NULLREGION
) return;
5017 /* Get scroll info once before loop */
5018 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5020 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5022 /* narrow down the columns we need to paint */
5023 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5025 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5027 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5028 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5029 ranges_additem(colRanges
, index
);
5032 /* is right most vertical line visible? */
5033 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5035 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5036 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5037 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5040 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5042 hOldPen
= SelectObject ( hdc
, hPen
);
5044 /* draw the vertical lines for the columns */
5045 iterator_rangesitems(&j
, colRanges
);
5046 while(iterator_next(&j
))
5048 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5049 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5050 rcItem
.left
+= Origin
.x
;
5051 rcItem
.right
+= Origin
.x
;
5052 rcItem
.top
= infoPtr
->rcList
.top
;
5053 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5054 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5055 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5056 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5058 iterator_destroy(&j
);
5059 /* draw rightmost grid line if visible */
5062 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5063 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5064 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5066 rcItem
.right
+= Origin
.x
;
5068 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5069 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5072 /* draw the horizontal lines for the rows */
5073 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5074 rcItem
.left
= infoPtr
->rcList
.left
;
5075 rcItem
.right
= infoPtr
->rcList
.right
;
5076 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5078 rcItem
.bottom
= rcItem
.top
= y
;
5079 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5080 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5081 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5084 SelectObject( hdc
, hOldPen
);
5085 DeleteObject( hPen
);
5088 ranges_destroy(colRanges
);
5093 * Draws listview items when in list display mode.
5096 * [I] infoPtr : valid pointer to the listview structure
5097 * [I] hdc : device context handle
5098 * [I] cdmode : custom draw mode
5103 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5105 POINT Origin
, Position
;
5107 /* Get scroll info once before loop */
5108 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5110 while(iterator_prev(i
))
5112 SelectObject(hdc
, infoPtr
->hFont
);
5113 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5114 Position
.x
+= Origin
.x
;
5115 Position
.y
+= Origin
.y
;
5117 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5124 * Draws listview items.
5127 * [I] infoPtr : valid pointer to the listview structure
5128 * [I] hdc : device context handle
5129 * [I] prcErase : rect to be erased before refresh (may be NULL)
5134 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5136 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5137 NMLVCUSTOMDRAW nmlvcd
;
5144 HBITMAP hbmp
= NULL
;
5147 LISTVIEW_DUMP(infoPtr
);
5149 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5150 TRACE("double buffering\n");
5152 hdc
= CreateCompatibleDC(hdcOrig
);
5154 ERR("Failed to create DC for backbuffer\n");
5157 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5158 infoPtr
->rcList
.bottom
);
5160 ERR("Failed to create bitmap for backbuffer\n");
5165 SelectObject(hdc
, hbmp
);
5166 SelectObject(hdc
, infoPtr
->hFont
);
5168 if(GetClipBox(hdcOrig
, &rcClient
))
5169 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5171 /* Save dc values we're gonna trash while drawing
5172 * FIXME: Should be done in LISTVIEW_DrawItem() */
5173 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5174 oldBkMode
= GetBkMode(hdc
);
5175 oldBkColor
= GetBkColor(hdc
);
5176 oldTextColor
= GetTextColor(hdc
);
5179 infoPtr
->bIsDrawing
= TRUE
;
5182 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5183 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5184 /* If no erasing was done (usually because RedrawWindow was called
5185 * with RDW_INVALIDATE only) we need to copy the old contents into
5186 * the backbuffer before continuing. */
5187 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5188 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5189 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5190 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5193 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5194 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5195 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5196 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5198 /* nothing to draw */
5199 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5201 /* figure out what we need to draw */
5202 iterator_visibleitems(&i
, infoPtr
, hdc
);
5203 range
= iterator_range(&i
);
5205 /* send cache hint notification */
5206 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5210 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5211 nmlv
.iFrom
= range
.lower
;
5212 nmlv
.iTo
= range
.upper
- 1;
5213 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5216 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5217 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5220 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5221 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5222 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5223 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5225 /* if we have a focus rect and it's visible, draw it */
5226 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5227 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5228 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5230 iterator_destroy(&i
);
5233 /* For LVS_EX_GRIDLINES go and draw lines */
5234 /* This includes the case where there were *no* items */
5235 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5236 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5238 /* Draw marquee rectangle if appropriate */
5239 if (infoPtr
->bMarqueeSelect
)
5240 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5242 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5243 notify_postpaint(infoPtr
, &nmlvcd
);
5246 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5247 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5248 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5249 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5254 SelectObject(hdc
, hOldFont
);
5255 SetBkMode(hdc
, oldBkMode
);
5256 SetBkColor(hdc
, oldBkColor
);
5257 SetTextColor(hdc
, oldTextColor
);
5260 infoPtr
->bIsDrawing
= FALSE
;
5266 * Calculates the approximate width and height of a given number of items.
5269 * [I] infoPtr : valid pointer to the listview structure
5270 * [I] nItemCount : number of items
5271 * [I] wWidth : width
5272 * [I] wHeight : height
5275 * Returns a DWORD. The width in the low word and the height in high word.
5277 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5278 WORD wWidth
, WORD wHeight
)
5280 DWORD dwViewRect
= 0;
5282 if (nItemCount
== -1)
5283 nItemCount
= infoPtr
->nItemCount
;
5285 if (infoPtr
->uView
== LV_VIEW_LIST
)
5287 INT nItemCountPerColumn
= 1;
5288 INT nColumnCount
= 0;
5290 if (wHeight
== 0xFFFF)
5292 /* use current height */
5293 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5296 if (wHeight
< infoPtr
->nItemHeight
)
5297 wHeight
= infoPtr
->nItemHeight
;
5301 if (infoPtr
->nItemHeight
> 0)
5303 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5304 if (nItemCountPerColumn
== 0)
5305 nItemCountPerColumn
= 1;
5307 if (nItemCount
% nItemCountPerColumn
!= 0)
5308 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5310 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5314 /* Microsoft padding magic */
5315 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5316 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5318 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5320 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5324 if (infoPtr
->nItemCount
> 0)
5326 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5327 wWidth
= rcBox
.right
- rcBox
.left
;
5328 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5332 /* use current height and width */
5333 if (wHeight
== 0xffff)
5334 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5335 if (wWidth
== 0xffff)
5336 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5339 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5341 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5347 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5348 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5350 if (wWidth
== 0xffff)
5351 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5353 if (wWidth
< nItemWidth
)
5354 wWidth
= nItemWidth
;
5356 cols
= wWidth
/ nItemWidth
;
5357 if (cols
> nItemCount
)
5364 rows
= nItemCount
/ cols
;
5365 if (nItemCount
% cols
)
5371 wHeight
= (nItemHeight
* rows
)+2;
5372 wWidth
= (nItemWidth
* cols
)+2;
5374 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5376 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5377 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5384 * Cancel edit label with saving item text.
5387 * [I] infoPtr : valid pointer to the listview structure
5390 * Always returns TRUE.
5392 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5394 if (infoPtr
->hwndEdit
)
5396 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5397 HWND edit
= infoPtr
->hwndEdit
;
5399 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5400 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5408 * Create a drag image list for the specified item.
5411 * [I] infoPtr : valid pointer to the listview structure
5412 * [I] iItem : index of item
5413 * [O] lppt : Upper-left corner of the image
5416 * Returns a handle to the image list if successful, NULL otherwise.
5418 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5424 HBITMAP hbmp
, hOldbmp
;
5426 HIMAGELIST dragList
= 0;
5427 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5429 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5432 rcItem
.left
= LVIR_BOUNDS
;
5433 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5436 lppt
->x
= rcItem
.left
;
5437 lppt
->y
= rcItem
.top
;
5439 size
.cx
= rcItem
.right
- rcItem
.left
;
5440 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5442 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5443 hdc
= CreateCompatibleDC(hdcOrig
);
5444 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5445 hOldbmp
= SelectObject(hdc
, hbmp
);
5446 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5448 SetRect(&rcItem
, 0, 0, size
.cx
, size
.cy
);
5449 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5452 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5454 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5455 SelectObject(hdc
, hOldbmp
);
5456 ImageList_Add(dragList
, hbmp
, 0);
5459 SelectObject(hdc
, hOldbmp
);
5461 SelectObject(hdc
, hOldFont
);
5464 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5466 TRACE("ret=%p\n", dragList
);
5474 * Removes all listview items and subitems.
5477 * [I] infoPtr : valid pointer to the listview structure
5483 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5485 HDPA hdpaSubItems
= NULL
;
5486 BOOL suppress
= FALSE
;
5494 /* we do it directly, to avoid notifications */
5495 ranges_clear(infoPtr
->selectionRanges
);
5496 infoPtr
->nSelectionMark
= -1;
5497 infoPtr
->nFocusedItem
= -1;
5498 SetRectEmpty(&infoPtr
->rcFocus
);
5499 /* But we are supposed to leave nHotItem as is! */
5501 /* send LVN_DELETEALLITEMS notification */
5502 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5506 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5508 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5511 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5513 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5515 /* send LVN_DELETEITEM notification, if not suppressed
5516 and if it is not a virtual listview */
5517 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5518 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5519 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5520 /* free id struct */
5521 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5522 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5523 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5525 /* both item and subitem start with ITEMHDR header */
5526 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5528 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5529 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5532 DPA_Destroy(hdpaSubItems
);
5533 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5535 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5536 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5537 infoPtr
->nItemCount
--;
5542 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5543 LISTVIEW_UpdateScroll(infoPtr
);
5545 LISTVIEW_InvalidateList(infoPtr
);
5552 * Scrolls, and updates the columns, when a column is changing width.
5555 * [I] infoPtr : valid pointer to the listview structure
5556 * [I] nColumn : column to scroll
5557 * [I] dx : amount of scroll, in pixels
5562 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5564 COLUMN_INFO
*lpColumnInfo
;
5570 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5571 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5572 rcCol
= lpColumnInfo
->rcHeader
;
5573 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5574 rcCol
.left
= rcCol
.right
;
5576 /* adjust the other columns */
5577 hdi
.mask
= HDI_ORDER
;
5578 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5580 INT nOrder
= hdi
.iOrder
;
5581 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5583 hdi
.mask
= HDI_ORDER
;
5584 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5585 if (hdi
.iOrder
>= nOrder
) {
5586 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5587 lpColumnInfo
->rcHeader
.left
+= dx
;
5588 lpColumnInfo
->rcHeader
.right
+= dx
;
5593 /* do not update screen if not in report mode */
5594 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5596 /* Need to reset the item width when inserting a new column */
5597 infoPtr
->nItemWidth
+= dx
;
5599 LISTVIEW_UpdateScroll(infoPtr
);
5600 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5602 /* scroll to cover the deleted column, and invalidate for redraw */
5603 rcOld
= infoPtr
->rcList
;
5604 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5605 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5610 * Removes a column from the listview control.
5613 * [I] infoPtr : valid pointer to the listview structure
5614 * [I] nColumn : column index
5620 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5624 TRACE("nColumn=%d\n", nColumn
);
5626 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5627 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5629 /* While the MSDN specifically says that column zero should not be deleted,
5630 what actually happens is that the column itself is deleted but no items or subitems
5634 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5636 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5639 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5640 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5642 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5644 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5646 INT nItem
, nSubItem
, i
;
5648 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5650 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5653 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5655 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5656 if (lpSubItem
->iSubItem
== nColumn
)
5659 lpDelItem
= lpSubItem
;
5661 else if (lpSubItem
->iSubItem
> nColumn
)
5663 lpSubItem
->iSubItem
--;
5667 /* if we found our subitem, zap it */
5671 if (is_text(lpDelItem
->hdr
.pszText
))
5672 Free(lpDelItem
->hdr
.pszText
);
5677 /* free dpa memory */
5678 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5683 /* update the other column info */
5684 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5685 LISTVIEW_InvalidateList(infoPtr
);
5687 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5688 LISTVIEW_UpdateItemSize(infoPtr
);
5695 * Invalidates the listview after an item's insertion or deletion.
5698 * [I] infoPtr : valid pointer to the listview structure
5699 * [I] nItem : item index
5700 * [I] dir : -1 if deleting, 1 if inserting
5705 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5707 INT nPerCol
, nItemCol
, nItemRow
;
5711 /* if we don't refresh, what's the point of scrolling? */
5712 if (!is_redrawing(infoPtr
)) return;
5714 assert (abs(dir
) == 1);
5716 /* arrange icons if autoarrange is on */
5717 if (is_autoarrange(infoPtr
))
5719 BOOL arrange
= TRUE
;
5720 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5721 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5722 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5725 /* scrollbars need updating */
5726 LISTVIEW_UpdateScroll(infoPtr
);
5728 /* figure out the item's position */
5729 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5730 nPerCol
= infoPtr
->nItemCount
+ 1;
5731 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5732 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5733 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5736 nItemCol
= nItem
/ nPerCol
;
5737 nItemRow
= nItem
% nPerCol
;
5738 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5740 /* move the items below up a slot */
5741 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5742 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5743 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5744 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5745 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5746 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5747 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5749 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5750 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5753 /* report has only that column, so we're done */
5754 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5756 /* now for LISTs, we have to deal with the columns to the right */
5757 SetRect(&rcScroll
, (nItemCol
+ 1) * infoPtr
->nItemWidth
, 0,
5758 (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
,
5759 nPerCol
* infoPtr
->nItemHeight
);
5760 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5761 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5762 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5767 * Removes an item from the listview control.
5770 * [I] infoPtr : valid pointer to the listview structure
5771 * [I] nItem : item index
5777 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5780 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5781 INT focus
= infoPtr
->nFocusedItem
;
5783 TRACE("(nItem=%d)\n", nItem
);
5785 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5787 /* remove selection, and focus */
5789 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5790 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5792 /* send LVN_DELETEITEM notification. */
5793 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5795 /* we need to do this here, because we'll be deleting stuff */
5797 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5799 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5807 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5808 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5810 /* free id struct */
5811 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5812 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5813 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5815 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5817 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5818 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5821 DPA_Destroy(hdpaSubItems
);
5826 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5827 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5830 infoPtr
->nItemCount
--;
5831 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5832 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5834 /* now is the invalidation fun */
5836 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5843 * Callback implementation for editlabel control
5846 * [I] infoPtr : valid pointer to the listview structure
5847 * [I] storeText : store edit box text as item text
5848 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5854 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5856 HWND hwndSelf
= infoPtr
->hwndSelf
;
5857 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5858 NMLVDISPINFOW dispInfo
;
5859 INT editedItem
= infoPtr
->nEditLabelItem
;
5861 WCHAR
*pszText
= NULL
;
5866 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5870 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5872 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5873 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5878 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5880 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5881 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5882 dispInfo
.item
.iItem
= editedItem
;
5883 dispInfo
.item
.iSubItem
= 0;
5884 dispInfo
.item
.stateMask
= ~0;
5885 dispInfo
.item
.pszText
= szDispText
;
5886 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5887 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5894 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5897 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5898 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5899 textfreeT(tmp
, FALSE
);
5902 /* add the text from the edit in */
5903 dispInfo
.item
.mask
|= LVIF_TEXT
;
5904 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5905 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5907 /* Do we need to update the Item Text */
5908 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5910 infoPtr
->nEditLabelItem
= -1;
5911 infoPtr
->hwndEdit
= 0;
5913 if (!res
) goto cleanup
;
5915 if (!IsWindow(hwndSelf
))
5920 if (!pszText
) return TRUE
;
5927 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5929 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5930 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5931 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5933 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5939 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5940 dispInfo
.item
.mask
= LVIF_TEXT
;
5941 dispInfo
.item
.iItem
= editedItem
;
5942 dispInfo
.item
.iSubItem
= 0;
5943 dispInfo
.item
.pszText
= pszText
;
5944 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5945 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5955 * Subclassed edit control windproc function
5958 * [I] hwnd : the edit window handle
5959 * [I] uMsg : the message that is to be processed
5960 * [I] wParam : first message parameter
5961 * [I] lParam : second message parameter
5962 * [I] isW : TRUE if input is Unicode
5967 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5969 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5972 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5973 hwnd
, uMsg
, wParam
, lParam
, isW
);
5978 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5982 WNDPROC editProc
= infoPtr
->EditWndProc
;
5983 infoPtr
->EditWndProc
= 0;
5984 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5985 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5989 if (VK_ESCAPE
== (INT
)wParam
)
5994 else if (VK_RETURN
== (INT
)wParam
)
5998 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6002 if (infoPtr
->hwndEdit
)
6003 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
6005 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6011 * Subclassed edit control Unicode windproc function
6014 * [I] hwnd : the edit window handle
6015 * [I] uMsg : the message that is to be processed
6016 * [I] wParam : first message parameter
6017 * [I] lParam : second message parameter
6021 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6023 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6028 * Subclassed edit control ANSI windproc function
6031 * [I] hwnd : the edit window handle
6032 * [I] uMsg : the message that is to be processed
6033 * [I] wParam : first message parameter
6034 * [I] lParam : second message parameter
6038 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6040 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6045 * Creates a subclassed edit control
6048 * [I] infoPtr : valid pointer to the listview structure
6049 * [I] text : initial text for the edit
6050 * [I] style : the window style
6051 * [I] isW : TRUE if input is Unicode
6055 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6057 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6058 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6061 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6063 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6065 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6067 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6069 if (!hedit
) return 0;
6071 infoPtr
->EditWndProc
= (WNDPROC
)
6072 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6073 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6075 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6076 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6083 * Begin in place editing of specified list view item
6086 * [I] infoPtr : valid pointer to the listview structure
6087 * [I] nItem : item index
6088 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6094 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6096 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6097 HWND hwndSelf
= infoPtr
->hwndSelf
;
6098 NMLVDISPINFOW dispInfo
;
6099 HFONT hOldFont
= NULL
;
6105 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6107 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6109 /* remove existing edit box */
6110 if (infoPtr
->hwndEdit
)
6112 SetFocus(infoPtr
->hwndSelf
);
6113 infoPtr
->hwndEdit
= 0;
6116 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6118 infoPtr
->nEditLabelItem
= nItem
;
6120 LISTVIEW_SetSelection(infoPtr
, nItem
);
6121 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6122 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6124 rect
.left
= LVIR_LABEL
;
6125 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6127 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6128 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6129 dispInfo
.item
.iItem
= nItem
;
6130 dispInfo
.item
.iSubItem
= 0;
6131 dispInfo
.item
.stateMask
= ~0;
6132 dispInfo
.item
.pszText
= disptextW
;
6133 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6134 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6136 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6137 if (!infoPtr
->hwndEdit
) return 0;
6139 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6141 if (!IsWindow(hwndSelf
))
6143 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6144 infoPtr
->hwndEdit
= 0;
6148 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6150 /* position and display edit box */
6151 hdc
= GetDC(infoPtr
->hwndSelf
);
6153 /* select the font to get appropriate metric dimensions */
6155 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6157 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6158 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6159 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6161 /* get string length in pixels */
6162 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6164 /* add extra spacing for the next character */
6165 GetTextMetricsW(hdc
, &tm
);
6166 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6169 SelectObject(hdc
, hOldFont
);
6171 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6173 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6176 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6177 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6178 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6179 SetFocus(infoPtr
->hwndEdit
);
6180 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6181 return infoPtr
->hwndEdit
;
6187 * Ensures the specified item is visible, scrolling into view if necessary.
6190 * [I] infoPtr : valid pointer to the listview structure
6191 * [I] nItem : item index
6192 * [I] bPartial : partially or entirely visible
6198 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6200 INT nScrollPosHeight
= 0;
6201 INT nScrollPosWidth
= 0;
6202 INT nHorzAdjust
= 0;
6203 INT nVertAdjust
= 0;
6206 RECT rcItem
, rcTemp
;
6208 rcItem
.left
= LVIR_BOUNDS
;
6209 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6211 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6213 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6215 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6216 if (infoPtr
->uView
== LV_VIEW_LIST
)
6217 nScrollPosWidth
= infoPtr
->nItemWidth
;
6218 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6219 nScrollPosWidth
= 1;
6221 if (rcItem
.left
< infoPtr
->rcList
.left
)
6224 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6229 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6233 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6235 /* scroll up/down, but not in LVS_LIST mode */
6236 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6237 nScrollPosHeight
= infoPtr
->nItemHeight
;
6238 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6239 nScrollPosHeight
= 1;
6241 if (rcItem
.top
< infoPtr
->rcList
.top
)
6244 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6249 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6253 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6255 if (nScrollPosWidth
)
6257 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6258 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6259 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6262 if (nScrollPosHeight
)
6264 INT diff
= nVertDiff
/ nScrollPosHeight
;
6265 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6266 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6274 * Searches for an item with specific characteristics.
6277 * [I] hwnd : window handle
6278 * [I] nStart : base item index
6279 * [I] lpFindInfo : item information to look for
6282 * SUCCESS : index of item
6285 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6286 const LVFINDINFOW
*lpFindInfo
)
6288 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6289 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6290 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6291 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6292 POINT Position
, Destination
;
6295 /* Search in virtual listviews should be done by application, not by
6296 listview control, so we just send LVN_ODFINDITEMW and return the result */
6297 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6301 nmlv
.iStart
= nStart
;
6302 nmlv
.lvfi
= *lpFindInfo
;
6303 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6306 if (!lpFindInfo
|| nItem
< 0) return -1;
6309 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6310 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6312 lvItem
.mask
|= LVIF_TEXT
;
6313 lvItem
.pszText
= szDispText
;
6314 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6317 if (lpFindInfo
->flags
& LVFI_WRAP
)
6320 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6321 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6326 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6327 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6328 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6329 switch(lpFindInfo
->vkDirection
)
6331 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6332 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6333 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6334 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6335 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6336 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6337 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6339 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6340 Destination
.x
= rcArea
.right
;
6341 Destination
.y
= rcArea
.bottom
;
6343 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6347 else Destination
.x
= Destination
.y
= 0;
6349 /* if LVFI_PARAM is specified, all other flags are ignored */
6350 if (lpFindInfo
->flags
& LVFI_PARAM
)
6352 lvItem
.mask
|= LVIF_PARAM
;
6354 lvItem
.mask
&= ~LVIF_TEXT
;
6358 for (; nItem
< nLast
; nItem
++)
6360 lvItem
.iItem
= nItem
;
6361 lvItem
.iSubItem
= 0;
6362 lvItem
.pszText
= szDispText
;
6363 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6365 if (lvItem
.mask
& LVIF_PARAM
)
6367 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6373 if (lvItem
.mask
& LVIF_TEXT
)
6375 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6377 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6378 if (!p
|| p
!= lvItem
.pszText
) continue;
6382 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6386 if (!bNearest
) return nItem
;
6388 /* This is very inefficient. To do a good job here,
6389 * we need a sorted array of (x,y) item positions */
6390 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6392 /* compute the distance^2 to the destination */
6393 xdist
= Destination
.x
- Position
.x
;
6394 ydist
= Destination
.y
- Position
.y
;
6395 dist
= xdist
* xdist
+ ydist
* ydist
;
6397 /* remember the distance, and item if it's closer */
6401 nNearestItem
= nItem
;
6408 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6413 return nNearestItem
;
6418 * Searches for an item with specific characteristics.
6421 * [I] hwnd : window handle
6422 * [I] nStart : base item index
6423 * [I] lpFindInfo : item information to look for
6426 * SUCCESS : index of item
6429 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6430 const LVFINDINFOA
*lpFindInfo
)
6432 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6433 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6438 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6439 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6440 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6441 textfreeT(strW
, FALSE
);
6447 * Retrieves column attributes.
6450 * [I] infoPtr : valid pointer to the listview structure
6451 * [I] nColumn : column index
6452 * [IO] lpColumn : column information
6453 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6454 * otherwise it is in fact a LPLVCOLUMNA
6460 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6462 COLUMN_INFO
*lpColumnInfo
;
6465 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6466 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6468 /* initialize memory */
6469 ZeroMemory(&hdi
, sizeof(hdi
));
6471 if (lpColumn
->mask
& LVCF_TEXT
)
6473 hdi
.mask
|= HDI_TEXT
;
6474 hdi
.pszText
= lpColumn
->pszText
;
6475 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6478 if (lpColumn
->mask
& LVCF_IMAGE
)
6479 hdi
.mask
|= HDI_IMAGE
;
6481 if (lpColumn
->mask
& LVCF_ORDER
)
6482 hdi
.mask
|= HDI_ORDER
;
6484 if (lpColumn
->mask
& LVCF_SUBITEM
)
6485 hdi
.mask
|= HDI_LPARAM
;
6487 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6489 if (lpColumn
->mask
& LVCF_FMT
)
6490 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6492 if (lpColumn
->mask
& LVCF_WIDTH
)
6493 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6495 if (lpColumn
->mask
& LVCF_IMAGE
)
6496 lpColumn
->iImage
= hdi
.iImage
;
6498 if (lpColumn
->mask
& LVCF_ORDER
)
6499 lpColumn
->iOrder
= hdi
.iOrder
;
6501 if (lpColumn
->mask
& LVCF_SUBITEM
)
6502 lpColumn
->iSubItem
= hdi
.lParam
;
6504 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6505 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6510 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6512 if (!infoPtr
->hwndHeader
) return FALSE
;
6513 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6518 * Retrieves the column width.
6521 * [I] infoPtr : valid pointer to the listview structure
6522 * [I] int : column index
6525 * SUCCESS : column width
6528 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6530 INT nColumnWidth
= 0;
6533 TRACE("nColumn=%d\n", nColumn
);
6535 /* we have a 'column' in LIST and REPORT mode only */
6536 switch(infoPtr
->uView
)
6539 nColumnWidth
= infoPtr
->nItemWidth
;
6541 case LV_VIEW_DETAILS
:
6542 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6543 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6544 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6546 hdItem
.mask
= HDI_WIDTH
;
6547 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6549 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6552 nColumnWidth
= hdItem
.cxy
;
6556 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6557 return nColumnWidth
;
6562 * In list or report display mode, retrieves the number of items that can fit
6563 * vertically in the visible area. In icon or small icon display mode,
6564 * retrieves the total number of visible items.
6567 * [I] infoPtr : valid pointer to the listview structure
6570 * Number of fully visible items.
6572 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6574 switch (infoPtr
->uView
)
6577 case LV_VIEW_SMALLICON
:
6578 return infoPtr
->nItemCount
;
6579 case LV_VIEW_DETAILS
:
6580 return LISTVIEW_GetCountPerColumn(infoPtr
);
6582 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6590 * Retrieves an image list handle.
6593 * [I] infoPtr : valid pointer to the listview structure
6594 * [I] nImageList : image list identifier
6597 * SUCCESS : image list handle
6600 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6604 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6605 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6606 case LVSIL_STATE
: return infoPtr
->himlState
;
6607 case LVSIL_GROUPHEADER
:
6608 FIXME("LVSIL_GROUPHEADER not supported\n");
6611 WARN("got unknown imagelist index - %d\n", nImageList
);
6616 /* LISTVIEW_GetISearchString */
6620 * Retrieves item attributes.
6623 * [I] hwnd : window handle
6624 * [IO] lpLVItem : item info
6625 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6626 * if FALSE, then lpLVItem is a LPLVITEMA.
6629 * This is the internal 'GetItem' interface -- it tries to
6630 * be smart and avoid text copies, if possible, by modifying
6631 * lpLVItem->pszText to point to the text string. Please note
6632 * that this is not always possible (e.g. OWNERDATA), so on
6633 * entry you *must* supply valid values for pszText, and cchTextMax.
6634 * The only difference to the documented interface is that upon
6635 * return, you should use *only* the lpLVItem->pszText, rather than
6636 * the buffer pointer you provided on input. Most code already does
6637 * that, so it's not a problem.
6638 * For the two cases when the text must be copied (that is,
6639 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6645 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6647 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6648 NMLVDISPINFOW dispInfo
;
6654 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6656 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6659 if (lpLVItem
->mask
== 0) return TRUE
;
6660 TRACE("mask=%x\n", lpLVItem
->mask
);
6662 /* make a local copy */
6663 isubitem
= lpLVItem
->iSubItem
;
6665 /* a quick optimization if all we're asked is the focus state
6666 * these queries are worth optimising since they are common,
6667 * and can be answered in constant time, without the heavy accesses */
6668 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6669 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6671 lpLVItem
->state
= 0;
6672 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6673 lpLVItem
->state
|= LVIS_FOCUSED
;
6677 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6679 /* if the app stores all the data, handle it separately */
6680 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6682 dispInfo
.item
.state
= 0;
6684 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6685 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6686 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6688 UINT mask
= lpLVItem
->mask
;
6690 /* NOTE: copy only fields which we _know_ are initialized, some apps
6691 * depend on the uninitialized fields being 0 */
6692 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6693 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6694 dispInfo
.item
.iSubItem
= isubitem
;
6695 if (lpLVItem
->mask
& LVIF_TEXT
)
6697 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6699 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6702 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6703 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6706 if (lpLVItem
->mask
& LVIF_STATE
)
6707 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6708 /* could be zeroed on LVIF_NORECOMPUTE case */
6709 if (dispInfo
.item
.mask
)
6711 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6712 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6713 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6715 /* full size structure expected - _WIN32IE >= 0x560 */
6716 *lpLVItem
= dispInfo
.item
;
6718 else if (lpLVItem
->mask
& LVIF_INDENT
)
6720 /* indent member expected - _WIN32IE >= 0x300 */
6721 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6725 /* minimal structure expected */
6726 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6728 lpLVItem
->mask
= mask
;
6729 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6733 /* make sure lParam is zeroed out */
6734 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6736 /* callback marked pointer required here */
6737 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6738 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6740 /* we store only a little state, so if we're not asked, we're done */
6741 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6743 /* if focus is handled by us, report it */
6744 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6746 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6747 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6748 lpLVItem
->state
|= LVIS_FOCUSED
;
6751 /* and do the same for selection, if we handle it */
6752 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6754 lpLVItem
->state
&= ~LVIS_SELECTED
;
6755 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6756 lpLVItem
->state
|= LVIS_SELECTED
;
6762 /* find the item and subitem structures before we proceed */
6763 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6764 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6769 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6770 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6773 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6778 pItemHdr
= &lpItem
->hdr
;
6780 /* Do we need to query the state from the app? */
6781 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6783 dispInfo
.item
.mask
|= LVIF_STATE
;
6784 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6787 /* Do we need to enquire about the image? */
6788 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6789 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6791 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6792 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6795 /* Only items support indentation */
6796 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6799 dispInfo
.item
.mask
|= LVIF_INDENT
;
6800 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6803 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6804 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6805 !is_text(pItemHdr
->pszText
))
6807 dispInfo
.item
.mask
|= LVIF_TEXT
;
6808 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6809 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6810 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6811 *dispInfo
.item
.pszText
= '\0';
6814 /* If we don't have all the requested info, query the application */
6815 if (dispInfo
.item
.mask
)
6817 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6818 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6819 dispInfo
.item
.lParam
= lpItem
->lParam
;
6820 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6821 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6824 /* we should not store values for subitems */
6825 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6827 /* Now, handle the iImage field */
6828 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6830 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6831 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6832 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6834 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6836 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6837 lpLVItem
->iImage
= pItemHdr
->iImage
;
6839 lpLVItem
->iImage
= 0;
6842 /* The pszText field */
6843 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6845 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6846 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6848 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6850 else if (lpLVItem
->mask
& LVIF_TEXT
)
6852 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6853 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6854 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6857 /* Next is the lParam field */
6858 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6860 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6861 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6862 lpItem
->lParam
= dispInfo
.item
.lParam
;
6864 else if (lpLVItem
->mask
& LVIF_PARAM
)
6865 lpLVItem
->lParam
= lpItem
->lParam
;
6867 /* if this is a subitem, we're done */
6868 if (isubitem
) return TRUE
;
6870 /* ... the state field (this one is different due to uCallbackmask) */
6871 if (lpLVItem
->mask
& LVIF_STATE
)
6873 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6874 if (dispInfo
.item
.mask
& LVIF_STATE
)
6876 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6877 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6879 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6881 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6882 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6883 lpLVItem
->state
|= LVIS_FOCUSED
;
6885 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6887 lpLVItem
->state
&= ~LVIS_SELECTED
;
6888 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6889 lpLVItem
->state
|= LVIS_SELECTED
;
6893 /* and last, but not least, the indent field */
6894 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6896 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6897 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6898 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6900 else if (lpLVItem
->mask
& LVIF_INDENT
)
6902 lpLVItem
->iIndent
= lpItem
->iIndent
;
6910 * Retrieves item attributes.
6913 * [I] hwnd : window handle
6914 * [IO] lpLVItem : item info
6915 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6916 * if FALSE, then lpLVItem is a LPLVITEMA.
6919 * This is the external 'GetItem' interface -- it properly copies
6920 * the text in the provided buffer.
6926 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6931 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6934 pszText
= lpLVItem
->pszText
;
6935 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6936 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6938 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6939 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6941 pszText
= LPSTR_TEXTCALLBACKW
;
6943 lpLVItem
->pszText
= pszText
;
6951 * Retrieves the position (upper-left) of the listview control item.
6952 * Note that for LVS_ICON style, the upper-left is that of the icon
6953 * and not the bounding box.
6956 * [I] infoPtr : valid pointer to the listview structure
6957 * [I] nItem : item index
6958 * [O] lpptPosition : coordinate information
6964 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6968 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6970 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6972 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6973 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6975 if (infoPtr
->uView
== LV_VIEW_ICON
)
6977 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6978 lpptPosition
->y
+= ICON_TOP_PADDING
;
6980 lpptPosition
->x
+= Origin
.x
;
6981 lpptPosition
->y
+= Origin
.y
;
6983 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6990 * Retrieves the bounding rectangle for a listview control item.
6993 * [I] infoPtr : valid pointer to the listview structure
6994 * [I] nItem : item index
6995 * [IO] lprc : bounding rectangle coordinates
6996 * lprc->left specifies the portion of the item for which the bounding
6997 * rectangle will be retrieved.
6999 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
7000 * including the icon and label.
7003 * * Experiment shows that native control returns:
7004 * * width = min (48, length of text line)
7005 * * .left = position.x - (width - iconsize.cx)/2
7006 * * .right = .left + width
7007 * * height = #lines of text * ntmHeight + icon height + 8
7008 * * .top = position.y - 2
7009 * * .bottom = .top + height
7010 * * separation between items .y = itemSpacing.cy - height
7011 * * .x = itemSpacing.cx - width
7012 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7015 * * Experiment shows that native control returns:
7016 * * width = iconSize.cx + 16
7017 * * .left = position.x - (width - iconsize.cx)/2
7018 * * .right = .left + width
7019 * * height = iconSize.cy + 4
7020 * * .top = position.y - 2
7021 * * .bottom = .top + height
7022 * * separation between items .y = itemSpacing.cy - height
7023 * * .x = itemSpacing.cx - width
7024 * LVIR_LABEL Returns the bounding rectangle of the item text.
7027 * * Experiment shows that native control returns:
7028 * * width = text length
7029 * * .left = position.x - width/2
7030 * * .right = .left + width
7031 * * height = ntmH * linecount + 2
7032 * * .top = position.y + iconSize.cy + 6
7033 * * .bottom = .top + height
7034 * * separation between items .y = itemSpacing.cy - height
7035 * * .x = itemSpacing.cx - width
7036 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7037 * rectangles, but excludes columns in report view.
7044 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7045 * upon whether the window has the focus currently and on whether the item
7046 * is the one with the focus. Ensure that the control's record of which
7047 * item has the focus agrees with the items' records.
7049 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7051 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7052 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7053 POINT Position
, Origin
;
7057 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7059 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7061 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7062 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7064 /* Be smart and try to figure out the minimum we have to do */
7065 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7066 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7067 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7068 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7069 oversizedBox
= TRUE
;
7071 /* get what we need from the item before hand, so we make
7072 * only one request. This can speed up things, if data
7073 * is stored on the app side */
7075 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7076 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7077 lvItem
.iItem
= nItem
;
7078 lvItem
.iSubItem
= 0;
7079 lvItem
.pszText
= szDispText
;
7080 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7081 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7082 /* we got the state already up, simulate it here, to avoid a reget */
7083 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7085 lvItem
.mask
|= LVIF_STATE
;
7086 lvItem
.stateMask
= LVIS_FOCUSED
;
7087 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7090 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7091 lprc
->left
= LVIR_BOUNDS
;
7097 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7101 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7105 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7108 case LVIR_SELECTBOUNDS
:
7109 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7113 WARN("Unknown value: %d\n", lprc
->left
);
7117 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7119 if (mode
!= LVIR_BOUNDS
)
7120 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7121 Position
.y
+ Origin
.y
);
7123 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7126 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7128 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7135 * Retrieves the spacing between listview control items.
7138 * [I] infoPtr : valid pointer to the listview structure
7139 * [IO] lprc : rectangle to receive the output
7140 * on input, lprc->top = nSubItem
7141 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7143 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7144 * not only those of the first column.
7150 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7152 RECT rect
= { 0, 0, 0, 0 };
7156 if (!lprc
) return FALSE
;
7158 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7159 /* Subitem of '0' means item itself, and this works for all control view modes */
7161 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7163 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7165 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7166 /* this works for any item index, no matter if it exists or not */
7167 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7169 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7172 rect
.bottom
= infoPtr
->nItemHeight
;
7176 /* Native implementation is broken for this case and garbage is left for left and right fields,
7177 we zero them to get predictable output */
7178 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7179 lprc
->bottom
= infoPtr
->nItemHeight
;
7180 OffsetRect(lprc
, origin
.x
, y
);
7181 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7189 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7190 if (infoPtr
->himlSmall
)
7191 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7193 rect
.right
= rect
.left
;
7195 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7203 ERR("Unknown bounds=%d\n", lprc
->left
);
7207 OffsetRect(&rect
, origin
.x
, y
);
7209 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7216 * Retrieves the spacing between listview control items.
7219 * [I] infoPtr : valid pointer to the listview structure
7220 * [I] bSmall : flag for small or large icon
7223 * Horizontal + vertical spacing
7225 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7231 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7235 if (infoPtr
->uView
== LV_VIEW_ICON
)
7236 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7238 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7245 * Retrieves the state of a listview control item.
7248 * [I] infoPtr : valid pointer to the listview structure
7249 * [I] nItem : item index
7250 * [I] uMask : state mask
7253 * State specified by the mask.
7255 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7259 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7261 lvItem
.iItem
= nItem
;
7262 lvItem
.iSubItem
= 0;
7263 lvItem
.mask
= LVIF_STATE
;
7264 lvItem
.stateMask
= uMask
;
7265 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7267 return lvItem
.state
& uMask
;
7272 * Retrieves the text of a listview control item or subitem.
7275 * [I] hwnd : window handle
7276 * [I] nItem : item index
7277 * [IO] lpLVItem : item information
7278 * [I] isW : TRUE if lpLVItem is Unicode
7281 * SUCCESS : string length
7284 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7286 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7288 lpLVItem
->mask
= LVIF_TEXT
;
7289 lpLVItem
->iItem
= nItem
;
7290 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7292 return textlenT(lpLVItem
->pszText
, isW
);
7297 * Searches for an item based on properties + relationships.
7300 * [I] infoPtr : valid pointer to the listview structure
7301 * [I] nItem : item index
7302 * [I] uFlags : relationship flag
7305 * SUCCESS : item index
7308 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7311 LVFINDINFOW lvFindInfo
;
7312 INT nCountPerColumn
;
7316 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7317 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7319 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7321 if (uFlags
& LVNI_CUT
)
7324 if (uFlags
& LVNI_DROPHILITED
)
7325 uMask
|= LVIS_DROPHILITED
;
7327 if (uFlags
& LVNI_FOCUSED
)
7328 uMask
|= LVIS_FOCUSED
;
7330 if (uFlags
& LVNI_SELECTED
)
7331 uMask
|= LVIS_SELECTED
;
7333 /* if we're asked for the focused item, that's only one,
7334 * so it's worth optimizing */
7335 if (uFlags
& LVNI_FOCUSED
)
7337 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7338 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7341 if (uFlags
& LVNI_ABOVE
)
7343 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7348 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7354 /* Special case for autoarrange - move 'til the top of a list */
7355 if (is_autoarrange(infoPtr
))
7357 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7358 while (nItem
- nCountPerRow
>= 0)
7360 nItem
-= nCountPerRow
;
7361 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7366 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7367 lvFindInfo
.vkDirection
= VK_UP
;
7368 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7369 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7371 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7376 else if (uFlags
& LVNI_BELOW
)
7378 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7380 while (nItem
< infoPtr
->nItemCount
)
7383 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7389 /* Special case for autoarrange - move 'til the bottom of a list */
7390 if (is_autoarrange(infoPtr
))
7392 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7393 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7395 nItem
+= nCountPerRow
;
7396 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7401 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7402 lvFindInfo
.vkDirection
= VK_DOWN
;
7403 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7404 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7406 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7411 else if (uFlags
& LVNI_TOLEFT
)
7413 if (infoPtr
->uView
== LV_VIEW_LIST
)
7415 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7416 while (nItem
- nCountPerColumn
>= 0)
7418 nItem
-= nCountPerColumn
;
7419 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7423 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7425 /* Special case for autoarrange - move 'til the beginning of a row */
7426 if (is_autoarrange(infoPtr
))
7428 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7429 while (nItem
% nCountPerRow
> 0)
7432 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7437 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7438 lvFindInfo
.vkDirection
= VK_LEFT
;
7439 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7440 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7442 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7447 else if (uFlags
& LVNI_TORIGHT
)
7449 if (infoPtr
->uView
== LV_VIEW_LIST
)
7451 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7452 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7454 nItem
+= nCountPerColumn
;
7455 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7459 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7461 /* Special case for autoarrange - move 'til the end of a row */
7462 if (is_autoarrange(infoPtr
))
7464 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7465 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7468 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7473 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7474 lvFindInfo
.vkDirection
= VK_RIGHT
;
7475 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7476 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7478 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7487 /* search by index */
7488 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7490 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7498 /* LISTVIEW_GetNumberOfWorkAreas */
7502 * Retrieves the origin coordinates when in icon or small icon display mode.
7505 * [I] infoPtr : valid pointer to the listview structure
7506 * [O] lpptOrigin : coordinate information
7511 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7513 INT nHorzPos
= 0, nVertPos
= 0;
7514 SCROLLINFO scrollInfo
;
7516 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7517 scrollInfo
.fMask
= SIF_POS
;
7519 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7520 nHorzPos
= scrollInfo
.nPos
;
7521 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7522 nVertPos
= scrollInfo
.nPos
;
7524 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7526 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7527 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7528 if (infoPtr
->uView
== LV_VIEW_LIST
)
7529 nHorzPos
*= infoPtr
->nItemWidth
;
7530 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7531 nVertPos
*= infoPtr
->nItemHeight
;
7533 lpptOrigin
->x
-= nHorzPos
;
7534 lpptOrigin
->y
-= nVertPos
;
7536 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7541 * Retrieves the width of a string.
7544 * [I] hwnd : window handle
7545 * [I] lpszText : text string to process
7546 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7549 * SUCCESS : string width (in pixels)
7552 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7557 if (is_text(lpszText
))
7559 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7560 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7561 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7564 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7566 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7567 SelectObject(hdc
, hOldFont
);
7568 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7570 return stringSize
.cx
;
7575 * Determines which listview item is located at the specified position.
7578 * [I] infoPtr : valid pointer to the listview structure
7579 * [IO] lpht : hit test information
7580 * [I] subitem : fill out iSubItem.
7581 * [I] select : return the index only if the hit selects the item
7584 * (mm 20001022): We must not allow iSubItem to be touched, for
7585 * an app might pass only a structure with space up to iItem!
7586 * (MS Office 97 does that for instance in the file open dialog)
7589 * SUCCESS : item index
7592 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7594 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7595 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7596 POINT Origin
, Position
, opt
;
7602 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7606 if (subitem
) lpht
->iSubItem
= 0;
7608 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7610 /* set whole list relation flags */
7611 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7613 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7614 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7615 lpht
->flags
|= LVHT_TOLEFT
;
7617 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7618 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7622 if (infoPtr
->rcList
.bottom
< opt
.y
)
7623 lpht
->flags
|= LVHT_BELOW
;
7627 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7628 lpht
->flags
|= LVHT_TOLEFT
;
7629 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7630 lpht
->flags
|= LVHT_TORIGHT
;
7632 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7633 lpht
->flags
|= LVHT_ABOVE
;
7634 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7635 lpht
->flags
|= LVHT_BELOW
;
7638 /* even if item is invalid try to find subitem */
7639 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7644 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7646 lpht
->iSubItem
= -1;
7647 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7649 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7651 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7657 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7659 /* if we're outside horizontal columns bounds there's nothing to test further */
7660 if (lpht
->iSubItem
== -1)
7663 lpht
->flags
= LVHT_NOWHERE
;
7668 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7669 if (lpht
->flags
) return -1;
7671 lpht
->flags
|= LVHT_NOWHERE
;
7673 /* first deal with the large items */
7674 rcSearch
.left
= lpht
->pt
.x
;
7675 rcSearch
.top
= lpht
->pt
.y
;
7676 rcSearch
.right
= rcSearch
.left
+ 1;
7677 rcSearch
.bottom
= rcSearch
.top
+ 1;
7679 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7680 iterator_next(&i
); /* go to first item in the sequence */
7682 iterator_destroy(&i
);
7684 TRACE("lpht->iItem=%d\n", iItem
);
7685 if (iItem
== -1) return -1;
7687 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7688 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7689 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7690 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7691 lvItem
.iItem
= iItem
;
7692 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7693 lvItem
.pszText
= szDispText
;
7694 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7695 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7696 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7698 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7699 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7700 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7702 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7703 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7705 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7707 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7710 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7711 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7715 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7716 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7718 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7719 if (!PtInRect(&rcBounds
, opt
)) return -1;
7721 /* That's a special case - row rectangle is used as item rectangle and
7722 returned flags contain all item parts. */
7723 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7725 if (PtInRect(&rcIcon
, opt
))
7726 lpht
->flags
|= LVHT_ONITEMICON
;
7727 else if (PtInRect(&rcLabel
, opt
))
7728 lpht
->flags
|= LVHT_ONITEMLABEL
;
7729 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7730 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7731 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7733 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7735 if (lpht
->flags
& LVHT_ONITEM
)
7736 lpht
->flags
&= ~LVHT_NOWHERE
;
7737 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7739 if (select
&& !is_fullrow
)
7741 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7743 /* get main item bounds */
7744 lvItem
.iSubItem
= 0;
7745 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7746 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7747 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7749 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7751 return lpht
->iItem
= iItem
;
7756 * Inserts a new item in the listview control.
7759 * [I] infoPtr : valid pointer to the listview structure
7760 * [I] lpLVItem : item information
7761 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7764 * SUCCESS : new item index
7767 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7774 BOOL is_sorted
, has_changed
;
7776 HWND hwndSelf
= infoPtr
->hwndSelf
;
7778 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7780 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7782 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7783 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7785 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7787 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7789 /* insert item in listview control data structure */
7790 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7791 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7793 /* link with id struct */
7794 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7796 lpID
->item
= hdpaSubItems
;
7797 lpID
->id
= get_next_itemid(infoPtr
);
7798 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7800 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7801 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7803 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7805 /* calculate new item index */
7812 while (i
< infoPtr
->nItemCount
)
7814 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7815 item_s
= DPA_GetPtr(hItem
, 0);
7817 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7818 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7820 if (cmpv
>= 0) break;
7826 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7828 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7829 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7830 if (nItem
== -1) goto fail
;
7831 infoPtr
->nItemCount
++;
7833 /* shift indices first so they don't get tangled */
7834 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7836 /* set the item attributes */
7837 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7839 /* full size structure expected - _WIN32IE >= 0x560 */
7842 else if (lpLVItem
->mask
& LVIF_INDENT
)
7844 /* indent member expected - _WIN32IE >= 0x300 */
7845 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7849 /* minimal structure expected */
7850 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7853 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7855 if (item
.mask
& LVIF_STATE
)
7857 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7858 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7859 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7863 item
.mask
|= LVIF_STATE
;
7864 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7865 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7869 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7871 /* make room for the position, if we are in the right mode */
7872 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7874 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7876 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7878 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7883 /* send LVN_INSERTITEM notification */
7884 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7886 nmlv
.lParam
= lpItem
->lParam
;
7887 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7888 if (!IsWindow(hwndSelf
))
7891 /* align items (set position of each item) */
7892 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7896 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7897 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7899 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7901 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7904 /* now is the invalidation fun */
7905 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7909 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7910 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7911 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7912 infoPtr
->nItemCount
--;
7914 DPA_DeletePtr(hdpaSubItems
, 0);
7915 DPA_Destroy (hdpaSubItems
);
7922 * Checks item visibility.
7925 * [I] infoPtr : valid pointer to the listview structure
7926 * [I] nFirst : item index to check for
7929 * Item visible : TRUE
7930 * Item invisible or failure : FALSE
7932 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7934 POINT Origin
, Position
;
7939 TRACE("nItem=%d\n", nItem
);
7941 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7943 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7944 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7945 rcItem
.left
= Position
.x
+ Origin
.x
;
7946 rcItem
.top
= Position
.y
+ Origin
.y
;
7947 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7948 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7950 hdc
= GetDC(infoPtr
->hwndSelf
);
7951 if (!hdc
) return FALSE
;
7952 ret
= RectVisible(hdc
, &rcItem
);
7953 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7960 * Redraws a range of items.
7963 * [I] infoPtr : valid pointer to the listview structure
7964 * [I] nFirst : first item
7965 * [I] nLast : last item
7971 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7975 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7976 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7979 for (i
= nFirst
; i
<= nLast
; i
++)
7980 LISTVIEW_InvalidateItem(infoPtr
, i
);
7987 * Scroll the content of a listview.
7990 * [I] infoPtr : valid pointer to the listview structure
7991 * [I] dx : horizontal scroll amount in pixels
7992 * [I] dy : vertical scroll amount in pixels
7999 * If the control is in report view (LV_VIEW_DETAILS) the control can
8000 * be scrolled only in line increments. "dy" will be rounded to the
8001 * nearest number of pixels that are a whole line. Ex: if line height
8002 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
8003 * is passed, then the scroll will be 0. (per MSDN 7/2002)
8005 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8007 switch(infoPtr
->uView
) {
8008 case LV_VIEW_DETAILS
:
8009 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
8010 dy
/= infoPtr
->nItemHeight
;
8013 if (dy
!= 0) return FALSE
;
8019 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8020 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8027 * Sets the background color.
8030 * [I] infoPtr : valid pointer to the listview structure
8031 * [I] color : background color
8037 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8039 TRACE("(color=%x)\n", color
);
8041 if(infoPtr
->clrBk
!= color
) {
8042 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8043 infoPtr
->clrBk
= color
;
8044 if (color
== CLR_NONE
)
8045 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8048 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8049 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8056 /* LISTVIEW_SetBkImage */
8058 /*** Helper for {Insert,Set}ColumnT *only* */
8059 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8060 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8062 if (lpColumn
->mask
& LVCF_FMT
)
8064 /* format member is valid */
8065 lphdi
->mask
|= HDI_FORMAT
;
8067 /* set text alignment (leftmost column must be left-aligned) */
8068 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8069 lphdi
->fmt
|= HDF_LEFT
;
8070 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8071 lphdi
->fmt
|= HDF_RIGHT
;
8072 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8073 lphdi
->fmt
|= HDF_CENTER
;
8075 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8076 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8078 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8080 lphdi
->fmt
|= HDF_IMAGE
;
8081 lphdi
->iImage
= I_IMAGECALLBACK
;
8084 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8085 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8088 if (lpColumn
->mask
& LVCF_WIDTH
)
8090 lphdi
->mask
|= HDI_WIDTH
;
8091 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8093 /* make it fill the remainder of the controls width */
8097 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8099 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8100 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8103 /* retrieve the layout of the header */
8104 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8105 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8107 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8110 lphdi
->cxy
= lpColumn
->cx
;
8113 if (lpColumn
->mask
& LVCF_TEXT
)
8115 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8116 lphdi
->fmt
|= HDF_STRING
;
8117 lphdi
->pszText
= lpColumn
->pszText
;
8118 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8121 if (lpColumn
->mask
& LVCF_IMAGE
)
8123 lphdi
->mask
|= HDI_IMAGE
;
8124 lphdi
->iImage
= lpColumn
->iImage
;
8127 if (lpColumn
->mask
& LVCF_ORDER
)
8129 lphdi
->mask
|= HDI_ORDER
;
8130 lphdi
->iOrder
= lpColumn
->iOrder
;
8137 * Inserts a new column.
8140 * [I] infoPtr : valid pointer to the listview structure
8141 * [I] nColumn : column index
8142 * [I] lpColumn : column information
8143 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8146 * SUCCESS : new column index
8149 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8150 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8152 COLUMN_INFO
*lpColumnInfo
;
8156 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8158 if (!lpColumn
|| nColumn
< 0) return -1;
8159 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8161 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8162 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8165 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8166 * (can be seen in SPY) otherwise column never gets added.
8168 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8169 hdi
.mask
|= HDI_WIDTH
;
8174 * when the iSubItem is available Windows copies it to the header lParam. It seems
8175 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8177 if (lpColumn
->mask
& LVCF_SUBITEM
)
8179 hdi
.mask
|= HDI_LPARAM
;
8180 hdi
.lParam
= lpColumn
->iSubItem
;
8183 /* create header if not present */
8184 LISTVIEW_CreateHeader(infoPtr
);
8185 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8186 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8188 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8191 /* insert item in header control */
8192 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8193 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8194 nColumn
, (LPARAM
)&hdi
);
8195 if (nNewColumn
== -1) return -1;
8196 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8198 /* create our own column info */
8199 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8200 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8202 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8203 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8204 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8207 /* now we have to actually adjust the data */
8208 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8210 SUBITEM_INFO
*lpSubItem
;
8216 item
.iSubItem
= nNewColumn
;
8217 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8218 item
.iImage
= I_IMAGECALLBACK
;
8219 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8221 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8223 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8224 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8226 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8227 if (lpSubItem
->iSubItem
>= nNewColumn
)
8228 lpSubItem
->iSubItem
++;
8231 /* add new subitem for each item */
8233 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8237 /* make space for the new column */
8238 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8239 LISTVIEW_UpdateItemSize(infoPtr
);
8244 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8247 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8255 * Sets the attributes of a header item.
8258 * [I] infoPtr : valid pointer to the listview structure
8259 * [I] nColumn : column index
8260 * [I] lpColumn : column attributes
8261 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8267 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8268 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8270 HDITEMW hdi
, hdiget
;
8273 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8275 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8277 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8278 if (lpColumn
->mask
& LVCF_FMT
)
8280 hdi
.mask
|= HDI_FORMAT
;
8281 hdiget
.mask
= HDI_FORMAT
;
8282 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8283 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8285 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8287 /* set header item attributes */
8288 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8289 if (!bResult
) return FALSE
;
8291 if (lpColumn
->mask
& LVCF_FMT
)
8293 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8294 INT oldFmt
= lpColumnInfo
->fmt
;
8296 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8297 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8299 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8303 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8304 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8311 * Sets the column order array
8314 * [I] infoPtr : valid pointer to the listview structure
8315 * [I] iCount : number of elements in column order array
8316 * [I] lpiArray : pointer to column order array
8322 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8324 if (!infoPtr
->hwndHeader
) return FALSE
;
8325 infoPtr
->colRectsDirty
= TRUE
;
8326 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8331 * Sets the width of a column
8334 * [I] infoPtr : valid pointer to the listview structure
8335 * [I] nColumn : column index
8336 * [I] cx : column width
8342 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8344 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8348 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8350 /* set column width only if in report or list mode */
8351 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8353 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8354 with _USEHEADER being the lowest */
8355 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8356 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8358 /* resize all columns if in LV_VIEW_LIST mode */
8359 if(infoPtr
->uView
== LV_VIEW_LIST
)
8361 infoPtr
->nItemWidth
= cx
;
8362 LISTVIEW_InvalidateList(infoPtr
);
8366 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8368 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8373 lvItem
.mask
= LVIF_TEXT
;
8375 lvItem
.iSubItem
= nColumn
;
8376 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8377 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8379 lvItem
.pszText
= szDispText
;
8380 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8381 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8382 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8384 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8385 max_cx
+= infoPtr
->iconSize
.cx
;
8386 max_cx
+= TRAILING_LABEL_PADDING
;
8389 /* autosize based on listview items width */
8390 if(cx
== LVSCW_AUTOSIZE
)
8392 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8394 /* if iCol is the last column make it fill the remainder of the controls width */
8395 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8400 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8401 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8403 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8407 /* Despite what the MS docs say, if this is not the last
8408 column, then MS resizes the column to the width of the
8409 largest text string in the column, including headers
8410 and items. This is different from LVSCW_AUTOSIZE in that
8411 LVSCW_AUTOSIZE ignores the header string length. */
8414 /* retrieve header text */
8415 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8416 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8417 hdi
.pszText
= szDispText
;
8418 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8420 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8421 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8422 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8423 INT bitmap_margin
= 0;
8426 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8427 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8429 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8430 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8432 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8434 INT icon_cx
, icon_cy
;
8436 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8437 cx
+= icon_cx
+ 2*bitmap_margin
;
8439 else if (hdi
.fmt
& HDF_BITMAP
)
8443 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8444 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8447 SelectObject(hdc
, old_font
);
8448 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8450 cx
= max (cx
, max_cx
);
8454 if (cx
< 0) return FALSE
;
8456 /* call header to update the column change */
8457 hdi
.mask
= HDI_WIDTH
;
8458 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8459 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8460 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8464 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8467 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8470 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8472 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8473 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8476 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8477 ILC_COLOR
| ILC_MASK
, 2, 2);
8478 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8479 hdc
= CreateCompatibleDC(hdc_wnd
);
8480 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8481 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8482 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8484 SetRect(&rc
, 0, 0, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8485 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8486 FillRect(hdc
, &rc
, hbr_white
);
8487 InflateRect(&rc
, -2, -2);
8488 FillRect(hdc
, &rc
, hbr_black
);
8490 SelectObject(hdc
, hbm_im
);
8491 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8492 SelectObject(hdc
, hbm_orig
);
8493 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8495 SelectObject(hdc
, hbm_im
);
8496 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8497 SelectObject(hdc
, hbm_orig
);
8498 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8500 DeleteObject(hbm_mask
);
8501 DeleteObject(hbm_im
);
8509 * Sets the extended listview style.
8512 * [I] infoPtr : valid pointer to the listview structure
8514 * [I] dwStyle : style
8517 * SUCCESS : previous style
8520 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8522 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8524 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8528 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8530 infoPtr
->dwLvExStyle
= ex_style
;
8532 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8534 HIMAGELIST himl
= 0;
8535 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8538 item
.mask
= LVIF_STATE
;
8539 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8540 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8541 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8543 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8544 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8545 ImageList_Destroy(infoPtr
->himlState
);
8547 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8548 /* checkbox list replaces previous custom list or... */
8549 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8550 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8551 /* ...previous was checkbox list */
8552 (old_ex_style
& LVS_EX_CHECKBOXES
))
8553 ImageList_Destroy(himl
);
8556 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8560 /* if not already created */
8561 LISTVIEW_CreateHeader(infoPtr
);
8563 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8564 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8565 style
|= HDS_DRAGDROP
;
8567 style
&= ~HDS_DRAGDROP
;
8568 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8571 /* GRIDLINES adds decoration at top so changes sizes */
8572 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8574 LISTVIEW_CreateHeader(infoPtr
);
8575 LISTVIEW_UpdateSize(infoPtr
);
8578 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8580 LISTVIEW_CreateHeader(infoPtr
);
8583 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8585 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8586 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8589 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8591 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8592 LISTVIEW_CreateHeader(infoPtr
);
8594 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8595 LISTVIEW_UpdateSize(infoPtr
);
8596 LISTVIEW_UpdateScroll(infoPtr
);
8599 LISTVIEW_InvalidateList(infoPtr
);
8600 return old_ex_style
;
8605 * Sets the new hot cursor used during hot tracking and hover selection.
8608 * [I] infoPtr : valid pointer to the listview structure
8609 * [I] hCursor : the new hot cursor handle
8612 * Returns the previous hot cursor
8614 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8616 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8618 infoPtr
->hHotCursor
= hCursor
;
8626 * Sets the hot item index.
8629 * [I] infoPtr : valid pointer to the listview structure
8630 * [I] iIndex : index
8633 * SUCCESS : previous hot item index
8634 * FAILURE : -1 (no hot item)
8636 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8638 INT iOldIndex
= infoPtr
->nHotItem
;
8640 infoPtr
->nHotItem
= iIndex
;
8648 * Sets the amount of time the cursor must hover over an item before it is selected.
8651 * [I] infoPtr : valid pointer to the listview structure
8652 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8655 * Returns the previous hover time
8657 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8659 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8661 infoPtr
->dwHoverTime
= dwHoverTime
;
8663 return oldHoverTime
;
8668 * Sets spacing for icons of LVS_ICON style.
8671 * [I] infoPtr : valid pointer to the listview structure
8672 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8673 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8676 * MAKELONG(oldcx, oldcy)
8678 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8680 INT iconWidth
= 0, iconHeight
= 0;
8681 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8683 TRACE("requested=(%d,%d)\n", cx
, cy
);
8685 /* set to defaults, if instructed to */
8686 if (cx
== -1 && cy
== -1)
8688 infoPtr
->autoSpacing
= TRUE
;
8689 if (infoPtr
->himlNormal
)
8690 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8691 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8692 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8695 infoPtr
->autoSpacing
= FALSE
;
8697 /* if 0 then keep width */
8699 infoPtr
->iconSpacing
.cx
= cx
;
8701 /* if 0 then keep height */
8703 infoPtr
->iconSpacing
.cy
= cy
;
8705 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8706 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8707 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8708 infoPtr
->ntmHeight
);
8710 /* these depend on the iconSpacing */
8711 LISTVIEW_UpdateItemSize(infoPtr
);
8716 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8720 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8727 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8728 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8737 * [I] infoPtr : valid pointer to the listview structure
8738 * [I] nType : image list type
8739 * [I] himl : image list handle
8742 * SUCCESS : old image list
8745 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8747 INT oldHeight
= infoPtr
->nItemHeight
;
8748 HIMAGELIST himlOld
= 0;
8750 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8755 himlOld
= infoPtr
->himlNormal
;
8756 infoPtr
->himlNormal
= himl
;
8757 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8758 if (infoPtr
->autoSpacing
)
8759 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8763 himlOld
= infoPtr
->himlSmall
;
8764 infoPtr
->himlSmall
= himl
;
8765 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8766 if (infoPtr
->hwndHeader
)
8767 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8771 himlOld
= infoPtr
->himlState
;
8772 infoPtr
->himlState
= himl
;
8773 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8774 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8778 ERR("Unknown icon type=%d\n", nType
);
8782 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8783 if (infoPtr
->nItemHeight
!= oldHeight
)
8784 LISTVIEW_UpdateScroll(infoPtr
);
8791 * Preallocates memory (does *not* set the actual count of items !)
8794 * [I] infoPtr : valid pointer to the listview structure
8795 * [I] nItems : item count (projected number of items to allocate)
8796 * [I] dwFlags : update flags
8802 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8804 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8806 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8808 INT nOldCount
= infoPtr
->nItemCount
;
8809 infoPtr
->nItemCount
= nItems
;
8811 if (nItems
< nOldCount
)
8813 RANGE range
= { nItems
, nOldCount
};
8814 ranges_del(infoPtr
->selectionRanges
, range
);
8815 if (infoPtr
->nFocusedItem
>= nItems
)
8817 LISTVIEW_SetItemFocus(infoPtr
, -1);
8818 SetRectEmpty(&infoPtr
->rcFocus
);
8822 LISTVIEW_UpdateScroll(infoPtr
);
8824 /* the flags are valid only in ownerdata report and list modes */
8825 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8827 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8828 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8830 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8831 LISTVIEW_InvalidateList(infoPtr
);
8838 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8839 nFrom
= min(nOldCount
, nItems
);
8840 nTo
= max(nOldCount
, nItems
);
8842 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8844 SetRect(&rcErase
, 0, nFrom
* infoPtr
->nItemHeight
, infoPtr
->nItemWidth
,
8845 nTo
* infoPtr
->nItemHeight
);
8846 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8847 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8848 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8850 else /* LV_VIEW_LIST */
8852 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8854 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8855 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8856 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8857 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8858 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8859 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8860 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8862 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8864 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8865 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8866 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8867 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8868 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8874 /* According to MSDN for non-LVS_OWNERDATA this is just
8875 * a performance issue. The control allocates its internal
8876 * data structures for the number of items specified. It
8877 * cuts down on the number of memory allocations. Therefore
8878 * we will just issue a WARN here
8880 WARN("for non-ownerdata performance option not implemented.\n");
8888 * Sets the position of an item.
8891 * [I] infoPtr : valid pointer to the listview structure
8892 * [I] nItem : item index
8893 * [I] pt : coordinate
8899 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8903 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8905 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8906 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8909 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8911 /* This point value seems to be an undocumented feature.
8912 * The best guess is that it means either at the origin,
8913 * or at true beginning of the list. I will assume the origin. */
8914 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8917 if (infoPtr
->uView
== LV_VIEW_ICON
)
8919 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8920 Pt
.y
-= ICON_TOP_PADDING
;
8925 infoPtr
->bAutoarrange
= FALSE
;
8927 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8932 * Sets the state of one or many items.
8935 * [I] infoPtr : valid pointer to the listview structure
8936 * [I] nItem : item index
8937 * [I] item : item or subitem info
8943 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8948 if (!item
) return FALSE
;
8950 lvItem
.iItem
= nItem
;
8951 lvItem
.iSubItem
= 0;
8952 lvItem
.mask
= LVIF_STATE
;
8953 lvItem
.state
= item
->state
;
8954 lvItem
.stateMask
= item
->stateMask
;
8955 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8962 /* special case optimization for recurring attempt to deselect all */
8963 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8966 /* select all isn't allowed in LVS_SINGLESEL */
8967 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8970 /* focus all isn't allowed */
8971 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8973 notify
= infoPtr
->bDoChangeNotify
;
8974 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8976 infoPtr
->bDoChangeNotify
= FALSE
;
8977 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8978 oldstate
|= LVIS_SELECTED
;
8979 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
8982 /* apply to all items */
8983 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8984 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
8986 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8990 infoPtr
->bDoChangeNotify
= notify
;
8994 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
8995 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
8996 nmlv
.uChanged
= LVIF_STATE
;
8997 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
9000 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
9004 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9011 * Sets the text of an item or subitem.
9014 * [I] hwnd : window handle
9015 * [I] nItem : item index
9016 * [I] lpLVItem : item or subitem info
9017 * [I] isW : TRUE if input is Unicode
9023 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9027 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9028 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9030 lvItem
.iItem
= nItem
;
9031 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9032 lvItem
.mask
= LVIF_TEXT
;
9033 lvItem
.pszText
= lpLVItem
->pszText
;
9034 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9036 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9038 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9043 * Set item index that marks the start of a multiple selection.
9046 * [I] infoPtr : valid pointer to the listview structure
9047 * [I] nIndex : index
9050 * Index number or -1 if there is no selection mark.
9052 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9054 INT nOldIndex
= infoPtr
->nSelectionMark
;
9056 TRACE("(nIndex=%d)\n", nIndex
);
9058 infoPtr
->nSelectionMark
= nIndex
;
9065 * Sets the text background color.
9068 * [I] infoPtr : valid pointer to the listview structure
9069 * [I] color : text background color
9075 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9077 TRACE("(color=%x)\n", color
);
9079 infoPtr
->clrTextBk
= color
;
9085 * Sets the text foreground color.
9088 * [I] infoPtr : valid pointer to the listview structure
9089 * [I] color : text color
9095 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9097 TRACE("(color=%x)\n", color
);
9099 infoPtr
->clrText
= color
;
9105 * Sets new ToolTip window to ListView control.
9108 * [I] infoPtr : valid pointer to the listview structure
9109 * [I] hwndNewToolTip : handle to new ToolTip
9114 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9116 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9117 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9118 return hwndOldToolTip
;
9123 * sets the Unicode character format flag for the control
9125 * [I] infoPtr :valid pointer to the listview structure
9126 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9129 * Old Unicode Format
9131 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9133 SHORT rc
= infoPtr
->notifyFormat
;
9134 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9135 return rc
== NFR_UNICODE
;
9140 * sets the control view mode
9142 * [I] infoPtr :valid pointer to the listview structure
9143 * [I] nView :new view mode value
9149 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9153 if (infoPtr
->uView
== nView
) return 1;
9155 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9156 if (nView
== LV_VIEW_TILE
)
9158 FIXME("View LV_VIEW_TILE unimplemented\n");
9162 infoPtr
->uView
= nView
;
9164 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9165 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9167 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9168 SetRectEmpty(&infoPtr
->rcFocus
);
9170 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9171 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9176 case LV_VIEW_SMALLICON
:
9177 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9179 case LV_VIEW_DETAILS
:
9184 LISTVIEW_CreateHeader( infoPtr
);
9186 hl
.prc
= &infoPtr
->rcList
;
9188 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9189 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9190 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9197 LISTVIEW_UpdateItemSize(infoPtr
);
9198 LISTVIEW_UpdateSize(infoPtr
);
9199 LISTVIEW_UpdateScroll(infoPtr
);
9200 LISTVIEW_InvalidateList(infoPtr
);
9202 TRACE("nView=%d\n", nView
);
9207 /* LISTVIEW_SetWorkAreas */
9211 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9214 * [I] first : pointer to first ITEM_INFO to compare
9215 * [I] second : pointer to second ITEM_INFO to compare
9216 * [I] lParam : HWND of control
9219 * if first comes before second : negative
9220 * if first comes after second : positive
9221 * if first and second are equivalent : zero
9223 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9225 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9226 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9227 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9229 /* Forward the call to the client defined callback */
9230 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9235 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9238 * [I] first : pointer to first ITEM_INFO to compare
9239 * [I] second : pointer to second ITEM_INFO to compare
9240 * [I] lParam : HWND of control
9243 * if first comes before second : negative
9244 * if first comes after second : positive
9245 * if first and second are equivalent : zero
9247 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9249 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9250 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9251 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9253 /* Forward the call to the client defined callback */
9254 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9259 * Sorts the listview items.
9262 * [I] infoPtr : valid pointer to the listview structure
9263 * [I] pfnCompare : application-defined value
9264 * [I] lParamSort : pointer to comparison callback
9265 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9271 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9272 LPARAM lParamSort
, BOOL IsEx
)
9276 LPVOID selectionMarkItem
= NULL
;
9277 LPVOID focusedItem
= NULL
;
9280 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9282 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9284 if (!pfnCompare
) return FALSE
;
9285 if (!infoPtr
->hdpaItems
) return FALSE
;
9287 /* if there are 0 or 1 items, there is no need to sort */
9288 if (infoPtr
->nItemCount
< 2) return TRUE
;
9290 /* clear selection */
9291 ranges_clear(infoPtr
->selectionRanges
);
9293 /* save selection mark and focused item */
9294 if (infoPtr
->nSelectionMark
>= 0)
9295 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9296 if (infoPtr
->nFocusedItem
>= 0)
9297 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9299 infoPtr
->pfnCompare
= pfnCompare
;
9300 infoPtr
->lParamSort
= lParamSort
;
9302 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9304 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9306 /* restore selection ranges */
9307 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9309 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9310 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9312 if (lpItem
->state
& LVIS_SELECTED
)
9313 ranges_additem(infoPtr
->selectionRanges
, i
);
9315 /* restore selection mark and focused item */
9316 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9317 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9319 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9321 /* refresh the display */
9322 LISTVIEW_InvalidateList(infoPtr
);
9328 * Update theme handle after a theme change.
9331 * [I] infoPtr : valid pointer to the listview structure
9335 * FAILURE : something else
9337 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9339 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9340 CloseThemeData(theme
);
9341 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9347 * Updates an items or rearranges the listview control.
9350 * [I] infoPtr : valid pointer to the listview structure
9351 * [I] nItem : item index
9357 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9359 TRACE("(nItem=%d)\n", nItem
);
9361 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9363 /* rearrange with default alignment style */
9364 if (is_autoarrange(infoPtr
))
9365 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9367 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9374 * Draw the track line at the place defined in the infoPtr structure.
9375 * The line is drawn with a XOR pen so drawing the line for the second time
9376 * in the same place erases the line.
9379 * [I] infoPtr : valid pointer to the listview structure
9385 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9389 if (infoPtr
->xTrackLine
== -1)
9392 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9394 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9395 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9396 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9402 * Called when an edit control should be displayed. This function is called after
9403 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9406 * [I] hwnd : Handle to the listview
9407 * [I] uMsg : WM_TIMER (ignored)
9408 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9409 * [I] dwTimer : The elapsed time (ignored)
9414 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9416 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9417 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9419 KillTimer(hwnd
, idEvent
);
9420 editItem
->fEnabled
= FALSE
;
9421 /* check if the item is still selected */
9422 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9423 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9428 * Creates the listview control - the WM_NCCREATE phase.
9431 * [I] hwnd : window handle
9432 * [I] lpcs : the create parameters
9438 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9440 LISTVIEW_INFO
*infoPtr
;
9443 TRACE("(lpcs=%p)\n", lpcs
);
9445 /* initialize info pointer */
9446 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9447 if (!infoPtr
) return FALSE
;
9449 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9451 infoPtr
->hwndSelf
= hwnd
;
9452 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9453 map_style_view(infoPtr
);
9454 /* determine the type of structures to use */
9455 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9456 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9458 /* initialize color information */
9459 infoPtr
->clrBk
= CLR_NONE
;
9460 infoPtr
->clrText
= CLR_DEFAULT
;
9461 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9462 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9464 /* set default values */
9465 infoPtr
->nFocusedItem
= -1;
9466 infoPtr
->nSelectionMark
= -1;
9467 infoPtr
->nHotItem
= -1;
9468 infoPtr
->redraw
= TRUE
;
9469 infoPtr
->bNoItemMetrics
= TRUE
;
9470 infoPtr
->bDoChangeNotify
= TRUE
;
9471 infoPtr
->autoSpacing
= TRUE
;
9472 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9473 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9474 infoPtr
->nEditLabelItem
= -1;
9475 infoPtr
->nLButtonDownItem
= -1;
9476 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9477 infoPtr
->cWheelRemainder
= 0;
9478 infoPtr
->nMeasureItemHeight
= 0;
9479 infoPtr
->xTrackLine
= -1; /* no track line */
9480 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9481 infoPtr
->iVersion
= COMCTL32_VERSION
;
9482 infoPtr
->colRectsDirty
= FALSE
;
9484 /* get default font (icon title) */
9485 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9486 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9487 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9488 LISTVIEW_SaveTextMetrics(infoPtr
);
9490 /* allocate memory for the data structure */
9491 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9492 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9493 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9494 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9495 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9496 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9500 DestroyWindow(infoPtr
->hwndHeader
);
9501 ranges_destroy(infoPtr
->selectionRanges
);
9502 DPA_Destroy(infoPtr
->hdpaItems
);
9503 DPA_Destroy(infoPtr
->hdpaItemIds
);
9504 DPA_Destroy(infoPtr
->hdpaPosX
);
9505 DPA_Destroy(infoPtr
->hdpaPosY
);
9506 DPA_Destroy(infoPtr
->hdpaColumns
);
9513 * Creates the listview control - the WM_CREATE phase. Most of the data is
9514 * already set up in LISTVIEW_NCCreate
9517 * [I] hwnd : window handle
9518 * [I] lpcs : the create parameters
9524 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9526 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9528 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9530 infoPtr
->dwStyle
= lpcs
->style
;
9531 map_style_view(infoPtr
);
9533 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9534 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9535 /* on error defaulting to ANSI notifications */
9536 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9537 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9539 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9541 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9544 infoPtr
->hwndHeader
= 0;
9546 /* init item size to avoid division by 0 */
9547 LISTVIEW_UpdateItemSize (infoPtr
);
9548 LISTVIEW_UpdateSize (infoPtr
);
9550 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9552 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9554 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9556 LISTVIEW_UpdateScroll(infoPtr
);
9557 /* send WM_MEASUREITEM notification */
9558 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9561 OpenThemeData(hwnd
, themeClass
);
9563 /* initialize the icon sizes */
9564 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9565 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9571 * Destroys the listview control.
9574 * [I] infoPtr : valid pointer to the listview structure
9580 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9582 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9583 CloseThemeData(theme
);
9585 /* delete all items */
9586 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9593 * Enables the listview control.
9596 * [I] infoPtr : valid pointer to the listview structure
9597 * [I] bEnable : specifies whether to enable or disable the window
9603 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9605 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9606 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9612 * Erases the background of the listview control.
9615 * [I] infoPtr : valid pointer to the listview structure
9616 * [I] hdc : device context handle
9622 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9626 TRACE("(hdc=%p)\n", hdc
);
9628 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9630 if (infoPtr
->clrBk
== CLR_NONE
)
9632 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9633 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9634 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9636 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9639 /* for double buffered controls we need to do this during refresh */
9640 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9642 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9648 * Helper function for LISTVIEW_[HV]Scroll *only*.
9649 * Performs vertical/horizontal scrolling by a give amount.
9652 * [I] infoPtr : valid pointer to the listview structure
9653 * [I] dx : amount of horizontal scroll
9654 * [I] dy : amount of vertical scroll
9656 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9658 /* now we can scroll the list */
9659 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9660 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9661 /* if we have focus, adjust rect */
9662 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9663 UpdateWindow(infoPtr
->hwndSelf
);
9668 * Performs vertical scrolling.
9671 * [I] infoPtr : valid pointer to the listview structure
9672 * [I] nScrollCode : scroll code
9673 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9674 * [I] hScrollWnd : scrollbar control window handle
9680 * SB_LINEUP/SB_LINEDOWN:
9681 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9682 * for LVS_REPORT is 1 line
9683 * for LVS_LIST cannot occur
9686 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9689 INT nOldScrollPos
, nNewScrollPos
;
9690 SCROLLINFO scrollInfo
;
9693 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9694 debugscrollcode(nScrollCode
), nScrollDiff
);
9696 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9698 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9699 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9701 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9703 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9705 nOldScrollPos
= scrollInfo
.nPos
;
9706 switch (nScrollCode
)
9712 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9716 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9720 nScrollDiff
= -scrollInfo
.nPage
;
9724 nScrollDiff
= scrollInfo
.nPage
;
9727 case SB_THUMBPOSITION
:
9729 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9736 /* quit right away if pos isn't changing */
9737 if (nScrollDiff
== 0) return 0;
9739 /* calculate new position, and handle overflows */
9740 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9741 if (nScrollDiff
> 0) {
9742 if (nNewScrollPos
< nOldScrollPos
||
9743 nNewScrollPos
> scrollInfo
.nMax
)
9744 nNewScrollPos
= scrollInfo
.nMax
;
9746 if (nNewScrollPos
> nOldScrollPos
||
9747 nNewScrollPos
< scrollInfo
.nMin
)
9748 nNewScrollPos
= scrollInfo
.nMin
;
9751 /* set the new position, and reread in case it changed */
9752 scrollInfo
.fMask
= SIF_POS
;
9753 scrollInfo
.nPos
= nNewScrollPos
;
9754 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9756 /* carry on only if it really changed */
9757 if (nNewScrollPos
== nOldScrollPos
) return 0;
9759 /* now adjust to client coordinates */
9760 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9761 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9763 /* and scroll the window */
9764 scroll_list(infoPtr
, 0, nScrollDiff
);
9771 * Performs horizontal scrolling.
9774 * [I] infoPtr : valid pointer to the listview structure
9775 * [I] nScrollCode : scroll code
9776 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9777 * [I] hScrollWnd : scrollbar control window handle
9783 * SB_LINELEFT/SB_LINERIGHT:
9784 * for LVS_ICON, LVS_SMALLICON 1 pixel
9785 * for LVS_REPORT is 1 pixel
9786 * for LVS_LIST is 1 column --> which is a 1 because the
9787 * scroll is based on columns not pixels
9790 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9793 INT nOldScrollPos
, nNewScrollPos
;
9794 SCROLLINFO scrollInfo
;
9797 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9798 debugscrollcode(nScrollCode
), nScrollDiff
);
9800 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9802 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9803 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9805 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9807 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9809 nOldScrollPos
= scrollInfo
.nPos
;
9811 switch (nScrollCode
)
9817 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9821 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9825 nScrollDiff
= -scrollInfo
.nPage
;
9829 nScrollDiff
= scrollInfo
.nPage
;
9832 case SB_THUMBPOSITION
:
9834 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9841 /* quit right away if pos isn't changing */
9842 if (nScrollDiff
== 0) return 0;
9844 /* calculate new position, and handle overflows */
9845 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9846 if (nScrollDiff
> 0) {
9847 if (nNewScrollPos
< nOldScrollPos
||
9848 nNewScrollPos
> scrollInfo
.nMax
)
9849 nNewScrollPos
= scrollInfo
.nMax
;
9851 if (nNewScrollPos
> nOldScrollPos
||
9852 nNewScrollPos
< scrollInfo
.nMin
)
9853 nNewScrollPos
= scrollInfo
.nMin
;
9856 /* set the new position, and reread in case it changed */
9857 scrollInfo
.fMask
= SIF_POS
;
9858 scrollInfo
.nPos
= nNewScrollPos
;
9859 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9861 /* carry on only if it really changed */
9862 if (nNewScrollPos
== nOldScrollPos
) return 0;
9864 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9866 /* now adjust to client coordinates */
9867 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9868 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9870 /* and scroll the window */
9871 scroll_list(infoPtr
, nScrollDiff
, 0);
9876 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9878 UINT pulScrollLines
= 3;
9880 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9882 switch(infoPtr
->uView
)
9885 case LV_VIEW_SMALLICON
:
9887 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9888 * should be fixed in the future.
9890 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9891 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9894 case LV_VIEW_DETAILS
:
9895 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9897 /* if scrolling changes direction, ignore left overs */
9898 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9899 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9900 infoPtr
->cWheelRemainder
+= wheelDelta
;
9902 infoPtr
->cWheelRemainder
= wheelDelta
;
9903 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9906 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9907 cLineScroll
= pulScrollLines
* (float)infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9908 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
9909 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9914 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9925 * [I] infoPtr : valid pointer to the listview structure
9926 * [I] nVirtualKey : virtual key
9927 * [I] lKeyData : key data
9932 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9934 HWND hwndSelf
= infoPtr
->hwndSelf
;
9936 NMLVKEYDOWN nmKeyDown
;
9938 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9940 /* send LVN_KEYDOWN notification */
9941 nmKeyDown
.wVKey
= nVirtualKey
;
9942 nmKeyDown
.flags
= 0;
9943 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9944 if (!IsWindow(hwndSelf
))
9947 switch (nVirtualKey
)
9950 nItem
= infoPtr
->nFocusedItem
;
9951 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9952 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9956 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9958 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9959 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9964 if (infoPtr
->nItemCount
> 0)
9969 if (infoPtr
->nItemCount
> 0)
9970 nItem
= infoPtr
->nItemCount
- 1;
9974 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9978 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9982 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9986 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9990 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9992 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9993 if (infoPtr
->nFocusedItem
== topidx
)
9994 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9999 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
10000 * LISTVIEW_GetCountPerRow(infoPtr
);
10001 if(nItem
< 0) nItem
= 0;
10005 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10007 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10008 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10009 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10010 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10012 nItem
= topidx
+ cnt
- 1;
10015 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10016 * LISTVIEW_GetCountPerRow(infoPtr
);
10017 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10021 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10022 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10032 * [I] infoPtr : valid pointer to the listview structure
10037 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10041 /* drop any left over scroll amount */
10042 infoPtr
->cWheelRemainder
= 0;
10044 /* if we did not have the focus, there's nothing more to do */
10045 if (!infoPtr
->bFocus
) return 0;
10047 /* send NM_KILLFOCUS notification */
10048 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10050 /* if we have a focus rectangle, get rid of it */
10051 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10053 /* if have a marquee selection, stop it */
10054 if (infoPtr
->bMarqueeSelect
)
10056 /* Remove the marquee rectangle and release our mouse capture */
10057 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10060 SetRectEmpty(&infoPtr
->marqueeRect
);
10062 infoPtr
->bMarqueeSelect
= FALSE
;
10063 infoPtr
->bScrolling
= FALSE
;
10064 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10067 /* set window focus flag */
10068 infoPtr
->bFocus
= FALSE
;
10070 /* invalidate the selected items before resetting focus flag */
10071 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10078 * Processes double click messages (left mouse button).
10081 * [I] infoPtr : valid pointer to the listview structure
10082 * [I] wKey : key flag
10083 * [I] x,y : mouse coordinate
10088 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10090 LVHITTESTINFO htInfo
;
10092 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10094 /* Cancel the item edition if any */
10095 if (infoPtr
->itemEdit
.fEnabled
)
10097 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10098 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10101 /* send NM_RELEASEDCAPTURE notification */
10102 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10107 /* send NM_DBLCLK notification */
10108 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10109 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10111 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10112 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10117 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10122 r
.top
= r
.bottom
= pt
.y
;
10123 r
.left
= r
.right
= pt
.x
;
10125 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10127 SetCapture(infoPtr
->hwndSelf
);
10131 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10133 if (msg
.message
== WM_MOUSEMOVE
)
10135 pt
.x
= (short)LOWORD(msg
.lParam
);
10136 pt
.y
= (short)HIWORD(msg
.lParam
);
10137 if (PtInRect(&r
, pt
))
10145 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10146 msg
.message
<= WM_RBUTTONDBLCLK
)
10151 DispatchMessageW(&msg
);
10154 if (GetCapture() != infoPtr
->hwndSelf
)
10165 * Processes mouse down messages (left mouse button).
10168 * infoPtr [I ] valid pointer to the listview structure
10169 * wKey [I ] key flag
10170 * x,y [I ] mouse coordinate
10175 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10177 LVHITTESTINFO lvHitTestInfo
;
10178 static BOOL bGroupSelect
= TRUE
;
10179 POINT pt
= { x
, y
};
10182 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10184 /* send NM_RELEASEDCAPTURE notification */
10185 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10187 /* set left button down flag and record the click position */
10188 infoPtr
->bLButtonDown
= TRUE
;
10189 infoPtr
->ptClickPos
= pt
;
10190 infoPtr
->bDragging
= FALSE
;
10191 infoPtr
->bMarqueeSelect
= FALSE
;
10192 infoPtr
->bScrolling
= FALSE
;
10194 lvHitTestInfo
.pt
.x
= x
;
10195 lvHitTestInfo
.pt
.y
= y
;
10197 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10198 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10199 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10201 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10203 toggle_checkbox_state(infoPtr
, nItem
);
10207 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10209 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10210 infoPtr
->nEditLabelItem
= nItem
;
10212 LISTVIEW_SetSelection(infoPtr
, nItem
);
10216 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10220 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10221 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10222 infoPtr
->nSelectionMark
= nItem
;
10228 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10229 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10231 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10232 infoPtr
->nSelectionMark
= nItem
;
10235 else if (wKey
& MK_CONTROL
)
10239 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10241 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10242 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10243 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10244 infoPtr
->nSelectionMark
= nItem
;
10246 else if (wKey
& MK_SHIFT
)
10248 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10252 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10254 infoPtr
->nEditLabelItem
= nItem
;
10255 infoPtr
->nLButtonDownItem
= nItem
;
10257 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10260 /* set selection (clears other pre-existing selections) */
10261 LISTVIEW_SetSelection(infoPtr
, nItem
);
10265 if (!infoPtr
->bFocus
)
10266 SetFocus(infoPtr
->hwndSelf
);
10268 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10269 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10273 if (!infoPtr
->bFocus
)
10274 SetFocus(infoPtr
->hwndSelf
);
10276 /* remove all selections */
10277 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10278 LISTVIEW_DeselectAll(infoPtr
);
10287 * Processes mouse up messages (left mouse button).
10290 * infoPtr [I ] valid pointer to the listview structure
10291 * wKey [I ] key flag
10292 * x,y [I ] mouse coordinate
10297 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10299 LVHITTESTINFO lvHitTestInfo
;
10301 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10303 if (!infoPtr
->bLButtonDown
) return 0;
10305 lvHitTestInfo
.pt
.x
= x
;
10306 lvHitTestInfo
.pt
.y
= y
;
10308 /* send NM_CLICK notification */
10309 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10310 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10312 /* set left button flag */
10313 infoPtr
->bLButtonDown
= FALSE
;
10315 /* set a single selection, reset others */
10316 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10317 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10318 infoPtr
->nLButtonDownItem
= -1;
10320 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10322 /* Remove the marquee rectangle and release our mouse capture */
10323 if (infoPtr
->bMarqueeSelect
)
10325 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10329 SetRectEmpty(&infoPtr
->marqueeRect
);
10330 SetRectEmpty(&infoPtr
->marqueeDrawRect
);
10332 infoPtr
->bDragging
= FALSE
;
10333 infoPtr
->bMarqueeSelect
= FALSE
;
10334 infoPtr
->bScrolling
= FALSE
;
10336 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10340 /* if we clicked on a selected item, edit the label */
10341 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10343 /* we want to make sure the user doesn't want to do a double click. So we will
10344 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10346 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10347 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10348 SetTimer(infoPtr
->hwndSelf
,
10349 (UINT_PTR
)&infoPtr
->itemEdit
,
10350 GetDoubleClickTime(),
10351 LISTVIEW_DelayedEditItem
);
10359 * Destroys the listview control (called after WM_DESTROY).
10362 * [I] infoPtr : valid pointer to the listview structure
10367 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10373 /* destroy data structure */
10374 DPA_Destroy(infoPtr
->hdpaItems
);
10375 DPA_Destroy(infoPtr
->hdpaItemIds
);
10376 DPA_Destroy(infoPtr
->hdpaPosX
);
10377 DPA_Destroy(infoPtr
->hdpaPosY
);
10379 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10380 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10381 DPA_Destroy(infoPtr
->hdpaColumns
);
10382 ranges_destroy(infoPtr
->selectionRanges
);
10384 /* destroy image lists */
10385 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10387 ImageList_Destroy(infoPtr
->himlNormal
);
10388 ImageList_Destroy(infoPtr
->himlSmall
);
10389 ImageList_Destroy(infoPtr
->himlState
);
10392 /* destroy font, bkgnd brush */
10393 infoPtr
->hFont
= 0;
10394 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10395 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10397 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10399 /* free listview info pointer*/
10407 * Handles notifications.
10410 * [I] infoPtr : valid pointer to the listview structure
10411 * [I] lpnmhdr : notification information
10416 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10420 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10422 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10424 /* remember: HDN_LAST < HDN_FIRST */
10425 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10426 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10428 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10430 switch (lpnmhdr
->code
)
10435 COLUMN_INFO
*lpColumnInfo
;
10439 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10442 /* remove the old line (if any) */
10443 LISTVIEW_DrawTrackLine(infoPtr
);
10445 /* compute & draw the new line */
10446 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10447 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10448 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10449 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10450 LISTVIEW_DrawTrackLine(infoPtr
);
10451 return notify_forward_header(infoPtr
, lpnmh
);
10454 case HDN_ENDTRACKA
:
10455 case HDN_ENDTRACKW
:
10456 /* remove the track line (if any) */
10457 LISTVIEW_DrawTrackLine(infoPtr
);
10458 infoPtr
->xTrackLine
= -1;
10459 return notify_forward_header(infoPtr
, lpnmh
);
10461 case HDN_BEGINDRAG
:
10462 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10463 return notify_forward_header(infoPtr
, lpnmh
);
10466 infoPtr
->colRectsDirty
= TRUE
;
10467 LISTVIEW_InvalidateList(infoPtr
);
10468 return notify_forward_header(infoPtr
, lpnmh
);
10470 case HDN_ITEMCHANGEDW
:
10471 case HDN_ITEMCHANGEDA
:
10473 COLUMN_INFO
*lpColumnInfo
;
10477 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10479 hdi
.mask
= HDI_WIDTH
;
10480 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10484 cxy
= lpnmh
->pitem
->cxy
;
10486 /* determine how much we change since the last know position */
10487 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10488 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10491 lpColumnInfo
->rcHeader
.right
+= dx
;
10493 hdi
.mask
= HDI_ORDER
;
10494 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10496 /* not the rightmost one */
10497 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10499 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10500 hdi
.iOrder
+ 1, 0);
10501 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10505 /* only needs to update the scrolls */
10506 infoPtr
->nItemWidth
+= dx
;
10507 LISTVIEW_UpdateScroll(infoPtr
);
10509 LISTVIEW_UpdateItemSize(infoPtr
);
10510 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10513 RECT rcCol
= lpColumnInfo
->rcHeader
;
10515 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10516 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10518 rcCol
.top
= infoPtr
->rcList
.top
;
10519 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10521 /* resizing left-aligned columns leaves most of the left side untouched */
10522 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10524 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10527 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10530 /* when shrinking the last column clear the now unused field */
10531 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10537 /* deal with right from rightmost column area */
10538 right
.left
= rcCol
.right
;
10539 right
.top
= rcCol
.top
;
10540 right
.bottom
= rcCol
.bottom
;
10541 right
.right
= infoPtr
->rcList
.right
;
10543 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10546 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10552 case HDN_ITEMCLICKW
:
10553 case HDN_ITEMCLICKA
:
10555 /* Handle sorting by Header Column */
10558 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10560 nmlv
.iSubItem
= lpnmh
->iItem
;
10561 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10562 return notify_forward_header(infoPtr
, lpnmh
);
10565 case HDN_DIVIDERDBLCLICKW
:
10566 case HDN_DIVIDERDBLCLICKA
:
10567 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10568 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10569 split needed for that */
10570 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10571 return notify_forward_header(infoPtr
, lpnmh
);
10578 * Paint non-client area of control.
10581 * [I] infoPtr : valid pointer to the listview structureof the sender
10582 * [I] region : update region
10585 * TRUE - frame was painted
10586 * FALSE - call default window proc
10588 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10590 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10594 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10595 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10598 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10600 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10602 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10603 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10604 if (region
!= (HRGN
)1)
10605 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10606 OffsetRect(&r
, -r
.left
, -r
.top
);
10608 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10609 OffsetRect(&r
, -r
.left
, -r
.top
);
10611 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10612 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10613 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10614 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10616 /* Call default proc to get the scrollbars etc. painted */
10617 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10624 * Determines the type of structure to use.
10627 * [I] infoPtr : valid pointer to the listview structureof the sender
10628 * [I] hwndFrom : listview window handle
10629 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10634 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10636 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10638 if (nCommand
== NF_REQUERY
)
10639 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10641 return infoPtr
->notifyFormat
;
10646 * Paints/Repaints the listview control. Internal use.
10649 * [I] infoPtr : valid pointer to the listview structure
10650 * [I] hdc : device context handle
10655 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10657 TRACE("(hdc=%p)\n", hdc
);
10659 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10661 infoPtr
->bNoItemMetrics
= FALSE
;
10662 LISTVIEW_UpdateItemSize(infoPtr
);
10663 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10664 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10665 LISTVIEW_UpdateScroll(infoPtr
);
10668 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10671 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10676 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10677 if (!hdc
) return 1;
10678 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10679 EndPaint(infoPtr
->hwndSelf
, &ps
);
10687 * Paints/Repaints the listview control, WM_PAINT handler.
10690 * [I] infoPtr : valid pointer to the listview structure
10691 * [I] hdc : device context handle
10696 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10698 TRACE("(hdc=%p)\n", hdc
);
10700 if (!is_redrawing(infoPtr
))
10701 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10703 return LISTVIEW_Paint(infoPtr
, hdc
);
10708 * Paints/Repaints the listview control.
10711 * [I] infoPtr : valid pointer to the listview structure
10712 * [I] hdc : device context handle
10713 * [I] options : drawing options
10718 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10720 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10722 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10725 if (options
& PRF_ERASEBKGND
)
10726 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10728 if (options
& PRF_CLIENT
)
10729 LISTVIEW_Paint(infoPtr
, hdc
);
10737 * Processes double click messages (right mouse button).
10740 * [I] infoPtr : valid pointer to the listview structure
10741 * [I] wKey : key flag
10742 * [I] x,y : mouse coordinate
10747 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10749 LVHITTESTINFO lvHitTestInfo
;
10751 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10753 /* send NM_RELEASEDCAPTURE notification */
10754 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10756 /* send NM_RDBLCLK notification */
10757 lvHitTestInfo
.pt
.x
= x
;
10758 lvHitTestInfo
.pt
.y
= y
;
10759 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10760 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10767 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10770 * [I] infoPtr : valid pointer to the listview structure
10771 * [I] wKey : key flag
10772 * [I] x, y : mouse coordinate
10777 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10782 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10784 /* send NM_RELEASEDCAPTURE notification */
10785 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10787 /* determine the index of the selected item */
10790 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10792 /* make sure the listview control window has the focus */
10793 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10795 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10797 LISTVIEW_SetItemFocus(infoPtr
, item
);
10798 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10799 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10800 LISTVIEW_SetSelection(infoPtr
, item
);
10803 LISTVIEW_DeselectAll(infoPtr
);
10805 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10807 if (ht
.iItem
!= -1)
10811 memset(&nmlv
, 0, sizeof(nmlv
));
10812 nmlv
.iItem
= ht
.iItem
;
10813 nmlv
.ptAction
= ht
.pt
;
10815 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10820 SetFocus(infoPtr
->hwndSelf
);
10824 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10826 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10828 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10829 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10830 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10842 * [I] infoPtr : valid pointer to the listview structure
10843 * [I] hwnd : window handle of window containing the cursor
10844 * [I] nHittest : hit-test code
10845 * [I] wMouseMsg : ideintifier of the mouse message
10848 * TRUE if cursor is set
10851 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10853 LVHITTESTINFO lvHitTestInfo
;
10855 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10857 if (!infoPtr
->hHotCursor
) goto forward
;
10859 GetCursorPos(&lvHitTestInfo
.pt
);
10860 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10862 SetCursor(infoPtr
->hHotCursor
);
10868 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10876 * [I] infoPtr : valid pointer to the listview structure
10877 * [I] hwndLoseFocus : handle of previously focused window
10882 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10884 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10886 /* if we have the focus already, there's nothing to do */
10887 if (infoPtr
->bFocus
) return 0;
10889 /* send NM_SETFOCUS notification */
10890 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10892 /* set window focus flag */
10893 infoPtr
->bFocus
= TRUE
;
10895 /* put the focus rect back on */
10896 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10898 /* redraw all visible selected items */
10899 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10909 * [I] infoPtr : valid pointer to the listview structure
10910 * [I] fRedraw : font handle
10911 * [I] fRedraw : redraw flag
10916 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10918 HFONT oldFont
= infoPtr
->hFont
;
10919 INT oldHeight
= infoPtr
->nItemHeight
;
10921 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10923 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10924 if (infoPtr
->hFont
== oldFont
) return 0;
10926 LISTVIEW_SaveTextMetrics(infoPtr
);
10928 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10930 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10932 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10933 LISTVIEW_UpdateSize(infoPtr
);
10934 LISTVIEW_UpdateScroll(infoPtr
);
10936 else if (infoPtr
->nItemHeight
!= oldHeight
)
10937 LISTVIEW_UpdateScroll(infoPtr
);
10939 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10946 * Message handling for WM_SETREDRAW.
10947 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10950 * [I] infoPtr : valid pointer to the listview structure
10951 * [I] redraw: state of redraw flag
10956 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL redraw
)
10958 TRACE("old=%d, new=%d\n", infoPtr
->redraw
, redraw
);
10960 if (infoPtr
->redraw
== !!redraw
)
10963 if (!(infoPtr
->redraw
= !!redraw
))
10966 if (is_autoarrange(infoPtr
))
10967 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10968 LISTVIEW_UpdateScroll(infoPtr
);
10970 /* despite what the WM_SETREDRAW docs says, apps expect us
10971 * to invalidate the listview here... stupid! */
10972 LISTVIEW_InvalidateList(infoPtr
);
10979 * Resizes the listview control. This function processes WM_SIZE
10980 * messages. At this time, the width and height are not used.
10983 * [I] infoPtr : valid pointer to the listview structure
10984 * [I] Width : new width
10985 * [I] Height : new height
10990 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10992 RECT rcOld
= infoPtr
->rcList
;
10994 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10996 LISTVIEW_UpdateSize(infoPtr
);
10997 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10999 /* do not bother with display related stuff if we're not redrawing */
11000 if (!is_redrawing(infoPtr
)) return 0;
11002 if (is_autoarrange(infoPtr
))
11003 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11005 LISTVIEW_UpdateScroll(infoPtr
);
11007 /* refresh all only for lists whose height changed significantly */
11008 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11009 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11010 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11011 LISTVIEW_InvalidateList(infoPtr
);
11018 * Sets the size information.
11021 * [I] infoPtr : valid pointer to the listview structure
11026 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11028 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11030 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11032 if (infoPtr
->uView
== LV_VIEW_LIST
)
11034 /* Apparently the "LIST" style is supposed to have the same
11035 * number of items in a column even if there is no scroll bar.
11036 * Since if a scroll bar already exists then the bottom is already
11037 * reduced, only reduce if the scroll bar does not currently exist.
11038 * The "2" is there to mimic the native control. I think it may be
11039 * related to either padding or edges. (GLA 7/2002)
11041 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11042 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11043 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11046 /* if control created invisible header isn't created */
11047 if (infoPtr
->hwndHeader
)
11052 hl
.prc
= &infoPtr
->rcList
;
11054 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11055 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11057 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11058 wp
.flags
|= SWP_SHOWWINDOW
;
11061 wp
.flags
|= SWP_HIDEWINDOW
;
11065 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11066 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11068 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11070 /* extra padding for grid */
11071 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11072 infoPtr
->rcList
.top
+= 2;
11074 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11079 * Processes WM_STYLECHANGED messages.
11082 * [I] infoPtr : valid pointer to the listview structure
11083 * [I] wStyleType : window style type (normal or extended)
11084 * [I] lpss : window style information
11089 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11090 const STYLESTRUCT
*lpss
)
11092 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11093 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11096 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11097 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11099 if (wStyleType
!= GWL_STYLE
) return 0;
11101 infoPtr
->dwStyle
= lpss
->styleNew
;
11103 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11104 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11105 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11107 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11108 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11109 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11111 if (uNewView
!= uOldView
)
11115 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11116 changing style updates current view only when view bits change. */
11117 map_style_view(infoPtr
);
11118 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11119 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11121 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11122 SetRectEmpty(&infoPtr
->rcFocus
);
11124 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11125 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11127 if (uNewView
== LVS_REPORT
)
11132 LISTVIEW_CreateHeader( infoPtr
);
11134 hl
.prc
= &infoPtr
->rcList
;
11136 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11137 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11138 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11139 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11142 LISTVIEW_UpdateItemSize(infoPtr
);
11145 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11147 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11149 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11151 /* Turn off the header control */
11152 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11153 TRACE("Hide header control, was 0x%08x\n", style
);
11154 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11156 /* Turn on the header control */
11157 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11159 TRACE("Show header control, was 0x%08x\n", style
);
11160 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11166 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11167 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11168 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11170 /* update the size of the client area */
11171 LISTVIEW_UpdateSize(infoPtr
);
11173 /* add scrollbars if needed */
11174 LISTVIEW_UpdateScroll(infoPtr
);
11176 /* invalidate client area + erase background */
11177 LISTVIEW_InvalidateList(infoPtr
);
11184 * Processes WM_STYLECHANGING messages.
11187 * [I] wStyleType : window style type (normal or extended)
11188 * [I0] lpss : window style information
11193 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11196 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11197 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11199 /* don't forward LVS_OWNERDATA only if not already set to */
11200 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11202 if (lpss
->styleOld
& LVS_OWNERDATA
)
11203 lpss
->styleNew
|= LVS_OWNERDATA
;
11205 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11213 * Processes WM_SHOWWINDOW messages.
11216 * [I] infoPtr : valid pointer to the listview structure
11217 * [I] bShown : window is being shown (FALSE when hidden)
11218 * [I] iStatus : window show status
11223 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11225 /* header delayed creation */
11226 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11228 LISTVIEW_CreateHeader(infoPtr
);
11230 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11231 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11234 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11239 * Processes CCM_GETVERSION messages.
11242 * [I] infoPtr : valid pointer to the listview structure
11247 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11249 return infoPtr
->iVersion
;
11254 * Processes CCM_SETVERSION messages.
11257 * [I] infoPtr : valid pointer to the listview structure
11258 * [I] iVersion : version to be set
11261 * -1 when requested version is greater than DLL version;
11262 * previous version otherwise
11264 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11266 INT iOldVersion
= infoPtr
->iVersion
;
11268 if (iVersion
> COMCTL32_VERSION
)
11271 infoPtr
->iVersion
= iVersion
;
11273 TRACE("new version %d\n", iVersion
);
11275 return iOldVersion
;
11280 * Window procedure of the listview control.
11283 static LRESULT WINAPI
11284 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11286 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11288 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11290 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11291 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11295 case LVM_APPROXIMATEVIEWRECT
:
11296 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11297 LOWORD(lParam
), HIWORD(lParam
));
11299 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11301 case LVM_CANCELEDITLABEL
:
11302 return LISTVIEW_CancelEditLabel(infoPtr
);
11304 case LVM_CREATEDRAGIMAGE
:
11305 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11307 case LVM_DELETEALLITEMS
:
11308 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11310 case LVM_DELETECOLUMN
:
11311 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11313 case LVM_DELETEITEM
:
11314 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11316 case LVM_EDITLABELA
:
11317 case LVM_EDITLABELW
:
11318 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11319 uMsg
== LVM_EDITLABELW
);
11320 /* case LVM_ENABLEGROUPVIEW: */
11322 case LVM_ENSUREVISIBLE
:
11323 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11325 case LVM_FINDITEMW
:
11326 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11328 case LVM_FINDITEMA
:
11329 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11331 case LVM_GETBKCOLOR
:
11332 return infoPtr
->clrBk
;
11334 /* case LVM_GETBKIMAGE: */
11336 case LVM_GETCALLBACKMASK
:
11337 return infoPtr
->uCallbackMask
;
11339 case LVM_GETCOLUMNA
:
11340 case LVM_GETCOLUMNW
:
11341 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11342 uMsg
== LVM_GETCOLUMNW
);
11344 case LVM_GETCOLUMNORDERARRAY
:
11345 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11347 case LVM_GETCOLUMNWIDTH
:
11348 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11350 case LVM_GETCOUNTPERPAGE
:
11351 return LISTVIEW_GetCountPerPage(infoPtr
);
11353 case LVM_GETEDITCONTROL
:
11354 return (LRESULT
)infoPtr
->hwndEdit
;
11356 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11357 return infoPtr
->dwLvExStyle
;
11359 /* case LVM_GETGROUPINFO: */
11361 /* case LVM_GETGROUPMETRICS: */
11363 case LVM_GETHEADER
:
11364 return (LRESULT
)infoPtr
->hwndHeader
;
11366 case LVM_GETHOTCURSOR
:
11367 return (LRESULT
)infoPtr
->hHotCursor
;
11369 case LVM_GETHOTITEM
:
11370 return infoPtr
->nHotItem
;
11372 case LVM_GETHOVERTIME
:
11373 return infoPtr
->dwHoverTime
;
11375 case LVM_GETIMAGELIST
:
11376 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11378 /* case LVM_GETINSERTMARK: */
11380 /* case LVM_GETINSERTMARKCOLOR: */
11382 /* case LVM_GETINSERTMARKRECT: */
11384 case LVM_GETISEARCHSTRINGA
:
11385 case LVM_GETISEARCHSTRINGW
:
11386 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11391 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11393 case LVM_GETITEMCOUNT
:
11394 return infoPtr
->nItemCount
;
11396 case LVM_GETITEMPOSITION
:
11397 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11399 case LVM_GETITEMRECT
:
11400 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11402 case LVM_GETITEMSPACING
:
11403 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11405 case LVM_GETITEMSTATE
:
11406 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11408 case LVM_GETITEMTEXTA
:
11409 case LVM_GETITEMTEXTW
:
11410 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11411 uMsg
== LVM_GETITEMTEXTW
);
11413 case LVM_GETNEXTITEM
:
11414 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11416 case LVM_GETNUMBEROFWORKAREAS
:
11417 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11420 case LVM_GETORIGIN
:
11421 if (!lParam
) return FALSE
;
11422 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11423 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11424 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11427 /* case LVM_GETOUTLINECOLOR: */
11429 /* case LVM_GETSELECTEDCOLUMN: */
11431 case LVM_GETSELECTEDCOUNT
:
11432 return LISTVIEW_GetSelectedCount(infoPtr
);
11434 case LVM_GETSELECTIONMARK
:
11435 return infoPtr
->nSelectionMark
;
11437 case LVM_GETSTRINGWIDTHA
:
11438 case LVM_GETSTRINGWIDTHW
:
11439 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11440 uMsg
== LVM_GETSTRINGWIDTHW
);
11442 case LVM_GETSUBITEMRECT
:
11443 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11445 case LVM_GETTEXTBKCOLOR
:
11446 return infoPtr
->clrTextBk
;
11448 case LVM_GETTEXTCOLOR
:
11449 return infoPtr
->clrText
;
11451 /* case LVM_GETTILEINFO: */
11453 /* case LVM_GETTILEVIEWINFO: */
11455 case LVM_GETTOOLTIPS
:
11456 if( !infoPtr
->hwndToolTip
)
11457 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11458 return (LRESULT
)infoPtr
->hwndToolTip
;
11460 case LVM_GETTOPINDEX
:
11461 return LISTVIEW_GetTopIndex(infoPtr
);
11463 case LVM_GETUNICODEFORMAT
:
11464 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11467 return infoPtr
->uView
;
11469 case LVM_GETVIEWRECT
:
11470 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11472 case LVM_GETWORKAREAS
:
11473 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11476 /* case LVM_HASGROUP: */
11479 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11481 case LVM_INSERTCOLUMNA
:
11482 case LVM_INSERTCOLUMNW
:
11483 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11484 uMsg
== LVM_INSERTCOLUMNW
);
11486 /* case LVM_INSERTGROUP: */
11488 /* case LVM_INSERTGROUPSORTED: */
11490 case LVM_INSERTITEMA
:
11491 case LVM_INSERTITEMW
:
11492 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11494 /* case LVM_INSERTMARKHITTEST: */
11496 /* case LVM_ISGROUPVIEWENABLED: */
11498 case LVM_ISITEMVISIBLE
:
11499 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11501 case LVM_MAPIDTOINDEX
:
11502 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11504 case LVM_MAPINDEXTOID
:
11505 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11507 /* case LVM_MOVEGROUP: */
11509 /* case LVM_MOVEITEMTOGROUP: */
11511 case LVM_REDRAWITEMS
:
11512 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11514 /* case LVM_REMOVEALLGROUPS: */
11516 /* case LVM_REMOVEGROUP: */
11519 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11521 case LVM_SETBKCOLOR
:
11522 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11524 /* case LVM_SETBKIMAGE: */
11526 case LVM_SETCALLBACKMASK
:
11527 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11530 case LVM_SETCOLUMNA
:
11531 case LVM_SETCOLUMNW
:
11532 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11533 uMsg
== LVM_SETCOLUMNW
);
11535 case LVM_SETCOLUMNORDERARRAY
:
11536 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11538 case LVM_SETCOLUMNWIDTH
:
11539 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11541 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11542 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11544 /* case LVM_SETGROUPINFO: */
11546 /* case LVM_SETGROUPMETRICS: */
11548 case LVM_SETHOTCURSOR
:
11549 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11551 case LVM_SETHOTITEM
:
11552 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11554 case LVM_SETHOVERTIME
:
11555 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11557 case LVM_SETICONSPACING
:
11559 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11560 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11562 case LVM_SETIMAGELIST
:
11563 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11565 /* case LVM_SETINFOTIP: */
11567 /* case LVM_SETINSERTMARK: */
11569 /* case LVM_SETINSERTMARKCOLOR: */
11574 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11575 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11578 case LVM_SETITEMCOUNT
:
11579 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11581 case LVM_SETITEMPOSITION
:
11584 pt
.x
= (short)LOWORD(lParam
);
11585 pt
.y
= (short)HIWORD(lParam
);
11586 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11589 case LVM_SETITEMPOSITION32
:
11590 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11592 case LVM_SETITEMSTATE
:
11593 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11595 case LVM_SETITEMTEXTA
:
11596 case LVM_SETITEMTEXTW
:
11597 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11598 uMsg
== LVM_SETITEMTEXTW
);
11600 /* case LVM_SETOUTLINECOLOR: */
11602 /* case LVM_SETSELECTEDCOLUMN: */
11604 case LVM_SETSELECTIONMARK
:
11605 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11607 case LVM_SETTEXTBKCOLOR
:
11608 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11610 case LVM_SETTEXTCOLOR
:
11611 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11613 /* case LVM_SETTILEINFO: */
11615 /* case LVM_SETTILEVIEWINFO: */
11617 /* case LVM_SETTILEWIDTH: */
11619 case LVM_SETTOOLTIPS
:
11620 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11622 case LVM_SETUNICODEFORMAT
:
11623 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11626 return LISTVIEW_SetView(infoPtr
, wParam
);
11628 /* case LVM_SETWORKAREAS: */
11630 /* case LVM_SORTGROUPS: */
11632 case LVM_SORTITEMS
:
11633 case LVM_SORTITEMSEX
:
11634 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11635 uMsg
== LVM_SORTITEMSEX
);
11636 case LVM_SUBITEMHITTEST
:
11637 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11640 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11642 case CCM_GETVERSION
:
11643 return LISTVIEW_GetVersion(infoPtr
);
11645 case CCM_SETVERSION
:
11646 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11649 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11652 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11655 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11658 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11661 return LISTVIEW_Destroy(infoPtr
);
11664 return LISTVIEW_Enable(infoPtr
);
11666 case WM_ERASEBKGND
:
11667 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11669 case WM_GETDLGCODE
:
11670 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11673 return (LRESULT
)infoPtr
->hFont
;
11676 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11679 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11682 return LISTVIEW_KillFocus(infoPtr
);
11684 case WM_LBUTTONDBLCLK
:
11685 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11687 case WM_LBUTTONDOWN
:
11688 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11691 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11694 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11696 case WM_MOUSEHOVER
:
11697 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11700 return LISTVIEW_NCDestroy(infoPtr
);
11703 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11706 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11708 case WM_NOTIFYFORMAT
:
11709 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11711 case WM_PRINTCLIENT
:
11712 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11715 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11717 case WM_RBUTTONDBLCLK
:
11718 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11720 case WM_RBUTTONDOWN
:
11721 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11724 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11727 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11730 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11733 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11735 case WM_SHOWWINDOW
:
11736 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11738 case WM_STYLECHANGED
:
11739 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11741 case WM_STYLECHANGING
:
11742 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11744 case WM_SYSCOLORCHANGE
:
11745 COMCTL32_RefreshSysColors();
11748 /* case WM_TIMER: */
11749 case WM_THEMECHANGED
:
11750 return LISTVIEW_ThemeChanged(infoPtr
);
11753 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11755 case WM_MOUSEWHEEL
:
11756 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11757 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11758 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11760 case WM_WINDOWPOSCHANGED
:
11761 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11763 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11764 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11766 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11768 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11770 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11772 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11774 /* case WM_WININICHANGE: */
11777 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11778 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11780 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11787 * Registers the window class.
11795 void LISTVIEW_Register(void)
11797 WNDCLASSW wndClass
;
11799 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11800 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11801 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11802 wndClass
.cbClsExtra
= 0;
11803 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11804 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11805 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11806 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11807 RegisterClassW(&wndClass
);
11812 * Unregisters the window class.
11820 void LISTVIEW_Unregister(void)
11822 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11827 * Handle any WM_COMMAND messages
11830 * [I] infoPtr : valid pointer to the listview structure
11831 * [I] wParam : the first message parameter
11832 * [I] lParam : the second message parameter
11837 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11840 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11842 if (!infoPtr
->hwndEdit
) return 0;
11844 switch (HIWORD(wParam
))
11849 * Adjust the edit window size
11851 WCHAR buffer
[1024];
11852 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11853 HFONT hFont
, hOldFont
= 0;
11857 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11858 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11859 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11861 /* Select font to get the right dimension of the string */
11862 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11865 hOldFont
= SelectObject(hdc
, hFont
);
11868 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11870 TEXTMETRICW textMetric
;
11872 /* Add Extra spacing for the next character */
11873 GetTextMetricsW(hdc
, &textMetric
);
11874 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11876 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11877 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11880 SelectObject(hdc
, hOldFont
);
11882 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11888 LISTVIEW_CancelEditLabel(infoPtr
);
11893 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);