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
;
592 buf
+= len
; size
-= len
;
593 if (pScrollInfo
->fMask
& SIF_RANGE
)
594 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
596 if (len
== -1) goto end
;
597 buf
+= len
; size
-= len
;
598 if (pScrollInfo
->fMask
& SIF_PAGE
)
599 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
601 if (len
== -1) goto end
;
602 buf
+= len
; size
-= len
;
603 if (pScrollInfo
->fMask
& SIF_POS
)
604 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
606 if (len
== -1) goto end
;
607 buf
+= len
; size
-= len
;
608 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
609 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
611 if (len
== -1) goto end
;
615 buf
= text
+ strlen(text
);
617 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
621 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
623 if (!plvnm
) return "(null)";
624 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
625 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
626 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
627 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
630 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
632 char* buf
= debug_getbuf(), *text
= buf
;
633 int len
, size
= DEBUG_BUFFER_SIZE
;
635 if (lpLVItem
== NULL
) return "(null)";
636 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
637 if (len
== -1) goto end
;
638 buf
+= len
; size
-= len
;
639 if (lpLVItem
->mask
& LVIF_STATE
)
640 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
642 if (len
== -1) goto end
;
643 buf
+= len
; size
-= len
;
644 if (lpLVItem
->mask
& LVIF_TEXT
)
645 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
647 if (len
== -1) goto end
;
648 buf
+= len
; size
-= len
;
649 if (lpLVItem
->mask
& LVIF_IMAGE
)
650 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
652 if (len
== -1) goto end
;
653 buf
+= len
; size
-= len
;
654 if (lpLVItem
->mask
& LVIF_PARAM
)
655 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
657 if (len
== -1) goto end
;
658 buf
+= len
; size
-= len
;
659 if (lpLVItem
->mask
& LVIF_INDENT
)
660 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
662 if (len
== -1) goto end
;
666 buf
= text
+ strlen(text
);
668 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
672 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
674 char* buf
= debug_getbuf(), *text
= buf
;
675 int len
, size
= DEBUG_BUFFER_SIZE
;
677 if (lpColumn
== NULL
) return "(null)";
678 len
= snprintf(buf
, size
, "{");
679 if (len
== -1) goto end
;
680 buf
+= len
; size
-= len
;
681 if (lpColumn
->mask
& LVCF_SUBITEM
)
682 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
684 if (len
== -1) goto end
;
685 buf
+= len
; size
-= len
;
686 if (lpColumn
->mask
& LVCF_FMT
)
687 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
689 if (len
== -1) goto end
;
690 buf
+= len
; size
-= len
;
691 if (lpColumn
->mask
& LVCF_WIDTH
)
692 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
694 if (len
== -1) goto end
;
695 buf
+= len
; size
-= len
;
696 if (lpColumn
->mask
& LVCF_TEXT
)
697 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
699 if (len
== -1) goto end
;
700 buf
+= len
; size
-= len
;
701 if (lpColumn
->mask
& LVCF_IMAGE
)
702 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
704 if (len
== -1) goto end
;
705 buf
+= len
; size
-= len
;
706 if (lpColumn
->mask
& LVCF_ORDER
)
707 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
709 if (len
== -1) goto end
;
713 buf
= text
+ strlen(text
);
715 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
719 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
721 if (!lpht
) return "(null)";
723 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
724 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
727 /* Return the corresponding text for a given scroll value */
728 static inline LPCSTR
debugscrollcode(int nScrollCode
)
732 case SB_LINELEFT
: return "SB_LINELEFT";
733 case SB_LINERIGHT
: return "SB_LINERIGHT";
734 case SB_PAGELEFT
: return "SB_PAGELEFT";
735 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
736 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
737 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
738 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
739 case SB_INTERNAL
: return "SB_INTERNAL";
740 default: return "unknown";
745 /******** Notification functions ************************************/
747 static int get_ansi_notification(UINT unicodeNotificationCode
)
749 switch (unicodeNotificationCode
)
751 case LVN_BEGINLABELEDITA
:
752 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
753 case LVN_ENDLABELEDITA
:
754 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
755 case LVN_GETDISPINFOA
:
756 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
757 case LVN_SETDISPINFOA
:
758 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
759 case LVN_ODFINDITEMA
:
760 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
761 case LVN_GETINFOTIPA
:
762 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
763 /* header forwards */
765 case HDN_TRACKW
: return HDN_TRACKA
;
767 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
768 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
769 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
770 case HDN_ITEMCHANGINGA
:
771 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
772 case HDN_ITEMCHANGEDA
:
773 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
775 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
776 case HDN_DIVIDERDBLCLICKA
:
777 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
780 FIXME("unknown notification %x\n", unicodeNotificationCode
);
781 return unicodeNotificationCode
;
784 /* forwards header notifications to listview parent */
785 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
787 LPCWSTR text
= NULL
, filter
= NULL
;
789 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
791 /* on unicode format exit earlier */
792 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
793 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
796 /* header always supplies unicode notifications,
797 all we have to do is to convert strings to ANSI */
800 /* convert item text */
801 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
803 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
804 lpnmh
->pitem
->pszText
= NULL
;
805 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
807 /* convert filter text */
808 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
809 lpnmh
->pitem
->pvFilter
)
811 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
812 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= NULL
;
813 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
816 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
818 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
824 Free(lpnmh
->pitem
->pszText
);
825 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
829 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
830 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
836 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
840 TRACE("(code=%d)\n", code
);
842 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
843 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
845 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
847 TRACE(" <= %ld\n", result
);
852 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
855 HWND hwnd
= infoPtr
->hwndSelf
;
856 notify_hdr(infoPtr
, code
, &nmh
);
857 return IsWindow(hwnd
);
860 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
870 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
871 item
.iItem
= htInfo
->iItem
;
873 item
.stateMask
= (UINT
)-1;
874 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
875 nmia
.lParam
= item
.lParam
;
876 nmia
.uOldState
= item
.state
;
877 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
878 nmia
.uChanged
= LVIF_STATE
;
881 nmia
.iItem
= htInfo
->iItem
;
882 nmia
.iSubItem
= htInfo
->iSubItem
;
883 nmia
.ptAction
= htInfo
->pt
;
885 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
886 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
887 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
889 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
892 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
894 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
895 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
898 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
899 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
903 HWND hwnd
= infoPtr
->hwndSelf
;
906 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
907 ZeroMemory(&nmia
, sizeof(nmia
));
908 nmia
.iItem
= lvht
->iItem
;
909 nmia
.iSubItem
= lvht
->iSubItem
;
910 nmia
.ptAction
= lvht
->pt
;
911 item
.mask
= LVIF_PARAM
;
912 item
.iItem
= lvht
->iItem
;
914 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
915 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
916 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
919 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
923 HWND hwnd
= infoPtr
->hwndSelf
;
925 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
927 item
.mask
= LVIF_PARAM
;
930 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
931 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
932 return IsWindow(hwnd
);
936 Send notification. depends on dispinfoW having same
937 structure as dispinfoA.
938 infoPtr : listview struct
939 code : *Unicode* notification code
940 pdi : dispinfo structure (can be unicode or ansi)
941 isW : TRUE if dispinfo is Unicode
943 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
945 INT length
= 0, ret_length
;
946 LPWSTR buffer
= NULL
, ret_text
;
947 BOOL return_ansi
= FALSE
;
948 BOOL return_unicode
= FALSE
;
951 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
953 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
954 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
957 ret_length
= pdi
->item
.cchTextMax
;
958 ret_text
= pdi
->item
.pszText
;
960 if (return_unicode
|| return_ansi
)
962 if (code
!= LVN_GETDISPINFOW
)
964 length
= return_ansi
?
965 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
966 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
970 length
= pdi
->item
.cchTextMax
;
971 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
974 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
975 if (!buffer
) return FALSE
;
978 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
981 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
984 pdi
->item
.pszText
= buffer
;
985 pdi
->item
.cchTextMax
= length
;
988 if (infoPtr
->notifyFormat
== NFR_ANSI
)
989 code
= get_ansi_notification(code
);
991 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
992 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
993 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
995 if (return_ansi
|| return_unicode
)
997 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
999 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
1001 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
1003 strcpyW(ret_text
, pdi
->item
.pszText
);
1005 else if (return_ansi
) /* note : pointer can be changed by app ! */
1007 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
1008 ret_length
, NULL
, NULL
);
1011 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
1012 ret_text
, ret_length
);
1014 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
1015 pdi
->item
.cchTextMax
= ret_length
;
1021 /* if dipsinfo holder changed notification code then convert */
1022 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1024 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1026 buffer
= Alloc(length
* sizeof(CHAR
));
1027 if (!buffer
) return FALSE
;
1029 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1030 ret_length
, NULL
, NULL
);
1032 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1039 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1040 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1042 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1043 lpnmlvcd
->nmcd
.hdc
= hdc
;
1044 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1045 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1046 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1047 if (!lplvItem
) return;
1048 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1049 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1050 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1051 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1052 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1053 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1056 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1058 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1061 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1062 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1063 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1064 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1065 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1066 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1070 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1072 COLORREF backcolor
, textcolor
;
1074 /* apparently, for selected items, we have to override the returned values */
1077 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1079 if (infoPtr
->bFocus
)
1081 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1082 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1084 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1086 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1087 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1092 backcolor
= lpnmlvcd
->clrTextBk
;
1093 textcolor
= lpnmlvcd
->clrText
;
1095 if (backcolor
== CLR_DEFAULT
)
1096 backcolor
= comctl32_color
.clrWindow
;
1097 if (textcolor
== CLR_DEFAULT
)
1098 textcolor
= comctl32_color
.clrWindowText
;
1100 /* Set the text attributes */
1101 if (backcolor
!= CLR_NONE
)
1103 SetBkMode(hdc
, OPAQUE
);
1104 SetBkColor(hdc
, backcolor
);
1107 SetBkMode(hdc
, TRANSPARENT
);
1108 SetTextColor(hdc
, textcolor
);
1111 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1113 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1116 /* returns TRUE when repaint needed, FALSE otherwise */
1117 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1119 MEASUREITEMSTRUCT mis
;
1120 mis
.CtlType
= ODT_LISTVIEW
;
1121 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1125 mis
.itemHeight
= infoPtr
->nItemHeight
;
1126 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1127 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1129 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1135 /******** Item iterator functions **********************************/
1137 static RANGES
ranges_create(int count
);
1138 static void ranges_destroy(RANGES ranges
);
1139 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1140 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1141 static void ranges_dump(RANGES ranges
);
1143 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1145 RANGE range
= { nItem
, nItem
+ 1 };
1147 return ranges_add(ranges
, range
);
1150 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1152 RANGE range
= { nItem
, nItem
+ 1 };
1154 return ranges_del(ranges
, range
);
1158 * ITERATOR DOCUMENTATION
1160 * The iterator functions allow for easy, and convenient iteration
1161 * over items of interest in the list. Typically, you create an
1162 * iterator, use it, and destroy it, as such:
1165 * iterator_xxxitems(&i, ...);
1166 * while (iterator_{prev,next}(&i)
1168 * //code which uses i.nItem
1170 * iterator_destroy(&i);
1172 * where xxx is either: framed, or visible.
1173 * Note that it is important that the code destroys the iterator
1174 * after it's done with it, as the creation of the iterator may
1175 * allocate memory, which thus needs to be freed.
1177 * You can iterate both forwards, and backwards through the list,
1178 * by using iterator_next or iterator_prev respectively.
1180 * Lower numbered items are draw on top of higher number items in
1181 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1182 * items may overlap). So, to test items, you should use
1184 * which lists the items top to bottom (in Z-order).
1185 * For drawing items, you should use
1187 * which lists the items bottom to top (in Z-order).
1188 * If you keep iterating over the items after the end-of-items
1189 * marker (-1) is returned, the iterator will start from the
1190 * beginning. Typically, you don't need to test for -1,
1191 * because iterator_{next,prev} will return TRUE if more items
1192 * are to be iterated over, or FALSE otherwise.
1194 * Note: the iterator is defined to be bidirectional. That is,
1195 * any number of prev followed by any number of next, or
1196 * five versa, should leave the iterator at the same item:
1197 * prev * n, next * n = next * n, prev * n
1199 * The iterator has a notion of an out-of-order, special item,
1200 * which sits at the start of the list. This is used in
1201 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1202 * which needs to be first, as it may overlap other items.
1204 * The code is a bit messy because we have:
1205 * - a special item to deal with
1206 * - simple range, or composite range
1208 * If you find bugs, or want to add features, please make sure you
1209 * always check/modify *both* iterator_prev, and iterator_next.
1213 * This function iterates through the items in increasing order,
1214 * but prefixed by the special item, then -1. That is:
1215 * special, 1, 2, 3, ..., n, -1.
1216 * Each item is listed only once.
1218 static inline BOOL
iterator_next(ITERATOR
* i
)
1222 i
->nItem
= i
->nSpecial
;
1223 if (i
->nItem
!= -1) return TRUE
;
1225 if (i
->nItem
== i
->nSpecial
)
1227 if (i
->ranges
) i
->index
= 0;
1233 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1234 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1239 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1240 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1243 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1245 i
->nItem
= i
->range
.lower
;
1246 if (i
->nItem
>= 0) goto testitem
;
1253 * This function iterates through the items in decreasing order,
1254 * followed by the special item, then -1. That is:
1255 * n, n-1, ..., 3, 2, 1, special, -1.
1256 * Each item is listed only once.
1258 static inline BOOL
iterator_prev(ITERATOR
* i
)
1265 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1268 if (i
->nItem
== i
->nSpecial
)
1276 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1277 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1283 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1286 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1288 i
->nItem
= i
->range
.upper
;
1289 if (i
->nItem
> 0) goto testitem
;
1291 return (i
->nItem
= i
->nSpecial
) != -1;
1294 static RANGE
iterator_range(const ITERATOR
*i
)
1298 if (!i
->ranges
) return i
->range
;
1300 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1302 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1303 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1305 else range
.lower
= range
.upper
= 0;
1311 * Releases resources associated with this iterator.
1313 static inline void iterator_destroy(const ITERATOR
*i
)
1315 ranges_destroy(i
->ranges
);
1319 * Create an empty iterator.
1321 static inline BOOL
iterator_empty(ITERATOR
* i
)
1323 ZeroMemory(i
, sizeof(*i
));
1324 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1329 * Create an iterator over a range.
1331 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1339 * Create an iterator over a bunch of ranges.
1340 * Please note that the iterator will take ownership of the ranges,
1341 * and will free them upon destruction.
1343 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1351 * Creates an iterator over the items which intersect frame.
1352 * Uses absolute coordinates rather than compensating for the current offset.
1354 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1356 RECT rcItem
, rcTemp
;
1358 /* in case we fail, we want to return an empty iterator */
1359 if (!iterator_empty(i
)) return FALSE
;
1361 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1363 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1367 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1369 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1370 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1371 i
->nSpecial
= infoPtr
->nFocusedItem
;
1373 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1374 /* to do better here, we need to have PosX, and PosY sorted */
1375 TRACE("building icon ranges:\n");
1376 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1378 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1379 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1380 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1381 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1382 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1383 ranges_additem(i
->ranges
, nItem
);
1387 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1391 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1392 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1394 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1395 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1396 if (range
.upper
<= range
.lower
) return TRUE
;
1397 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1398 TRACE(" report=%s\n", debugrange(&i
->range
));
1402 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1403 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1404 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1411 if (infoPtr
->nItemWidth
)
1413 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1414 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1418 nFirstCol
= max(frame
->left
, 0);
1419 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1422 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1424 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1425 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1427 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1429 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1430 TRACE("building list ranges:\n");
1431 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1433 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1434 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1435 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1436 TRACE(" list=%s\n", debugrange(&item_range
));
1437 ranges_add(i
->ranges
, item_range
);
1445 * Creates an iterator over the items which intersect lprc.
1447 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1452 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1454 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1455 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1457 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1461 * Creates an iterator over the items which intersect the visible region of hdc.
1463 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1465 POINT Origin
, Position
;
1466 RECT rcItem
, rcClip
;
1469 rgntype
= GetClipBox(hdc
, &rcClip
);
1470 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1471 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1472 if (rgntype
== SIMPLEREGION
) return TRUE
;
1474 /* first deal with the special item */
1475 if (i
->nSpecial
!= -1)
1477 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1478 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1481 /* if we can't deal with the region, we'll just go with the simple range */
1482 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1483 TRACE("building visible range:\n");
1484 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1486 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1487 if (!ranges_add(i
->ranges
, i
->range
))
1489 ranges_destroy(i
->ranges
);
1495 /* now delete the invisible items from the list */
1496 while(iterator_next(i
))
1498 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1499 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1500 rcItem
.top
= Position
.y
+ Origin
.y
;
1501 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1502 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1503 if (!RectVisible(hdc
, &rcItem
))
1504 ranges_delitem(i
->ranges
, i
->nItem
);
1506 /* the iterator should restart on the next iterator_next */
1512 /* Remove common elements from two iterators */
1513 /* Passed iterators have to point on the first elements */
1514 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1516 if(!iter1
->ranges
|| !iter2
->ranges
) {
1519 if(iter1
->ranges
|| iter2
->ranges
||
1520 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1521 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1522 ERR("result is not a one range iterator\n");
1526 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1529 lower
= iter1
->range
.lower
;
1530 upper
= iter1
->range
.upper
;
1532 if(lower
< iter2
->range
.lower
)
1533 iter1
->range
.upper
= iter2
->range
.lower
;
1534 else if(upper
> iter2
->range
.upper
)
1535 iter1
->range
.lower
= iter2
->range
.upper
;
1537 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1539 if(iter2
->range
.lower
< lower
)
1540 iter2
->range
.upper
= lower
;
1541 else if(iter2
->range
.upper
> upper
)
1542 iter2
->range
.lower
= upper
;
1544 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1549 iterator_next(iter1
);
1550 iterator_next(iter2
);
1553 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1556 if(iter1
->nItem
== iter2
->nItem
) {
1557 int delete = iter1
->nItem
;
1559 iterator_prev(iter1
);
1560 iterator_prev(iter2
);
1561 ranges_delitem(iter1
->ranges
, delete);
1562 ranges_delitem(iter2
->ranges
, delete);
1563 iterator_next(iter1
);
1564 iterator_next(iter2
);
1565 } else if(iter1
->nItem
> iter2
->nItem
)
1566 iterator_next(iter2
);
1568 iterator_next(iter1
);
1571 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1572 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1576 /******** Misc helper functions ************************************/
1578 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1579 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1581 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1582 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1585 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1587 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1588 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1591 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1593 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1594 if(state
== 1 || state
== 2)
1598 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1599 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1600 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1604 /* this should be called after window style got updated,
1605 it used to reset view state to match current window style */
1606 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1608 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1611 infoPtr
->uView
= LV_VIEW_ICON
;
1614 infoPtr
->uView
= LV_VIEW_DETAILS
;
1617 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1620 infoPtr
->uView
= LV_VIEW_LIST
;
1624 /* computes next item id value */
1625 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1627 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1631 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1632 return lpID
->id
+ 1;
1637 /******** Internal API functions ************************************/
1639 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1641 static COLUMN_INFO mainItem
;
1643 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1644 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1646 /* update cached column rectangles */
1647 if (infoPtr
->colRectsDirty
)
1650 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1653 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1654 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1655 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1657 Ptr
->colRectsDirty
= FALSE
;
1660 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1663 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1665 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1668 if (infoPtr
->hwndHeader
) return 0;
1670 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1672 /* setup creation flags */
1673 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1674 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1676 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1679 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1680 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1681 if (!infoPtr
->hwndHeader
) return -1;
1683 /* set header unicode format */
1684 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1686 /* set header font */
1687 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1689 /* set header image list */
1690 if (infoPtr
->himlSmall
)
1691 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1693 LISTVIEW_UpdateSize(infoPtr
);
1698 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1700 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1703 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1705 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1706 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1707 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1710 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1712 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1715 /* used to handle collapse main item column case */
1716 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1718 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1719 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1722 /* Listview invalidation functions: use _only_ these functions to invalidate */
1724 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1726 return infoPtr
->redraw
;
1729 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1731 if(!is_redrawing(infoPtr
)) return;
1732 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1733 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1736 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1740 if(!is_redrawing(infoPtr
)) return;
1741 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1742 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1745 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1747 POINT Origin
, Position
;
1750 if(!is_redrawing(infoPtr
)) return;
1751 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1752 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1753 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1754 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1756 rcBox
.bottom
= infoPtr
->nItemHeight
;
1757 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1758 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1761 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1763 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1766 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1770 if(!is_redrawing(infoPtr
)) return;
1771 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1772 rcCol
.top
= infoPtr
->rcList
.top
;
1773 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1774 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1779 * Retrieves the number of items that can fit vertically in the client area.
1782 * [I] infoPtr : valid pointer to the listview structure
1785 * Number of items per row.
1787 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1789 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1791 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1796 * Retrieves the number of items that can fit horizontally in the client
1800 * [I] infoPtr : valid pointer to the listview structure
1803 * Number of items per column.
1805 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1807 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1809 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1813 /*************************************************************************
1814 * LISTVIEW_ProcessLetterKeys
1816 * Processes keyboard messages generated by pressing the letter keys
1818 * What this does is perform a case insensitive search from the
1819 * current position with the following quirks:
1820 * - If two chars or more are pressed in quick succession we search
1821 * for the corresponding string (e.g. 'abc').
1822 * - If there is a delay we wipe away the current search string and
1823 * restart with just that char.
1824 * - If the user keeps pressing the same character, whether slowly or
1825 * fast, so that the search string is entirely composed of this
1826 * character ('aaaaa' for instance), then we search for first item
1827 * that starting with that character.
1828 * - If the user types the above character in quick succession, then
1829 * we must also search for the corresponding string ('aaaaa'), and
1830 * go to that string if there is a match.
1833 * [I] hwnd : handle to the window
1834 * [I] charCode : the character code, the actual character
1835 * [I] keyData : key data
1843 * - The current implementation has a list of characters it will
1844 * accept and it ignores everything else. In particular it will
1845 * ignore accentuated characters which seems to match what
1846 * Windows does. But I'm not sure it makes sense to follow
1848 * - We don't sound a beep when the search fails.
1852 * TREEVIEW_ProcessLetterKeys
1854 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1856 WCHAR buffer
[MAX_PATH
];
1863 /* simple parameter checking */
1864 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1866 /* only allow the valid WM_CHARs through */
1867 if (!isalnumW(charCode
) &&
1868 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1869 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1870 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1871 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1872 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1873 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1874 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1875 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1876 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1879 /* update the search parameters */
1880 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1881 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1882 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1884 if (diff
>= 0 && diff
< KEY_DELAY
)
1886 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1887 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1889 if (infoPtr
->charCode
!= charCode
)
1890 infoPtr
->charCode
= charCode
= 0;
1894 infoPtr
->charCode
= charCode
;
1895 infoPtr
->szSearchParam
[0] = charCode
;
1896 infoPtr
->nSearchParamLength
= 1;
1899 /* should start from next after focused item, so next item that matches
1900 will be selected, if there isn't any and focused matches it will be selected
1901 on second search stage from beginning of the list */
1902 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1904 /* with some accumulated search data available start with current focus, otherwise
1905 it's excluded from search */
1906 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1907 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1912 /* let application handle this for virtual listview */
1913 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1917 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1918 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1919 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1920 nmlv
.iStart
= startidx
;
1922 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1924 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1928 int i
= startidx
, endidx
;
1930 /* and search from the current position */
1932 endidx
= infoPtr
->nItemCount
;
1934 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1937 /* start from first item if not found with >= startidx */
1938 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1944 for (i
= startidx
; i
< endidx
; i
++)
1947 item
.mask
= LVIF_TEXT
;
1950 item
.pszText
= buffer
;
1951 item
.cchTextMax
= MAX_PATH
;
1952 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1954 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1959 /* this is used to find first char match when search string is not available yet,
1960 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1961 already waiting for user to complete a string */
1962 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1964 /* this would work but we must keep looking for a longer match */
1969 if ( nItem
!= -1 || /* found something */
1970 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1971 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1977 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1982 /*************************************************************************
1983 * LISTVIEW_UpdateHeaderSize [Internal]
1985 * Function to resize the header control
1988 * [I] hwnd : handle to a window
1989 * [I] nNewScrollPos : scroll pos to set
1994 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1999 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
2001 if (!infoPtr
->hwndHeader
) return;
2003 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
2004 point
[0].x
= winRect
.left
;
2005 point
[0].y
= winRect
.top
;
2006 point
[1].x
= winRect
.right
;
2007 point
[1].y
= winRect
.bottom
;
2009 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
2010 point
[0].x
= -nNewScrollPos
;
2011 point
[1].x
+= nNewScrollPos
;
2013 SetWindowPos(infoPtr
->hwndHeader
,0,
2014 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
2015 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
2016 SWP_NOZORDER
| SWP_NOACTIVATE
);
2021 * Update the scrollbars. This functions should be called whenever
2022 * the content, size or view changes.
2025 * [I] infoPtr : valid pointer to the listview structure
2030 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2032 SCROLLINFO horzInfo
, vertInfo
;
2035 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2037 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2038 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2039 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2041 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2042 if (infoPtr
->uView
== LV_VIEW_LIST
)
2044 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2045 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2047 /* scroll by at least one column per page */
2048 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2049 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2051 if (infoPtr
->nItemWidth
)
2052 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2054 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2056 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2058 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2062 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2065 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2067 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2072 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2073 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2075 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2076 horzInfo
.nMax
= rcHeader
.right
;
2077 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2081 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2082 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2083 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2084 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2085 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2087 /* Setting the horizontal scroll can change the listview size
2088 * (and potentially everything else) so we need to recompute
2089 * everything again for the vertical scroll
2092 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2093 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2094 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2096 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2098 vertInfo
.nMax
= infoPtr
->nItemCount
;
2100 /* scroll by at least one page */
2101 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2102 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2104 if (infoPtr
->nItemHeight
> 0)
2105 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2107 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2111 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2114 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2115 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2116 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2117 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2118 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2120 /* Change of the range may have changed the scroll pos. If so move the content */
2121 if (dx
!= 0 || dy
!= 0)
2124 listRect
= infoPtr
->rcList
;
2125 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2126 SW_ERASE
| SW_INVALIDATE
);
2129 /* Update the Header Control */
2130 if (infoPtr
->hwndHeader
)
2132 horzInfo
.fMask
= SIF_POS
;
2133 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2134 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2141 * Shows/hides the focus rectangle.
2144 * [I] infoPtr : valid pointer to the listview structure
2145 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2150 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2154 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2156 if (infoPtr
->nFocusedItem
< 0) return;
2158 /* we need some gymnastics in ICON mode to handle large items */
2159 if (infoPtr
->uView
== LV_VIEW_ICON
)
2163 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2164 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2166 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2171 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2173 /* for some reason, owner draw should work only in report mode */
2174 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2179 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2180 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2182 item
.iItem
= infoPtr
->nFocusedItem
;
2184 item
.mask
= LVIF_PARAM
;
2185 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2187 ZeroMemory(&dis
, sizeof(dis
));
2188 dis
.CtlType
= ODT_LISTVIEW
;
2189 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2190 dis
.itemID
= item
.iItem
;
2191 dis
.itemAction
= ODA_FOCUS
;
2192 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2193 dis
.hwndItem
= infoPtr
->hwndSelf
;
2195 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2196 dis
.itemData
= item
.lParam
;
2198 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2200 SelectObject(hdc
, hOldFont
);
2204 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2207 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2211 * Invalidates all visible selected items.
2213 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2217 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2218 while(iterator_next(&i
))
2220 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2221 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2223 iterator_destroy(&i
);
2228 * DESCRIPTION: [INTERNAL]
2229 * Computes an item's (left,top) corner, relative to rcView.
2230 * That is, the position has NOT been made relative to the Origin.
2231 * This is deliberate, to avoid computing the Origin over, and
2232 * over again, when this function is called in a loop. Instead,
2233 * one can factor the computation of the Origin before the loop,
2234 * and offset the value returned by this function, on every iteration.
2237 * [I] infoPtr : valid pointer to the listview structure
2238 * [I] nItem : item number
2239 * [O] lpptOrig : item top, left corner
2244 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2246 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2248 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2250 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2251 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2253 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2255 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2256 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2257 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2259 else /* LV_VIEW_DETAILS */
2261 lpptPosition
->x
= REPORT_MARGINX
;
2262 /* item is always at zero indexed column */
2263 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2264 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2265 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2270 * DESCRIPTION: [INTERNAL]
2271 * Compute the rectangles of an item. This is to localize all
2272 * the computations in one place. If you are not interested in some
2273 * of these values, simply pass in a NULL -- the function is smart
2274 * enough to compute only what's necessary. The function computes
2275 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2276 * one, the BOX rectangle. This rectangle is very cheap to compute,
2277 * and is guaranteed to contain all the other rectangles. Computing
2278 * the ICON rect is also cheap, but all the others are potentially
2279 * expensive. This gives an easy and effective optimization when
2280 * searching (like point inclusion, or rectangle intersection):
2281 * first test against the BOX, and if TRUE, test against the desired
2283 * If the function does not have all the necessary information
2284 * to computed the requested rectangles, will crash with a
2285 * failed assertion. This is done so we catch all programming
2286 * errors, given that the function is called only from our code.
2288 * We have the following 'special' meanings for a few fields:
2289 * * If LVIS_FOCUSED is set, we assume the item has the focus
2290 * This is important in ICON mode, where it might get a larger
2291 * then usual rectangle
2293 * Please note that subitem support works only in REPORT mode.
2296 * [I] infoPtr : valid pointer to the listview structure
2297 * [I] lpLVItem : item to compute the measures for
2298 * [O] lprcBox : ptr to Box rectangle
2299 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2300 * [0] lprcSelectBox : ptr to select box rectangle
2301 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2302 * [O] lprcIcon : ptr to Icon rectangle
2303 * Same as LVM_GETITEMRECT with LVIR_ICON
2304 * [O] lprcStateIcon: ptr to State Icon rectangle
2305 * [O] lprcLabel : ptr to Label rectangle
2306 * Same as LVM_GETITEMRECT with LVIR_LABEL
2311 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2312 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2313 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2315 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2316 RECT Box
, SelectBox
, Icon
, Label
;
2317 COLUMN_INFO
*lpColumnInfo
= NULL
;
2318 SIZE labelSize
= { 0, 0 };
2320 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2322 /* Be smart and try to figure out the minimum we have to do */
2323 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2324 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2326 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2327 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2329 if (lprcSelectBox
) doSelectBox
= TRUE
;
2330 if (lprcLabel
) doLabel
= TRUE
;
2331 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2338 /************************************************************/
2339 /* compute the box rectangle (it should be cheap to do) */
2340 /************************************************************/
2341 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2342 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2344 if (lpLVItem
->iSubItem
)
2346 Box
= lpColumnInfo
->rcHeader
;
2351 Box
.right
= infoPtr
->nItemWidth
;
2354 Box
.bottom
= infoPtr
->nItemHeight
;
2356 /******************************************************************/
2357 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2358 /******************************************************************/
2361 LONG state_width
= 0;
2363 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2364 state_width
= infoPtr
->iconStateSize
.cx
;
2366 if (infoPtr
->uView
== LV_VIEW_ICON
)
2368 Icon
.left
= Box
.left
+ state_width
;
2369 if (infoPtr
->himlNormal
)
2370 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2371 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2372 Icon
.right
= Icon
.left
;
2373 Icon
.bottom
= Icon
.top
;
2374 if (infoPtr
->himlNormal
)
2376 Icon
.right
+= infoPtr
->iconSize
.cx
;
2377 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2380 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2382 Icon
.left
= Box
.left
+ state_width
;
2384 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2386 /* we need the indent in report mode */
2387 assert(lpLVItem
->mask
& LVIF_INDENT
);
2388 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2392 Icon
.right
= Icon
.left
;
2393 if (infoPtr
->himlSmall
&&
2394 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2395 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2396 Icon
.right
+= infoPtr
->iconSize
.cx
;
2397 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2399 if(lprcIcon
) *lprcIcon
= Icon
;
2400 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2402 /* TODO: is this correct? */
2405 lprcStateIcon
->left
= Icon
.left
- state_width
;
2406 lprcStateIcon
->right
= Icon
.left
;
2407 lprcStateIcon
->top
= Icon
.top
;
2408 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2409 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2412 else Icon
.right
= 0;
2414 /************************************************************/
2415 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2416 /************************************************************/
2419 /* calculate how far to the right can the label stretch */
2420 Label
.right
= Box
.right
;
2421 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2423 if (lpLVItem
->iSubItem
== 0)
2425 /* we need a zero based rect here */
2426 Label
= lpColumnInfo
->rcHeader
;
2427 OffsetRect(&Label
, -Label
.left
, 0);
2431 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2433 labelSize
.cx
= infoPtr
->nItemWidth
;
2434 labelSize
.cy
= infoPtr
->nItemHeight
;
2438 /* we need the text in non owner draw mode */
2439 assert(lpLVItem
->mask
& LVIF_TEXT
);
2440 if (is_text(lpLVItem
->pszText
))
2442 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2443 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2444 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2448 /* compute rough rectangle where the label will go */
2449 SetRectEmpty(&rcText
);
2450 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2451 rcText
.bottom
= infoPtr
->nItemHeight
;
2452 if (infoPtr
->uView
== LV_VIEW_ICON
)
2453 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2455 /* now figure out the flags */
2456 if (infoPtr
->uView
== LV_VIEW_ICON
)
2457 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2459 uFormat
= LV_SL_DT_FLAGS
;
2461 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2463 if (rcText
.right
!= rcText
.left
)
2464 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2466 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2468 SelectObject(hdc
, hOldFont
);
2469 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2473 if (infoPtr
->uView
== LV_VIEW_ICON
)
2475 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2476 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2477 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2478 Label
.right
= Label
.left
+ labelSize
.cx
;
2479 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2480 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2482 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2483 labelSize
.cy
/= infoPtr
->ntmHeight
;
2484 labelSize
.cy
= max(labelSize
.cy
, 1);
2485 labelSize
.cy
*= infoPtr
->ntmHeight
;
2487 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2489 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2491 Label
.left
= Icon
.right
;
2492 Label
.top
= Box
.top
;
2493 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2494 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2495 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2497 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2499 Label
.left
= Icon
.right
;
2500 Label
.top
= Box
.top
;
2501 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2502 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2505 if (lprcLabel
) *lprcLabel
= Label
;
2506 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2509 /************************************************************/
2510 /* compute SELECT bounding box */
2511 /************************************************************/
2514 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2516 SelectBox
.left
= Icon
.left
;
2517 SelectBox
.top
= Box
.top
;
2518 SelectBox
.bottom
= Box
.bottom
;
2521 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2523 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2527 UnionRect(&SelectBox
, &Icon
, &Label
);
2529 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2530 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2533 /* Fix the Box if necessary */
2536 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2537 else *lprcBox
= Box
;
2539 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2543 * DESCRIPTION: [INTERNAL]
2546 * [I] infoPtr : valid pointer to the listview structure
2547 * [I] nItem : item number
2548 * [O] lprcBox : ptr to Box rectangle
2553 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2555 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2556 POINT Position
, Origin
;
2559 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2560 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2562 /* Be smart and try to figure out the minimum we have to do */
2564 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2565 lvItem
.mask
|= LVIF_TEXT
;
2566 lvItem
.iItem
= nItem
;
2567 lvItem
.iSubItem
= 0;
2568 lvItem
.pszText
= szDispText
;
2569 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2570 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2571 if (infoPtr
->uView
== LV_VIEW_ICON
)
2573 lvItem
.mask
|= LVIF_STATE
;
2574 lvItem
.stateMask
= LVIS_FOCUSED
;
2575 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2577 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2579 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2580 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2582 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2585 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2588 /* LISTVIEW_MapIdToIndex helper */
2589 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2591 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2592 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2594 if (id1
->id
== id2
->id
) return 0;
2596 return (id1
->id
< id2
->id
) ? -1 : 1;
2601 * Returns the item index for id specified.
2604 * [I] infoPtr : valid pointer to the listview structure
2605 * [I] iID : item id to get index for
2608 * Item index, or -1 on failure.
2610 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2615 TRACE("iID=%d\n", iID
);
2617 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2618 if (infoPtr
->nItemCount
== 0) return -1;
2621 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2625 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2626 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2634 * Returns the item id for index given.
2637 * [I] infoPtr : valid pointer to the listview structure
2638 * [I] iItem : item index to get id for
2643 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2648 TRACE("iItem=%d\n", iItem
);
2650 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2651 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2653 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2654 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2656 return lpItem
->id
->id
;
2661 * Returns the current icon position, and advances it along the top.
2662 * The returned position is not offset by Origin.
2665 * [I] infoPtr : valid pointer to the listview structure
2666 * [O] lpPos : will get the current icon position
2671 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2673 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2675 *lpPos
= infoPtr
->currIconPos
;
2677 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2678 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2680 infoPtr
->currIconPos
.x
= 0;
2681 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2687 * Returns the current icon position, and advances it down the left edge.
2688 * The returned position is not offset by Origin.
2691 * [I] infoPtr : valid pointer to the listview structure
2692 * [O] lpPos : will get the current icon position
2697 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2699 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2701 *lpPos
= infoPtr
->currIconPos
;
2703 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2704 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2706 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2707 infoPtr
->currIconPos
.y
= 0;
2713 * Moves an icon to the specified position.
2714 * It takes care of invalidating the item, etc.
2717 * [I] infoPtr : valid pointer to the listview structure
2718 * [I] nItem : the item to move
2719 * [I] lpPos : the new icon position
2720 * [I] isNew : flags the item as being new
2726 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2732 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2733 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2735 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2736 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2739 /* Allocating a POINTER for every item is too resource intensive,
2740 * so we'll keep the (x,y) in different arrays */
2741 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2742 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2744 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2751 * Arranges listview items in icon display mode.
2754 * [I] infoPtr : valid pointer to the listview structure
2755 * [I] nAlignCode : alignment code
2761 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2763 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2767 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2769 TRACE("nAlignCode=%d\n", nAlignCode
);
2771 if (nAlignCode
== LVA_DEFAULT
)
2773 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2774 else nAlignCode
= LVA_ALIGNTOP
;
2779 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2780 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2781 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2782 default: return FALSE
;
2785 infoPtr
->bAutoarrange
= TRUE
;
2786 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2787 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2789 next_pos(infoPtr
, &pos
);
2790 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2798 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2799 * For LVS_REPORT always returns empty rectangle.
2802 * [I] infoPtr : valid pointer to the listview structure
2803 * [O] lprcView : bounding rectangle
2809 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2813 SetRectEmpty(lprcView
);
2815 switch (infoPtr
->uView
)
2818 case LV_VIEW_SMALLICON
:
2819 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2821 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2822 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2823 lprcView
->right
= max(lprcView
->right
, x
);
2824 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2826 if (infoPtr
->nItemCount
> 0)
2828 lprcView
->right
+= infoPtr
->nItemWidth
;
2829 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2834 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2835 x
= infoPtr
->nItemCount
/ y
;
2836 if (infoPtr
->nItemCount
% y
) x
++;
2837 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2838 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2845 * Retrieves the bounding rectangle of all the items.
2848 * [I] infoPtr : valid pointer to the listview structure
2849 * [O] lprcView : bounding rectangle
2855 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2859 TRACE("(lprcView=%p)\n", lprcView
);
2861 if (!lprcView
) return FALSE
;
2863 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2865 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2867 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2868 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2871 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2878 * Retrieves the subitem pointer associated with the subitem index.
2881 * [I] hdpaSubItems : DPA handle for a specific item
2882 * [I] nSubItem : index of subitem
2885 * SUCCESS : subitem pointer
2888 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2890 SUBITEM_INFO
*lpSubItem
;
2893 /* we should binary search here if need be */
2894 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2896 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2897 if (lpSubItem
->iSubItem
== nSubItem
)
2907 * Calculates the desired item width.
2910 * [I] infoPtr : valid pointer to the listview structure
2913 * The desired item width.
2915 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2919 TRACE("uView=%d\n", infoPtr
->uView
);
2921 if (infoPtr
->uView
== LV_VIEW_ICON
)
2922 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2923 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2925 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2930 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2931 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2933 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2934 nItemWidth
= rcHeader
.right
;
2937 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2939 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2943 lvItem
.mask
= LVIF_TEXT
;
2944 lvItem
.iSubItem
= 0;
2946 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2949 lvItem
.pszText
= szDispText
;
2950 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2951 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2952 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2956 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2957 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2959 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2967 * Calculates the desired item height.
2970 * [I] infoPtr : valid pointer to the listview structure
2973 * The desired item height.
2975 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2979 TRACE("uView=%d\n", infoPtr
->uView
);
2981 if (infoPtr
->uView
== LV_VIEW_ICON
)
2982 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2985 nItemHeight
= infoPtr
->ntmHeight
;
2986 if (infoPtr
->himlState
)
2987 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2988 if (infoPtr
->himlSmall
)
2989 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2990 nItemHeight
+= HEIGHT_PADDING
;
2991 if (infoPtr
->nMeasureItemHeight
> 0)
2992 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2995 return max(nItemHeight
, 1);
3000 * Updates the width, and height of an item.
3003 * [I] infoPtr : valid pointer to the listview structure
3008 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
3010 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
3011 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3017 * Retrieves and saves important text metrics info for the current
3021 * [I] infoPtr : valid pointer to the listview structure
3024 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3026 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3027 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3028 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3032 if (GetTextMetricsW(hdc
, &tm
))
3034 infoPtr
->ntmHeight
= tm
.tmHeight
;
3035 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3038 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3039 infoPtr
->nEllipsisWidth
= sz
.cx
;
3041 SelectObject(hdc
, hOldFont
);
3042 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3044 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3049 * A compare function for ranges
3052 * [I] range1 : pointer to range 1;
3053 * [I] range2 : pointer to range 2;
3057 * > 0 : if range 1 > range 2
3058 * < 0 : if range 2 > range 1
3059 * = 0 : if range intersects range 2
3061 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3065 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3067 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3072 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3077 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3079 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3084 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3086 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3087 ranges_dump(ranges
);
3088 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3090 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3091 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3092 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3094 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3095 assert (prev
->upper
<= curr
->lower
);
3096 assert (curr
->lower
< curr
->upper
);
3100 TRACE("--- Done checking---\n");
3103 static RANGES
ranges_create(int count
)
3105 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3106 if (!ranges
) return NULL
;
3107 ranges
->hdpa
= DPA_Create(count
);
3108 if (ranges
->hdpa
) return ranges
;
3113 static void ranges_clear(RANGES ranges
)
3117 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3118 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3119 DPA_DeleteAllPtrs(ranges
->hdpa
);
3123 static void ranges_destroy(RANGES ranges
)
3125 if (!ranges
) return;
3126 ranges_clear(ranges
);
3127 DPA_Destroy(ranges
->hdpa
);
3131 static RANGES
ranges_clone(RANGES ranges
)
3136 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3138 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3140 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3141 if (!newrng
) goto fail
;
3142 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3143 if (!DPA_SetPtr(clone
->hdpa
, i
, newrng
))
3152 TRACE ("clone failed\n");
3153 ranges_destroy(clone
);
3157 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3161 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3162 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3167 static void ranges_dump(RANGES ranges
)
3171 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3172 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3175 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3177 RANGE srchrng
= { nItem
, nItem
+ 1 };
3179 TRACE("(nItem=%d)\n", nItem
);
3180 ranges_check(ranges
, "before contain");
3181 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3184 static INT
ranges_itemcount(RANGES ranges
)
3188 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3190 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3191 count
+= sel
->upper
- sel
->lower
;
3197 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3199 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3202 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3203 if (index
== -1) return TRUE
;
3205 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3207 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3208 if (chkrng
->lower
>= nItem
)
3209 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3210 if (chkrng
->upper
> nItem
)
3211 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3216 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3221 TRACE("(%s)\n", debugrange(&range
));
3222 ranges_check(ranges
, "before add");
3224 /* try find overlapping regions first */
3225 srchrgn
.lower
= range
.lower
- 1;
3226 srchrgn
.upper
= range
.upper
+ 1;
3227 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3233 TRACE("Adding new range\n");
3235 /* create the brand new range to insert */
3236 newrgn
= Alloc(sizeof(RANGE
));
3237 if(!newrgn
) goto fail
;
3240 /* figure out where to insert it */
3241 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3242 TRACE("index=%d\n", index
);
3243 if (index
== -1) index
= 0;
3245 /* and get it over with */
3246 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3254 RANGE
*chkrgn
, *mrgrgn
;
3255 INT fromindex
, mergeindex
;
3257 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3258 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3260 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3261 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3263 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3265 /* merge now common ranges */
3267 srchrgn
.lower
= chkrgn
->lower
- 1;
3268 srchrgn
.upper
= chkrgn
->upper
+ 1;
3272 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3273 if (mergeindex
== -1) break;
3274 if (mergeindex
== index
)
3276 fromindex
= index
+ 1;
3280 TRACE("Merge with index %i\n", mergeindex
);
3282 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3283 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3284 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3286 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3287 if (mergeindex
< index
) index
--;
3291 ranges_check(ranges
, "after add");
3295 ranges_check(ranges
, "failed add");
3299 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3304 TRACE("(%s)\n", debugrange(&range
));
3305 ranges_check(ranges
, "before del");
3307 /* we don't use DPAS_SORTED here, since we need *
3308 * to find the first overlapping range */
3309 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3312 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3314 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3316 /* case 1: Same range */
3317 if ( (chkrgn
->upper
== range
.upper
) &&
3318 (chkrgn
->lower
== range
.lower
) )
3320 DPA_DeletePtr(ranges
->hdpa
, index
);
3324 /* case 2: engulf */
3325 else if ( (chkrgn
->upper
<= range
.upper
) &&
3326 (chkrgn
->lower
>= range
.lower
) )
3328 DPA_DeletePtr(ranges
->hdpa
, index
);
3331 /* case 3: overlap upper */
3332 else if ( (chkrgn
->upper
<= range
.upper
) &&
3333 (chkrgn
->lower
< range
.lower
) )
3335 chkrgn
->upper
= range
.lower
;
3337 /* case 4: overlap lower */
3338 else if ( (chkrgn
->upper
> range
.upper
) &&
3339 (chkrgn
->lower
>= range
.lower
) )
3341 chkrgn
->lower
= range
.upper
;
3344 /* case 5: fully internal */
3349 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3350 newrgn
->lower
= chkrgn
->lower
;
3351 newrgn
->upper
= range
.lower
;
3352 chkrgn
->lower
= range
.upper
;
3353 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3361 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3364 ranges_check(ranges
, "after del");
3368 ranges_check(ranges
, "failed del");
3374 * Removes all selection ranges
3377 * [I] infoPtr : valid pointer to the listview structure
3378 * [I] toSkip : item range to skip removing the selection
3384 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3393 lvItem
.stateMask
= LVIS_SELECTED
;
3395 /* need to clone the DPA because callbacks can change it */
3396 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3397 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3398 while(iterator_next(&i
))
3399 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3400 /* note that the iterator destructor will free the cloned range */
3401 iterator_destroy(&i
);
3406 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3410 if (!(toSkip
= ranges_create(1))) return FALSE
;
3411 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3412 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3413 ranges_destroy(toSkip
);
3417 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3419 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3424 * Retrieves the number of items that are marked as selected.
3427 * [I] infoPtr : valid pointer to the listview structure
3430 * Number of items selected.
3432 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3434 INT nSelectedCount
= 0;
3436 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3439 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3441 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3446 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3448 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3449 return nSelectedCount
;
3454 * Manages the item focus.
3457 * [I] infoPtr : valid pointer to the listview structure
3458 * [I] nItem : item index
3461 * TRUE : focused item changed
3462 * FALSE : focused item has NOT changed
3464 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3466 INT oldFocus
= infoPtr
->nFocusedItem
;
3469 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3471 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3472 lvItem
.stateMask
= LVIS_FOCUSED
;
3473 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3475 return oldFocus
!= infoPtr
->nFocusedItem
;
3478 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3480 if (nShiftItem
< nItem
) return nShiftItem
;
3482 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3484 if (direction
> 0) return nShiftItem
+ direction
;
3486 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3489 /* This function updates focus index.
3492 focus : current focus index
3493 item : index of item to be added/removed
3494 direction : add/remove flag
3496 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3498 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3500 infoPtr
->bDoChangeNotify
= FALSE
;
3501 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3502 if (focus
!= infoPtr
->nFocusedItem
)
3503 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3504 infoPtr
->bDoChangeNotify
= old_change
;
3509 * Updates the various indices after an item has been inserted or deleted.
3512 * [I] infoPtr : valid pointer to the listview structure
3513 * [I] nItem : item index
3514 * [I] direction : Direction of shift, +1 or -1.
3519 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3521 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3523 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3524 assert(abs(direction
) == 1);
3525 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3527 /* But we are not supposed to modify nHotItem! */
3532 * Adds a block of selections.
3535 * [I] infoPtr : valid pointer to the listview structure
3536 * [I] nItem : item index
3539 * Whether the window is still valid.
3541 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3543 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3544 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3545 HWND hwndSelf
= infoPtr
->hwndSelf
;
3546 NMLVODSTATECHANGE nmlv
;
3551 /* Temporarily disable change notification
3552 * If the control is LVS_OWNERDATA, we need to send
3553 * only one LVN_ODSTATECHANGED notification.
3554 * See MSDN documentation for LVN_ITEMCHANGED.
3556 bOldChange
= infoPtr
->bDoChangeNotify
;
3557 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3559 if (nFirst
== -1) nFirst
= nItem
;
3561 item
.state
= LVIS_SELECTED
;
3562 item
.stateMask
= LVIS_SELECTED
;
3564 for (i
= nFirst
; i
<= nLast
; i
++)
3565 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3567 ZeroMemory(&nmlv
, sizeof(nmlv
));
3568 nmlv
.iFrom
= nFirst
;
3571 nmlv
.uNewState
= item
.state
;
3573 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3574 if (!IsWindow(hwndSelf
))
3576 infoPtr
->bDoChangeNotify
= bOldChange
;
3583 * Sets a single group selection.
3586 * [I] infoPtr : valid pointer to the listview structure
3587 * [I] nItem : item index
3592 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3599 if (!(selection
= ranges_create(100))) return;
3601 item
.state
= LVIS_SELECTED
;
3602 item
.stateMask
= LVIS_SELECTED
;
3604 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3606 if (infoPtr
->nSelectionMark
== -1)
3608 infoPtr
->nSelectionMark
= nItem
;
3609 ranges_additem(selection
, nItem
);
3615 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3616 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3617 ranges_add(selection
, sel
);
3622 RECT rcItem
, rcSel
, rcSelMark
;
3625 rcItem
.left
= LVIR_BOUNDS
;
3626 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3627 ranges_destroy (selection
);
3630 rcSelMark
.left
= LVIR_BOUNDS
;
3631 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3632 ranges_destroy (selection
);
3635 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3636 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3637 while(iterator_next(&i
))
3639 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3640 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3642 iterator_destroy(&i
);
3645 /* disable per item notifications on LVS_OWNERDATA style
3646 FIXME: single LVN_ODSTATECHANGED should be used */
3647 bOldChange
= infoPtr
->bDoChangeNotify
;
3648 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3650 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3653 iterator_rangesitems(&i
, selection
);
3654 while(iterator_next(&i
))
3655 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3656 /* this will also destroy the selection */
3657 iterator_destroy(&i
);
3659 infoPtr
->bDoChangeNotify
= bOldChange
;
3661 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3666 * Sets a single selection.
3669 * [I] infoPtr : valid pointer to the listview structure
3670 * [I] nItem : item index
3675 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3679 TRACE("nItem=%d\n", nItem
);
3681 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3683 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3684 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3685 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3687 infoPtr
->nSelectionMark
= nItem
;
3692 * Set selection(s) with keyboard.
3695 * [I] infoPtr : valid pointer to the listview structure
3696 * [I] nItem : item index
3697 * [I] space : VK_SPACE code sent
3700 * SUCCESS : TRUE (needs to be repainted)
3701 * FAILURE : FALSE (nothing has changed)
3703 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3705 /* FIXME: pass in the state */
3706 WORD wShift
= GetKeyState(VK_SHIFT
) & 0x8000;
3707 WORD wCtrl
= GetKeyState(VK_CONTROL
) & 0x8000;
3708 BOOL bResult
= FALSE
;
3710 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3711 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3715 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3716 LISTVIEW_SetSelection(infoPtr
, nItem
);
3720 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3724 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3725 lvItem
.stateMask
= LVIS_SELECTED
;
3728 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3729 if (lvItem
.state
& LVIS_SELECTED
)
3730 infoPtr
->nSelectionMark
= nItem
;
3732 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3735 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3738 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3742 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3744 LVHITTESTINFO lvHitTestInfo
;
3746 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3747 lvHitTestInfo
.pt
.x
= pt
.x
;
3748 lvHitTestInfo
.pt
.y
= pt
.y
;
3750 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3752 lpLVItem
->mask
= LVIF_PARAM
;
3753 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3754 lpLVItem
->iSubItem
= 0;
3756 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3759 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3761 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3762 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3763 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3768 * Called when the mouse is being actively tracked and has hovered for a specified
3772 * [I] infoPtr : valid pointer to the listview structure
3773 * [I] fwKeys : key indicator
3774 * [I] x,y : mouse position
3777 * 0 if the message was processed, non-zero if there was an error
3780 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3781 * over the item for a certain period of time.
3784 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3788 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3790 if (LISTVIEW_IsHotTracking(infoPtr
))
3798 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3799 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3801 SetFocus(infoPtr
->hwndSelf
);
3807 #define SCROLL_LEFT 0x1
3808 #define SCROLL_RIGHT 0x2
3809 #define SCROLL_UP 0x4
3810 #define SCROLL_DOWN 0x8
3814 * Utility routine to draw and highlight items within a marquee selection rectangle.
3817 * [I] infoPtr : valid pointer to the listview structure
3818 * [I] coords_orig : original co-ordinates of the cursor
3819 * [I] coords_offs : offsetted coordinates of the cursor
3820 * [I] offset : offset amount
3821 * [I] scroll : Bitmask of which directions we should scroll, if at all
3826 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3827 const POINT
*coords_offs
, const POINT
*offset
,
3830 BOOL controlDown
= FALSE
;
3832 ITERATOR old_elems
, new_elems
;
3835 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3837 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3838 rect
.right
= coords_offs
->x
;
3842 rect
.left
= coords_offs
->x
;
3843 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3846 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3848 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3849 rect
.bottom
= coords_offs
->y
;
3853 rect
.top
= coords_offs
->y
;
3854 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3857 /* Cancel out the old marquee rectangle and draw the new one */
3858 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3860 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3861 the cursor is further away */
3863 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3864 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3866 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3867 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3869 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3870 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3872 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3873 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3875 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3877 infoPtr
->marqueeRect
= rect
;
3878 infoPtr
->marqueeDrawRect
= rect
;
3879 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3881 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3882 iterator_remove_common_items(&old_elems
, &new_elems
);
3884 /* Iterate over no longer selected items */
3885 while (iterator_next(&old_elems
))
3887 if (old_elems
.nItem
> -1)
3889 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3892 item
.state
= LVIS_SELECTED
;
3894 item
.stateMask
= LVIS_SELECTED
;
3896 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3899 iterator_destroy(&old_elems
);
3902 /* Iterate over newly selected items */
3903 if (GetKeyState(VK_CONTROL
) & 0x8000)
3906 while (iterator_next(&new_elems
))
3908 if (new_elems
.nItem
> -1)
3910 /* If CTRL is pressed, invert. If not, always select the item. */
3911 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3914 item
.state
= LVIS_SELECTED
;
3916 item
.stateMask
= LVIS_SELECTED
;
3918 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3921 iterator_destroy(&new_elems
);
3923 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3928 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3929 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3932 * [I] hwnd : Handle to the listview
3933 * [I] uMsg : WM_TIMER (ignored)
3934 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3935 * [I] dwTimer : The elapsed time (ignored)
3940 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3942 LISTVIEW_INFO
*infoPtr
;
3943 SCROLLINFO scrollInfo
;
3949 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3954 /* Get the current cursor position and convert to client coordinates */
3955 GetCursorPos(&coords_orig
);
3956 ScreenToClient(hWnd
, &coords_orig
);
3958 /* Ensure coordinates are within client bounds */
3959 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3960 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3963 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3965 /* Offset coordinates by the appropriate amount */
3966 coords_offs
.x
-= offset
.x
;
3967 coords_offs
.y
-= offset
.y
;
3969 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3970 scrollInfo
.fMask
= SIF_ALL
;
3972 /* Work out in which directions we can scroll */
3973 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3975 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3976 scroll
|= SCROLL_UP
;
3978 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3979 scroll
|= SCROLL_DOWN
;
3982 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3984 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3985 scroll
|= SCROLL_LEFT
;
3987 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3988 scroll
|= SCROLL_RIGHT
;
3991 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3992 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3993 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3994 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3996 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
4002 * Called whenever WM_MOUSEMOVE is received.
4005 * [I] infoPtr : valid pointer to the listview structure
4006 * [I] fwKeys : key indicator
4007 * [I] x,y : mouse position
4010 * 0 if the message is processed, non-zero if there was an error
4012 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4018 if (!(fwKeys
& MK_LBUTTON
))
4019 infoPtr
->bLButtonDown
= FALSE
;
4021 if (infoPtr
->bLButtonDown
)
4023 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4024 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4026 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4028 if (infoPtr
->bMarqueeSelect
)
4038 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4040 /* Ensure coordinates are within client bounds */
4041 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4042 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4044 /* Offset coordinates by the appropriate amount */
4045 coords_offs
.x
-= offset
.x
;
4046 coords_offs
.y
-= offset
.y
;
4048 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4049 move the mouse again */
4051 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4052 (y
>= infoPtr
->rcList
.bottom
))
4054 if (!infoPtr
->bScrolling
)
4056 infoPtr
->bScrolling
= TRUE
;
4057 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4062 infoPtr
->bScrolling
= FALSE
;
4063 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4066 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4074 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4076 /* reset item marker */
4077 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4078 infoPtr
->nLButtonDownItem
= -1;
4080 if (!PtInRect(&rect
, pt
))
4082 /* this path covers the following:
4083 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4084 2. change focus with keys
4085 3. move mouse over item from step 1 selects it and moves focus on it */
4086 if (infoPtr
->nLButtonDownItem
!= -1 &&
4087 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4091 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4092 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4094 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4095 infoPtr
->nLButtonDownItem
= -1;
4098 if (!infoPtr
->bDragging
)
4100 ht
.pt
= infoPtr
->ptClickPos
;
4101 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4103 /* If the click is outside the range of an item, begin a
4104 highlight. If not, begin an item drag. */
4109 /* If we're allowing multiple selections, send notification.
4110 If return value is non-zero, cancel. */
4111 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4113 /* Store the absolute coordinates of the click */
4115 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4117 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4118 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4120 /* Begin selection and capture mouse */
4121 infoPtr
->bMarqueeSelect
= TRUE
;
4122 SetCapture(infoPtr
->hwndSelf
);
4129 ZeroMemory(&nmlv
, sizeof(nmlv
));
4130 nmlv
.iItem
= ht
.iItem
;
4131 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4133 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4134 infoPtr
->bDragging
= TRUE
;
4142 /* see if we are supposed to be tracking mouse hovering */
4143 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4144 TRACKMOUSEEVENT trackinfo
;
4147 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4148 trackinfo
.dwFlags
= TME_QUERY
;
4150 /* see if we are already tracking this hwnd */
4151 _TrackMouseEvent(&trackinfo
);
4154 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
4157 if((trackinfo
.dwFlags
& flags
) != flags
|| trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4158 trackinfo
.dwFlags
= flags
;
4159 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4160 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4162 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4163 _TrackMouseEvent(&trackinfo
);
4172 * Tests whether the item is assignable to a list with style lStyle
4174 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4176 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4177 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4178 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4186 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4189 * [I] infoPtr : valid pointer to the listview structure
4190 * [I] lpLVItem : valid pointer to new item attributes
4191 * [I] isNew : the item being set is being inserted
4192 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4193 * [O] bChanged : will be set to TRUE if the item really changed
4199 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4205 /* stateMask is ignored for LVM_INSERTITEM */
4206 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4210 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4212 if (lpLVItem
->mask
== 0) return TRUE
;
4214 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4216 /* a virtual listview only stores selection and focus */
4217 if (lpLVItem
->mask
& ~LVIF_STATE
)
4223 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4224 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4228 /* we need to get the lParam and state of the item */
4229 item
.iItem
= lpLVItem
->iItem
;
4230 item
.iSubItem
= lpLVItem
->iSubItem
;
4231 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4232 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4236 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4238 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4239 /* determine what fields will change */
4240 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4241 uChanged
|= LVIF_STATE
;
4243 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4244 uChanged
|= LVIF_IMAGE
;
4246 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4247 uChanged
|= LVIF_PARAM
;
4249 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4250 uChanged
|= LVIF_INDENT
;
4252 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4253 uChanged
|= LVIF_TEXT
;
4255 TRACE("change mask=0x%x\n", uChanged
);
4257 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4258 nmlv
.iItem
= lpLVItem
->iItem
;
4259 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4260 nmlv
.uOldState
= item
.state
;
4261 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4262 nmlv
.lParam
= item
.lParam
;
4264 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4265 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4266 are enabled. Even nothing really changed we still need to send this,
4267 in this case uChanged mask is just set to passed item mask. */
4268 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4270 HWND hwndSelf
= infoPtr
->hwndSelf
;
4272 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4274 if (!IsWindow(hwndSelf
))
4278 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4279 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4280 /* this means we won't hit a focus change path later */
4281 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4283 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4284 infoPtr
->nFocusedItem
++;
4287 if (!uChanged
) return TRUE
;
4290 /* copy information */
4291 if (lpLVItem
->mask
& LVIF_TEXT
)
4292 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4294 if (lpLVItem
->mask
& LVIF_IMAGE
)
4295 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4297 if (lpLVItem
->mask
& LVIF_PARAM
)
4298 lpItem
->lParam
= lpLVItem
->lParam
;
4300 if (lpLVItem
->mask
& LVIF_INDENT
)
4301 lpItem
->iIndent
= lpLVItem
->iIndent
;
4303 if (uChanged
& LVIF_STATE
)
4305 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4307 lpItem
->state
&= ~stateMask
;
4308 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4310 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4312 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4313 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4315 else if (stateMask
& LVIS_SELECTED
)
4317 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4319 /* If we are asked to change focus, and we manage it, do it.
4320 It's important to have all new item data stored at this point,
4321 because changing existing focus could result in a redrawing operation,
4322 which in turn could ask for disp data, application should see all data
4323 for inserted item when processing LVN_GETDISPINFO.
4325 The way this works application will see nested item change notifications -
4326 changed item notifications interrupted by ones from item losing focus. */
4327 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4329 if (lpLVItem
->state
& LVIS_FOCUSED
)
4331 /* update selection mark */
4332 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4333 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4335 if (infoPtr
->nFocusedItem
!= -1)
4337 /* remove current focus */
4338 item
.mask
= LVIF_STATE
;
4340 item
.stateMask
= LVIS_FOCUSED
;
4342 /* recurse with redrawing an item */
4343 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4346 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4347 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4349 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4351 infoPtr
->nFocusedItem
= -1;
4356 /* if we're inserting the item, we're done */
4357 if (isNew
) return TRUE
;
4359 /* send LVN_ITEMCHANGED notification */
4360 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4361 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4368 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4371 * [I] infoPtr : valid pointer to the listview structure
4372 * [I] lpLVItem : valid pointer to new subitem attributes
4373 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4374 * [O] bChanged : will be set to TRUE if the item really changed
4380 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4383 SUBITEM_INFO
*lpSubItem
;
4385 /* we do not support subitems for virtual listviews */
4386 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4388 /* set subitem only if column is present */
4389 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4391 /* First do some sanity checks */
4392 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4393 particularly useful. We currently do not actually do anything with
4394 the flag on subitems.
4396 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4397 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4399 /* get the subitem structure, and create it if not there */
4400 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4401 assert (hdpaSubItems
);
4403 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4406 SUBITEM_INFO
*tmpSubItem
;
4409 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4410 if (!lpSubItem
) return FALSE
;
4411 /* we could binary search here, if need be...*/
4412 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4414 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4415 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4417 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4422 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4423 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4427 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4429 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4433 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4435 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4444 * Sets item attributes.
4447 * [I] infoPtr : valid pointer to the listview structure
4448 * [I] lpLVItem : new item attributes
4449 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4455 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4457 HWND hwndSelf
= infoPtr
->hwndSelf
;
4458 LPWSTR pszText
= NULL
;
4459 BOOL bResult
, bChanged
= FALSE
;
4462 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4464 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4467 /* Store old item area */
4468 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4470 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4471 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4473 pszText
= lpLVItem
->pszText
;
4474 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4477 /* actually set the fields */
4478 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4480 if (lpLVItem
->iSubItem
)
4481 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4483 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4484 if (!IsWindow(hwndSelf
))
4487 /* redraw item, if necessary */
4488 if (bChanged
&& !infoPtr
->bIsDrawing
)
4490 /* this little optimization eliminates some nasty flicker */
4491 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4492 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4493 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4494 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4497 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4498 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4504 textfreeT(lpLVItem
->pszText
, isW
);
4505 lpLVItem
->pszText
= pszText
;
4513 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4516 * [I] infoPtr : valid pointer to the listview structure
4521 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4524 SCROLLINFO scrollInfo
;
4526 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4527 scrollInfo
.fMask
= SIF_POS
;
4529 if (infoPtr
->uView
== LV_VIEW_LIST
)
4531 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4532 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4534 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4536 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4537 nItem
= scrollInfo
.nPos
;
4541 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4542 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4545 TRACE("nItem=%d\n", nItem
);
4553 * Erases the background of the given rectangle
4556 * [I] infoPtr : valid pointer to the listview structure
4557 * [I] hdc : device context handle
4558 * [I] lprcBox : clipping rectangle
4564 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4566 if (!infoPtr
->hBkBrush
) return FALSE
;
4568 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4570 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4573 /* Draw main item or subitem */
4574 static void LISTVIEW_DrawItemPart(LISTVIEW_INFO
*infoPtr
, LVITEMW
*item
, const NMLVCUSTOMDRAW
*nmlvcd
, const POINT
*pos
)
4576 RECT rcSelect
, rcLabel
, rcBox
, rcStateIcon
, rcIcon
;
4577 const RECT
*background
;
4582 /* now check if we need to update the focus rectangle */
4583 focus
= infoPtr
->bFocus
&& (item
->state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4584 if (!focus
) item
->state
&= ~LVIS_FOCUSED
;
4586 LISTVIEW_GetItemMetrics(infoPtr
, item
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4587 OffsetRect(&rcBox
, pos
->x
, pos
->y
);
4588 OffsetRect(&rcSelect
, pos
->x
, pos
->y
);
4589 OffsetRect(&rcIcon
, pos
->x
, pos
->y
);
4590 OffsetRect(&rcStateIcon
, pos
->x
, pos
->y
);
4591 OffsetRect(&rcLabel
, pos
->x
, pos
->y
);
4592 TRACE("%d: box=%s, select=%s, icon=%s. label=%s\n", item
->iSubItem
,
4593 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4594 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4596 /* FIXME: temporary hack */
4597 rcSelect
.left
= rcLabel
.left
;
4599 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& item
->iSubItem
== 0)
4601 if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4602 OffsetRect(&rcSelect
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4603 OffsetRect(&rcIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4604 OffsetRect(&rcStateIcon
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4605 OffsetRect(&rcLabel
, LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
, 0);
4608 /* in icon mode, the label rect is really what we want to draw the
4610 /* in detail mode, we want to paint background for label rect when
4611 * item is not selected or listview has full row select; otherwise paint
4612 * background for text only */
4613 if ( infoPtr
->uView
== LV_VIEW_ICON
||
4614 (infoPtr
->uView
== LV_VIEW_DETAILS
&& (!(item
->state
& LVIS_SELECTED
) ||
4615 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))))
4616 background
= &rcLabel
;
4618 background
= &rcSelect
;
4620 if (nmlvcd
->clrTextBk
!= CLR_NONE
)
4621 ExtTextOutW(nmlvcd
->nmcd
.hdc
, background
->left
, background
->top
, ETO_OPAQUE
, background
, NULL
, 0, NULL
);
4623 if (item
->state
& LVIS_FOCUSED
)
4625 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4627 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4629 /* we have to update left focus bound too if item isn't in leftmost column
4630 and reduce right box bound */
4631 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4635 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4637 INT Originx
= pos
->x
- LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
;
4638 INT rightmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4639 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4641 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, rightmost
)->rcHeader
.right
+ Originx
;
4642 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4645 rcSelect
.right
= rcBox
.right
;
4647 infoPtr
->rcFocus
= rcSelect
;
4650 infoPtr
->rcFocus
= rcLabel
;
4654 if (infoPtr
->himlState
&& STATEIMAGEINDEX(item
->state
) && (item
->iSubItem
== 0))
4656 UINT stateimage
= STATEIMAGEINDEX(item
->state
);
4659 TRACE("stateimage=%d\n", stateimage
);
4660 ImageList_Draw(infoPtr
->himlState
, stateimage
-1, nmlvcd
->nmcd
.hdc
, rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4665 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4666 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4670 TRACE("iImage=%d\n", item
->iImage
);
4672 if (item
->state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4673 style
= ILD_SELECTED
;
4677 ImageList_DrawEx(himl
, item
->iImage
, nmlvcd
->nmcd
.hdc
, rcIcon
.left
, rcIcon
.top
,
4678 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4679 item
->state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4680 style
| (item
->state
& LVIS_OVERLAYMASK
));
4683 /* Don't bother painting item being edited */
4684 if (infoPtr
->hwndEdit
&& item
->iItem
== infoPtr
->nEditLabelItem
&& item
->iSubItem
== 0) return;
4686 /* figure out the text drawing flags */
4687 format
= (infoPtr
->uView
== LV_VIEW_ICON
? (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4688 if (infoPtr
->uView
== LV_VIEW_ICON
)
4689 format
= (focus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4690 else if (item
->iSubItem
)
4692 switch (LISTVIEW_GetColumnInfo(infoPtr
, item
->iSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4694 case LVCFMT_RIGHT
: format
|= DT_RIGHT
; break;
4695 case LVCFMT_CENTER
: format
|= DT_CENTER
; break;
4696 default: format
|= DT_LEFT
;
4699 if (!(format
& (DT_RIGHT
| DT_CENTER
)))
4701 if (himl
&& item
->iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4702 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4704 else if (format
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4706 /* for GRIDLINES reduce the bottom so the text formats correctly */
4707 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4710 DrawTextW(nmlvcd
->nmcd
.hdc
, item
->pszText
, -1, &rcLabel
, format
);
4718 * [I] infoPtr : valid pointer to the listview structure
4719 * [I] hdc : device context handle
4720 * [I] nItem : item index
4721 * [I] nSubItem : subitem index
4722 * [I] pos : item position in client coordinates
4723 * [I] cdmode : custom draw mode
4729 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, ITERATOR
*subitems
, POINT pos
, DWORD cdmode
)
4731 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4732 static WCHAR callbackW
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4733 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4735 NMLVCUSTOMDRAW nmlvcd
;
4738 TRACE("(hdc=%p, nItem=%d, subitems=%p, pos=%s)\n", hdc
, nItem
, subitems
, wine_dbgstr_point(&pos
));
4740 /* get information needed for drawing the item */
4741 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_STATE
;
4742 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4743 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4744 lvItem
.iItem
= nItem
;
4745 lvItem
.iSubItem
= 0;
4748 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4749 lvItem
.pszText
= szDispText
;
4750 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4751 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4752 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4754 /* now check if we need to update the focus rectangle */
4755 focus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4756 if (!focus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4758 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, NULL
, NULL
, NULL
);
4759 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4761 /* Full custom draw stage sequence looks like this:
4766 - CDDS_ITEMPREPAINT|CDDS_SUBITEM | => sent n times, where n is number of subitems,
4767 CDDS_ITEMPOSTPAINT|CDDS_SUBITEM | including item itself
4768 - CDDS_ITEMPOSTPAINT
4773 - CDDS_ITEMPOSTPAINT
4776 /* fill in the custom draw structure */
4777 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4778 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4779 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_ITEMPREPAINT
, &nmlvcd
);
4780 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4784 while (iterator_next(subitems
))
4786 DWORD subitemstage
= CDRF_DODEFAULT
;
4788 /* We need to query for each subitem, item's data (subitem == 0) is already here at this point */
4789 if (subitems
->nItem
)
4791 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
| LVIF_INDENT
;
4792 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4793 lvItem
.iItem
= nItem
;
4794 lvItem
.iSubItem
= subitems
->nItem
;
4797 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4798 lvItem
.pszText
= szDispText
;
4799 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4800 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4801 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4802 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= callbackW
;
4803 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4805 /* update custom draw data */
4806 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &nmlvcd
.nmcd
.rc
, NULL
, NULL
, NULL
, NULL
);
4807 OffsetRect(&nmlvcd
.nmcd
.rc
, pos
.x
, pos
.y
);
4808 nmlvcd
.iSubItem
= subitems
->nItem
;
4811 if (cdsubitemmode
& CDRF_NOTIFYSUBITEMDRAW
)
4812 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4815 nmlvcd
.clrTextBk
= infoPtr
->clrTextBk
;
4816 nmlvcd
.clrText
= infoPtr
->clrText
;
4819 if (subitems
->nItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4820 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4821 else if (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4822 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4824 if (!(subitemstage
& CDRF_SKIPDEFAULT
))
4825 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4827 if (subitemstage
& CDRF_NOTIFYPOSTPAINT
)
4828 subitemstage
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4833 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4834 LISTVIEW_DrawItemPart(infoPtr
, &lvItem
, &nmlvcd
, &pos
);
4838 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4840 nmlvcd
.iSubItem
= 0;
4841 notify_customdraw(infoPtr
, CDDS_ITEMPOSTPAINT
, &nmlvcd
);
4849 * Draws listview items when in owner draw mode.
4852 * [I] infoPtr : valid pointer to the listview structure
4853 * [I] hdc : device context handle
4858 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4860 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4861 DWORD cditemmode
= CDRF_DODEFAULT
;
4862 NMLVCUSTOMDRAW nmlvcd
;
4863 POINT Origin
, Position
;
4869 ZeroMemory(&dis
, sizeof(dis
));
4871 /* Get scroll info once before loop */
4872 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4874 /* iterate through the invalidated rows */
4875 while(iterator_next(i
))
4877 item
.iItem
= i
->nItem
;
4879 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4880 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4881 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4883 dis
.CtlType
= ODT_LISTVIEW
;
4885 dis
.itemID
= item
.iItem
;
4886 dis
.itemAction
= ODA_DRAWENTIRE
;
4888 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4889 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4890 dis
.hwndItem
= infoPtr
->hwndSelf
;
4892 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4893 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4894 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4895 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4896 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4897 dis
.itemData
= item
.lParam
;
4899 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4902 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4903 * structure for the rest. of the paint cycle
4905 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4906 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4907 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4909 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4911 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4912 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4915 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4916 notify_postpaint(infoPtr
, &nmlvcd
);
4922 * Draws listview items when in report display mode.
4925 * [I] infoPtr : valid pointer to the listview structure
4926 * [I] hdc : device context handle
4927 * [I] cdmode : custom draw mode
4932 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4935 RECT rcClip
, rcItem
;
4943 /* figure out what to draw */
4944 rgntype
= GetClipBox(hdc
, &rcClip
);
4945 if (rgntype
== NULLREGION
) return;
4947 /* Get scroll info once before loop */
4948 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4950 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4952 /* narrow down the columns we need to paint */
4953 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4955 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4957 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4958 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4959 ranges_additem(colRanges
, index
);
4961 iterator_rangesitems(&j
, colRanges
);
4963 /* in full row select, we _have_ to draw the main item */
4964 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4967 /* iterate through the invalidated rows */
4968 while(iterator_next(i
))
4974 SelectObject(hdc
, infoPtr
->hFont
);
4975 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4976 Position
.x
= Origin
.x
;
4977 Position
.y
+= Origin
.y
;
4979 subitems
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4981 /* iterate through the invalidated columns */
4982 while(iterator_next(&j
))
4984 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4986 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4989 rcItem
.bottom
= infoPtr
->nItemHeight
;
4990 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4991 if (!RectVisible(hdc
, &rcItem
)) continue;
4994 ranges_additem(subitems
, j
.nItem
);
4997 iterator_rangesitems(&k
, subitems
);
4998 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, &k
, Position
, cdmode
);
4999 iterator_destroy(&k
);
5001 iterator_destroy(&j
);
5006 * Draws the gridlines if necessary when in report display mode.
5009 * [I] infoPtr : valid pointer to the listview structure
5010 * [I] hdc : device context handle
5015 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
5021 RECT rcClip
, rcItem
= {0};
5029 /* figure out what to draw */
5030 rgntype
= GetClipBox(hdc
, &rcClip
);
5031 if (rgntype
== NULLREGION
) return;
5033 /* Get scroll info once before loop */
5034 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5036 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
5038 /* narrow down the columns we need to paint */
5039 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
5041 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
5043 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5044 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
5045 ranges_additem(colRanges
, index
);
5048 /* is right most vertical line visible? */
5049 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
5051 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5052 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5053 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
5056 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
5058 hOldPen
= SelectObject ( hdc
, hPen
);
5060 /* draw the vertical lines for the columns */
5061 iterator_rangesitems(&j
, colRanges
);
5062 while(iterator_next(&j
))
5064 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
5065 if (rcItem
.left
== 0) continue; /* skip leftmost column */
5066 rcItem
.left
+= Origin
.x
;
5067 rcItem
.right
+= Origin
.x
;
5068 rcItem
.top
= infoPtr
->rcList
.top
;
5069 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
5070 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
5071 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5072 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
5074 iterator_destroy(&j
);
5075 /* draw rightmost grid line if visible */
5078 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
5079 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
5080 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
5082 rcItem
.right
+= Origin
.x
;
5084 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
5085 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
5088 /* draw the horizontal lines for the rows */
5089 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
5090 rcItem
.left
= infoPtr
->rcList
.left
;
5091 rcItem
.right
= infoPtr
->rcList
.right
;
5092 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
5094 rcItem
.bottom
= rcItem
.top
= y
;
5095 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
5096 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
5097 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
5100 SelectObject( hdc
, hOldPen
);
5101 DeleteObject( hPen
);
5104 ranges_destroy(colRanges
);
5109 * Draws listview items when in list display mode.
5112 * [I] infoPtr : valid pointer to the listview structure
5113 * [I] hdc : device context handle
5114 * [I] cdmode : custom draw mode
5119 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5121 POINT Origin
, Position
;
5123 /* Get scroll info once before loop */
5124 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5126 while(iterator_prev(i
))
5128 SelectObject(hdc
, infoPtr
->hFont
);
5129 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5130 Position
.x
+= Origin
.x
;
5131 Position
.y
+= Origin
.y
;
5133 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, NULL
, Position
, cdmode
);
5140 * Draws listview items.
5143 * [I] infoPtr : valid pointer to the listview structure
5144 * [I] hdc : device context handle
5145 * [I] prcErase : rect to be erased before refresh (may be NULL)
5150 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5152 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5153 NMLVCUSTOMDRAW nmlvcd
;
5160 HBITMAP hbmp
= NULL
;
5163 LISTVIEW_DUMP(infoPtr
);
5165 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5166 TRACE("double buffering\n");
5168 hdc
= CreateCompatibleDC(hdcOrig
);
5170 ERR("Failed to create DC for backbuffer\n");
5173 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5174 infoPtr
->rcList
.bottom
);
5176 ERR("Failed to create bitmap for backbuffer\n");
5181 SelectObject(hdc
, hbmp
);
5182 SelectObject(hdc
, infoPtr
->hFont
);
5184 if(GetClipBox(hdcOrig
, &rcClient
))
5185 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5187 /* Save dc values we're gonna trash while drawing
5188 * FIXME: Should be done in LISTVIEW_DrawItem() */
5189 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5190 oldBkMode
= GetBkMode(hdc
);
5191 oldBkColor
= GetBkColor(hdc
);
5192 oldTextColor
= GetTextColor(hdc
);
5195 infoPtr
->bIsDrawing
= TRUE
;
5198 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5199 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5200 /* If no erasing was done (usually because RedrawWindow was called
5201 * with RDW_INVALIDATE only) we need to copy the old contents into
5202 * the backbuffer before continuing. */
5203 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5204 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5205 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5206 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5209 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5210 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5211 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5212 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5214 /* nothing to draw */
5215 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5217 /* figure out what we need to draw */
5218 iterator_visibleitems(&i
, infoPtr
, hdc
);
5219 range
= iterator_range(&i
);
5221 /* send cache hint notification */
5222 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5226 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5227 nmlv
.iFrom
= range
.lower
;
5228 nmlv
.iTo
= range
.upper
- 1;
5229 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5232 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5233 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5236 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5237 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5238 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5239 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5241 /* if we have a focus rect and it's visible, draw it */
5242 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5243 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5244 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5246 iterator_destroy(&i
);
5249 /* For LVS_EX_GRIDLINES go and draw lines */
5250 /* This includes the case where there were *no* items */
5251 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5252 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5254 /* Draw marquee rectangle if appropriate */
5255 if (infoPtr
->bMarqueeSelect
)
5256 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5258 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5259 notify_postpaint(infoPtr
, &nmlvcd
);
5262 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5263 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5264 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5265 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5270 SelectObject(hdc
, hOldFont
);
5271 SetBkMode(hdc
, oldBkMode
);
5272 SetBkColor(hdc
, oldBkColor
);
5273 SetTextColor(hdc
, oldTextColor
);
5276 infoPtr
->bIsDrawing
= FALSE
;
5282 * Calculates the approximate width and height of a given number of items.
5285 * [I] infoPtr : valid pointer to the listview structure
5286 * [I] nItemCount : number of items
5287 * [I] wWidth : width
5288 * [I] wHeight : height
5291 * Returns a DWORD. The width in the low word and the height in high word.
5293 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5294 WORD wWidth
, WORD wHeight
)
5296 DWORD dwViewRect
= 0;
5298 if (nItemCount
== -1)
5299 nItemCount
= infoPtr
->nItemCount
;
5301 if (infoPtr
->uView
== LV_VIEW_LIST
)
5303 INT nItemCountPerColumn
= 1;
5304 INT nColumnCount
= 0;
5306 if (wHeight
== 0xFFFF)
5308 /* use current height */
5309 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5312 if (wHeight
< infoPtr
->nItemHeight
)
5313 wHeight
= infoPtr
->nItemHeight
;
5317 if (infoPtr
->nItemHeight
> 0)
5319 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5320 if (nItemCountPerColumn
== 0)
5321 nItemCountPerColumn
= 1;
5323 if (nItemCount
% nItemCountPerColumn
!= 0)
5324 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5326 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5330 /* Microsoft padding magic */
5331 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5332 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5334 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5336 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5340 if (infoPtr
->nItemCount
> 0)
5342 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5343 wWidth
= rcBox
.right
- rcBox
.left
;
5344 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5348 /* use current height and width */
5349 if (wHeight
== 0xffff)
5350 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5351 if (wWidth
== 0xffff)
5352 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5355 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5357 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5363 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5364 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5366 if (wWidth
== 0xffff)
5367 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5369 if (wWidth
< nItemWidth
)
5370 wWidth
= nItemWidth
;
5372 cols
= wWidth
/ nItemWidth
;
5373 if (cols
> nItemCount
)
5380 rows
= nItemCount
/ cols
;
5381 if (nItemCount
% cols
)
5387 wHeight
= (nItemHeight
* rows
)+2;
5388 wWidth
= (nItemWidth
* cols
)+2;
5390 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5392 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5393 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5400 * Cancel edit label with saving item text.
5403 * [I] infoPtr : valid pointer to the listview structure
5406 * Always returns TRUE.
5408 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5410 if (infoPtr
->hwndEdit
)
5412 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5413 HWND edit
= infoPtr
->hwndEdit
;
5415 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5416 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5424 * Create a drag image list for the specified item.
5427 * [I] infoPtr : valid pointer to the listview structure
5428 * [I] iItem : index of item
5429 * [O] lppt : Upper-left corner of the image
5432 * Returns a handle to the image list if successful, NULL otherwise.
5434 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5440 HBITMAP hbmp
, hOldbmp
;
5442 HIMAGELIST dragList
= 0;
5443 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5445 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5448 rcItem
.left
= LVIR_BOUNDS
;
5449 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5452 lppt
->x
= rcItem
.left
;
5453 lppt
->y
= rcItem
.top
;
5455 size
.cx
= rcItem
.right
- rcItem
.left
;
5456 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5458 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5459 hdc
= CreateCompatibleDC(hdcOrig
);
5460 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5461 hOldbmp
= SelectObject(hdc
, hbmp
);
5462 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5464 SetRect(&rcItem
, 0, 0, size
.cx
, size
.cy
);
5465 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5468 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, NULL
, pos
, CDRF_DODEFAULT
))
5470 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5471 SelectObject(hdc
, hOldbmp
);
5472 ImageList_Add(dragList
, hbmp
, 0);
5475 SelectObject(hdc
, hOldbmp
);
5477 SelectObject(hdc
, hOldFont
);
5480 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5482 TRACE("ret=%p\n", dragList
);
5490 * Removes all listview items and subitems.
5493 * [I] infoPtr : valid pointer to the listview structure
5499 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5501 HDPA hdpaSubItems
= NULL
;
5502 BOOL suppress
= FALSE
;
5510 /* we do it directly, to avoid notifications */
5511 ranges_clear(infoPtr
->selectionRanges
);
5512 infoPtr
->nSelectionMark
= -1;
5513 infoPtr
->nFocusedItem
= -1;
5514 SetRectEmpty(&infoPtr
->rcFocus
);
5515 /* But we are supposed to leave nHotItem as is! */
5517 /* send LVN_DELETEALLITEMS notification */
5518 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) || !destroy
)
5522 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
5524 suppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5527 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5529 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5531 /* send LVN_DELETEITEM notification, if not suppressed
5532 and if it is not a virtual listview */
5533 if (!suppress
) notify_deleteitem(infoPtr
, i
);
5534 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5535 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5536 /* free id struct */
5537 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5538 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5539 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5541 /* both item and subitem start with ITEMHDR header */
5542 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5544 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5545 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5548 DPA_Destroy(hdpaSubItems
);
5549 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5551 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5552 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5553 infoPtr
->nItemCount
--;
5558 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5559 LISTVIEW_UpdateScroll(infoPtr
);
5561 LISTVIEW_InvalidateList(infoPtr
);
5568 * Scrolls, and updates the columns, when a column is changing width.
5571 * [I] infoPtr : valid pointer to the listview structure
5572 * [I] nColumn : column to scroll
5573 * [I] dx : amount of scroll, in pixels
5578 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5580 COLUMN_INFO
*lpColumnInfo
;
5586 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5587 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5588 rcCol
= lpColumnInfo
->rcHeader
;
5589 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5590 rcCol
.left
= rcCol
.right
;
5592 /* adjust the other columns */
5593 hdi
.mask
= HDI_ORDER
;
5594 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5596 INT nOrder
= hdi
.iOrder
;
5597 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5599 hdi
.mask
= HDI_ORDER
;
5600 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5601 if (hdi
.iOrder
>= nOrder
) {
5602 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5603 lpColumnInfo
->rcHeader
.left
+= dx
;
5604 lpColumnInfo
->rcHeader
.right
+= dx
;
5609 /* do not update screen if not in report mode */
5610 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5612 /* Need to reset the item width when inserting a new column */
5613 infoPtr
->nItemWidth
+= dx
;
5615 LISTVIEW_UpdateScroll(infoPtr
);
5616 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5618 /* scroll to cover the deleted column, and invalidate for redraw */
5619 rcOld
= infoPtr
->rcList
;
5620 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5621 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5626 * Removes a column from the listview control.
5629 * [I] infoPtr : valid pointer to the listview structure
5630 * [I] nColumn : column index
5636 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5640 TRACE("nColumn=%d\n", nColumn
);
5642 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5645 /* While the MSDN specifically says that column zero should not be deleted,
5646 what actually happens is that the column itself is deleted but no items or subitems
5650 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5652 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5655 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5656 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5658 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5660 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5662 INT nItem
, nSubItem
, i
;
5664 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5666 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5669 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5671 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5672 if (lpSubItem
->iSubItem
== nColumn
)
5675 lpDelItem
= lpSubItem
;
5677 else if (lpSubItem
->iSubItem
> nColumn
)
5679 lpSubItem
->iSubItem
--;
5683 /* if we found our subitem, zap it */
5687 if (is_text(lpDelItem
->hdr
.pszText
))
5688 Free(lpDelItem
->hdr
.pszText
);
5693 /* free dpa memory */
5694 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5699 /* update the other column info */
5700 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5701 LISTVIEW_InvalidateList(infoPtr
);
5703 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5704 LISTVIEW_UpdateItemSize(infoPtr
);
5711 * Invalidates the listview after an item's insertion or deletion.
5714 * [I] infoPtr : valid pointer to the listview structure
5715 * [I] nItem : item index
5716 * [I] dir : -1 if deleting, 1 if inserting
5721 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5723 INT nPerCol
, nItemCol
, nItemRow
;
5727 /* if we don't refresh, what's the point of scrolling? */
5728 if (!is_redrawing(infoPtr
)) return;
5730 assert (abs(dir
) == 1);
5732 /* arrange icons if autoarrange is on */
5733 if (is_autoarrange(infoPtr
))
5735 BOOL arrange
= TRUE
;
5736 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5737 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5738 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5741 /* scrollbars need updating */
5742 LISTVIEW_UpdateScroll(infoPtr
);
5744 /* figure out the item's position */
5745 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5746 nPerCol
= infoPtr
->nItemCount
+ 1;
5747 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5748 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5749 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5752 nItemCol
= nItem
/ nPerCol
;
5753 nItemRow
= nItem
% nPerCol
;
5754 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5756 /* move the items below up a slot */
5757 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5758 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5759 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5760 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5761 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5762 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5763 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5765 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5766 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5769 /* report has only that column, so we're done */
5770 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5772 /* now for LISTs, we have to deal with the columns to the right */
5773 SetRect(&rcScroll
, (nItemCol
+ 1) * infoPtr
->nItemWidth
, 0,
5774 (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
,
5775 nPerCol
* infoPtr
->nItemHeight
);
5776 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5777 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5778 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5783 * Removes an item from the listview control.
5786 * [I] infoPtr : valid pointer to the listview structure
5787 * [I] nItem : item index
5793 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5796 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5797 INT focus
= infoPtr
->nFocusedItem
;
5799 TRACE("(nItem=%d)\n", nItem
);
5801 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5803 /* remove selection, and focus */
5805 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5806 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5808 /* send LVN_DELETEITEM notification. */
5809 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5811 /* we need to do this here, because we'll be deleting stuff */
5813 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5815 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5823 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5824 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5826 /* free id struct */
5827 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5828 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5829 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5831 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5833 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5834 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5837 DPA_Destroy(hdpaSubItems
);
5842 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5843 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5846 infoPtr
->nItemCount
--;
5847 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5848 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5850 /* now is the invalidation fun */
5852 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5859 * Callback implementation for editlabel control
5862 * [I] infoPtr : valid pointer to the listview structure
5863 * [I] storeText : store edit box text as item text
5864 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5870 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5872 HWND hwndSelf
= infoPtr
->hwndSelf
;
5873 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5874 NMLVDISPINFOW dispInfo
;
5875 INT editedItem
= infoPtr
->nEditLabelItem
;
5877 WCHAR
*pszText
= NULL
;
5882 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5886 if (!(pszText
= Alloc(len
* (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5890 GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
);
5892 GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
);
5896 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5898 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5899 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5900 dispInfo
.item
.iItem
= editedItem
;
5901 dispInfo
.item
.iSubItem
= 0;
5902 dispInfo
.item
.stateMask
= ~0;
5903 dispInfo
.item
.pszText
= szDispText
;
5904 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5905 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5912 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5915 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5916 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5917 textfreeT(tmp
, FALSE
);
5920 /* add the text from the edit in */
5921 dispInfo
.item
.mask
|= LVIF_TEXT
;
5922 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5923 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5925 /* Do we need to update the Item Text */
5926 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5928 infoPtr
->nEditLabelItem
= -1;
5929 infoPtr
->hwndEdit
= 0;
5931 if (!res
) goto cleanup
;
5933 if (!IsWindow(hwndSelf
))
5938 if (!pszText
) return TRUE
;
5945 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5947 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5948 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5949 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5951 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5957 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5958 dispInfo
.item
.mask
= LVIF_TEXT
;
5959 dispInfo
.item
.iItem
= editedItem
;
5960 dispInfo
.item
.iSubItem
= 0;
5961 dispInfo
.item
.pszText
= pszText
;
5962 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5963 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5973 * Subclassed edit control windproc function
5976 * [I] hwnd : the edit window handle
5977 * [I] uMsg : the message that is to be processed
5978 * [I] wParam : first message parameter
5979 * [I] lParam : second message parameter
5980 * [I] isW : TRUE if input is Unicode
5985 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5987 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5990 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5991 hwnd
, uMsg
, wParam
, lParam
, isW
);
5996 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
6000 WNDPROC editProc
= infoPtr
->EditWndProc
;
6001 infoPtr
->EditWndProc
= 0;
6002 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
6003 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6007 if (VK_ESCAPE
== (INT
)wParam
)
6012 else if (VK_RETURN
== (INT
)wParam
)
6016 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
6020 if (infoPtr
->hwndEdit
)
6021 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
6023 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
6029 * Subclassed edit control Unicode windproc function
6032 * [I] hwnd : the edit window handle
6033 * [I] uMsg : the message that is to be processed
6034 * [I] wParam : first message parameter
6035 * [I] lParam : second message parameter
6039 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6041 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
6046 * Subclassed edit control ANSI windproc function
6049 * [I] hwnd : the edit window handle
6050 * [I] uMsg : the message that is to be processed
6051 * [I] wParam : first message parameter
6052 * [I] lParam : second message parameter
6056 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
6058 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
6063 * Creates a subclassed edit control
6066 * [I] infoPtr : valid pointer to the listview structure
6067 * [I] text : initial text for the edit
6068 * [I] style : the window style
6069 * [I] isW : TRUE if input is Unicode
6073 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
6075 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
6076 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
6079 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
6081 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
6083 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6085 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
6087 if (!hedit
) return 0;
6089 infoPtr
->EditWndProc
= (WNDPROC
)
6090 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
6091 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
6093 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
6094 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
6101 * Begin in place editing of specified list view item
6104 * [I] infoPtr : valid pointer to the listview structure
6105 * [I] nItem : item index
6106 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6112 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6114 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6115 HWND hwndSelf
= infoPtr
->hwndSelf
;
6116 NMLVDISPINFOW dispInfo
;
6117 HFONT hOldFont
= NULL
;
6123 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6125 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6127 /* remove existing edit box */
6128 if (infoPtr
->hwndEdit
)
6130 SetFocus(infoPtr
->hwndSelf
);
6131 infoPtr
->hwndEdit
= 0;
6134 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6136 infoPtr
->nEditLabelItem
= nItem
;
6138 LISTVIEW_SetSelection(infoPtr
, nItem
);
6139 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6140 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6142 rect
.left
= LVIR_LABEL
;
6143 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6145 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6146 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6147 dispInfo
.item
.iItem
= nItem
;
6148 dispInfo
.item
.iSubItem
= 0;
6149 dispInfo
.item
.stateMask
= ~0;
6150 dispInfo
.item
.pszText
= disptextW
;
6151 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6152 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6154 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6155 if (!infoPtr
->hwndEdit
) return 0;
6157 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6159 if (!IsWindow(hwndSelf
))
6161 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6162 infoPtr
->hwndEdit
= 0;
6166 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6168 /* position and display edit box */
6169 hdc
= GetDC(infoPtr
->hwndSelf
);
6171 /* select the font to get appropriate metric dimensions */
6173 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6175 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6176 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6177 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6179 /* get string length in pixels */
6180 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6182 /* add extra spacing for the next character */
6183 GetTextMetricsW(hdc
, &tm
);
6184 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6187 SelectObject(hdc
, hOldFont
);
6189 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6191 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6194 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6195 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6196 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6197 SetFocus(infoPtr
->hwndEdit
);
6198 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6199 return infoPtr
->hwndEdit
;
6205 * Ensures the specified item is visible, scrolling into view if necessary.
6208 * [I] infoPtr : valid pointer to the listview structure
6209 * [I] nItem : item index
6210 * [I] bPartial : partially or entirely visible
6216 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6218 INT nScrollPosHeight
= 0;
6219 INT nScrollPosWidth
= 0;
6220 INT nHorzAdjust
= 0;
6221 INT nVertAdjust
= 0;
6224 RECT rcItem
, rcTemp
;
6226 rcItem
.left
= LVIR_BOUNDS
;
6227 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6229 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6231 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6233 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6234 if (infoPtr
->uView
== LV_VIEW_LIST
)
6235 nScrollPosWidth
= infoPtr
->nItemWidth
;
6236 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6237 nScrollPosWidth
= 1;
6239 if (rcItem
.left
< infoPtr
->rcList
.left
)
6242 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6247 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6251 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6253 /* scroll up/down, but not in LVS_LIST mode */
6254 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6255 nScrollPosHeight
= infoPtr
->nItemHeight
;
6256 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6257 nScrollPosHeight
= 1;
6259 if (rcItem
.top
< infoPtr
->rcList
.top
)
6262 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6267 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6271 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6273 if (nScrollPosWidth
)
6275 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6276 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6277 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6280 if (nScrollPosHeight
)
6282 INT diff
= nVertDiff
/ nScrollPosHeight
;
6283 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6284 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6292 * Searches for an item with specific characteristics.
6295 * [I] hwnd : window handle
6296 * [I] nStart : base item index
6297 * [I] lpFindInfo : item information to look for
6300 * SUCCESS : index of item
6303 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6304 const LVFINDINFOW
*lpFindInfo
)
6306 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6307 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6308 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6309 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6310 POINT Position
, Destination
;
6313 /* Search in virtual listviews should be done by application, not by
6314 listview control, so we just send LVN_ODFINDITEMW and return the result */
6315 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6319 nmlv
.iStart
= nStart
;
6320 nmlv
.lvfi
= *lpFindInfo
;
6321 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6324 if (!lpFindInfo
|| nItem
< 0) return -1;
6327 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6328 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6330 lvItem
.mask
|= LVIF_TEXT
;
6331 lvItem
.pszText
= szDispText
;
6332 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6335 if (lpFindInfo
->flags
& LVFI_WRAP
)
6338 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6339 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6344 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6345 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6346 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6347 switch(lpFindInfo
->vkDirection
)
6349 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6350 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6351 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6352 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6353 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6354 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6355 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6357 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6358 Destination
.x
= rcArea
.right
;
6359 Destination
.y
= rcArea
.bottom
;
6361 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6365 else Destination
.x
= Destination
.y
= 0;
6367 /* if LVFI_PARAM is specified, all other flags are ignored */
6368 if (lpFindInfo
->flags
& LVFI_PARAM
)
6370 lvItem
.mask
|= LVIF_PARAM
;
6372 lvItem
.mask
&= ~LVIF_TEXT
;
6376 for (; nItem
< nLast
; nItem
++)
6378 lvItem
.iItem
= nItem
;
6379 lvItem
.iSubItem
= 0;
6380 lvItem
.pszText
= szDispText
;
6381 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6383 if (lvItem
.mask
& LVIF_PARAM
)
6385 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6391 if (lvItem
.mask
& LVIF_TEXT
)
6393 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6395 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6396 if (!p
|| p
!= lvItem
.pszText
) continue;
6400 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6404 if (!bNearest
) return nItem
;
6406 /* This is very inefficient. To do a good job here,
6407 * we need a sorted array of (x,y) item positions */
6408 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6410 /* compute the distance^2 to the destination */
6411 xdist
= Destination
.x
- Position
.x
;
6412 ydist
= Destination
.y
- Position
.y
;
6413 dist
= xdist
* xdist
+ ydist
* ydist
;
6415 /* remember the distance, and item if it's closer */
6419 nNearestItem
= nItem
;
6426 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6431 return nNearestItem
;
6436 * Searches for an item with specific characteristics.
6439 * [I] hwnd : window handle
6440 * [I] nStart : base item index
6441 * [I] lpFindInfo : item information to look for
6444 * SUCCESS : index of item
6447 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6448 const LVFINDINFOA
*lpFindInfo
)
6450 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6451 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6456 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6457 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6458 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6459 textfreeT(strW
, FALSE
);
6465 * Retrieves column attributes.
6468 * [I] infoPtr : valid pointer to the listview structure
6469 * [I] nColumn : column index
6470 * [IO] lpColumn : column information
6471 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6472 * otherwise it is in fact a LPLVCOLUMNA
6478 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6480 COLUMN_INFO
*lpColumnInfo
;
6483 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6484 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6486 /* initialize memory */
6487 ZeroMemory(&hdi
, sizeof(hdi
));
6489 if (lpColumn
->mask
& LVCF_TEXT
)
6491 hdi
.mask
|= HDI_TEXT
;
6492 hdi
.pszText
= lpColumn
->pszText
;
6493 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6496 if (lpColumn
->mask
& LVCF_IMAGE
)
6497 hdi
.mask
|= HDI_IMAGE
;
6499 if (lpColumn
->mask
& LVCF_ORDER
)
6500 hdi
.mask
|= HDI_ORDER
;
6502 if (lpColumn
->mask
& LVCF_SUBITEM
)
6503 hdi
.mask
|= HDI_LPARAM
;
6505 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6507 if (lpColumn
->mask
& LVCF_FMT
)
6508 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6510 if (lpColumn
->mask
& LVCF_WIDTH
)
6511 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6513 if (lpColumn
->mask
& LVCF_IMAGE
)
6514 lpColumn
->iImage
= hdi
.iImage
;
6516 if (lpColumn
->mask
& LVCF_ORDER
)
6517 lpColumn
->iOrder
= hdi
.iOrder
;
6519 if (lpColumn
->mask
& LVCF_SUBITEM
)
6520 lpColumn
->iSubItem
= hdi
.lParam
;
6522 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6523 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6528 static inline BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6530 if (!infoPtr
->hwndHeader
) return FALSE
;
6531 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6536 * Retrieves the column width.
6539 * [I] infoPtr : valid pointer to the listview structure
6540 * [I] int : column index
6543 * SUCCESS : column width
6546 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6548 INT nColumnWidth
= 0;
6551 TRACE("nColumn=%d\n", nColumn
);
6553 /* we have a 'column' in LIST and REPORT mode only */
6554 switch(infoPtr
->uView
)
6557 nColumnWidth
= infoPtr
->nItemWidth
;
6559 case LV_VIEW_DETAILS
:
6560 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6561 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6562 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6564 hdItem
.mask
= HDI_WIDTH
;
6565 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6567 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6570 nColumnWidth
= hdItem
.cxy
;
6574 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6575 return nColumnWidth
;
6580 * In list or report display mode, retrieves the number of items that can fit
6581 * vertically in the visible area. In icon or small icon display mode,
6582 * retrieves the total number of visible items.
6585 * [I] infoPtr : valid pointer to the listview structure
6588 * Number of fully visible items.
6590 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6592 switch (infoPtr
->uView
)
6595 case LV_VIEW_SMALLICON
:
6596 return infoPtr
->nItemCount
;
6597 case LV_VIEW_DETAILS
:
6598 return LISTVIEW_GetCountPerColumn(infoPtr
);
6600 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6608 * Retrieves an image list handle.
6611 * [I] infoPtr : valid pointer to the listview structure
6612 * [I] nImageList : image list identifier
6615 * SUCCESS : image list handle
6618 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6622 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6623 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6624 case LVSIL_STATE
: return infoPtr
->himlState
;
6625 case LVSIL_GROUPHEADER
:
6626 FIXME("LVSIL_GROUPHEADER not supported\n");
6629 WARN("got unknown imagelist index - %d\n", nImageList
);
6634 /* LISTVIEW_GetISearchString */
6638 * Retrieves item attributes.
6641 * [I] hwnd : window handle
6642 * [IO] lpLVItem : item info
6643 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6644 * if FALSE, then lpLVItem is a LPLVITEMA.
6647 * This is the internal 'GetItem' interface -- it tries to
6648 * be smart and avoid text copies, if possible, by modifying
6649 * lpLVItem->pszText to point to the text string. Please note
6650 * that this is not always possible (e.g. OWNERDATA), so on
6651 * entry you *must* supply valid values for pszText, and cchTextMax.
6652 * The only difference to the documented interface is that upon
6653 * return, you should use *only* the lpLVItem->pszText, rather than
6654 * the buffer pointer you provided on input. Most code already does
6655 * that, so it's not a problem.
6656 * For the two cases when the text must be copied (that is,
6657 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6663 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6665 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6666 NMLVDISPINFOW dispInfo
;
6672 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6674 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6677 if (lpLVItem
->mask
== 0) return TRUE
;
6678 TRACE("mask=%x\n", lpLVItem
->mask
);
6680 /* make a local copy */
6681 isubitem
= lpLVItem
->iSubItem
;
6683 /* a quick optimization if all we're asked is the focus state
6684 * these queries are worth optimising since they are common,
6685 * and can be answered in constant time, without the heavy accesses */
6686 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6687 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6689 lpLVItem
->state
= 0;
6690 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6691 lpLVItem
->state
|= LVIS_FOCUSED
;
6695 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6697 /* if the app stores all the data, handle it separately */
6698 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6700 dispInfo
.item
.state
= 0;
6702 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6703 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6704 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6706 UINT mask
= lpLVItem
->mask
;
6708 /* NOTE: copy only fields which we _know_ are initialized, some apps
6709 * depend on the uninitialized fields being 0 */
6710 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6711 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6712 dispInfo
.item
.iSubItem
= isubitem
;
6713 if (lpLVItem
->mask
& LVIF_TEXT
)
6715 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6717 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6720 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6721 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6724 if (lpLVItem
->mask
& LVIF_STATE
)
6725 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6726 /* could be zeroed on LVIF_NORECOMPUTE case */
6727 if (dispInfo
.item
.mask
)
6729 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6730 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6731 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6733 /* full size structure expected - _WIN32IE >= 0x560 */
6734 *lpLVItem
= dispInfo
.item
;
6736 else if (lpLVItem
->mask
& LVIF_INDENT
)
6738 /* indent member expected - _WIN32IE >= 0x300 */
6739 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6743 /* minimal structure expected */
6744 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6746 lpLVItem
->mask
= mask
;
6747 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6751 /* make sure lParam is zeroed out */
6752 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6754 /* callback marked pointer required here */
6755 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6756 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6758 /* we store only a little state, so if we're not asked, we're done */
6759 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6761 /* if focus is handled by us, report it */
6762 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6764 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6765 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6766 lpLVItem
->state
|= LVIS_FOCUSED
;
6769 /* and do the same for selection, if we handle it */
6770 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6772 lpLVItem
->state
&= ~LVIS_SELECTED
;
6773 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6774 lpLVItem
->state
|= LVIS_SELECTED
;
6780 /* find the item and subitem structures before we proceed */
6781 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6782 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6787 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6788 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6791 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6796 pItemHdr
= &lpItem
->hdr
;
6798 /* Do we need to query the state from the app? */
6799 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6801 dispInfo
.item
.mask
|= LVIF_STATE
;
6802 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6805 /* Do we need to enquire about the image? */
6806 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6807 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6809 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6810 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6813 /* Only items support indentation */
6814 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6817 dispInfo
.item
.mask
|= LVIF_INDENT
;
6818 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6821 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6822 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6823 !is_text(pItemHdr
->pszText
))
6825 dispInfo
.item
.mask
|= LVIF_TEXT
;
6826 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6827 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6828 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6829 *dispInfo
.item
.pszText
= '\0';
6832 /* If we don't have all the requested info, query the application */
6833 if (dispInfo
.item
.mask
)
6835 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6836 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6837 dispInfo
.item
.lParam
= lpItem
->lParam
;
6838 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6839 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6842 /* we should not store values for subitems */
6843 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6845 /* Now, handle the iImage field */
6846 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6848 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6849 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6850 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6852 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6854 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6855 lpLVItem
->iImage
= pItemHdr
->iImage
;
6857 lpLVItem
->iImage
= 0;
6860 /* The pszText field */
6861 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6863 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6864 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6866 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6868 else if (lpLVItem
->mask
& LVIF_TEXT
)
6870 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6871 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6872 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6875 /* Next is the lParam field */
6876 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6878 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6879 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6880 lpItem
->lParam
= dispInfo
.item
.lParam
;
6882 else if (lpLVItem
->mask
& LVIF_PARAM
)
6883 lpLVItem
->lParam
= lpItem
->lParam
;
6885 /* if this is a subitem, we're done */
6886 if (isubitem
) return TRUE
;
6888 /* ... the state field (this one is different due to uCallbackmask) */
6889 if (lpLVItem
->mask
& LVIF_STATE
)
6891 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6892 if (dispInfo
.item
.mask
& LVIF_STATE
)
6894 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6895 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6897 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6899 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6900 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6901 lpLVItem
->state
|= LVIS_FOCUSED
;
6903 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6905 lpLVItem
->state
&= ~LVIS_SELECTED
;
6906 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6907 lpLVItem
->state
|= LVIS_SELECTED
;
6911 /* and last, but not least, the indent field */
6912 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6914 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6915 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6916 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6918 else if (lpLVItem
->mask
& LVIF_INDENT
)
6920 lpLVItem
->iIndent
= lpItem
->iIndent
;
6928 * Retrieves item attributes.
6931 * [I] hwnd : window handle
6932 * [IO] lpLVItem : item info
6933 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6934 * if FALSE, then lpLVItem is a LPLVITEMA.
6937 * This is the external 'GetItem' interface -- it properly copies
6938 * the text in the provided buffer.
6944 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6949 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6952 pszText
= lpLVItem
->pszText
;
6953 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6954 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6956 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6957 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6959 pszText
= LPSTR_TEXTCALLBACKW
;
6961 lpLVItem
->pszText
= pszText
;
6969 * Retrieves the position (upper-left) of the listview control item.
6970 * Note that for LVS_ICON style, the upper-left is that of the icon
6971 * and not the bounding box.
6974 * [I] infoPtr : valid pointer to the listview structure
6975 * [I] nItem : item index
6976 * [O] lpptPosition : coordinate information
6982 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6986 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6988 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6990 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6991 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6993 if (infoPtr
->uView
== LV_VIEW_ICON
)
6995 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6996 lpptPosition
->y
+= ICON_TOP_PADDING
;
6998 lpptPosition
->x
+= Origin
.x
;
6999 lpptPosition
->y
+= Origin
.y
;
7001 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
7008 * Retrieves the bounding rectangle for a listview control item.
7011 * [I] infoPtr : valid pointer to the listview structure
7012 * [I] nItem : item index
7013 * [IO] lprc : bounding rectangle coordinates
7014 * lprc->left specifies the portion of the item for which the bounding
7015 * rectangle will be retrieved.
7017 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
7018 * including the icon and label.
7021 * * Experiment shows that native control returns:
7022 * * width = min (48, length of text line)
7023 * * .left = position.x - (width - iconsize.cx)/2
7024 * * .right = .left + width
7025 * * height = #lines of text * ntmHeight + icon height + 8
7026 * * .top = position.y - 2
7027 * * .bottom = .top + height
7028 * * separation between items .y = itemSpacing.cy - height
7029 * * .x = itemSpacing.cx - width
7030 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
7033 * * Experiment shows that native control returns:
7034 * * width = iconSize.cx + 16
7035 * * .left = position.x - (width - iconsize.cx)/2
7036 * * .right = .left + width
7037 * * height = iconSize.cy + 4
7038 * * .top = position.y - 2
7039 * * .bottom = .top + height
7040 * * separation between items .y = itemSpacing.cy - height
7041 * * .x = itemSpacing.cx - width
7042 * LVIR_LABEL Returns the bounding rectangle of the item text.
7045 * * Experiment shows that native control returns:
7046 * * width = text length
7047 * * .left = position.x - width/2
7048 * * .right = .left + width
7049 * * height = ntmH * linecount + 2
7050 * * .top = position.y + iconSize.cy + 6
7051 * * .bottom = .top + height
7052 * * separation between items .y = itemSpacing.cy - height
7053 * * .x = itemSpacing.cx - width
7054 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
7055 * rectangles, but excludes columns in report view.
7062 * Note that the bounding rectangle of the label in the LVS_ICON view depends
7063 * upon whether the window has the focus currently and on whether the item
7064 * is the one with the focus. Ensure that the control's record of which
7065 * item has the focus agrees with the items' records.
7067 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
7069 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7070 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
7071 POINT Position
, Origin
;
7075 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
7077 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7079 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7080 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7082 /* Be smart and try to figure out the minimum we have to do */
7083 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
7084 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
7085 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
7086 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
7087 oversizedBox
= TRUE
;
7089 /* get what we need from the item before hand, so we make
7090 * only one request. This can speed up things, if data
7091 * is stored on the app side */
7093 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7094 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
7095 lvItem
.iItem
= nItem
;
7096 lvItem
.iSubItem
= 0;
7097 lvItem
.pszText
= szDispText
;
7098 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7099 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7100 /* we got the state already up, simulate it here, to avoid a reget */
7101 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7103 lvItem
.mask
|= LVIF_STATE
;
7104 lvItem
.stateMask
= LVIS_FOCUSED
;
7105 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7108 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7109 lprc
->left
= LVIR_BOUNDS
;
7115 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7119 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7123 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7126 case LVIR_SELECTBOUNDS
:
7127 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7131 WARN("Unknown value: %d\n", lprc
->left
);
7135 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7137 if (mode
!= LVIR_BOUNDS
)
7138 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7139 Position
.y
+ Origin
.y
);
7141 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7144 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7146 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7153 * Retrieves the spacing between listview control items.
7156 * [I] infoPtr : valid pointer to the listview structure
7157 * [IO] lprc : rectangle to receive the output
7158 * on input, lprc->top = nSubItem
7159 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7161 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7162 * not only those of the first column.
7168 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7170 RECT rect
= { 0, 0, 0, 0 };
7174 if (!lprc
) return FALSE
;
7176 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7177 /* Subitem of '0' means item itself, and this works for all control view modes */
7179 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7181 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7183 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7184 /* this works for any item index, no matter if it exists or not */
7185 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7187 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7190 rect
.bottom
= infoPtr
->nItemHeight
;
7194 /* Native implementation is broken for this case and garbage is left for left and right fields,
7195 we zero them to get predictable output */
7196 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7197 lprc
->bottom
= infoPtr
->nItemHeight
;
7198 OffsetRect(lprc
, origin
.x
, y
);
7199 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7207 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7208 if (infoPtr
->himlSmall
)
7209 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7211 rect
.right
= rect
.left
;
7213 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7221 ERR("Unknown bounds=%d\n", lprc
->left
);
7225 OffsetRect(&rect
, origin
.x
, y
);
7227 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7234 * Retrieves the spacing between listview control items.
7237 * [I] infoPtr : valid pointer to the listview structure
7238 * [I] bSmall : flag for small or large icon
7241 * Horizontal + vertical spacing
7243 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7249 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7253 if (infoPtr
->uView
== LV_VIEW_ICON
)
7254 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7256 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7263 * Retrieves the state of a listview control item.
7266 * [I] infoPtr : valid pointer to the listview structure
7267 * [I] nItem : item index
7268 * [I] uMask : state mask
7271 * State specified by the mask.
7273 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7277 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7279 lvItem
.iItem
= nItem
;
7280 lvItem
.iSubItem
= 0;
7281 lvItem
.mask
= LVIF_STATE
;
7282 lvItem
.stateMask
= uMask
;
7283 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7285 return lvItem
.state
& uMask
;
7290 * Retrieves the text of a listview control item or subitem.
7293 * [I] hwnd : window handle
7294 * [I] nItem : item index
7295 * [IO] lpLVItem : item information
7296 * [I] isW : TRUE if lpLVItem is Unicode
7299 * SUCCESS : string length
7302 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7304 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7306 lpLVItem
->mask
= LVIF_TEXT
;
7307 lpLVItem
->iItem
= nItem
;
7308 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7310 return textlenT(lpLVItem
->pszText
, isW
);
7315 * Searches for an item based on properties + relationships.
7318 * [I] infoPtr : valid pointer to the listview structure
7319 * [I] nItem : item index
7320 * [I] uFlags : relationship flag
7323 * SUCCESS : item index
7326 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7329 LVFINDINFOW lvFindInfo
;
7330 INT nCountPerColumn
;
7334 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7335 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7337 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7339 if (uFlags
& LVNI_CUT
)
7342 if (uFlags
& LVNI_DROPHILITED
)
7343 uMask
|= LVIS_DROPHILITED
;
7345 if (uFlags
& LVNI_FOCUSED
)
7346 uMask
|= LVIS_FOCUSED
;
7348 if (uFlags
& LVNI_SELECTED
)
7349 uMask
|= LVIS_SELECTED
;
7351 /* if we're asked for the focused item, that's only one,
7352 * so it's worth optimizing */
7353 if (uFlags
& LVNI_FOCUSED
)
7355 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7356 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7359 if (uFlags
& LVNI_ABOVE
)
7361 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7366 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7372 /* Special case for autoarrange - move 'til the top of a list */
7373 if (is_autoarrange(infoPtr
))
7375 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7376 while (nItem
- nCountPerRow
>= 0)
7378 nItem
-= nCountPerRow
;
7379 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7384 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7385 lvFindInfo
.vkDirection
= VK_UP
;
7386 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7387 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7389 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7394 else if (uFlags
& LVNI_BELOW
)
7396 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7398 while (nItem
< infoPtr
->nItemCount
)
7401 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7407 /* Special case for autoarrange - move 'til the bottom of a list */
7408 if (is_autoarrange(infoPtr
))
7410 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7411 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7413 nItem
+= nCountPerRow
;
7414 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7419 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7420 lvFindInfo
.vkDirection
= VK_DOWN
;
7421 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7422 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7424 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7429 else if (uFlags
& LVNI_TOLEFT
)
7431 if (infoPtr
->uView
== LV_VIEW_LIST
)
7433 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7434 while (nItem
- nCountPerColumn
>= 0)
7436 nItem
-= nCountPerColumn
;
7437 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7441 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7443 /* Special case for autoarrange - move 'til the beginning of a row */
7444 if (is_autoarrange(infoPtr
))
7446 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7447 while (nItem
% nCountPerRow
> 0)
7450 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7455 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7456 lvFindInfo
.vkDirection
= VK_LEFT
;
7457 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7458 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7460 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7465 else if (uFlags
& LVNI_TORIGHT
)
7467 if (infoPtr
->uView
== LV_VIEW_LIST
)
7469 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7470 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7472 nItem
+= nCountPerColumn
;
7473 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7477 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7479 /* Special case for autoarrange - move 'til the end of a row */
7480 if (is_autoarrange(infoPtr
))
7482 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7483 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7486 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7491 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7492 lvFindInfo
.vkDirection
= VK_RIGHT
;
7493 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7494 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7496 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7505 /* search by index */
7506 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7508 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7516 /* LISTVIEW_GetNumberOfWorkAreas */
7520 * Retrieves the origin coordinates when in icon or small icon display mode.
7523 * [I] infoPtr : valid pointer to the listview structure
7524 * [O] lpptOrigin : coordinate information
7529 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7531 INT nHorzPos
= 0, nVertPos
= 0;
7532 SCROLLINFO scrollInfo
;
7534 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7535 scrollInfo
.fMask
= SIF_POS
;
7537 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7538 nHorzPos
= scrollInfo
.nPos
;
7539 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7540 nVertPos
= scrollInfo
.nPos
;
7542 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7544 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7545 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7546 if (infoPtr
->uView
== LV_VIEW_LIST
)
7547 nHorzPos
*= infoPtr
->nItemWidth
;
7548 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7549 nVertPos
*= infoPtr
->nItemHeight
;
7551 lpptOrigin
->x
-= nHorzPos
;
7552 lpptOrigin
->y
-= nVertPos
;
7554 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7559 * Retrieves the width of a string.
7562 * [I] hwnd : window handle
7563 * [I] lpszText : text string to process
7564 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7567 * SUCCESS : string width (in pixels)
7570 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7575 if (is_text(lpszText
))
7577 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7578 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7579 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7582 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7584 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7585 SelectObject(hdc
, hOldFont
);
7586 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7588 return stringSize
.cx
;
7593 * Determines which listview item is located at the specified position.
7596 * [I] infoPtr : valid pointer to the listview structure
7597 * [IO] lpht : hit test information
7598 * [I] subitem : fill out iSubItem.
7599 * [I] select : return the index only if the hit selects the item
7602 * (mm 20001022): We must not allow iSubItem to be touched, for
7603 * an app might pass only a structure with space up to iItem!
7604 * (MS Office 97 does that for instance in the file open dialog)
7607 * SUCCESS : item index
7610 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7612 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7613 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7614 POINT Origin
, Position
, opt
;
7620 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7624 if (subitem
) lpht
->iSubItem
= 0;
7626 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7628 /* set whole list relation flags */
7629 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7631 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7632 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7633 lpht
->flags
|= LVHT_TOLEFT
;
7635 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7636 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7640 if (infoPtr
->rcList
.bottom
< opt
.y
)
7641 lpht
->flags
|= LVHT_BELOW
;
7645 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7646 lpht
->flags
|= LVHT_TOLEFT
;
7647 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7648 lpht
->flags
|= LVHT_TORIGHT
;
7650 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7651 lpht
->flags
|= LVHT_ABOVE
;
7652 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7653 lpht
->flags
|= LVHT_BELOW
;
7656 /* even if item is invalid try to find subitem */
7657 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7662 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7664 lpht
->iSubItem
= -1;
7665 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7667 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7669 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7675 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7677 /* if we're outside horizontal columns bounds there's nothing to test further */
7678 if (lpht
->iSubItem
== -1)
7681 lpht
->flags
= LVHT_NOWHERE
;
7686 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7687 if (lpht
->flags
) return -1;
7689 lpht
->flags
|= LVHT_NOWHERE
;
7691 /* first deal with the large items */
7692 rcSearch
.left
= lpht
->pt
.x
;
7693 rcSearch
.top
= lpht
->pt
.y
;
7694 rcSearch
.right
= rcSearch
.left
+ 1;
7695 rcSearch
.bottom
= rcSearch
.top
+ 1;
7697 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7698 iterator_next(&i
); /* go to first item in the sequence */
7700 iterator_destroy(&i
);
7702 TRACE("lpht->iItem=%d\n", iItem
);
7703 if (iItem
== -1) return -1;
7705 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7706 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7707 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7708 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7709 lvItem
.iItem
= iItem
;
7710 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7711 lvItem
.pszText
= szDispText
;
7712 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7713 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7714 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7716 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7717 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7718 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7720 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7721 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7723 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7725 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7728 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7729 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7733 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7734 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7736 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7737 if (!PtInRect(&rcBounds
, opt
)) return -1;
7739 /* That's a special case - row rectangle is used as item rectangle and
7740 returned flags contain all item parts. */
7741 is_fullrow
= (infoPtr
->uView
== LV_VIEW_DETAILS
) && ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
));
7743 if (PtInRect(&rcIcon
, opt
))
7744 lpht
->flags
|= LVHT_ONITEMICON
;
7745 else if (PtInRect(&rcLabel
, opt
))
7746 lpht
->flags
|= LVHT_ONITEMLABEL
;
7747 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7748 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7749 if (is_fullrow
&& !(lpht
->flags
& LVHT_ONITEM
))
7751 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7753 if (lpht
->flags
& LVHT_ONITEM
)
7754 lpht
->flags
&= ~LVHT_NOWHERE
;
7755 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7757 if (select
&& !is_fullrow
)
7759 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7761 /* get main item bounds */
7762 lvItem
.iSubItem
= 0;
7763 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7764 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7765 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7767 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7769 return lpht
->iItem
= iItem
;
7774 * Inserts a new item in the listview control.
7777 * [I] infoPtr : valid pointer to the listview structure
7778 * [I] lpLVItem : item information
7779 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7782 * SUCCESS : new item index
7785 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7792 BOOL is_sorted
, has_changed
;
7794 HWND hwndSelf
= infoPtr
->hwndSelf
;
7796 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7798 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7800 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7801 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7803 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7805 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7807 /* insert item in listview control data structure */
7808 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7809 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7811 /* link with id struct */
7812 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7814 lpID
->item
= hdpaSubItems
;
7815 lpID
->id
= get_next_itemid(infoPtr
);
7816 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7818 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7819 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7821 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7823 /* calculate new item index */
7830 while (i
< infoPtr
->nItemCount
)
7832 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7833 item_s
= DPA_GetPtr(hItem
, 0);
7835 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7836 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7838 if (cmpv
>= 0) break;
7844 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7846 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7847 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7848 if (nItem
== -1) goto fail
;
7849 infoPtr
->nItemCount
++;
7851 /* shift indices first so they don't get tangled */
7852 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7854 /* set the item attributes */
7855 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7857 /* full size structure expected - _WIN32IE >= 0x560 */
7860 else if (lpLVItem
->mask
& LVIF_INDENT
)
7862 /* indent member expected - _WIN32IE >= 0x300 */
7863 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7867 /* minimal structure expected */
7868 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7871 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7873 if (item
.mask
& LVIF_STATE
)
7875 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7876 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7877 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7881 item
.mask
|= LVIF_STATE
;
7882 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7883 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7887 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7889 /* make room for the position, if we are in the right mode */
7890 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7892 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7894 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7896 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7901 /* send LVN_INSERTITEM notification */
7902 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7904 nmlv
.lParam
= lpItem
->lParam
;
7905 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7906 if (!IsWindow(hwndSelf
))
7909 /* align items (set position of each item) */
7910 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7914 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7915 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7917 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7919 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7922 /* now is the invalidation fun */
7923 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7927 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7928 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7929 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7930 infoPtr
->nItemCount
--;
7932 DPA_DeletePtr(hdpaSubItems
, 0);
7933 DPA_Destroy (hdpaSubItems
);
7940 * Checks item visibility.
7943 * [I] infoPtr : valid pointer to the listview structure
7944 * [I] nFirst : item index to check for
7947 * Item visible : TRUE
7948 * Item invisible or failure : FALSE
7950 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7952 POINT Origin
, Position
;
7957 TRACE("nItem=%d\n", nItem
);
7959 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7961 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7962 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7963 rcItem
.left
= Position
.x
+ Origin
.x
;
7964 rcItem
.top
= Position
.y
+ Origin
.y
;
7965 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7966 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7968 hdc
= GetDC(infoPtr
->hwndSelf
);
7969 if (!hdc
) return FALSE
;
7970 ret
= RectVisible(hdc
, &rcItem
);
7971 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7978 * Redraws a range of items.
7981 * [I] infoPtr : valid pointer to the listview structure
7982 * [I] nFirst : first item
7983 * [I] nLast : last item
7989 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7993 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7994 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7997 for (i
= nFirst
; i
<= nLast
; i
++)
7998 LISTVIEW_InvalidateItem(infoPtr
, i
);
8005 * Scroll the content of a listview.
8008 * [I] infoPtr : valid pointer to the listview structure
8009 * [I] dx : horizontal scroll amount in pixels
8010 * [I] dy : vertical scroll amount in pixels
8017 * If the control is in report view (LV_VIEW_DETAILS) the control can
8018 * be scrolled only in line increments. "dy" will be rounded to the
8019 * nearest number of pixels that are a whole line. Ex: if line height
8020 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
8021 * is passed, then the scroll will be 0. (per MSDN 7/2002)
8023 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8025 switch(infoPtr
->uView
) {
8026 case LV_VIEW_DETAILS
:
8027 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
8028 dy
/= infoPtr
->nItemHeight
;
8031 if (dy
!= 0) return FALSE
;
8037 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
8038 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
8045 * Sets the background color.
8048 * [I] infoPtr : valid pointer to the listview structure
8049 * [I] color : background color
8055 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8057 TRACE("(color=%x)\n", color
);
8059 if(infoPtr
->clrBk
!= color
) {
8060 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8061 infoPtr
->clrBk
= color
;
8062 if (color
== CLR_NONE
)
8063 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
8066 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
8067 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
8074 /* LISTVIEW_SetBkImage */
8076 /*** Helper for {Insert,Set}ColumnT *only* */
8077 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
8078 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8080 if (lpColumn
->mask
& LVCF_FMT
)
8082 /* format member is valid */
8083 lphdi
->mask
|= HDI_FORMAT
;
8085 /* set text alignment (leftmost column must be left-aligned) */
8086 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8087 lphdi
->fmt
|= HDF_LEFT
;
8088 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
8089 lphdi
->fmt
|= HDF_RIGHT
;
8090 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
8091 lphdi
->fmt
|= HDF_CENTER
;
8093 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
8094 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8096 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8098 lphdi
->fmt
|= HDF_IMAGE
;
8099 lphdi
->iImage
= I_IMAGECALLBACK
;
8102 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8103 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8106 if (lpColumn
->mask
& LVCF_WIDTH
)
8108 lphdi
->mask
|= HDI_WIDTH
;
8109 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8111 /* make it fill the remainder of the controls width */
8115 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8117 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8118 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8121 /* retrieve the layout of the header */
8122 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8123 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8125 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8128 lphdi
->cxy
= lpColumn
->cx
;
8131 if (lpColumn
->mask
& LVCF_TEXT
)
8133 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8134 lphdi
->fmt
|= HDF_STRING
;
8135 lphdi
->pszText
= lpColumn
->pszText
;
8136 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8139 if (lpColumn
->mask
& LVCF_IMAGE
)
8141 lphdi
->mask
|= HDI_IMAGE
;
8142 lphdi
->iImage
= lpColumn
->iImage
;
8145 if (lpColumn
->mask
& LVCF_ORDER
)
8147 lphdi
->mask
|= HDI_ORDER
;
8148 lphdi
->iOrder
= lpColumn
->iOrder
;
8155 * Inserts a new column.
8158 * [I] infoPtr : valid pointer to the listview structure
8159 * [I] nColumn : column index
8160 * [I] lpColumn : column information
8161 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8164 * SUCCESS : new column index
8167 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8168 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8170 COLUMN_INFO
*lpColumnInfo
;
8174 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8176 if (!lpColumn
|| nColumn
< 0) return -1;
8177 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8179 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8180 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8183 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8184 * (can be seen in SPY) otherwise column never gets added.
8186 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8187 hdi
.mask
|= HDI_WIDTH
;
8192 * when the iSubItem is available Windows copies it to the header lParam. It seems
8193 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8195 if (lpColumn
->mask
& LVCF_SUBITEM
)
8197 hdi
.mask
|= HDI_LPARAM
;
8198 hdi
.lParam
= lpColumn
->iSubItem
;
8201 /* create header if not present */
8202 LISTVIEW_CreateHeader(infoPtr
);
8203 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8204 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8206 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8209 /* insert item in header control */
8210 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8211 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8212 nColumn
, (LPARAM
)&hdi
);
8213 if (nNewColumn
== -1) return -1;
8214 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8216 /* create our own column info */
8217 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8218 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8220 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8221 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8222 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8225 /* now we have to actually adjust the data */
8226 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8228 SUBITEM_INFO
*lpSubItem
;
8234 item
.iSubItem
= nNewColumn
;
8235 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8236 item
.iImage
= I_IMAGECALLBACK
;
8237 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8239 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8241 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8242 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8244 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8245 if (lpSubItem
->iSubItem
>= nNewColumn
)
8246 lpSubItem
->iSubItem
++;
8249 /* add new subitem for each item */
8251 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8255 /* make space for the new column */
8256 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8257 LISTVIEW_UpdateItemSize(infoPtr
);
8262 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8265 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8273 * Sets the attributes of a header item.
8276 * [I] infoPtr : valid pointer to the listview structure
8277 * [I] nColumn : column index
8278 * [I] lpColumn : column attributes
8279 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8285 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8286 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8288 HDITEMW hdi
, hdiget
;
8291 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8293 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8295 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8296 if (lpColumn
->mask
& LVCF_FMT
)
8298 hdi
.mask
|= HDI_FORMAT
;
8299 hdiget
.mask
= HDI_FORMAT
;
8300 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8301 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8303 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8305 /* set header item attributes */
8306 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8307 if (!bResult
) return FALSE
;
8309 if (lpColumn
->mask
& LVCF_FMT
)
8311 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8312 INT oldFmt
= lpColumnInfo
->fmt
;
8314 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8315 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8317 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8321 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8322 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8329 * Sets the column order array
8332 * [I] infoPtr : valid pointer to the listview structure
8333 * [I] iCount : number of elements in column order array
8334 * [I] lpiArray : pointer to column order array
8340 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8342 if (!infoPtr
->hwndHeader
) return FALSE
;
8343 infoPtr
->colRectsDirty
= TRUE
;
8344 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8349 * Sets the width of a column
8352 * [I] infoPtr : valid pointer to the listview structure
8353 * [I] nColumn : column index
8354 * [I] cx : column width
8360 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8362 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8366 TRACE("(nColumn=%d, cx=%d)\n", nColumn
, cx
);
8368 /* set column width only if in report or list mode */
8369 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8371 /* take care of invalid cx values - LVSCW_AUTOSIZE_* values are negative,
8372 with _USEHEADER being the lowest */
8373 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< LVSCW_AUTOSIZE_USEHEADER
) cx
= LVSCW_AUTOSIZE
;
8374 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
<= 0) return FALSE
;
8376 /* resize all columns if in LV_VIEW_LIST mode */
8377 if(infoPtr
->uView
== LV_VIEW_LIST
)
8379 infoPtr
->nItemWidth
= cx
;
8380 LISTVIEW_InvalidateList(infoPtr
);
8384 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8386 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8391 lvItem
.mask
= LVIF_TEXT
;
8393 lvItem
.iSubItem
= nColumn
;
8394 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8395 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8397 lvItem
.pszText
= szDispText
;
8398 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8399 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8400 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8402 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8403 max_cx
+= infoPtr
->iconSize
.cx
;
8404 max_cx
+= TRAILING_LABEL_PADDING
;
8407 /* autosize based on listview items width */
8408 if(cx
== LVSCW_AUTOSIZE
)
8410 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8412 /* if iCol is the last column make it fill the remainder of the controls width */
8413 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8418 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8419 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8421 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8425 /* Despite what the MS docs say, if this is not the last
8426 column, then MS resizes the column to the width of the
8427 largest text string in the column, including headers
8428 and items. This is different from LVSCW_AUTOSIZE in that
8429 LVSCW_AUTOSIZE ignores the header string length. */
8432 /* retrieve header text */
8433 hdi
.mask
= HDI_TEXT
|HDI_FORMAT
|HDI_IMAGE
|HDI_BITMAP
;
8434 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8435 hdi
.pszText
= szDispText
;
8436 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8438 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8439 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8440 HIMAGELIST himl
= (HIMAGELIST
)SendMessageW(infoPtr
->hwndHeader
, HDM_GETIMAGELIST
, 0, 0);
8441 INT bitmap_margin
= 0;
8444 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8445 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8447 if (hdi
.fmt
& (HDF_IMAGE
|HDF_BITMAP
))
8448 bitmap_margin
= SendMessageW(infoPtr
->hwndHeader
, HDM_GETBITMAPMARGIN
, 0, 0);
8450 if ((hdi
.fmt
& HDF_IMAGE
) && himl
)
8452 INT icon_cx
, icon_cy
;
8454 if (!ImageList_GetIconSize(himl
, &icon_cx
, &icon_cy
))
8455 cx
+= icon_cx
+ 2*bitmap_margin
;
8457 else if (hdi
.fmt
& HDF_BITMAP
)
8461 GetObjectW(hdi
.hbm
, sizeof(BITMAP
), &bmp
);
8462 cx
+= bmp
.bmWidth
+ 2*bitmap_margin
;
8465 SelectObject(hdc
, old_font
);
8466 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8468 cx
= max (cx
, max_cx
);
8472 if (cx
< 0) return FALSE
;
8474 /* call header to update the column change */
8475 hdi
.mask
= HDI_WIDTH
;
8476 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8477 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8478 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8482 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8485 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8488 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8490 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8491 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8494 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8495 ILC_COLOR
| ILC_MASK
, 2, 2);
8496 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8497 hdc
= CreateCompatibleDC(hdc_wnd
);
8498 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8499 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8500 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8502 SetRect(&rc
, 0, 0, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8503 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8504 FillRect(hdc
, &rc
, hbr_white
);
8505 InflateRect(&rc
, -2, -2);
8506 FillRect(hdc
, &rc
, hbr_black
);
8508 SelectObject(hdc
, hbm_im
);
8509 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8510 SelectObject(hdc
, hbm_orig
);
8511 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8513 SelectObject(hdc
, hbm_im
);
8514 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8515 SelectObject(hdc
, hbm_orig
);
8516 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8518 DeleteObject(hbm_mask
);
8519 DeleteObject(hbm_im
);
8527 * Sets the extended listview style.
8530 * [I] infoPtr : valid pointer to the listview structure
8532 * [I] dwStyle : style
8535 * SUCCESS : previous style
8538 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8540 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8542 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8546 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8548 infoPtr
->dwLvExStyle
= ex_style
;
8550 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8552 HIMAGELIST himl
= 0;
8553 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8556 item
.mask
= LVIF_STATE
;
8557 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8558 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8559 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8561 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8562 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8563 ImageList_Destroy(infoPtr
->himlState
);
8565 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8566 /* checkbox list replaces previous custom list or... */
8567 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8568 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8569 /* ...previous was checkbox list */
8570 (old_ex_style
& LVS_EX_CHECKBOXES
))
8571 ImageList_Destroy(himl
);
8574 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8578 /* if not already created */
8579 LISTVIEW_CreateHeader(infoPtr
);
8581 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8582 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8583 style
|= HDS_DRAGDROP
;
8585 style
&= ~HDS_DRAGDROP
;
8586 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8589 /* GRIDLINES adds decoration at top so changes sizes */
8590 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8592 LISTVIEW_CreateHeader(infoPtr
);
8593 LISTVIEW_UpdateSize(infoPtr
);
8596 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8598 LISTVIEW_CreateHeader(infoPtr
);
8601 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8603 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8604 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8607 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8609 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8610 LISTVIEW_CreateHeader(infoPtr
);
8612 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8613 LISTVIEW_UpdateSize(infoPtr
);
8614 LISTVIEW_UpdateScroll(infoPtr
);
8617 LISTVIEW_InvalidateList(infoPtr
);
8618 return old_ex_style
;
8623 * Sets the new hot cursor used during hot tracking and hover selection.
8626 * [I] infoPtr : valid pointer to the listview structure
8627 * [I] hCursor : the new hot cursor handle
8630 * Returns the previous hot cursor
8632 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8634 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8636 infoPtr
->hHotCursor
= hCursor
;
8644 * Sets the hot item index.
8647 * [I] infoPtr : valid pointer to the listview structure
8648 * [I] iIndex : index
8651 * SUCCESS : previous hot item index
8652 * FAILURE : -1 (no hot item)
8654 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8656 INT iOldIndex
= infoPtr
->nHotItem
;
8658 infoPtr
->nHotItem
= iIndex
;
8666 * Sets the amount of time the cursor must hover over an item before it is selected.
8669 * [I] infoPtr : valid pointer to the listview structure
8670 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8673 * Returns the previous hover time
8675 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8677 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8679 infoPtr
->dwHoverTime
= dwHoverTime
;
8681 return oldHoverTime
;
8686 * Sets spacing for icons of LVS_ICON style.
8689 * [I] infoPtr : valid pointer to the listview structure
8690 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8691 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8694 * MAKELONG(oldcx, oldcy)
8696 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8698 INT iconWidth
= 0, iconHeight
= 0;
8699 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8701 TRACE("requested=(%d,%d)\n", cx
, cy
);
8703 /* set to defaults, if instructed to */
8704 if (cx
== -1 && cy
== -1)
8706 infoPtr
->autoSpacing
= TRUE
;
8707 if (infoPtr
->himlNormal
)
8708 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8709 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8710 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8713 infoPtr
->autoSpacing
= FALSE
;
8715 /* if 0 then keep width */
8717 infoPtr
->iconSpacing
.cx
= cx
;
8719 /* if 0 then keep height */
8721 infoPtr
->iconSpacing
.cy
= cy
;
8723 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8724 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8725 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8726 infoPtr
->ntmHeight
);
8728 /* these depend on the iconSpacing */
8729 LISTVIEW_UpdateItemSize(infoPtr
);
8734 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8738 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8745 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8746 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8755 * [I] infoPtr : valid pointer to the listview structure
8756 * [I] nType : image list type
8757 * [I] himl : image list handle
8760 * SUCCESS : old image list
8763 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8765 INT oldHeight
= infoPtr
->nItemHeight
;
8766 HIMAGELIST himlOld
= 0;
8768 TRACE("(nType=%d, himl=%p)\n", nType
, himl
);
8773 himlOld
= infoPtr
->himlNormal
;
8774 infoPtr
->himlNormal
= himl
;
8775 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8776 if (infoPtr
->autoSpacing
)
8777 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8781 himlOld
= infoPtr
->himlSmall
;
8782 infoPtr
->himlSmall
= himl
;
8783 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8784 if (infoPtr
->hwndHeader
)
8785 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8789 himlOld
= infoPtr
->himlState
;
8790 infoPtr
->himlState
= himl
;
8791 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8792 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8796 ERR("Unknown icon type=%d\n", nType
);
8800 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8801 if (infoPtr
->nItemHeight
!= oldHeight
)
8802 LISTVIEW_UpdateScroll(infoPtr
);
8809 * Preallocates memory (does *not* set the actual count of items !)
8812 * [I] infoPtr : valid pointer to the listview structure
8813 * [I] nItems : item count (projected number of items to allocate)
8814 * [I] dwFlags : update flags
8820 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8822 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8824 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8826 INT nOldCount
= infoPtr
->nItemCount
;
8827 infoPtr
->nItemCount
= nItems
;
8829 if (nItems
< nOldCount
)
8831 RANGE range
= { nItems
, nOldCount
};
8832 ranges_del(infoPtr
->selectionRanges
, range
);
8833 if (infoPtr
->nFocusedItem
>= nItems
)
8835 LISTVIEW_SetItemFocus(infoPtr
, -1);
8836 SetRectEmpty(&infoPtr
->rcFocus
);
8840 LISTVIEW_UpdateScroll(infoPtr
);
8842 /* the flags are valid only in ownerdata report and list modes */
8843 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8845 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8846 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8848 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8849 LISTVIEW_InvalidateList(infoPtr
);
8856 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8857 nFrom
= min(nOldCount
, nItems
);
8858 nTo
= max(nOldCount
, nItems
);
8860 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8862 SetRect(&rcErase
, 0, nFrom
* infoPtr
->nItemHeight
, infoPtr
->nItemWidth
,
8863 nTo
* infoPtr
->nItemHeight
);
8864 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8865 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8866 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8868 else /* LV_VIEW_LIST */
8870 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8872 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8873 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8874 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8875 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8876 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8877 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8878 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8880 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8882 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8883 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8884 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8885 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8886 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8892 /* According to MSDN for non-LVS_OWNERDATA this is just
8893 * a performance issue. The control allocates its internal
8894 * data structures for the number of items specified. It
8895 * cuts down on the number of memory allocations. Therefore
8896 * we will just issue a WARN here
8898 WARN("for non-ownerdata performance option not implemented.\n");
8906 * Sets the position of an item.
8909 * [I] infoPtr : valid pointer to the listview structure
8910 * [I] nItem : item index
8911 * [I] pt : coordinate
8917 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8921 TRACE("(nItem=%d, pt=%s)\n", nItem
, wine_dbgstr_point(pt
));
8923 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8924 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8927 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8929 /* This point value seems to be an undocumented feature.
8930 * The best guess is that it means either at the origin,
8931 * or at true beginning of the list. I will assume the origin. */
8932 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8935 if (infoPtr
->uView
== LV_VIEW_ICON
)
8937 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8938 Pt
.y
-= ICON_TOP_PADDING
;
8943 infoPtr
->bAutoarrange
= FALSE
;
8945 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8950 * Sets the state of one or many items.
8953 * [I] infoPtr : valid pointer to the listview structure
8954 * [I] nItem : item index
8955 * [I] item : item or subitem info
8961 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8966 if (!item
) return FALSE
;
8968 lvItem
.iItem
= nItem
;
8969 lvItem
.iSubItem
= 0;
8970 lvItem
.mask
= LVIF_STATE
;
8971 lvItem
.state
= item
->state
;
8972 lvItem
.stateMask
= item
->stateMask
;
8973 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8980 /* special case optimization for recurring attempt to deselect all */
8981 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8984 /* select all isn't allowed in LVS_SINGLESEL */
8985 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8988 /* focus all isn't allowed */
8989 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8991 notify
= infoPtr
->bDoChangeNotify
;
8992 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8994 infoPtr
->bDoChangeNotify
= FALSE
;
8995 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8996 oldstate
|= LVIS_SELECTED
;
8997 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
9000 /* apply to all items */
9001 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
9002 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
9004 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
9008 infoPtr
->bDoChangeNotify
= notify
;
9012 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
9013 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
9014 nmlv
.uChanged
= LVIF_STATE
;
9015 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
9018 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
9022 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
9029 * Sets the text of an item or subitem.
9032 * [I] hwnd : window handle
9033 * [I] nItem : item index
9034 * [I] lpLVItem : item or subitem info
9035 * [I] isW : TRUE if input is Unicode
9041 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
9045 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9046 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9048 lvItem
.iItem
= nItem
;
9049 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
9050 lvItem
.mask
= LVIF_TEXT
;
9051 lvItem
.pszText
= lpLVItem
->pszText
;
9052 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
9054 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
9056 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
9061 * Set item index that marks the start of a multiple selection.
9064 * [I] infoPtr : valid pointer to the listview structure
9065 * [I] nIndex : index
9068 * Index number or -1 if there is no selection mark.
9070 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
9072 INT nOldIndex
= infoPtr
->nSelectionMark
;
9074 TRACE("(nIndex=%d)\n", nIndex
);
9076 if (nIndex
>= -1 && nIndex
< infoPtr
->nItemCount
)
9077 infoPtr
->nSelectionMark
= nIndex
;
9084 * Sets the text background color.
9087 * [I] infoPtr : valid pointer to the listview structure
9088 * [I] color : text background color
9094 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9096 TRACE("(color=%x)\n", color
);
9098 infoPtr
->clrTextBk
= color
;
9104 * Sets the text foreground color.
9107 * [I] infoPtr : valid pointer to the listview structure
9108 * [I] color : text color
9114 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9116 TRACE("(color=%x)\n", color
);
9118 infoPtr
->clrText
= color
;
9124 * Sets new ToolTip window to ListView control.
9127 * [I] infoPtr : valid pointer to the listview structure
9128 * [I] hwndNewToolTip : handle to new ToolTip
9133 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9135 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9136 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9137 return hwndOldToolTip
;
9142 * sets the Unicode character format flag for the control
9144 * [I] infoPtr :valid pointer to the listview structure
9145 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9148 * Old Unicode Format
9150 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9152 SHORT rc
= infoPtr
->notifyFormat
;
9153 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9154 return rc
== NFR_UNICODE
;
9159 * sets the control view mode
9161 * [I] infoPtr :valid pointer to the listview structure
9162 * [I] nView :new view mode value
9168 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9172 if (infoPtr
->uView
== nView
) return 1;
9174 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9175 if (nView
== LV_VIEW_TILE
)
9177 FIXME("View LV_VIEW_TILE unimplemented\n");
9181 infoPtr
->uView
= nView
;
9183 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9184 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9186 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9187 SetRectEmpty(&infoPtr
->rcFocus
);
9189 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9190 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9195 case LV_VIEW_SMALLICON
:
9196 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9198 case LV_VIEW_DETAILS
:
9203 LISTVIEW_CreateHeader( infoPtr
);
9205 hl
.prc
= &infoPtr
->rcList
;
9207 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9208 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9209 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9216 LISTVIEW_UpdateItemSize(infoPtr
);
9217 LISTVIEW_UpdateSize(infoPtr
);
9218 LISTVIEW_UpdateScroll(infoPtr
);
9219 LISTVIEW_InvalidateList(infoPtr
);
9221 TRACE("nView=%d\n", nView
);
9226 /* LISTVIEW_SetWorkAreas */
9230 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9233 * [I] first : pointer to first ITEM_INFO to compare
9234 * [I] second : pointer to second ITEM_INFO to compare
9235 * [I] lParam : HWND of control
9238 * if first comes before second : negative
9239 * if first comes after second : positive
9240 * if first and second are equivalent : zero
9242 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9244 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9245 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9246 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9248 /* Forward the call to the client defined callback */
9249 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9254 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9257 * [I] first : pointer to first ITEM_INFO to compare
9258 * [I] second : pointer to second ITEM_INFO to compare
9259 * [I] lParam : HWND of control
9262 * if first comes before second : negative
9263 * if first comes after second : positive
9264 * if first and second are equivalent : zero
9266 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9268 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9269 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9270 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9272 /* Forward the call to the client defined callback */
9273 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9278 * Sorts the listview items.
9281 * [I] infoPtr : valid pointer to the listview structure
9282 * [I] pfnCompare : application-defined value
9283 * [I] lParamSort : pointer to comparison callback
9284 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9290 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9291 LPARAM lParamSort
, BOOL IsEx
)
9295 LPVOID selectionMarkItem
= NULL
;
9296 LPVOID focusedItem
= NULL
;
9299 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9301 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9303 if (!pfnCompare
) return FALSE
;
9304 if (!infoPtr
->hdpaItems
) return FALSE
;
9306 /* if there are 0 or 1 items, there is no need to sort */
9307 if (infoPtr
->nItemCount
< 2) return TRUE
;
9309 /* clear selection */
9310 ranges_clear(infoPtr
->selectionRanges
);
9312 /* save selection mark and focused item */
9313 if (infoPtr
->nSelectionMark
>= 0)
9314 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9315 if (infoPtr
->nFocusedItem
>= 0)
9316 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9318 infoPtr
->pfnCompare
= pfnCompare
;
9319 infoPtr
->lParamSort
= lParamSort
;
9321 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9323 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9325 /* restore selection ranges */
9326 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9328 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9329 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9331 if (lpItem
->state
& LVIS_SELECTED
)
9332 ranges_additem(infoPtr
->selectionRanges
, i
);
9334 /* restore selection mark and focused item */
9335 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9336 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9338 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9340 /* refresh the display */
9341 LISTVIEW_InvalidateList(infoPtr
);
9347 * Update theme handle after a theme change.
9350 * [I] infoPtr : valid pointer to the listview structure
9354 * FAILURE : something else
9356 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9358 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9359 CloseThemeData(theme
);
9360 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9366 * Updates an items or rearranges the listview control.
9369 * [I] infoPtr : valid pointer to the listview structure
9370 * [I] nItem : item index
9376 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9378 TRACE("(nItem=%d)\n", nItem
);
9380 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9382 /* rearrange with default alignment style */
9383 if (is_autoarrange(infoPtr
))
9384 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9386 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9393 * Draw the track line at the place defined in the infoPtr structure.
9394 * The line is drawn with a XOR pen so drawing the line for the second time
9395 * in the same place erases the line.
9398 * [I] infoPtr : valid pointer to the listview structure
9404 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9408 if (infoPtr
->xTrackLine
== -1)
9411 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9413 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9414 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9415 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9421 * Called when an edit control should be displayed. This function is called after
9422 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9425 * [I] hwnd : Handle to the listview
9426 * [I] uMsg : WM_TIMER (ignored)
9427 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9428 * [I] dwTimer : The elapsed time (ignored)
9433 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9435 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9436 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9438 KillTimer(hwnd
, idEvent
);
9439 editItem
->fEnabled
= FALSE
;
9440 /* check if the item is still selected */
9441 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9442 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9447 * Creates the listview control - the WM_NCCREATE phase.
9450 * [I] hwnd : window handle
9451 * [I] lpcs : the create parameters
9457 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9459 LISTVIEW_INFO
*infoPtr
;
9462 TRACE("(lpcs=%p)\n", lpcs
);
9464 /* initialize info pointer */
9465 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9466 if (!infoPtr
) return FALSE
;
9468 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9470 infoPtr
->hwndSelf
= hwnd
;
9471 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9472 map_style_view(infoPtr
);
9473 /* determine the type of structures to use */
9474 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9475 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9477 /* initialize color information */
9478 infoPtr
->clrBk
= CLR_NONE
;
9479 infoPtr
->clrText
= CLR_DEFAULT
;
9480 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9481 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9483 /* set default values */
9484 infoPtr
->nFocusedItem
= -1;
9485 infoPtr
->nSelectionMark
= -1;
9486 infoPtr
->nHotItem
= -1;
9487 infoPtr
->redraw
= TRUE
;
9488 infoPtr
->bNoItemMetrics
= TRUE
;
9489 infoPtr
->bDoChangeNotify
= TRUE
;
9490 infoPtr
->autoSpacing
= TRUE
;
9491 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9492 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9493 infoPtr
->nEditLabelItem
= -1;
9494 infoPtr
->nLButtonDownItem
= -1;
9495 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9496 infoPtr
->cWheelRemainder
= 0;
9497 infoPtr
->nMeasureItemHeight
= 0;
9498 infoPtr
->xTrackLine
= -1; /* no track line */
9499 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9500 infoPtr
->iVersion
= COMCTL32_VERSION
;
9501 infoPtr
->colRectsDirty
= FALSE
;
9503 /* get default font (icon title) */
9504 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9505 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9506 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9507 LISTVIEW_SaveTextMetrics(infoPtr
);
9509 /* allocate memory for the data structure */
9510 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9511 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9512 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9513 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9514 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9515 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9519 DestroyWindow(infoPtr
->hwndHeader
);
9520 ranges_destroy(infoPtr
->selectionRanges
);
9521 DPA_Destroy(infoPtr
->hdpaItems
);
9522 DPA_Destroy(infoPtr
->hdpaItemIds
);
9523 DPA_Destroy(infoPtr
->hdpaPosX
);
9524 DPA_Destroy(infoPtr
->hdpaPosY
);
9525 DPA_Destroy(infoPtr
->hdpaColumns
);
9532 * Creates the listview control - the WM_CREATE phase. Most of the data is
9533 * already set up in LISTVIEW_NCCreate
9536 * [I] hwnd : window handle
9537 * [I] lpcs : the create parameters
9543 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9545 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9547 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9549 infoPtr
->dwStyle
= lpcs
->style
;
9550 map_style_view(infoPtr
);
9552 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9553 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9554 /* on error defaulting to ANSI notifications */
9555 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9556 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9558 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9560 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9563 infoPtr
->hwndHeader
= 0;
9565 /* init item size to avoid division by 0 */
9566 LISTVIEW_UpdateItemSize (infoPtr
);
9567 LISTVIEW_UpdateSize (infoPtr
);
9569 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9571 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9573 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9575 LISTVIEW_UpdateScroll(infoPtr
);
9576 /* send WM_MEASUREITEM notification */
9577 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9580 OpenThemeData(hwnd
, themeClass
);
9582 /* initialize the icon sizes */
9583 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9584 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9590 * Destroys the listview control.
9593 * [I] infoPtr : valid pointer to the listview structure
9599 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9601 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9602 CloseThemeData(theme
);
9604 /* delete all items */
9605 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9612 * Enables the listview control.
9615 * [I] infoPtr : valid pointer to the listview structure
9616 * [I] bEnable : specifies whether to enable or disable the window
9622 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9624 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9625 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9631 * Erases the background of the listview control.
9634 * [I] infoPtr : valid pointer to the listview structure
9635 * [I] hdc : device context handle
9641 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9645 TRACE("(hdc=%p)\n", hdc
);
9647 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9649 if (infoPtr
->clrBk
== CLR_NONE
)
9651 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9652 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9653 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9655 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9658 /* for double buffered controls we need to do this during refresh */
9659 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9661 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9667 * Helper function for LISTVIEW_[HV]Scroll *only*.
9668 * Performs vertical/horizontal scrolling by a give amount.
9671 * [I] infoPtr : valid pointer to the listview structure
9672 * [I] dx : amount of horizontal scroll
9673 * [I] dy : amount of vertical scroll
9675 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9677 /* now we can scroll the list */
9678 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9679 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9680 /* if we have focus, adjust rect */
9681 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9682 UpdateWindow(infoPtr
->hwndSelf
);
9687 * Performs vertical scrolling.
9690 * [I] infoPtr : valid pointer to the listview structure
9691 * [I] nScrollCode : scroll code
9692 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9693 * [I] hScrollWnd : scrollbar control window handle
9699 * SB_LINEUP/SB_LINEDOWN:
9700 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9701 * for LVS_REPORT is 1 line
9702 * for LVS_LIST cannot occur
9705 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9708 INT nOldScrollPos
, nNewScrollPos
;
9709 SCROLLINFO scrollInfo
;
9712 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9713 debugscrollcode(nScrollCode
), nScrollDiff
);
9715 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9717 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9718 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9720 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9722 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9724 nOldScrollPos
= scrollInfo
.nPos
;
9725 switch (nScrollCode
)
9731 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9735 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9739 nScrollDiff
= -scrollInfo
.nPage
;
9743 nScrollDiff
= scrollInfo
.nPage
;
9746 case SB_THUMBPOSITION
:
9748 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9755 /* quit right away if pos isn't changing */
9756 if (nScrollDiff
== 0) return 0;
9758 /* calculate new position, and handle overflows */
9759 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9760 if (nScrollDiff
> 0) {
9761 if (nNewScrollPos
< nOldScrollPos
||
9762 nNewScrollPos
> scrollInfo
.nMax
)
9763 nNewScrollPos
= scrollInfo
.nMax
;
9765 if (nNewScrollPos
> nOldScrollPos
||
9766 nNewScrollPos
< scrollInfo
.nMin
)
9767 nNewScrollPos
= scrollInfo
.nMin
;
9770 /* set the new position, and reread in case it changed */
9771 scrollInfo
.fMask
= SIF_POS
;
9772 scrollInfo
.nPos
= nNewScrollPos
;
9773 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9775 /* carry on only if it really changed */
9776 if (nNewScrollPos
== nOldScrollPos
) return 0;
9778 /* now adjust to client coordinates */
9779 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9780 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9782 /* and scroll the window */
9783 scroll_list(infoPtr
, 0, nScrollDiff
);
9790 * Performs horizontal scrolling.
9793 * [I] infoPtr : valid pointer to the listview structure
9794 * [I] nScrollCode : scroll code
9795 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9796 * [I] hScrollWnd : scrollbar control window handle
9802 * SB_LINELEFT/SB_LINERIGHT:
9803 * for LVS_ICON, LVS_SMALLICON 1 pixel
9804 * for LVS_REPORT is 1 pixel
9805 * for LVS_LIST is 1 column --> which is a 1 because the
9806 * scroll is based on columns not pixels
9809 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9812 INT nOldScrollPos
, nNewScrollPos
;
9813 SCROLLINFO scrollInfo
;
9816 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9817 debugscrollcode(nScrollCode
), nScrollDiff
);
9819 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9821 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9822 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9824 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9826 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9828 nOldScrollPos
= scrollInfo
.nPos
;
9830 switch (nScrollCode
)
9836 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9840 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9844 nScrollDiff
= -scrollInfo
.nPage
;
9848 nScrollDiff
= scrollInfo
.nPage
;
9851 case SB_THUMBPOSITION
:
9853 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9860 /* quit right away if pos isn't changing */
9861 if (nScrollDiff
== 0) return 0;
9863 /* calculate new position, and handle overflows */
9864 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9865 if (nScrollDiff
> 0) {
9866 if (nNewScrollPos
< nOldScrollPos
||
9867 nNewScrollPos
> scrollInfo
.nMax
)
9868 nNewScrollPos
= scrollInfo
.nMax
;
9870 if (nNewScrollPos
> nOldScrollPos
||
9871 nNewScrollPos
< scrollInfo
.nMin
)
9872 nNewScrollPos
= scrollInfo
.nMin
;
9875 /* set the new position, and reread in case it changed */
9876 scrollInfo
.fMask
= SIF_POS
;
9877 scrollInfo
.nPos
= nNewScrollPos
;
9878 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9880 /* carry on only if it really changed */
9881 if (nNewScrollPos
== nOldScrollPos
) return 0;
9883 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9885 /* now adjust to client coordinates */
9886 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9887 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9889 /* and scroll the window */
9890 scroll_list(infoPtr
, nScrollDiff
, 0);
9895 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9897 UINT pulScrollLines
= 3;
9899 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9901 switch(infoPtr
->uView
)
9904 case LV_VIEW_SMALLICON
:
9906 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9907 * should be fixed in the future.
9909 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9910 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9913 case LV_VIEW_DETAILS
:
9914 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9916 /* if scrolling changes direction, ignore left overs */
9917 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9918 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9919 infoPtr
->cWheelRemainder
+= wheelDelta
;
9921 infoPtr
->cWheelRemainder
= wheelDelta
;
9922 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9925 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9926 cLineScroll
= pulScrollLines
* (float)infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9927 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
9928 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9933 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9944 * [I] infoPtr : valid pointer to the listview structure
9945 * [I] nVirtualKey : virtual key
9946 * [I] lKeyData : key data
9951 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9953 HWND hwndSelf
= infoPtr
->hwndSelf
;
9955 NMLVKEYDOWN nmKeyDown
;
9957 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9959 /* send LVN_KEYDOWN notification */
9960 nmKeyDown
.wVKey
= nVirtualKey
;
9961 nmKeyDown
.flags
= 0;
9962 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9963 if (!IsWindow(hwndSelf
))
9966 switch (nVirtualKey
)
9969 nItem
= infoPtr
->nFocusedItem
;
9970 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9971 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9975 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9977 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9978 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9983 if (infoPtr
->nItemCount
> 0)
9988 if (infoPtr
->nItemCount
> 0)
9989 nItem
= infoPtr
->nItemCount
- 1;
9993 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9997 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
10001 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
10005 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
10009 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10011 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10012 if (infoPtr
->nFocusedItem
== topidx
)
10013 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
10018 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
10019 * LISTVIEW_GetCountPerRow(infoPtr
);
10020 if(nItem
< 0) nItem
= 0;
10024 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10026 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
10027 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
10028 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
10029 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
10031 nItem
= topidx
+ cnt
- 1;
10034 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
10035 * LISTVIEW_GetCountPerRow(infoPtr
);
10036 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
10040 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
10041 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
10051 * [I] infoPtr : valid pointer to the listview structure
10056 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
10060 /* drop any left over scroll amount */
10061 infoPtr
->cWheelRemainder
= 0;
10063 /* if we did not have the focus, there's nothing more to do */
10064 if (!infoPtr
->bFocus
) return 0;
10066 /* send NM_KILLFOCUS notification */
10067 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
10069 /* if we have a focus rectangle, get rid of it */
10070 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
10072 /* if have a marquee selection, stop it */
10073 if (infoPtr
->bMarqueeSelect
)
10075 /* Remove the marquee rectangle and release our mouse capture */
10076 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
10079 SetRectEmpty(&infoPtr
->marqueeRect
);
10081 infoPtr
->bMarqueeSelect
= FALSE
;
10082 infoPtr
->bScrolling
= FALSE
;
10083 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10086 /* set window focus flag */
10087 infoPtr
->bFocus
= FALSE
;
10089 /* invalidate the selected items before resetting focus flag */
10090 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10097 * Processes double click messages (left mouse button).
10100 * [I] infoPtr : valid pointer to the listview structure
10101 * [I] wKey : key flag
10102 * [I] x,y : mouse coordinate
10107 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10109 LVHITTESTINFO htInfo
;
10111 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10113 /* Cancel the item edition if any */
10114 if (infoPtr
->itemEdit
.fEnabled
)
10116 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
10117 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10120 /* send NM_RELEASEDCAPTURE notification */
10121 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10126 /* send NM_DBLCLK notification */
10127 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10128 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10130 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10131 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10136 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10141 r
.top
= r
.bottom
= pt
.y
;
10142 r
.left
= r
.right
= pt
.x
;
10144 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10146 SetCapture(infoPtr
->hwndSelf
);
10150 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10152 if (msg
.message
== WM_MOUSEMOVE
)
10154 pt
.x
= (short)LOWORD(msg
.lParam
);
10155 pt
.y
= (short)HIWORD(msg
.lParam
);
10156 if (PtInRect(&r
, pt
))
10164 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10165 msg
.message
<= WM_RBUTTONDBLCLK
)
10170 DispatchMessageW(&msg
);
10173 if (GetCapture() != infoPtr
->hwndSelf
)
10184 * Processes mouse down messages (left mouse button).
10187 * infoPtr [I ] valid pointer to the listview structure
10188 * wKey [I ] key flag
10189 * x,y [I ] mouse coordinate
10194 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10196 LVHITTESTINFO lvHitTestInfo
;
10197 static BOOL bGroupSelect
= TRUE
;
10198 POINT pt
= { x
, y
};
10201 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10203 /* send NM_RELEASEDCAPTURE notification */
10204 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10206 /* set left button down flag and record the click position */
10207 infoPtr
->bLButtonDown
= TRUE
;
10208 infoPtr
->ptClickPos
= pt
;
10209 infoPtr
->bDragging
= FALSE
;
10210 infoPtr
->bMarqueeSelect
= FALSE
;
10211 infoPtr
->bScrolling
= FALSE
;
10213 lvHitTestInfo
.pt
.x
= x
;
10214 lvHitTestInfo
.pt
.y
= y
;
10216 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10217 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10218 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10220 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10222 toggle_checkbox_state(infoPtr
, nItem
);
10226 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10228 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10229 infoPtr
->nEditLabelItem
= nItem
;
10231 LISTVIEW_SetSelection(infoPtr
, nItem
);
10235 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10239 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10240 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10241 infoPtr
->nSelectionMark
= nItem
;
10247 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10248 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10250 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10251 infoPtr
->nSelectionMark
= nItem
;
10254 else if (wKey
& MK_CONTROL
)
10258 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10260 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10261 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10262 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10263 infoPtr
->nSelectionMark
= nItem
;
10265 else if (wKey
& MK_SHIFT
)
10267 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10271 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10273 infoPtr
->nEditLabelItem
= nItem
;
10274 infoPtr
->nLButtonDownItem
= nItem
;
10276 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10279 /* set selection (clears other pre-existing selections) */
10280 LISTVIEW_SetSelection(infoPtr
, nItem
);
10284 if (!infoPtr
->bFocus
)
10285 SetFocus(infoPtr
->hwndSelf
);
10287 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10288 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10292 if (!infoPtr
->bFocus
)
10293 SetFocus(infoPtr
->hwndSelf
);
10295 /* remove all selections */
10296 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10297 LISTVIEW_DeselectAll(infoPtr
);
10306 * Processes mouse up messages (left mouse button).
10309 * infoPtr [I ] valid pointer to the listview structure
10310 * wKey [I ] key flag
10311 * x,y [I ] mouse coordinate
10316 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10318 LVHITTESTINFO lvHitTestInfo
;
10320 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10322 if (!infoPtr
->bLButtonDown
) return 0;
10324 lvHitTestInfo
.pt
.x
= x
;
10325 lvHitTestInfo
.pt
.y
= y
;
10327 /* send NM_CLICK notification */
10328 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10329 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10331 /* set left button flag */
10332 infoPtr
->bLButtonDown
= FALSE
;
10334 /* set a single selection, reset others */
10335 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10336 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10337 infoPtr
->nLButtonDownItem
= -1;
10339 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10341 /* Remove the marquee rectangle and release our mouse capture */
10342 if (infoPtr
->bMarqueeSelect
)
10344 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10348 SetRectEmpty(&infoPtr
->marqueeRect
);
10349 SetRectEmpty(&infoPtr
->marqueeDrawRect
);
10351 infoPtr
->bDragging
= FALSE
;
10352 infoPtr
->bMarqueeSelect
= FALSE
;
10353 infoPtr
->bScrolling
= FALSE
;
10355 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10359 /* if we clicked on a selected item, edit the label */
10360 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10362 /* we want to make sure the user doesn't want to do a double click. So we will
10363 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10365 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10366 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10367 SetTimer(infoPtr
->hwndSelf
,
10368 (UINT_PTR
)&infoPtr
->itemEdit
,
10369 GetDoubleClickTime(),
10370 LISTVIEW_DelayedEditItem
);
10378 * Destroys the listview control (called after WM_DESTROY).
10381 * [I] infoPtr : valid pointer to the listview structure
10386 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10392 /* destroy data structure */
10393 DPA_Destroy(infoPtr
->hdpaItems
);
10394 DPA_Destroy(infoPtr
->hdpaItemIds
);
10395 DPA_Destroy(infoPtr
->hdpaPosX
);
10396 DPA_Destroy(infoPtr
->hdpaPosY
);
10398 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10399 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10400 DPA_Destroy(infoPtr
->hdpaColumns
);
10401 ranges_destroy(infoPtr
->selectionRanges
);
10403 /* destroy image lists */
10404 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10406 ImageList_Destroy(infoPtr
->himlNormal
);
10407 ImageList_Destroy(infoPtr
->himlSmall
);
10408 ImageList_Destroy(infoPtr
->himlState
);
10411 /* destroy font, bkgnd brush */
10412 infoPtr
->hFont
= 0;
10413 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10414 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10416 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10418 /* free listview info pointer*/
10426 * Handles notifications.
10429 * [I] infoPtr : valid pointer to the listview structure
10430 * [I] lpnmhdr : notification information
10435 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10439 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10441 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10443 /* remember: HDN_LAST < HDN_FIRST */
10444 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10445 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10447 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10449 switch (lpnmhdr
->code
)
10454 COLUMN_INFO
*lpColumnInfo
;
10458 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10461 /* remove the old line (if any) */
10462 LISTVIEW_DrawTrackLine(infoPtr
);
10464 /* compute & draw the new line */
10465 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10466 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10467 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10468 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10469 LISTVIEW_DrawTrackLine(infoPtr
);
10470 return notify_forward_header(infoPtr
, lpnmh
);
10473 case HDN_ENDTRACKA
:
10474 case HDN_ENDTRACKW
:
10475 /* remove the track line (if any) */
10476 LISTVIEW_DrawTrackLine(infoPtr
);
10477 infoPtr
->xTrackLine
= -1;
10478 return notify_forward_header(infoPtr
, lpnmh
);
10480 case HDN_BEGINDRAG
:
10481 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10482 return notify_forward_header(infoPtr
, lpnmh
);
10485 infoPtr
->colRectsDirty
= TRUE
;
10486 LISTVIEW_InvalidateList(infoPtr
);
10487 return notify_forward_header(infoPtr
, lpnmh
);
10489 case HDN_ITEMCHANGEDW
:
10490 case HDN_ITEMCHANGEDA
:
10492 COLUMN_INFO
*lpColumnInfo
;
10496 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10498 hdi
.mask
= HDI_WIDTH
;
10499 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10503 cxy
= lpnmh
->pitem
->cxy
;
10505 /* determine how much we change since the last know position */
10506 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10507 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10510 lpColumnInfo
->rcHeader
.right
+= dx
;
10512 hdi
.mask
= HDI_ORDER
;
10513 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10515 /* not the rightmost one */
10516 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10518 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10519 hdi
.iOrder
+ 1, 0);
10520 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10524 /* only needs to update the scrolls */
10525 infoPtr
->nItemWidth
+= dx
;
10526 LISTVIEW_UpdateScroll(infoPtr
);
10528 LISTVIEW_UpdateItemSize(infoPtr
);
10529 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10532 RECT rcCol
= lpColumnInfo
->rcHeader
;
10534 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10535 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10537 rcCol
.top
= infoPtr
->rcList
.top
;
10538 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10540 /* resizing left-aligned columns leaves most of the left side untouched */
10541 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10543 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10546 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10549 /* when shrinking the last column clear the now unused field */
10550 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10556 /* deal with right from rightmost column area */
10557 right
.left
= rcCol
.right
;
10558 right
.top
= rcCol
.top
;
10559 right
.bottom
= rcCol
.bottom
;
10560 right
.right
= infoPtr
->rcList
.right
;
10562 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10565 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10571 case HDN_ITEMCLICKW
:
10572 case HDN_ITEMCLICKA
:
10574 /* Handle sorting by Header Column */
10577 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10579 nmlv
.iSubItem
= lpnmh
->iItem
;
10580 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10581 return notify_forward_header(infoPtr
, lpnmh
);
10584 case HDN_DIVIDERDBLCLICKW
:
10585 case HDN_DIVIDERDBLCLICKA
:
10586 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10587 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10588 split needed for that */
10589 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10590 return notify_forward_header(infoPtr
, lpnmh
);
10597 * Paint non-client area of control.
10600 * [I] infoPtr : valid pointer to the listview structureof the sender
10601 * [I] region : update region
10604 * TRUE - frame was painted
10605 * FALSE - call default window proc
10607 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10609 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10613 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10614 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10617 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10619 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10621 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10622 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10623 if (region
!= (HRGN
)1)
10624 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10625 OffsetRect(&r
, -r
.left
, -r
.top
);
10627 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10628 OffsetRect(&r
, -r
.left
, -r
.top
);
10630 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10631 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10632 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10633 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10635 /* Call default proc to get the scrollbars etc. painted */
10636 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10643 * Determines the type of structure to use.
10646 * [I] infoPtr : valid pointer to the listview structureof the sender
10647 * [I] hwndFrom : listview window handle
10648 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10653 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10655 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10657 if (nCommand
== NF_REQUERY
)
10658 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10660 return infoPtr
->notifyFormat
;
10665 * Paints/Repaints the listview control. Internal use.
10668 * [I] infoPtr : valid pointer to the listview structure
10669 * [I] hdc : device context handle
10674 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10676 TRACE("(hdc=%p)\n", hdc
);
10678 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10680 infoPtr
->bNoItemMetrics
= FALSE
;
10681 LISTVIEW_UpdateItemSize(infoPtr
);
10682 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10683 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10684 LISTVIEW_UpdateScroll(infoPtr
);
10687 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10690 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10695 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10696 if (!hdc
) return 1;
10697 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10698 EndPaint(infoPtr
->hwndSelf
, &ps
);
10706 * Paints/Repaints the listview control, WM_PAINT handler.
10709 * [I] infoPtr : valid pointer to the listview structure
10710 * [I] hdc : device context handle
10715 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10717 TRACE("(hdc=%p)\n", hdc
);
10719 if (!is_redrawing(infoPtr
))
10720 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10722 return LISTVIEW_Paint(infoPtr
, hdc
);
10727 * Paints/Repaints the listview control.
10730 * [I] infoPtr : valid pointer to the listview structure
10731 * [I] hdc : device context handle
10732 * [I] options : drawing options
10737 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10739 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10741 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10744 if (options
& PRF_ERASEBKGND
)
10745 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10747 if (options
& PRF_CLIENT
)
10748 LISTVIEW_Paint(infoPtr
, hdc
);
10756 * Processes double click messages (right mouse button).
10759 * [I] infoPtr : valid pointer to the listview structure
10760 * [I] wKey : key flag
10761 * [I] x,y : mouse coordinate
10766 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10768 LVHITTESTINFO lvHitTestInfo
;
10770 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10772 /* send NM_RELEASEDCAPTURE notification */
10773 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10775 /* send NM_RDBLCLK notification */
10776 lvHitTestInfo
.pt
.x
= x
;
10777 lvHitTestInfo
.pt
.y
= y
;
10778 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10779 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10786 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10789 * [I] infoPtr : valid pointer to the listview structure
10790 * [I] wKey : key flag
10791 * [I] x, y : mouse coordinate
10796 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10801 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10803 /* send NM_RELEASEDCAPTURE notification */
10804 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10806 /* determine the index of the selected item */
10809 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10811 /* make sure the listview control window has the focus */
10812 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10814 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10816 LISTVIEW_SetItemFocus(infoPtr
, item
);
10817 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10818 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10819 LISTVIEW_SetSelection(infoPtr
, item
);
10822 LISTVIEW_DeselectAll(infoPtr
);
10824 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10826 if (ht
.iItem
!= -1)
10830 memset(&nmlv
, 0, sizeof(nmlv
));
10831 nmlv
.iItem
= ht
.iItem
;
10832 nmlv
.ptAction
= ht
.pt
;
10834 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10839 SetFocus(infoPtr
->hwndSelf
);
10843 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10845 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10847 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10848 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10849 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10861 * [I] infoPtr : valid pointer to the listview structure
10862 * [I] hwnd : window handle of window containing the cursor
10863 * [I] nHittest : hit-test code
10864 * [I] wMouseMsg : ideintifier of the mouse message
10867 * TRUE if cursor is set
10870 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10872 LVHITTESTINFO lvHitTestInfo
;
10874 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10876 if (!infoPtr
->hHotCursor
) goto forward
;
10878 GetCursorPos(&lvHitTestInfo
.pt
);
10879 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10881 SetCursor(infoPtr
->hHotCursor
);
10887 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10895 * [I] infoPtr : valid pointer to the listview structure
10896 * [I] hwndLoseFocus : handle of previously focused window
10901 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10903 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10905 /* if we have the focus already, there's nothing to do */
10906 if (infoPtr
->bFocus
) return 0;
10908 /* send NM_SETFOCUS notification */
10909 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10911 /* set window focus flag */
10912 infoPtr
->bFocus
= TRUE
;
10914 /* put the focus rect back on */
10915 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10917 /* redraw all visible selected items */
10918 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10928 * [I] infoPtr : valid pointer to the listview structure
10929 * [I] fRedraw : font handle
10930 * [I] fRedraw : redraw flag
10935 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10937 HFONT oldFont
= infoPtr
->hFont
;
10938 INT oldHeight
= infoPtr
->nItemHeight
;
10940 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10942 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10943 if (infoPtr
->hFont
== oldFont
) return 0;
10945 LISTVIEW_SaveTextMetrics(infoPtr
);
10947 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10949 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10951 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10952 LISTVIEW_UpdateSize(infoPtr
);
10953 LISTVIEW_UpdateScroll(infoPtr
);
10955 else if (infoPtr
->nItemHeight
!= oldHeight
)
10956 LISTVIEW_UpdateScroll(infoPtr
);
10958 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10965 * Message handling for WM_SETREDRAW.
10966 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10969 * [I] infoPtr : valid pointer to the listview structure
10970 * [I] redraw: state of redraw flag
10975 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL redraw
)
10977 TRACE("old=%d, new=%d\n", infoPtr
->redraw
, redraw
);
10979 if (infoPtr
->redraw
== !!redraw
)
10982 if (!(infoPtr
->redraw
= !!redraw
))
10985 if (is_autoarrange(infoPtr
))
10986 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10987 LISTVIEW_UpdateScroll(infoPtr
);
10989 /* despite what the WM_SETREDRAW docs says, apps expect us
10990 * to invalidate the listview here... stupid! */
10991 LISTVIEW_InvalidateList(infoPtr
);
10998 * Resizes the listview control. This function processes WM_SIZE
10999 * messages. At this time, the width and height are not used.
11002 * [I] infoPtr : valid pointer to the listview structure
11003 * [I] Width : new width
11004 * [I] Height : new height
11009 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
11011 RECT rcOld
= infoPtr
->rcList
;
11013 TRACE("(width=%d, height=%d)\n", Width
, Height
);
11015 LISTVIEW_UpdateSize(infoPtr
);
11016 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
11018 /* do not bother with display related stuff if we're not redrawing */
11019 if (!is_redrawing(infoPtr
)) return 0;
11021 if (is_autoarrange(infoPtr
))
11022 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11024 LISTVIEW_UpdateScroll(infoPtr
);
11026 /* refresh all only for lists whose height changed significantly */
11027 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
11028 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
11029 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
11030 LISTVIEW_InvalidateList(infoPtr
);
11037 * Sets the size information.
11040 * [I] infoPtr : valid pointer to the listview structure
11045 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
11047 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
11049 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
11051 if (infoPtr
->uView
== LV_VIEW_LIST
)
11053 /* Apparently the "LIST" style is supposed to have the same
11054 * number of items in a column even if there is no scroll bar.
11055 * Since if a scroll bar already exists then the bottom is already
11056 * reduced, only reduce if the scroll bar does not currently exist.
11057 * The "2" is there to mimic the native control. I think it may be
11058 * related to either padding or edges. (GLA 7/2002)
11060 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
11061 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
11062 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
11065 /* if control created invisible header isn't created */
11066 if (infoPtr
->hwndHeader
)
11071 hl
.prc
= &infoPtr
->rcList
;
11073 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11074 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11076 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
11077 wp
.flags
|= SWP_SHOWWINDOW
;
11080 wp
.flags
|= SWP_HIDEWINDOW
;
11084 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
11085 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
11087 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
11089 /* extra padding for grid */
11090 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
11091 infoPtr
->rcList
.top
+= 2;
11093 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
11098 * Processes WM_STYLECHANGED messages.
11101 * [I] infoPtr : valid pointer to the listview structure
11102 * [I] wStyleType : window style type (normal or extended)
11103 * [I] lpss : window style information
11108 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
11109 const STYLESTRUCT
*lpss
)
11111 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
11112 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
11115 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11116 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11118 if (wStyleType
!= GWL_STYLE
) return 0;
11120 infoPtr
->dwStyle
= lpss
->styleNew
;
11122 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11123 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11124 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11126 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11127 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11128 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11130 if (uNewView
!= uOldView
)
11134 /* LVM_SETVIEW doesn't change window style bits within LVS_TYPEMASK,
11135 changing style updates current view only when view bits change. */
11136 map_style_view(infoPtr
);
11137 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11138 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11140 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11141 SetRectEmpty(&infoPtr
->rcFocus
);
11143 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11144 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11146 if (uNewView
== LVS_REPORT
)
11151 LISTVIEW_CreateHeader( infoPtr
);
11153 hl
.prc
= &infoPtr
->rcList
;
11155 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11156 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11157 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11158 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11161 LISTVIEW_UpdateItemSize(infoPtr
);
11164 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11166 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11168 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11170 /* Turn off the header control */
11171 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11172 TRACE("Hide header control, was 0x%08x\n", style
);
11173 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11175 /* Turn on the header control */
11176 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11178 TRACE("Show header control, was 0x%08x\n", style
);
11179 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11185 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11186 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11187 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11189 /* update the size of the client area */
11190 LISTVIEW_UpdateSize(infoPtr
);
11192 /* add scrollbars if needed */
11193 LISTVIEW_UpdateScroll(infoPtr
);
11195 /* invalidate client area + erase background */
11196 LISTVIEW_InvalidateList(infoPtr
);
11203 * Processes WM_STYLECHANGING messages.
11206 * [I] wStyleType : window style type (normal or extended)
11207 * [I0] lpss : window style information
11212 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11215 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11216 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11218 /* don't forward LVS_OWNERDATA only if not already set to */
11219 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11221 if (lpss
->styleOld
& LVS_OWNERDATA
)
11222 lpss
->styleNew
|= LVS_OWNERDATA
;
11224 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11232 * Processes WM_SHOWWINDOW messages.
11235 * [I] infoPtr : valid pointer to the listview structure
11236 * [I] bShown : window is being shown (FALSE when hidden)
11237 * [I] iStatus : window show status
11242 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11244 /* header delayed creation */
11245 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11247 LISTVIEW_CreateHeader(infoPtr
);
11249 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11250 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11253 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11258 * Processes CCM_GETVERSION messages.
11261 * [I] infoPtr : valid pointer to the listview structure
11266 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11268 return infoPtr
->iVersion
;
11273 * Processes CCM_SETVERSION messages.
11276 * [I] infoPtr : valid pointer to the listview structure
11277 * [I] iVersion : version to be set
11280 * -1 when requested version is greater than DLL version;
11281 * previous version otherwise
11283 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11285 INT iOldVersion
= infoPtr
->iVersion
;
11287 if (iVersion
> COMCTL32_VERSION
)
11290 infoPtr
->iVersion
= iVersion
;
11292 TRACE("new version %d\n", iVersion
);
11294 return iOldVersion
;
11299 * Window procedure of the listview control.
11302 static LRESULT WINAPI
11303 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11305 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11307 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11309 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11310 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11314 case LVM_APPROXIMATEVIEWRECT
:
11315 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11316 LOWORD(lParam
), HIWORD(lParam
));
11318 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11320 case LVM_CANCELEDITLABEL
:
11321 return LISTVIEW_CancelEditLabel(infoPtr
);
11323 case LVM_CREATEDRAGIMAGE
:
11324 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11326 case LVM_DELETEALLITEMS
:
11327 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11329 case LVM_DELETECOLUMN
:
11330 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11332 case LVM_DELETEITEM
:
11333 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11335 case LVM_EDITLABELA
:
11336 case LVM_EDITLABELW
:
11337 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11338 uMsg
== LVM_EDITLABELW
);
11339 /* case LVM_ENABLEGROUPVIEW: */
11341 case LVM_ENSUREVISIBLE
:
11342 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11344 case LVM_FINDITEMW
:
11345 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11347 case LVM_FINDITEMA
:
11348 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11350 case LVM_GETBKCOLOR
:
11351 return infoPtr
->clrBk
;
11353 /* case LVM_GETBKIMAGE: */
11355 case LVM_GETCALLBACKMASK
:
11356 return infoPtr
->uCallbackMask
;
11358 case LVM_GETCOLUMNA
:
11359 case LVM_GETCOLUMNW
:
11360 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11361 uMsg
== LVM_GETCOLUMNW
);
11363 case LVM_GETCOLUMNORDERARRAY
:
11364 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11366 case LVM_GETCOLUMNWIDTH
:
11367 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11369 case LVM_GETCOUNTPERPAGE
:
11370 return LISTVIEW_GetCountPerPage(infoPtr
);
11372 case LVM_GETEDITCONTROL
:
11373 return (LRESULT
)infoPtr
->hwndEdit
;
11375 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11376 return infoPtr
->dwLvExStyle
;
11378 /* case LVM_GETGROUPINFO: */
11380 /* case LVM_GETGROUPMETRICS: */
11382 case LVM_GETHEADER
:
11383 return (LRESULT
)infoPtr
->hwndHeader
;
11385 case LVM_GETHOTCURSOR
:
11386 return (LRESULT
)infoPtr
->hHotCursor
;
11388 case LVM_GETHOTITEM
:
11389 return infoPtr
->nHotItem
;
11391 case LVM_GETHOVERTIME
:
11392 return infoPtr
->dwHoverTime
;
11394 case LVM_GETIMAGELIST
:
11395 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11397 /* case LVM_GETINSERTMARK: */
11399 /* case LVM_GETINSERTMARKCOLOR: */
11401 /* case LVM_GETINSERTMARKRECT: */
11403 case LVM_GETISEARCHSTRINGA
:
11404 case LVM_GETISEARCHSTRINGW
:
11405 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11410 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11412 case LVM_GETITEMCOUNT
:
11413 return infoPtr
->nItemCount
;
11415 case LVM_GETITEMPOSITION
:
11416 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11418 case LVM_GETITEMRECT
:
11419 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11421 case LVM_GETITEMSPACING
:
11422 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11424 case LVM_GETITEMSTATE
:
11425 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11427 case LVM_GETITEMTEXTA
:
11428 case LVM_GETITEMTEXTW
:
11429 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11430 uMsg
== LVM_GETITEMTEXTW
);
11432 case LVM_GETNEXTITEM
:
11433 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11435 case LVM_GETNUMBEROFWORKAREAS
:
11436 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11439 case LVM_GETORIGIN
:
11440 if (!lParam
) return FALSE
;
11441 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11442 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11443 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11446 /* case LVM_GETOUTLINECOLOR: */
11448 /* case LVM_GETSELECTEDCOLUMN: */
11450 case LVM_GETSELECTEDCOUNT
:
11451 return LISTVIEW_GetSelectedCount(infoPtr
);
11453 case LVM_GETSELECTIONMARK
:
11454 return infoPtr
->nSelectionMark
;
11456 case LVM_GETSTRINGWIDTHA
:
11457 case LVM_GETSTRINGWIDTHW
:
11458 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11459 uMsg
== LVM_GETSTRINGWIDTHW
);
11461 case LVM_GETSUBITEMRECT
:
11462 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11464 case LVM_GETTEXTBKCOLOR
:
11465 return infoPtr
->clrTextBk
;
11467 case LVM_GETTEXTCOLOR
:
11468 return infoPtr
->clrText
;
11470 /* case LVM_GETTILEINFO: */
11472 /* case LVM_GETTILEVIEWINFO: */
11474 case LVM_GETTOOLTIPS
:
11475 if( !infoPtr
->hwndToolTip
)
11476 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11477 return (LRESULT
)infoPtr
->hwndToolTip
;
11479 case LVM_GETTOPINDEX
:
11480 return LISTVIEW_GetTopIndex(infoPtr
);
11482 case LVM_GETUNICODEFORMAT
:
11483 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11486 return infoPtr
->uView
;
11488 case LVM_GETVIEWRECT
:
11489 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11491 case LVM_GETWORKAREAS
:
11492 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11495 /* case LVM_HASGROUP: */
11498 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11500 case LVM_INSERTCOLUMNA
:
11501 case LVM_INSERTCOLUMNW
:
11502 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11503 uMsg
== LVM_INSERTCOLUMNW
);
11505 /* case LVM_INSERTGROUP: */
11507 /* case LVM_INSERTGROUPSORTED: */
11509 case LVM_INSERTITEMA
:
11510 case LVM_INSERTITEMW
:
11511 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11513 /* case LVM_INSERTMARKHITTEST: */
11515 /* case LVM_ISGROUPVIEWENABLED: */
11517 case LVM_ISITEMVISIBLE
:
11518 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11520 case LVM_MAPIDTOINDEX
:
11521 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11523 case LVM_MAPINDEXTOID
:
11524 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11526 /* case LVM_MOVEGROUP: */
11528 /* case LVM_MOVEITEMTOGROUP: */
11530 case LVM_REDRAWITEMS
:
11531 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11533 /* case LVM_REMOVEALLGROUPS: */
11535 /* case LVM_REMOVEGROUP: */
11538 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11540 case LVM_SETBKCOLOR
:
11541 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11543 /* case LVM_SETBKIMAGE: */
11545 case LVM_SETCALLBACKMASK
:
11546 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11549 case LVM_SETCOLUMNA
:
11550 case LVM_SETCOLUMNW
:
11551 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11552 uMsg
== LVM_SETCOLUMNW
);
11554 case LVM_SETCOLUMNORDERARRAY
:
11555 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11557 case LVM_SETCOLUMNWIDTH
:
11558 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11560 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11561 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11563 /* case LVM_SETGROUPINFO: */
11565 /* case LVM_SETGROUPMETRICS: */
11567 case LVM_SETHOTCURSOR
:
11568 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11570 case LVM_SETHOTITEM
:
11571 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11573 case LVM_SETHOVERTIME
:
11574 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11576 case LVM_SETICONSPACING
:
11578 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11579 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11581 case LVM_SETIMAGELIST
:
11582 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11584 /* case LVM_SETINFOTIP: */
11586 /* case LVM_SETINSERTMARK: */
11588 /* case LVM_SETINSERTMARKCOLOR: */
11593 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11594 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11597 case LVM_SETITEMCOUNT
:
11598 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11600 case LVM_SETITEMPOSITION
:
11603 pt
.x
= (short)LOWORD(lParam
);
11604 pt
.y
= (short)HIWORD(lParam
);
11605 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11608 case LVM_SETITEMPOSITION32
:
11609 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11611 case LVM_SETITEMSTATE
:
11612 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11614 case LVM_SETITEMTEXTA
:
11615 case LVM_SETITEMTEXTW
:
11616 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11617 uMsg
== LVM_SETITEMTEXTW
);
11619 /* case LVM_SETOUTLINECOLOR: */
11621 /* case LVM_SETSELECTEDCOLUMN: */
11623 case LVM_SETSELECTIONMARK
:
11624 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11626 case LVM_SETTEXTBKCOLOR
:
11627 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11629 case LVM_SETTEXTCOLOR
:
11630 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11632 /* case LVM_SETTILEINFO: */
11634 /* case LVM_SETTILEVIEWINFO: */
11636 /* case LVM_SETTILEWIDTH: */
11638 case LVM_SETTOOLTIPS
:
11639 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11641 case LVM_SETUNICODEFORMAT
:
11642 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11645 return LISTVIEW_SetView(infoPtr
, wParam
);
11647 /* case LVM_SETWORKAREAS: */
11649 /* case LVM_SORTGROUPS: */
11651 case LVM_SORTITEMS
:
11652 case LVM_SORTITEMSEX
:
11653 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11654 uMsg
== LVM_SORTITEMSEX
);
11655 case LVM_SUBITEMHITTEST
:
11656 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11659 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11661 case CCM_GETVERSION
:
11662 return LISTVIEW_GetVersion(infoPtr
);
11664 case CCM_SETVERSION
:
11665 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11668 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11671 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11674 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11677 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11680 return LISTVIEW_Destroy(infoPtr
);
11683 return LISTVIEW_Enable(infoPtr
);
11685 case WM_ERASEBKGND
:
11686 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11688 case WM_GETDLGCODE
:
11689 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11692 return (LRESULT
)infoPtr
->hFont
;
11695 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11698 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11701 return LISTVIEW_KillFocus(infoPtr
);
11703 case WM_LBUTTONDBLCLK
:
11704 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11706 case WM_LBUTTONDOWN
:
11707 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11710 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11713 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11715 case WM_MOUSEHOVER
:
11716 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11719 return LISTVIEW_NCDestroy(infoPtr
);
11722 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11725 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11727 case WM_NOTIFYFORMAT
:
11728 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11730 case WM_PRINTCLIENT
:
11731 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11734 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11736 case WM_RBUTTONDBLCLK
:
11737 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11739 case WM_RBUTTONDOWN
:
11740 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11743 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11746 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11749 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11752 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11754 case WM_SHOWWINDOW
:
11755 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11757 case WM_STYLECHANGED
:
11758 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11760 case WM_STYLECHANGING
:
11761 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11763 case WM_SYSCOLORCHANGE
:
11764 COMCTL32_RefreshSysColors();
11767 /* case WM_TIMER: */
11768 case WM_THEMECHANGED
:
11769 return LISTVIEW_ThemeChanged(infoPtr
);
11772 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11774 case WM_MOUSEWHEEL
:
11775 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11776 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11777 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11779 case WM_WINDOWPOSCHANGED
:
11780 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11782 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11783 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11785 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11787 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11789 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11791 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11793 /* case WM_WININICHANGE: */
11796 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11797 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11799 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11806 * Registers the window class.
11814 void LISTVIEW_Register(void)
11816 WNDCLASSW wndClass
;
11818 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11819 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11820 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11821 wndClass
.cbClsExtra
= 0;
11822 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11823 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11824 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11825 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11826 RegisterClassW(&wndClass
);
11831 * Unregisters the window class.
11839 void LISTVIEW_Unregister(void)
11841 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11846 * Handle any WM_COMMAND messages
11849 * [I] infoPtr : valid pointer to the listview structure
11850 * [I] wParam : the first message parameter
11851 * [I] lParam : the second message parameter
11856 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11859 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11861 if (!infoPtr
->hwndEdit
) return 0;
11863 switch (HIWORD(wParam
))
11868 * Adjust the edit window size
11870 WCHAR buffer
[1024];
11871 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11872 HFONT hFont
, hOldFont
= 0;
11876 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11877 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11878 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11880 /* Select font to get the right dimension of the string */
11881 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11884 hOldFont
= SelectObject(hdc
, hFont
);
11887 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11889 TEXTMETRICW textMetric
;
11891 /* Add Extra spacing for the next character */
11892 GetTextMetricsW(hdc
, &textMetric
);
11893 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11895 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11896 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11899 SelectObject(hdc
, hOldFont
);
11901 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11907 LISTVIEW_CancelEditLabel(infoPtr
);
11912 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);