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-2013 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_SetColumnWidth ignores header images & bitmap
58 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
61 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
62 * linear in the number of items in the list, and this is
63 * unacceptable for large lists.
64 * -- if list is sorted by item text LISTVIEW_InsertItemT could use
65 * binary search to calculate item index (e.g. DPA_Search()).
66 * This requires sorted state to be reliably tracked in item modifiers.
67 * -- we should keep an ordered array of coordinates in iconic mode
68 * this would allow to frame items (iterator_frameditems),
69 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
76 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
82 * -- LVS_NOSCROLL (see Q137520)
86 * -- LVS_EX_BORDERSELECT
90 * -- LVS_EX_MULTIWORKAREAS
92 * -- LVS_EX_SIMPLESELECT
93 * -- LVS_EX_TWOCLICKACTIVATE
94 * -- LVS_EX_UNDERLINECOLD
95 * -- LVS_EX_UNDERLINEHOT
98 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
104 * -- LVM_ENABLEGROUPVIEW
105 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
106 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
107 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
108 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
109 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
110 * -- LVM_GETINSERTMARKRECT
111 * -- LVM_GETNUMBEROFWORKAREAS
112 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
113 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
114 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
115 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
116 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
117 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
118 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
119 * -- LVM_INSERTGROUPSORTED
120 * -- LVM_INSERTMARKHITTEST
121 * -- LVM_ISGROUPVIEWENABLED
123 * -- LVM_MOVEITEMTOGROUP
125 * -- LVM_SETTILEWIDTH
129 * -- ListView_GetHoverTime, ListView_SetHoverTime
130 * -- ListView_GetISearchString
131 * -- ListView_GetNumberOfWorkAreas
132 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
137 * Known differences in message stream from native control (not known if
138 * these differences cause problems):
139 * LVM_INSERTITEM issues LVM_SETITEMSTATE and LVM_SETITEM in certain cases.
140 * LVM_SETITEM does not always issue LVN_ITEMCHANGING/LVN_ITEMCHANGED.
141 * WM_CREATE does not issue WM_QUERYUISTATE and associated registry
142 * processing for "USEDOUBLECLICKTIME".
146 #include "wine/port.h"
161 #include "commctrl.h"
162 #include "comctl32.h"
165 #include "wine/debug.h"
166 #include "wine/unicode.h"
168 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
170 typedef struct tagCOLUMN_INFO
172 RECT rcHeader
; /* tracks the header's rectangle */
173 INT fmt
; /* same as LVCOLUMN.fmt */
177 typedef struct tagITEMHDR
181 } ITEMHDR
, *LPITEMHDR
;
183 typedef struct tagSUBITEM_INFO
189 typedef struct tagITEM_ID ITEM_ID
;
191 typedef struct tagITEM_INFO
202 UINT id
; /* item id */
203 HDPA item
; /* link to item data */
206 typedef struct tagRANGE
212 typedef struct tagRANGES
217 typedef struct tagITERATOR
226 typedef struct tagDELAYED_ITEM_EDIT
232 typedef struct tagLISTVIEW_INFO
236 RECT rcList
; /* This rectangle is really the window
237 * client rectangle possibly reduced by the
238 * horizontal scroll bar and/or header - see
239 * LISTVIEW_UpdateSize. This rectangle offset
240 * by the LISTVIEW_GetOrigin value is in
241 * client coordinates */
243 /* notification window */
246 BOOL bDoChangeNotify
; /* send change notification messages? */
253 INT nItemCount
; /* the number of items in the list */
254 HDPA hdpaItems
; /* array ITEM_INFO pointers */
255 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
256 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
257 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
258 RANGES selectionRanges
;
259 INT nSelectionMark
; /* item to start next multiselection from */
261 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
264 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
265 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
268 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
273 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
277 DWORD dwStyle
; /* the cached window GWL_STYLE */
278 DWORD dwLvExStyle
; /* extended listview style */
279 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
285 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
288 HIMAGELIST himlNormal
;
289 HIMAGELIST himlSmall
;
290 HIMAGELIST himlState
;
295 POINT currIconPos
; /* this is the position next icon will be placed */
299 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
301 /* marquee selection */
302 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
304 RECT marqueeRect
; /* absolute coordinates of marquee selection */
305 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
306 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
309 BOOL bFocus
; /* control has focus */
311 RECT rcFocus
; /* focus bounds */
322 INT ntmHeight
; /* Some cached metrics of the font used */
323 INT ntmMaxCharWidth
; /* by the listview to draw items */
326 /* mouse operation */
329 POINT ptClickPos
; /* point where the user clicked */
330 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
334 /* keyboard operation */
335 DWORD lastKeyPressTimestamp
;
337 INT nSearchParamLength
;
338 WCHAR szSearchParam
[ MAX_PATH
];
341 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
342 BOOL bIsDrawing
; /* Drawing in progress */
343 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
344 BOOL bRedraw
; /* WM_SETREDRAW switch */
347 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
353 /* How many we debug buffer to allocate */
354 #define DEBUG_BUFFERS 20
355 /* The size of a single debug buffer */
356 #define DEBUG_BUFFER_SIZE 256
358 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
359 #define SB_INTERNAL -1
361 /* maximum size of a label */
362 #define DISP_TEXT_SIZE 260
364 /* padding for items in list and small icon display modes */
365 #define WIDTH_PADDING 12
367 /* padding for items in list, report and small icon display modes */
368 #define HEIGHT_PADDING 1
370 /* offset of items in report display mode */
371 #define REPORT_MARGINX 2
373 /* padding for icon in large icon display mode
374 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
375 * that HITTEST will see.
376 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
377 * ICON_TOP_PADDING - sum of the two above.
378 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
379 * LABEL_HOR_PADDING - between text and sides of box
380 * LABEL_VERT_PADDING - between bottom of text and end of box
382 * ICON_LR_PADDING - additional width above icon size.
383 * ICON_LR_HALF - half of the above value
385 #define ICON_TOP_PADDING_NOTHITABLE 2
386 #define ICON_TOP_PADDING_HITABLE 2
387 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
388 #define ICON_BOTTOM_PADDING 4
389 #define LABEL_HOR_PADDING 5
390 #define LABEL_VERT_PADDING 7
391 #define ICON_LR_PADDING 16
392 #define ICON_LR_HALF (ICON_LR_PADDING/2)
394 /* default label width for items in list and small icon display modes */
395 #define DEFAULT_LABEL_WIDTH 40
396 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
397 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
399 /* default column width for items in list display mode */
400 #define DEFAULT_COLUMN_WIDTH 128
402 /* Size of "line" scroll for V & H scrolls */
403 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
405 /* Padding between image and label */
406 #define IMAGE_PADDING 2
408 /* Padding behind the label */
409 #define TRAILING_LABEL_PADDING 12
410 #define TRAILING_HEADER_PADDING 11
412 /* Border for the icon caption */
413 #define CAPTION_BORDER 2
415 /* Standard DrawText flags */
416 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
417 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
418 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
420 /* Image index from state */
421 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
423 /* The time in milliseconds to reset the search in the list */
424 #define KEY_DELAY 450
426 /* Dump the LISTVIEW_INFO structure to the debug channel */
427 #define LISTVIEW_DUMP(iP) do { \
428 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
429 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
430 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
431 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
432 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
433 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
434 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
435 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
436 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
437 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
440 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
443 * forward declarations
445 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
446 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
447 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
448 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
449 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
450 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
451 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
452 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
453 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
454 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
455 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
456 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
457 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
458 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
459 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
460 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
461 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
462 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
463 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
464 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
466 /******** Text handling functions *************************************/
468 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
469 * text string. The string may be ANSI or Unicode, in which case
470 * the boolean isW tells us the type of the string.
472 * The name of the function tell what type of strings it expects:
473 * W: Unicode, T: ANSI/Unicode - function of isW
476 static inline BOOL
is_text(LPCWSTR text
)
478 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
481 static inline int textlenT(LPCWSTR text
, BOOL isW
)
483 return !is_text(text
) ? 0 :
484 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
487 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
490 if (isSrcW
) lstrcpynW(dest
, src
, max
);
491 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
493 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
494 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
497 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
499 LPWSTR wstr
= (LPWSTR
)text
;
501 if (!isW
&& is_text(text
))
503 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
504 wstr
= Alloc(len
* sizeof(WCHAR
));
505 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
507 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
511 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
513 if (!isW
&& is_text(wstr
)) Free (wstr
);
517 * dest is a pointer to a Unicode string
518 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
520 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
524 if (src
== LPSTR_TEXTCALLBACKW
)
526 if (is_text(*dest
)) Free(*dest
);
527 *dest
= LPSTR_TEXTCALLBACKW
;
531 LPWSTR pszText
= textdupTtoW(src
, isW
);
532 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
533 bResult
= Str_SetPtrW(dest
, pszText
);
534 textfreeT(pszText
, isW
);
540 * compares a Unicode to a Unicode/ANSI text string
542 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
544 if (!aw
) return bt
? -1 : 0;
546 if (aw
== LPSTR_TEXTCALLBACKW
)
547 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
548 if (bt
!= LPSTR_TEXTCALLBACKW
)
550 LPWSTR bw
= textdupTtoW(bt
, isW
);
551 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
559 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
561 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
562 return CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
) - CSTR_EQUAL
;
565 /******** Debugging functions *****************************************/
567 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
569 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
570 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
573 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
575 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
576 n
= min(textlenT(text
, isW
), n
);
577 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
580 static char* debug_getbuf(void)
582 static int index
= 0;
583 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
584 return buffers
[index
++ % DEBUG_BUFFERS
];
587 static inline const char* debugrange(const RANGE
*lprng
)
589 if (!lprng
) return "(null)";
590 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
593 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
595 char* buf
= debug_getbuf(), *text
= buf
;
596 int len
, size
= DEBUG_BUFFER_SIZE
;
598 if (pScrollInfo
== NULL
) return "(null)";
599 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
600 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
601 if (pScrollInfo
->fMask
& SIF_RANGE
)
602 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
604 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
605 if (pScrollInfo
->fMask
& SIF_PAGE
)
606 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
608 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
609 if (pScrollInfo
->fMask
& SIF_POS
)
610 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
612 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
613 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
614 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
616 if (len
== -1) goto end
; buf
+= len
;
619 buf
= text
+ strlen(text
);
621 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
625 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
627 if (!plvnm
) return "(null)";
628 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
629 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
630 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
631 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
634 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
636 char* buf
= debug_getbuf(), *text
= buf
;
637 int len
, size
= DEBUG_BUFFER_SIZE
;
639 if (lpLVItem
== NULL
) return "(null)";
640 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
641 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
642 if (lpLVItem
->mask
& LVIF_STATE
)
643 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
645 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
646 if (lpLVItem
->mask
& LVIF_TEXT
)
647 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
649 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
650 if (lpLVItem
->mask
& LVIF_IMAGE
)
651 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
653 if (len
== -1) goto end
; 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
; buf
+= len
; size
-= len
;
658 if (lpLVItem
->mask
& LVIF_INDENT
)
659 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
661 if (len
== -1) goto end
; buf
+= len
;
664 buf
= text
+ strlen(text
);
666 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
670 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
672 char* buf
= debug_getbuf(), *text
= buf
;
673 int len
, size
= DEBUG_BUFFER_SIZE
;
675 if (lpColumn
== NULL
) return "(null)";
676 len
= snprintf(buf
, size
, "{");
677 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
678 if (lpColumn
->mask
& LVCF_SUBITEM
)
679 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
681 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
682 if (lpColumn
->mask
& LVCF_FMT
)
683 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
685 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
686 if (lpColumn
->mask
& LVCF_WIDTH
)
687 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
689 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
690 if (lpColumn
->mask
& LVCF_TEXT
)
691 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
693 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
694 if (lpColumn
->mask
& LVCF_IMAGE
)
695 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
697 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
698 if (lpColumn
->mask
& LVCF_ORDER
)
699 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
701 if (len
== -1) goto end
; buf
+= len
;
704 buf
= text
+ strlen(text
);
706 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
710 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
712 if (!lpht
) return "(null)";
714 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
715 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
718 /* Return the corresponding text for a given scroll value */
719 static inline LPCSTR
debugscrollcode(int nScrollCode
)
723 case SB_LINELEFT
: return "SB_LINELEFT";
724 case SB_LINERIGHT
: return "SB_LINERIGHT";
725 case SB_PAGELEFT
: return "SB_PAGELEFT";
726 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
727 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
728 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
729 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
730 case SB_INTERNAL
: return "SB_INTERNAL";
731 default: return "unknown";
736 /******** Notification functions ************************************/
738 static int get_ansi_notification(UINT unicodeNotificationCode
)
740 switch (unicodeNotificationCode
)
742 case LVN_BEGINLABELEDITA
:
743 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
744 case LVN_ENDLABELEDITA
:
745 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
746 case LVN_GETDISPINFOA
:
747 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
748 case LVN_SETDISPINFOA
:
749 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
750 case LVN_ODFINDITEMA
:
751 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
752 case LVN_GETINFOTIPA
:
753 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
754 /* header forwards */
756 case HDN_TRACKW
: return HDN_TRACKA
;
758 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
759 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
760 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
761 case HDN_ITEMCHANGINGA
:
762 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
763 case HDN_ITEMCHANGEDA
:
764 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
766 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
767 case HDN_DIVIDERDBLCLICKA
:
768 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
771 FIXME("unknown notification %x\n", unicodeNotificationCode
);
772 return unicodeNotificationCode
;
775 /* forwards header notifications to listview parent */
776 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
778 LPCWSTR text
= NULL
, filter
= NULL
;
780 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
782 /* on unicode format exit earlier */
783 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
784 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
787 /* header always supplies unicode notifications,
788 all we have to do is to convert strings to ANSI */
791 /* convert item text */
792 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
794 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
795 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
797 /* convert filter text */
798 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
799 lpnmh
->pitem
->pvFilter
)
801 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
802 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
805 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
807 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
813 Free(lpnmh
->pitem
->pszText
);
814 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
818 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
819 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
825 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
829 TRACE("(code=%d)\n", code
);
831 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
832 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
834 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
836 TRACE(" <= %ld\n", result
);
841 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
844 HWND hwnd
= infoPtr
->hwndSelf
;
845 notify_hdr(infoPtr
, code
, &nmh
);
846 return IsWindow(hwnd
);
849 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
860 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
861 item
.iItem
= htInfo
->iItem
;
863 item
.stateMask
= (UINT
)-1;
864 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
865 nmia
.lParam
= item
.lParam
;
866 nmia
.uOldState
= item
.state
;
867 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
868 nmia
.uChanged
= LVIF_STATE
;
871 nmia
.iItem
= htInfo
->iItem
;
872 nmia
.iSubItem
= htInfo
->iSubItem
;
873 nmia
.ptAction
= htInfo
->pt
;
875 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
876 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
877 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
879 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
882 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
884 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
885 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
888 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
889 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
893 HWND hwnd
= infoPtr
->hwndSelf
;
896 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
897 ZeroMemory(&nmia
, sizeof(nmia
));
898 nmia
.iItem
= lvht
->iItem
;
899 nmia
.iSubItem
= lvht
->iSubItem
;
900 nmia
.ptAction
= lvht
->pt
;
901 item
.mask
= LVIF_PARAM
;
902 item
.iItem
= lvht
->iItem
;
904 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
905 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
906 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
909 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
913 HWND hwnd
= infoPtr
->hwndSelf
;
915 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
917 item
.mask
= LVIF_PARAM
;
920 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
921 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
922 return IsWindow(hwnd
);
926 Send notification. depends on dispinfoW having same
927 structure as dispinfoA.
928 infoPtr : listview struct
929 code : *Unicode* notification code
930 pdi : dispinfo structure (can be unicode or ansi)
931 isW : TRUE if dispinfo is Unicode
933 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
935 INT length
= 0, ret_length
;
936 LPWSTR buffer
= NULL
, ret_text
;
937 BOOL return_ansi
= FALSE
;
938 BOOL return_unicode
= FALSE
;
941 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
943 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
944 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
947 ret_length
= pdi
->item
.cchTextMax
;
948 ret_text
= pdi
->item
.pszText
;
950 if (return_unicode
|| return_ansi
)
952 if (code
!= LVN_GETDISPINFOW
)
954 length
= return_ansi
?
955 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
956 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
960 length
= pdi
->item
.cchTextMax
;
961 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
964 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
965 if (!buffer
) return FALSE
;
968 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
971 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
974 pdi
->item
.pszText
= buffer
;
975 pdi
->item
.cchTextMax
= length
;
978 if (infoPtr
->notifyFormat
== NFR_ANSI
)
979 code
= get_ansi_notification(code
);
981 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
982 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
983 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
985 if (return_ansi
|| return_unicode
)
987 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
989 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
991 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
993 strcpyW(ret_text
, pdi
->item
.pszText
);
995 else if (return_ansi
) /* note : pointer can be changed by app ! */
997 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
998 ret_length
, NULL
, NULL
);
1001 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
1002 ret_text
, ret_length
);
1004 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
1005 pdi
->item
.cchTextMax
= ret_length
;
1011 /* if dipsinfo holder changed notification code then convert */
1012 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1014 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1016 buffer
= Alloc(length
* sizeof(CHAR
));
1017 if (!buffer
) return FALSE
;
1019 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1020 ret_length
, NULL
, NULL
);
1022 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1029 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1030 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1032 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1033 lpnmlvcd
->nmcd
.hdc
= hdc
;
1034 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1035 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1036 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1037 if (!lplvItem
) return;
1038 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1039 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1040 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1041 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1042 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1043 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1046 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1048 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1051 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1052 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1053 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1054 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1055 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1056 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1060 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1062 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
1063 lpnmlvcd
->clrTextBk
= comctl32_color
.clrWindow
;
1064 if (lpnmlvcd
->clrText
== CLR_DEFAULT
)
1065 lpnmlvcd
->clrText
= comctl32_color
.clrWindowText
;
1067 /* apparently, for selected items, we have to override the returned values */
1070 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1072 if (infoPtr
->bFocus
)
1074 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1075 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1077 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1079 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1080 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1085 /* Set the text attributes */
1086 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
1088 SetBkMode(hdc
, OPAQUE
);
1089 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
1092 SetBkMode(hdc
, TRANSPARENT
);
1093 SetTextColor(hdc
, lpnmlvcd
->clrText
);
1096 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1098 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1101 /* returns TRUE when repaint needed, FALSE otherwise */
1102 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1104 MEASUREITEMSTRUCT mis
;
1105 mis
.CtlType
= ODT_LISTVIEW
;
1106 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1110 mis
.itemHeight
= infoPtr
->nItemHeight
;
1111 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1112 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1114 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1120 /******** Item iterator functions **********************************/
1122 static RANGES
ranges_create(int count
);
1123 static void ranges_destroy(RANGES ranges
);
1124 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1125 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1126 static void ranges_dump(RANGES ranges
);
1128 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1130 RANGE range
= { nItem
, nItem
+ 1 };
1132 return ranges_add(ranges
, range
);
1135 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1137 RANGE range
= { nItem
, nItem
+ 1 };
1139 return ranges_del(ranges
, range
);
1143 * ITERATOR DOCUMENTATION
1145 * The iterator functions allow for easy, and convenient iteration
1146 * over items of interest in the list. Typically, you create a
1147 * iterator, use it, and destroy it, as such:
1150 * iterator_xxxitems(&i, ...);
1151 * while (iterator_{prev,next}(&i)
1153 * //code which uses i.nItem
1155 * iterator_destroy(&i);
1157 * where xxx is either: framed, or visible.
1158 * Note that it is important that the code destroys the iterator
1159 * after it's done with it, as the creation of the iterator may
1160 * allocate memory, which thus needs to be freed.
1162 * You can iterate both forwards, and backwards through the list,
1163 * by using iterator_next or iterator_prev respectively.
1165 * Lower numbered items are draw on top of higher number items in
1166 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1167 * items may overlap). So, to test items, you should use
1169 * which lists the items top to bottom (in Z-order).
1170 * For drawing items, you should use
1172 * which lists the items bottom to top (in Z-order).
1173 * If you keep iterating over the items after the end-of-items
1174 * marker (-1) is returned, the iterator will start from the
1175 * beginning. Typically, you don't need to test for -1,
1176 * because iterator_{next,prev} will return TRUE if more items
1177 * are to be iterated over, or FALSE otherwise.
1179 * Note: the iterator is defined to be bidirectional. That is,
1180 * any number of prev followed by any number of next, or
1181 * five versa, should leave the iterator at the same item:
1182 * prev * n, next * n = next * n, prev * n
1184 * The iterator has a notion of an out-of-order, special item,
1185 * which sits at the start of the list. This is used in
1186 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1187 * which needs to be first, as it may overlap other items.
1189 * The code is a bit messy because we have:
1190 * - a special item to deal with
1191 * - simple range, or composite range
1193 * If you find bugs, or want to add features, please make sure you
1194 * always check/modify *both* iterator_prev, and iterator_next.
1198 * This function iterates through the items in increasing order,
1199 * but prefixed by the special item, then -1. That is:
1200 * special, 1, 2, 3, ..., n, -1.
1201 * Each item is listed only once.
1203 static inline BOOL
iterator_next(ITERATOR
* i
)
1207 i
->nItem
= i
->nSpecial
;
1208 if (i
->nItem
!= -1) return TRUE
;
1210 if (i
->nItem
== i
->nSpecial
)
1212 if (i
->ranges
) i
->index
= 0;
1218 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1219 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1224 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1225 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1228 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1230 i
->nItem
= i
->range
.lower
;
1231 if (i
->nItem
>= 0) goto testitem
;
1238 * This function iterates through the items in decreasing order,
1239 * followed by the special item, then -1. That is:
1240 * n, n-1, ..., 3, 2, 1, special, -1.
1241 * Each item is listed only once.
1243 static inline BOOL
iterator_prev(ITERATOR
* i
)
1250 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1253 if (i
->nItem
== i
->nSpecial
)
1261 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1262 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1268 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1271 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1273 i
->nItem
= i
->range
.upper
;
1274 if (i
->nItem
> 0) goto testitem
;
1276 return (i
->nItem
= i
->nSpecial
) != -1;
1279 static RANGE
iterator_range(const ITERATOR
*i
)
1283 if (!i
->ranges
) return i
->range
;
1285 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1287 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1288 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1290 else range
.lower
= range
.upper
= 0;
1296 * Releases resources associated with this iterator.
1298 static inline void iterator_destroy(const ITERATOR
*i
)
1300 ranges_destroy(i
->ranges
);
1304 * Create an empty iterator.
1306 static inline BOOL
iterator_empty(ITERATOR
* i
)
1308 ZeroMemory(i
, sizeof(*i
));
1309 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1314 * Create an iterator over a range.
1316 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1324 * Create an iterator over a bunch of ranges.
1325 * Please note that the iterator will take ownership of the ranges,
1326 * and will free them upon destruction.
1328 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1336 * Creates an iterator over the items which intersect frame.
1337 * Uses absolute coordinates rather than compensating for the current offset.
1339 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1341 RECT rcItem
, rcTemp
;
1343 /* in case we fail, we want to return an empty iterator */
1344 if (!iterator_empty(i
)) return FALSE
;
1346 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1348 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1352 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1354 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1355 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1356 i
->nSpecial
= infoPtr
->nFocusedItem
;
1358 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1359 /* to do better here, we need to have PosX, and PosY sorted */
1360 TRACE("building icon ranges:\n");
1361 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1363 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1364 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1365 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1366 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1367 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1368 ranges_additem(i
->ranges
, nItem
);
1372 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1376 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1377 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1379 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1380 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1381 if (range
.upper
<= range
.lower
) return TRUE
;
1382 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1383 TRACE(" report=%s\n", debugrange(&i
->range
));
1387 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1388 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1389 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1396 if (infoPtr
->nItemWidth
)
1398 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1399 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1403 nFirstCol
= max(frame
->left
, 0);
1404 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1407 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1409 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1410 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1412 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1414 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1415 TRACE("building list ranges:\n");
1416 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1418 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1419 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1420 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1421 TRACE(" list=%s\n", debugrange(&item_range
));
1422 ranges_add(i
->ranges
, item_range
);
1430 * Creates an iterator over the items which intersect lprc.
1432 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1437 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1439 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1440 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1442 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1446 * Creates an iterator over the items which intersect the visible region of hdc.
1448 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1450 POINT Origin
, Position
;
1451 RECT rcItem
, rcClip
;
1454 rgntype
= GetClipBox(hdc
, &rcClip
);
1455 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1456 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1457 if (rgntype
== SIMPLEREGION
) return TRUE
;
1459 /* first deal with the special item */
1460 if (i
->nSpecial
!= -1)
1462 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1463 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1466 /* if we can't deal with the region, we'll just go with the simple range */
1467 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1468 TRACE("building visible range:\n");
1469 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1471 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1472 if (!ranges_add(i
->ranges
, i
->range
))
1474 ranges_destroy(i
->ranges
);
1480 /* now delete the invisible items from the list */
1481 while(iterator_next(i
))
1483 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1484 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1485 rcItem
.top
= Position
.y
+ Origin
.y
;
1486 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1487 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1488 if (!RectVisible(hdc
, &rcItem
))
1489 ranges_delitem(i
->ranges
, i
->nItem
);
1491 /* the iterator should restart on the next iterator_next */
1497 /* Remove common elements from two iterators */
1498 /* Passed iterators have to point on the first elements */
1499 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1501 if(!iter1
->ranges
|| !iter2
->ranges
) {
1504 if(iter1
->ranges
|| iter2
->ranges
||
1505 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1506 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1507 ERR("result is not a one range iterator\n");
1511 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1514 lower
= iter1
->range
.lower
;
1515 upper
= iter1
->range
.upper
;
1517 if(lower
< iter2
->range
.lower
)
1518 iter1
->range
.upper
= iter2
->range
.lower
;
1519 else if(upper
> iter2
->range
.upper
)
1520 iter1
->range
.lower
= iter2
->range
.upper
;
1522 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1524 if(iter2
->range
.lower
< lower
)
1525 iter2
->range
.upper
= lower
;
1526 else if(iter2
->range
.upper
> upper
)
1527 iter2
->range
.lower
= upper
;
1529 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1534 iterator_next(iter1
);
1535 iterator_next(iter2
);
1538 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1541 if(iter1
->nItem
== iter2
->nItem
) {
1542 int delete = iter1
->nItem
;
1544 iterator_prev(iter1
);
1545 iterator_prev(iter2
);
1546 ranges_delitem(iter1
->ranges
, delete);
1547 ranges_delitem(iter2
->ranges
, delete);
1548 iterator_next(iter1
);
1549 iterator_next(iter2
);
1550 } else if(iter1
->nItem
> iter2
->nItem
)
1551 iterator_next(iter2
);
1553 iterator_next(iter1
);
1556 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1557 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1561 /******** Misc helper functions ************************************/
1563 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1564 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1566 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1567 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1570 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1572 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1573 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1576 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1578 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1579 if(state
== 1 || state
== 2)
1583 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1584 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1585 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1589 /* this should be called after window style got updated,
1590 it used to reset view state to match current window style */
1591 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1593 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1596 infoPtr
->uView
= LV_VIEW_ICON
;
1599 infoPtr
->uView
= LV_VIEW_DETAILS
;
1602 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1605 infoPtr
->uView
= LV_VIEW_LIST
;
1609 /* computes next item id value */
1610 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1612 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1616 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1617 return lpID
->id
+ 1;
1622 /******** Internal API functions ************************************/
1624 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1626 static COLUMN_INFO mainItem
;
1628 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1629 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1631 /* update cached column rectangles */
1632 if (infoPtr
->colRectsDirty
)
1635 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1638 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1639 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1640 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1642 Ptr
->colRectsDirty
= FALSE
;
1645 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1648 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1650 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1653 if (infoPtr
->hwndHeader
) return 0;
1655 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1657 /* setup creation flags */
1658 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1659 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1661 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1664 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1665 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1666 if (!infoPtr
->hwndHeader
) return -1;
1668 /* set header unicode format */
1669 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1671 /* set header font */
1672 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1674 /* set header image list */
1675 if (infoPtr
->himlSmall
)
1676 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1678 LISTVIEW_UpdateSize(infoPtr
);
1683 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1685 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1688 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1690 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1691 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1692 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1695 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1697 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1700 /* used to handle collapse main item column case */
1701 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1703 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1704 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1707 /* Listview invalidation functions: use _only_ these functions to invalidate */
1709 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1711 return infoPtr
->bRedraw
;
1714 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1716 if(!is_redrawing(infoPtr
)) return;
1717 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1718 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1721 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1725 if(!is_redrawing(infoPtr
)) return;
1726 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1727 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1730 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1732 POINT Origin
, Position
;
1735 if(!is_redrawing(infoPtr
)) return;
1736 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1737 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1738 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1739 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1741 rcBox
.bottom
= infoPtr
->nItemHeight
;
1742 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1743 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1746 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1748 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1751 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1755 if(!is_redrawing(infoPtr
)) return;
1756 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1757 rcCol
.top
= infoPtr
->rcList
.top
;
1758 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1759 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1764 * Retrieves the number of items that can fit vertically in the client area.
1767 * [I] infoPtr : valid pointer to the listview structure
1770 * Number of items per row.
1772 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1774 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1776 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1781 * Retrieves the number of items that can fit horizontally in the client
1785 * [I] infoPtr : valid pointer to the listview structure
1788 * Number of items per column.
1790 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1792 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1794 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1798 /*************************************************************************
1799 * LISTVIEW_ProcessLetterKeys
1801 * Processes keyboard messages generated by pressing the letter keys
1803 * What this does is perform a case insensitive search from the
1804 * current position with the following quirks:
1805 * - If two chars or more are pressed in quick succession we search
1806 * for the corresponding string (e.g. 'abc').
1807 * - If there is a delay we wipe away the current search string and
1808 * restart with just that char.
1809 * - If the user keeps pressing the same character, whether slowly or
1810 * fast, so that the search string is entirely composed of this
1811 * character ('aaaaa' for instance), then we search for first item
1812 * that starting with that character.
1813 * - If the user types the above character in quick succession, then
1814 * we must also search for the corresponding string ('aaaaa'), and
1815 * go to that string if there is a match.
1818 * [I] hwnd : handle to the window
1819 * [I] charCode : the character code, the actual character
1820 * [I] keyData : key data
1828 * - The current implementation has a list of characters it will
1829 * accept and it ignores everything else. In particular it will
1830 * ignore accentuated characters which seems to match what
1831 * Windows does. But I'm not sure it makes sense to follow
1833 * - We don't sound a beep when the search fails.
1837 * TREEVIEW_ProcessLetterKeys
1839 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1841 WCHAR buffer
[MAX_PATH
];
1848 /* simple parameter checking */
1849 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1851 /* only allow the valid WM_CHARs through */
1852 if (!isalnumW(charCode
) &&
1853 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1854 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1855 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1856 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1857 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1858 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1859 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1860 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1861 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1864 /* update the search parameters */
1865 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1866 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1867 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1869 if (diff
>= 0 && diff
< KEY_DELAY
)
1871 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1872 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1874 if (infoPtr
->charCode
!= charCode
)
1875 infoPtr
->charCode
= charCode
= 0;
1879 infoPtr
->charCode
= charCode
;
1880 infoPtr
->szSearchParam
[0] = charCode
;
1881 infoPtr
->nSearchParamLength
= 1;
1884 /* should start from next after focused item, so next item that matches
1885 will be selected, if there isn't any and focused matches it will be selected
1886 on second search stage from beginning of the list */
1887 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1889 /* with some accumulated search data available start with current focus, otherwise
1890 it's excluded from search */
1891 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1892 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1897 /* let application handle this for virtual listview */
1898 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1902 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1903 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1904 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1905 nmlv
.iStart
= startidx
;
1907 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1909 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1913 int i
= startidx
, endidx
;
1915 /* and search from the current position */
1917 endidx
= infoPtr
->nItemCount
;
1919 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1922 /* start from first item if not found with >= startidx */
1923 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1929 for (i
= startidx
; i
< endidx
; i
++)
1932 item
.mask
= LVIF_TEXT
;
1935 item
.pszText
= buffer
;
1936 item
.cchTextMax
= MAX_PATH
;
1937 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1939 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1944 /* this is used to find first char match when search string is not available yet,
1945 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1946 already waiting for user to complete a string */
1947 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1949 /* this would work but we must keep looking for a longer match */
1954 if ( nItem
!= -1 || /* found something */
1955 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1956 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1962 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1967 /*************************************************************************
1968 * LISTVIEW_UpdateHeaderSize [Internal]
1970 * Function to resize the header control
1973 * [I] hwnd : handle to a window
1974 * [I] nNewScrollPos : scroll pos to set
1979 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1984 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1986 if (!infoPtr
->hwndHeader
) return;
1988 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1989 point
[0].x
= winRect
.left
;
1990 point
[0].y
= winRect
.top
;
1991 point
[1].x
= winRect
.right
;
1992 point
[1].y
= winRect
.bottom
;
1994 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1995 point
[0].x
= -nNewScrollPos
;
1996 point
[1].x
+= nNewScrollPos
;
1998 SetWindowPos(infoPtr
->hwndHeader
,0,
1999 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
2000 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
2001 SWP_NOZORDER
| SWP_NOACTIVATE
);
2006 * Update the scrollbars. This functions should be called whenever
2007 * the content, size or view changes.
2010 * [I] infoPtr : valid pointer to the listview structure
2015 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2017 SCROLLINFO horzInfo
, vertInfo
;
2020 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2022 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2023 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2024 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2026 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2027 if (infoPtr
->uView
== LV_VIEW_LIST
)
2029 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2030 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2032 /* scroll by at least one column per page */
2033 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2034 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2036 if (infoPtr
->nItemWidth
)
2037 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2039 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2041 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2043 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2047 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2050 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2052 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2057 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2058 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2060 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2061 horzInfo
.nMax
= rcHeader
.right
;
2062 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2066 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2067 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2068 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2069 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2070 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2072 /* Setting the horizontal scroll can change the listview size
2073 * (and potentially everything else) so we need to recompute
2074 * everything again for the vertical scroll
2077 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2078 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2079 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2081 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2083 vertInfo
.nMax
= infoPtr
->nItemCount
;
2085 /* scroll by at least one page */
2086 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2087 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2089 if (infoPtr
->nItemHeight
> 0)
2090 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2092 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2096 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2099 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2100 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2101 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2102 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2103 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2105 /* Change of the range may have changed the scroll pos. If so move the content */
2106 if (dx
!= 0 || dy
!= 0)
2109 listRect
= infoPtr
->rcList
;
2110 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2111 SW_ERASE
| SW_INVALIDATE
);
2114 /* Update the Header Control */
2115 if (infoPtr
->hwndHeader
)
2117 horzInfo
.fMask
= SIF_POS
;
2118 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2119 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2126 * Shows/hides the focus rectangle.
2129 * [I] infoPtr : valid pointer to the listview structure
2130 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2135 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2139 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2141 if (infoPtr
->nFocusedItem
< 0) return;
2143 /* we need some gymnastics in ICON mode to handle large items */
2144 if (infoPtr
->uView
== LV_VIEW_ICON
)
2148 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2149 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2151 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2156 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2158 /* for some reason, owner draw should work only in report mode */
2159 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2164 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2165 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2167 item
.iItem
= infoPtr
->nFocusedItem
;
2169 item
.mask
= LVIF_PARAM
;
2170 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2172 ZeroMemory(&dis
, sizeof(dis
));
2173 dis
.CtlType
= ODT_LISTVIEW
;
2174 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2175 dis
.itemID
= item
.iItem
;
2176 dis
.itemAction
= ODA_FOCUS
;
2177 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2178 dis
.hwndItem
= infoPtr
->hwndSelf
;
2180 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2181 dis
.itemData
= item
.lParam
;
2183 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2185 SelectObject(hdc
, hOldFont
);
2189 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2192 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2196 * Invalidates all visible selected items.
2198 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2202 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2203 while(iterator_next(&i
))
2205 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2206 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2208 iterator_destroy(&i
);
2213 * DESCRIPTION: [INTERNAL]
2214 * Computes an item's (left,top) corner, relative to rcView.
2215 * That is, the position has NOT been made relative to the Origin.
2216 * This is deliberate, to avoid computing the Origin over, and
2217 * over again, when this function is called in a loop. Instead,
2218 * one can factor the computation of the Origin before the loop,
2219 * and offset the value returned by this function, on every iteration.
2222 * [I] infoPtr : valid pointer to the listview structure
2223 * [I] nItem : item number
2224 * [O] lpptOrig : item top, left corner
2229 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2231 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2233 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2235 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2236 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2238 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2240 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2241 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2242 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2244 else /* LV_VIEW_DETAILS */
2246 lpptPosition
->x
= REPORT_MARGINX
;
2247 /* item is always at zero indexed column */
2248 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2249 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2250 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2255 * DESCRIPTION: [INTERNAL]
2256 * Compute the rectangles of an item. This is to localize all
2257 * the computations in one place. If you are not interested in some
2258 * of these values, simply pass in a NULL -- the function is smart
2259 * enough to compute only what's necessary. The function computes
2260 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2261 * one, the BOX rectangle. This rectangle is very cheap to compute,
2262 * and is guaranteed to contain all the other rectangles. Computing
2263 * the ICON rect is also cheap, but all the others are potentially
2264 * expensive. This gives an easy and effective optimization when
2265 * searching (like point inclusion, or rectangle intersection):
2266 * first test against the BOX, and if TRUE, test against the desired
2268 * If the function does not have all the necessary information
2269 * to computed the requested rectangles, will crash with a
2270 * failed assertion. This is done so we catch all programming
2271 * errors, given that the function is called only from our code.
2273 * We have the following 'special' meanings for a few fields:
2274 * * If LVIS_FOCUSED is set, we assume the item has the focus
2275 * This is important in ICON mode, where it might get a larger
2276 * then usual rectangle
2278 * Please note that subitem support works only in REPORT mode.
2281 * [I] infoPtr : valid pointer to the listview structure
2282 * [I] lpLVItem : item to compute the measures for
2283 * [O] lprcBox : ptr to Box rectangle
2284 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2285 * [0] lprcSelectBox : ptr to select box rectangle
2286 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2287 * [O] lprcIcon : ptr to Icon rectangle
2288 * Same as LVM_GETITEMRECT with LVIR_ICON
2289 * [O] lprcStateIcon: ptr to State Icon rectangle
2290 * [O] lprcLabel : ptr to Label rectangle
2291 * Same as LVM_GETITEMRECT with LVIR_LABEL
2296 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2297 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2298 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2300 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2301 RECT Box
, SelectBox
, Icon
, Label
;
2302 COLUMN_INFO
*lpColumnInfo
= NULL
;
2303 SIZE labelSize
= { 0, 0 };
2305 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2307 /* Be smart and try to figure out the minimum we have to do */
2308 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2309 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2311 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2312 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2314 if (lprcSelectBox
) doSelectBox
= TRUE
;
2315 if (lprcLabel
) doLabel
= TRUE
;
2316 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2323 /************************************************************/
2324 /* compute the box rectangle (it should be cheap to do) */
2325 /************************************************************/
2326 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2327 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2329 if (lpLVItem
->iSubItem
)
2331 Box
= lpColumnInfo
->rcHeader
;
2336 Box
.right
= infoPtr
->nItemWidth
;
2339 Box
.bottom
= infoPtr
->nItemHeight
;
2341 /******************************************************************/
2342 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2343 /******************************************************************/
2346 LONG state_width
= 0;
2348 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2349 state_width
= infoPtr
->iconStateSize
.cx
;
2351 if (infoPtr
->uView
== LV_VIEW_ICON
)
2353 Icon
.left
= Box
.left
+ state_width
;
2354 if (infoPtr
->himlNormal
)
2355 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2356 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2357 Icon
.right
= Icon
.left
;
2358 Icon
.bottom
= Icon
.top
;
2359 if (infoPtr
->himlNormal
)
2361 Icon
.right
+= infoPtr
->iconSize
.cx
;
2362 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2365 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2367 Icon
.left
= Box
.left
+ state_width
;
2369 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2371 /* we need the indent in report mode */
2372 assert(lpLVItem
->mask
& LVIF_INDENT
);
2373 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2377 Icon
.right
= Icon
.left
;
2378 if (infoPtr
->himlSmall
&&
2379 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2380 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2381 Icon
.right
+= infoPtr
->iconSize
.cx
;
2382 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2384 if(lprcIcon
) *lprcIcon
= Icon
;
2385 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2387 /* TODO: is this correct? */
2390 lprcStateIcon
->left
= Icon
.left
- state_width
;
2391 lprcStateIcon
->right
= Icon
.left
;
2392 lprcStateIcon
->top
= Icon
.top
;
2393 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2394 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2397 else Icon
.right
= 0;
2399 /************************************************************/
2400 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2401 /************************************************************/
2404 /* calculate how far to the right can the label stretch */
2405 Label
.right
= Box
.right
;
2406 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2408 if (lpLVItem
->iSubItem
== 0)
2410 /* we need a zero based rect here */
2411 Label
= lpColumnInfo
->rcHeader
;
2412 OffsetRect(&Label
, -Label
.left
, 0);
2416 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2418 labelSize
.cx
= infoPtr
->nItemWidth
;
2419 labelSize
.cy
= infoPtr
->nItemHeight
;
2423 /* we need the text in non owner draw mode */
2424 assert(lpLVItem
->mask
& LVIF_TEXT
);
2425 if (is_text(lpLVItem
->pszText
))
2427 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2428 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2429 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2433 /* compute rough rectangle where the label will go */
2434 SetRectEmpty(&rcText
);
2435 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2436 rcText
.bottom
= infoPtr
->nItemHeight
;
2437 if (infoPtr
->uView
== LV_VIEW_ICON
)
2438 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2440 /* now figure out the flags */
2441 if (infoPtr
->uView
== LV_VIEW_ICON
)
2442 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2444 uFormat
= LV_SL_DT_FLAGS
;
2446 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2448 if (rcText
.right
!= rcText
.left
)
2449 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2451 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2453 SelectObject(hdc
, hOldFont
);
2454 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2458 if (infoPtr
->uView
== LV_VIEW_ICON
)
2460 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2461 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2462 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2463 Label
.right
= Label
.left
+ labelSize
.cx
;
2464 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2465 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2467 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2468 labelSize
.cy
/= infoPtr
->ntmHeight
;
2469 labelSize
.cy
= max(labelSize
.cy
, 1);
2470 labelSize
.cy
*= infoPtr
->ntmHeight
;
2472 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2474 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2476 Label
.left
= Icon
.right
;
2477 Label
.top
= Box
.top
;
2478 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2479 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2480 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2482 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2484 Label
.left
= Icon
.right
;
2485 Label
.top
= Box
.top
;
2486 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2487 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2490 if (lprcLabel
) *lprcLabel
= Label
;
2491 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2494 /************************************************************/
2495 /* compute SELECT bounding box */
2496 /************************************************************/
2499 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2501 SelectBox
.left
= Icon
.left
;
2502 SelectBox
.top
= Box
.top
;
2503 SelectBox
.bottom
= Box
.bottom
;
2506 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2508 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2512 UnionRect(&SelectBox
, &Icon
, &Label
);
2514 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2515 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2518 /* Fix the Box if necessary */
2521 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2522 else *lprcBox
= Box
;
2524 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2528 * DESCRIPTION: [INTERNAL]
2531 * [I] infoPtr : valid pointer to the listview structure
2532 * [I] nItem : item number
2533 * [O] lprcBox : ptr to Box rectangle
2538 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2540 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2541 POINT Position
, Origin
;
2544 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2545 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2547 /* Be smart and try to figure out the minimum we have to do */
2549 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2550 lvItem
.mask
|= LVIF_TEXT
;
2551 lvItem
.iItem
= nItem
;
2552 lvItem
.iSubItem
= 0;
2553 lvItem
.pszText
= szDispText
;
2554 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2555 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2556 if (infoPtr
->uView
== LV_VIEW_ICON
)
2558 lvItem
.mask
|= LVIF_STATE
;
2559 lvItem
.stateMask
= LVIS_FOCUSED
;
2560 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2562 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2564 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2565 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2567 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2570 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2573 /* LISTVIEW_MapIdToIndex helper */
2574 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2576 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2577 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2579 if (id1
->id
== id2
->id
) return 0;
2581 return (id1
->id
< id2
->id
) ? -1 : 1;
2586 * Returns the item index for id specified.
2589 * [I] infoPtr : valid pointer to the listview structure
2590 * [I] iID : item id to get index for
2593 * Item index, or -1 on failure.
2595 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2600 TRACE("iID=%d\n", iID
);
2602 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2603 if (infoPtr
->nItemCount
== 0) return -1;
2606 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2610 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2611 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2619 * Returns the item id for index given.
2622 * [I] infoPtr : valid pointer to the listview structure
2623 * [I] iItem : item index to get id for
2628 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2633 TRACE("iItem=%d\n", iItem
);
2635 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2636 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2638 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2639 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2641 return lpItem
->id
->id
;
2646 * Returns the current icon position, and advances it along the top.
2647 * The returned position is not offset by Origin.
2650 * [I] infoPtr : valid pointer to the listview structure
2651 * [O] lpPos : will get the current icon position
2656 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2658 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2660 *lpPos
= infoPtr
->currIconPos
;
2662 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2663 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2665 infoPtr
->currIconPos
.x
= 0;
2666 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2672 * Returns the current icon position, and advances it down the left edge.
2673 * The returned position is not offset by Origin.
2676 * [I] infoPtr : valid pointer to the listview structure
2677 * [O] lpPos : will get the current icon position
2682 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2684 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2686 *lpPos
= infoPtr
->currIconPos
;
2688 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2689 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2691 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2692 infoPtr
->currIconPos
.y
= 0;
2698 * Moves an icon to the specified position.
2699 * It takes care of invalidating the item, etc.
2702 * [I] infoPtr : valid pointer to the listview structure
2703 * [I] nItem : the item to move
2704 * [I] lpPos : the new icon position
2705 * [I] isNew : flags the item as being new
2711 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2717 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2718 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2720 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2721 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2724 /* Allocating a POINTER for every item is too resource intensive,
2725 * so we'll keep the (x,y) in different arrays */
2726 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2727 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2729 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2736 * Arranges listview items in icon display mode.
2739 * [I] infoPtr : valid pointer to the listview structure
2740 * [I] nAlignCode : alignment code
2746 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2748 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2752 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2754 TRACE("nAlignCode=%d\n", nAlignCode
);
2756 if (nAlignCode
== LVA_DEFAULT
)
2758 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2759 else nAlignCode
= LVA_ALIGNTOP
;
2764 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2765 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2766 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2767 default: return FALSE
;
2770 infoPtr
->bAutoarrange
= TRUE
;
2771 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2772 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2774 next_pos(infoPtr
, &pos
);
2775 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2783 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2784 * For LVS_REPORT always returns empty rectangle.
2787 * [I] infoPtr : valid pointer to the listview structure
2788 * [O] lprcView : bounding rectangle
2794 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2798 SetRectEmpty(lprcView
);
2800 switch (infoPtr
->uView
)
2803 case LV_VIEW_SMALLICON
:
2804 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2806 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2807 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2808 lprcView
->right
= max(lprcView
->right
, x
);
2809 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2811 if (infoPtr
->nItemCount
> 0)
2813 lprcView
->right
+= infoPtr
->nItemWidth
;
2814 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2819 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2820 x
= infoPtr
->nItemCount
/ y
;
2821 if (infoPtr
->nItemCount
% y
) x
++;
2822 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2823 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2830 * Retrieves the bounding rectangle of all the items.
2833 * [I] infoPtr : valid pointer to the listview structure
2834 * [O] lprcView : bounding rectangle
2840 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2844 TRACE("(lprcView=%p)\n", lprcView
);
2846 if (!lprcView
) return FALSE
;
2848 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2850 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2852 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2853 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2856 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2863 * Retrieves the subitem pointer associated with the subitem index.
2866 * [I] hdpaSubItems : DPA handle for a specific item
2867 * [I] nSubItem : index of subitem
2870 * SUCCESS : subitem pointer
2873 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2875 SUBITEM_INFO
*lpSubItem
;
2878 /* we should binary search here if need be */
2879 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2881 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2882 if (lpSubItem
->iSubItem
== nSubItem
)
2892 * Calculates the desired item width.
2895 * [I] infoPtr : valid pointer to the listview structure
2898 * The desired item width.
2900 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2904 TRACE("uView=%d\n", infoPtr
->uView
);
2906 if (infoPtr
->uView
== LV_VIEW_ICON
)
2907 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2908 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2910 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2915 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2916 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2918 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2919 nItemWidth
= rcHeader
.right
;
2922 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2924 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2928 lvItem
.mask
= LVIF_TEXT
;
2929 lvItem
.iSubItem
= 0;
2931 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2934 lvItem
.pszText
= szDispText
;
2935 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2936 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2937 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2941 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2942 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2944 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2952 * Calculates the desired item height.
2955 * [I] infoPtr : valid pointer to the listview structure
2958 * The desired item height.
2960 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2964 TRACE("uView=%d\n", infoPtr
->uView
);
2966 if (infoPtr
->uView
== LV_VIEW_ICON
)
2967 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2970 nItemHeight
= infoPtr
->ntmHeight
;
2971 if (infoPtr
->himlState
)
2972 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2973 if (infoPtr
->himlSmall
)
2974 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2975 nItemHeight
+= HEIGHT_PADDING
;
2976 if (infoPtr
->nMeasureItemHeight
> 0)
2977 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2980 return max(nItemHeight
, 1);
2985 * Updates the width, and height of an item.
2988 * [I] infoPtr : valid pointer to the listview structure
2993 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2995 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2996 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
3002 * Retrieves and saves important text metrics info for the current
3006 * [I] infoPtr : valid pointer to the listview structure
3009 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3011 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3012 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3013 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3017 if (GetTextMetricsW(hdc
, &tm
))
3019 infoPtr
->ntmHeight
= tm
.tmHeight
;
3020 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3023 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3024 infoPtr
->nEllipsisWidth
= sz
.cx
;
3026 SelectObject(hdc
, hOldFont
);
3027 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3029 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3034 * A compare function for ranges
3037 * [I] range1 : pointer to range 1;
3038 * [I] range2 : pointer to range 2;
3042 * > 0 : if range 1 > range 2
3043 * < 0 : if range 2 > range 1
3044 * = 0 : if range intersects range 2
3046 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3050 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3052 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3057 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3062 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3064 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3069 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3071 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3072 ranges_dump(ranges
);
3073 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3075 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3076 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3077 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3079 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3080 assert (prev
->upper
<= curr
->lower
);
3081 assert (curr
->lower
< curr
->upper
);
3085 TRACE("--- Done checking---\n");
3088 static RANGES
ranges_create(int count
)
3090 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3091 if (!ranges
) return NULL
;
3092 ranges
->hdpa
= DPA_Create(count
);
3093 if (ranges
->hdpa
) return ranges
;
3098 static void ranges_clear(RANGES ranges
)
3102 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3103 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3104 DPA_DeleteAllPtrs(ranges
->hdpa
);
3108 static void ranges_destroy(RANGES ranges
)
3110 if (!ranges
) return;
3111 ranges_clear(ranges
);
3112 DPA_Destroy(ranges
->hdpa
);
3116 static RANGES
ranges_clone(RANGES ranges
)
3121 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3123 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3125 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3126 if (!newrng
) goto fail
;
3127 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3128 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
3133 TRACE ("clone failed\n");
3134 ranges_destroy(clone
);
3138 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3142 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3143 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3148 static void ranges_dump(RANGES ranges
)
3152 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3153 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3156 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3158 RANGE srchrng
= { nItem
, nItem
+ 1 };
3160 TRACE("(nItem=%d)\n", nItem
);
3161 ranges_check(ranges
, "before contain");
3162 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3165 static INT
ranges_itemcount(RANGES ranges
)
3169 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3171 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3172 count
+= sel
->upper
- sel
->lower
;
3178 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3180 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3183 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3184 if (index
== -1) return TRUE
;
3186 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3188 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3189 if (chkrng
->lower
>= nItem
)
3190 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3191 if (chkrng
->upper
> nItem
)
3192 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3197 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3202 TRACE("(%s)\n", debugrange(&range
));
3203 ranges_check(ranges
, "before add");
3205 /* try find overlapping regions first */
3206 srchrgn
.lower
= range
.lower
- 1;
3207 srchrgn
.upper
= range
.upper
+ 1;
3208 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3214 TRACE("Adding new range\n");
3216 /* create the brand new range to insert */
3217 newrgn
= Alloc(sizeof(RANGE
));
3218 if(!newrgn
) goto fail
;
3221 /* figure out where to insert it */
3222 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3223 TRACE("index=%d\n", index
);
3224 if (index
== -1) index
= 0;
3226 /* and get it over with */
3227 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3235 RANGE
*chkrgn
, *mrgrgn
;
3236 INT fromindex
, mergeindex
;
3238 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3239 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3241 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3242 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3244 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3246 /* merge now common ranges */
3248 srchrgn
.lower
= chkrgn
->lower
- 1;
3249 srchrgn
.upper
= chkrgn
->upper
+ 1;
3253 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3254 if (mergeindex
== -1) break;
3255 if (mergeindex
== index
)
3257 fromindex
= index
+ 1;
3261 TRACE("Merge with index %i\n", mergeindex
);
3263 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3264 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3265 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3267 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3268 if (mergeindex
< index
) index
--;
3272 ranges_check(ranges
, "after add");
3276 ranges_check(ranges
, "failed add");
3280 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3285 TRACE("(%s)\n", debugrange(&range
));
3286 ranges_check(ranges
, "before del");
3288 /* we don't use DPAS_SORTED here, since we need *
3289 * to find the first overlapping range */
3290 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3293 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3295 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3297 /* case 1: Same range */
3298 if ( (chkrgn
->upper
== range
.upper
) &&
3299 (chkrgn
->lower
== range
.lower
) )
3301 DPA_DeletePtr(ranges
->hdpa
, index
);
3305 /* case 2: engulf */
3306 else if ( (chkrgn
->upper
<= range
.upper
) &&
3307 (chkrgn
->lower
>= range
.lower
) )
3309 DPA_DeletePtr(ranges
->hdpa
, index
);
3312 /* case 3: overlap upper */
3313 else if ( (chkrgn
->upper
<= range
.upper
) &&
3314 (chkrgn
->lower
< range
.lower
) )
3316 chkrgn
->upper
= range
.lower
;
3318 /* case 4: overlap lower */
3319 else if ( (chkrgn
->upper
> range
.upper
) &&
3320 (chkrgn
->lower
>= range
.lower
) )
3322 chkrgn
->lower
= range
.upper
;
3325 /* case 5: fully internal */
3330 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3331 newrgn
->lower
= chkrgn
->lower
;
3332 newrgn
->upper
= range
.lower
;
3333 chkrgn
->lower
= range
.upper
;
3334 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3342 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3345 ranges_check(ranges
, "after del");
3349 ranges_check(ranges
, "failed del");
3355 * Removes all selection ranges
3358 * [I] infoPtr : valid pointer to the listview structure
3359 * [I] toSkip : item range to skip removing the selection
3365 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3374 lvItem
.stateMask
= LVIS_SELECTED
;
3376 /* need to clone the DPA because callbacks can change it */
3377 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3378 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3379 while(iterator_next(&i
))
3380 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3381 /* note that the iterator destructor will free the cloned range */
3382 iterator_destroy(&i
);
3387 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3391 if (!(toSkip
= ranges_create(1))) return FALSE
;
3392 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3393 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3394 ranges_destroy(toSkip
);
3398 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3400 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3405 * Retrieves the number of items that are marked as selected.
3408 * [I] infoPtr : valid pointer to the listview structure
3411 * Number of items selected.
3413 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3415 INT nSelectedCount
= 0;
3417 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3420 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3422 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3427 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3429 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3430 return nSelectedCount
;
3435 * Manages the item focus.
3438 * [I] infoPtr : valid pointer to the listview structure
3439 * [I] nItem : item index
3442 * TRUE : focused item changed
3443 * FALSE : focused item has NOT changed
3445 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3447 INT oldFocus
= infoPtr
->nFocusedItem
;
3450 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3452 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3453 lvItem
.stateMask
= LVIS_FOCUSED
;
3454 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3456 return oldFocus
!= infoPtr
->nFocusedItem
;
3459 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3461 if (nShiftItem
< nItem
) return nShiftItem
;
3463 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3465 if (direction
> 0) return nShiftItem
+ direction
;
3467 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3470 /* This function updates focus index.
3473 focus : current focus index
3474 item : index of item to be added/removed
3475 direction : add/remove flag
3477 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3479 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3481 infoPtr
->bDoChangeNotify
= FALSE
;
3482 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3483 if (focus
!= infoPtr
->nFocusedItem
)
3484 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3485 infoPtr
->bDoChangeNotify
= old_change
;
3490 * Updates the various indices after an item has been inserted or deleted.
3493 * [I] infoPtr : valid pointer to the listview structure
3494 * [I] nItem : item index
3495 * [I] direction : Direction of shift, +1 or -1.
3500 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3502 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3504 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3505 assert(abs(direction
) == 1);
3506 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3508 /* But we are not supposed to modify nHotItem! */
3513 * Adds a block of selections.
3516 * [I] infoPtr : valid pointer to the listview structure
3517 * [I] nItem : item index
3520 * Whether the window is still valid.
3522 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3524 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3525 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3526 HWND hwndSelf
= infoPtr
->hwndSelf
;
3527 NMLVODSTATECHANGE nmlv
;
3532 /* Temporarily disable change notification
3533 * If the control is LVS_OWNERDATA, we need to send
3534 * only one LVN_ODSTATECHANGED notification.
3535 * See MSDN documentation for LVN_ITEMCHANGED.
3537 bOldChange
= infoPtr
->bDoChangeNotify
;
3538 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3540 if (nFirst
== -1) nFirst
= nItem
;
3542 item
.state
= LVIS_SELECTED
;
3543 item
.stateMask
= LVIS_SELECTED
;
3545 for (i
= nFirst
; i
<= nLast
; i
++)
3546 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3548 ZeroMemory(&nmlv
, sizeof(nmlv
));
3549 nmlv
.iFrom
= nFirst
;
3552 nmlv
.uOldState
= item
.state
;
3554 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3555 if (!IsWindow(hwndSelf
))
3557 infoPtr
->bDoChangeNotify
= bOldChange
;
3564 * Sets a single group selection.
3567 * [I] infoPtr : valid pointer to the listview structure
3568 * [I] nItem : item index
3573 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3580 if (!(selection
= ranges_create(100))) return;
3582 item
.state
= LVIS_SELECTED
;
3583 item
.stateMask
= LVIS_SELECTED
;
3585 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3587 if (infoPtr
->nSelectionMark
== -1)
3589 infoPtr
->nSelectionMark
= nItem
;
3590 ranges_additem(selection
, nItem
);
3596 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3597 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3598 ranges_add(selection
, sel
);
3603 RECT rcItem
, rcSel
, rcSelMark
;
3606 rcItem
.left
= LVIR_BOUNDS
;
3607 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3608 ranges_destroy (selection
);
3611 rcSelMark
.left
= LVIR_BOUNDS
;
3612 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3613 ranges_destroy (selection
);
3616 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3617 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3618 while(iterator_next(&i
))
3620 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3621 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3623 iterator_destroy(&i
);
3626 /* disable per item notifications on LVS_OWNERDATA style
3627 FIXME: single LVN_ODSTATECHANGED should be used */
3628 bOldChange
= infoPtr
->bDoChangeNotify
;
3629 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3631 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3634 iterator_rangesitems(&i
, selection
);
3635 while(iterator_next(&i
))
3636 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3637 /* this will also destroy the selection */
3638 iterator_destroy(&i
);
3640 infoPtr
->bDoChangeNotify
= bOldChange
;
3642 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3647 * Sets a single selection.
3650 * [I] infoPtr : valid pointer to the listview structure
3651 * [I] nItem : item index
3656 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3660 TRACE("nItem=%d\n", nItem
);
3662 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3664 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3665 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3666 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3668 infoPtr
->nSelectionMark
= nItem
;
3673 * Set selection(s) with keyboard.
3676 * [I] infoPtr : valid pointer to the listview structure
3677 * [I] nItem : item index
3678 * [I] space : VK_SPACE code sent
3681 * SUCCESS : TRUE (needs to be repainted)
3682 * FAILURE : FALSE (nothing has changed)
3684 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3686 /* FIXME: pass in the state */
3687 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
3688 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
3689 BOOL bResult
= FALSE
;
3691 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3692 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3696 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3697 LISTVIEW_SetSelection(infoPtr
, nItem
);
3701 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3705 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3706 lvItem
.stateMask
= LVIS_SELECTED
;
3709 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3710 if (lvItem
.state
& LVIS_SELECTED
)
3711 infoPtr
->nSelectionMark
= nItem
;
3713 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3716 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3719 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3723 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3725 LVHITTESTINFO lvHitTestInfo
;
3727 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3728 lvHitTestInfo
.pt
.x
= pt
.x
;
3729 lvHitTestInfo
.pt
.y
= pt
.y
;
3731 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3733 lpLVItem
->mask
= LVIF_PARAM
;
3734 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3735 lpLVItem
->iSubItem
= 0;
3737 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3740 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3742 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3743 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3744 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3749 * Called when the mouse is being actively tracked and has hovered for a specified
3753 * [I] infoPtr : valid pointer to the listview structure
3754 * [I] fwKeys : key indicator
3755 * [I] x,y : mouse position
3758 * 0 if the message was processed, non-zero if there was an error
3761 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3762 * over the item for a certain period of time.
3765 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3769 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3771 if (LISTVIEW_IsHotTracking(infoPtr
))
3779 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3780 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3782 SetFocus(infoPtr
->hwndSelf
);
3788 #define SCROLL_LEFT 0x1
3789 #define SCROLL_RIGHT 0x2
3790 #define SCROLL_UP 0x4
3791 #define SCROLL_DOWN 0x8
3795 * Utility routine to draw and highlight items within a marquee selection rectangle.
3798 * [I] infoPtr : valid pointer to the listview structure
3799 * [I] coords_orig : original co-ordinates of the cursor
3800 * [I] coords_offs : offsetted coordinates of the cursor
3801 * [I] offset : offset amount
3802 * [I] scroll : Bitmask of which directions we should scroll, if at all
3807 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3808 const POINT
*coords_offs
, const POINT
*offset
,
3811 BOOL controlDown
= FALSE
;
3813 ITERATOR old_elems
, new_elems
;
3816 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3818 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3819 rect
.right
= coords_offs
->x
;
3823 rect
.left
= coords_offs
->x
;
3824 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3827 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3829 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3830 rect
.bottom
= coords_offs
->y
;
3834 rect
.top
= coords_offs
->y
;
3835 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3838 /* Cancel out the old marquee rectangle and draw the new one */
3839 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3841 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3842 the cursor is further away */
3844 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3845 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3847 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3848 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3850 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3851 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3853 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3854 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3856 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3858 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3860 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3861 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3863 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3864 iterator_remove_common_items(&old_elems
, &new_elems
);
3866 /* Iterate over no longer selected items */
3867 while (iterator_next(&old_elems
))
3869 if (old_elems
.nItem
> -1)
3871 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3874 item
.state
= LVIS_SELECTED
;
3876 item
.stateMask
= LVIS_SELECTED
;
3878 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3881 iterator_destroy(&old_elems
);
3884 /* Iterate over newly selected items */
3885 if (GetKeyState(VK_CONTROL
) & 0x8000)
3888 while (iterator_next(&new_elems
))
3890 if (new_elems
.nItem
> -1)
3892 /* If CTRL is pressed, invert. If not, always select the item. */
3893 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3896 item
.state
= LVIS_SELECTED
;
3898 item
.stateMask
= LVIS_SELECTED
;
3900 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3903 iterator_destroy(&new_elems
);
3905 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3910 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3911 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3914 * [I] hwnd : Handle to the listview
3915 * [I] uMsg : WM_TIMER (ignored)
3916 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3917 * [I] dwTimer : The elapsed time (ignored)
3922 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3924 LISTVIEW_INFO
*infoPtr
;
3925 SCROLLINFO scrollInfo
;
3931 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3936 /* Get the current cursor position and convert to client coordinates */
3937 GetCursorPos(&coords_orig
);
3938 ScreenToClient(hWnd
, &coords_orig
);
3940 /* Ensure coordinates are within client bounds */
3941 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3942 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3945 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3947 /* Offset coordinates by the appropriate amount */
3948 coords_offs
.x
-= offset
.x
;
3949 coords_offs
.y
-= offset
.y
;
3951 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3952 scrollInfo
.fMask
= SIF_ALL
;
3954 /* Work out in which directions we can scroll */
3955 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3957 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3958 scroll
|= SCROLL_UP
;
3960 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3961 scroll
|= SCROLL_DOWN
;
3964 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3966 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3967 scroll
|= SCROLL_LEFT
;
3969 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3970 scroll
|= SCROLL_RIGHT
;
3973 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3974 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3975 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3976 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3978 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3984 * Called whenever WM_MOUSEMOVE is received.
3987 * [I] infoPtr : valid pointer to the listview structure
3988 * [I] fwKeys : key indicator
3989 * [I] x,y : mouse position
3992 * 0 if the message is processed, non-zero if there was an error
3994 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
4000 if (!(fwKeys
& MK_LBUTTON
))
4001 infoPtr
->bLButtonDown
= FALSE
;
4003 if (infoPtr
->bLButtonDown
)
4005 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
4006 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4008 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4011 if (infoPtr
->bLButtonDown
)
4013 if (infoPtr
->bMarqueeSelect
)
4023 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4025 /* Ensure coordinates are within client bounds */
4026 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4027 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4029 /* Offset coordinates by the appropriate amount */
4030 coords_offs
.x
-= offset
.x
;
4031 coords_offs
.y
-= offset
.y
;
4033 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4034 move the mouse again */
4036 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4037 (y
>= infoPtr
->rcList
.bottom
))
4039 if (!infoPtr
->bScrolling
)
4041 infoPtr
->bScrolling
= TRUE
;
4042 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4047 infoPtr
->bScrolling
= FALSE
;
4048 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4051 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4059 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4061 /* reset item marker */
4062 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4063 infoPtr
->nLButtonDownItem
= -1;
4065 if (!PtInRect(&rect
, pt
))
4067 /* this path covers the following:
4068 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4069 2. change focus with keys
4070 3. move mouse over item from step 1 selects it and moves focus on it */
4071 if (infoPtr
->nLButtonDownItem
!= -1 &&
4072 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4076 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4077 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4079 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4080 infoPtr
->nLButtonDownItem
= -1;
4083 if (!infoPtr
->bDragging
)
4085 ht
.pt
= infoPtr
->ptClickPos
;
4086 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4088 /* If the click is outside the range of an item, begin a
4089 highlight. If not, begin an item drag. */
4094 /* If we're allowing multiple selections, send notification.
4095 If return value is non-zero, cancel. */
4096 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4098 /* Store the absolute coordinates of the click */
4100 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4102 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4103 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4105 /* Begin selection and capture mouse */
4106 infoPtr
->bMarqueeSelect
= TRUE
;
4107 SetCapture(infoPtr
->hwndSelf
);
4114 ZeroMemory(&nmlv
, sizeof(nmlv
));
4115 nmlv
.iItem
= ht
.iItem
;
4116 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4118 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4119 infoPtr
->bDragging
= TRUE
;
4127 /* see if we are supposed to be tracking mouse hovering */
4128 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4129 TRACKMOUSEEVENT trackinfo
;
4131 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4132 trackinfo
.dwFlags
= TME_QUERY
;
4134 /* see if we are already tracking this hwnd */
4135 _TrackMouseEvent(&trackinfo
);
4137 if(!(trackinfo
.dwFlags
& TME_HOVER
) || trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4138 trackinfo
.dwFlags
= TME_HOVER
;
4139 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4140 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4142 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4143 _TrackMouseEvent(&trackinfo
);
4152 * Tests whether the item is assignable to a list with style lStyle
4154 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4156 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4157 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4158 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4166 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4169 * [I] infoPtr : valid pointer to the listview structure
4170 * [I] lpLVItem : valid pointer to new item attributes
4171 * [I] isNew : the item being set is being inserted
4172 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4173 * [O] bChanged : will be set to TRUE if the item really changed
4179 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4185 /* stateMask is ignored for LVM_INSERTITEM */
4186 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4190 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4192 if (lpLVItem
->mask
== 0) return TRUE
;
4194 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4196 /* a virtual listview only stores selection and focus */
4197 if (lpLVItem
->mask
& ~LVIF_STATE
)
4203 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4204 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4208 /* we need to get the lParam and state of the item */
4209 item
.iItem
= lpLVItem
->iItem
;
4210 item
.iSubItem
= lpLVItem
->iSubItem
;
4211 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4212 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4216 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4218 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4219 /* determine what fields will change */
4220 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4221 uChanged
|= LVIF_STATE
;
4223 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4224 uChanged
|= LVIF_IMAGE
;
4226 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4227 uChanged
|= LVIF_PARAM
;
4229 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4230 uChanged
|= LVIF_INDENT
;
4232 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4233 uChanged
|= LVIF_TEXT
;
4235 TRACE("change mask=0x%x\n", uChanged
);
4237 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4238 nmlv
.iItem
= lpLVItem
->iItem
;
4239 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4240 nmlv
.uOldState
= item
.state
;
4241 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4242 nmlv
.lParam
= item
.lParam
;
4244 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4245 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4246 are enabled. Even nothing really changed we still need to send this,
4247 in this case uChanged mask is just set to passed item mask. */
4248 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4250 HWND hwndSelf
= infoPtr
->hwndSelf
;
4252 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4254 if (!IsWindow(hwndSelf
))
4258 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4259 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4260 /* this means we won't hit a focus change path later */
4261 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4263 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4264 infoPtr
->nFocusedItem
++;
4267 if (!uChanged
) return TRUE
;
4270 /* copy information */
4271 if (lpLVItem
->mask
& LVIF_TEXT
)
4272 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4274 if (lpLVItem
->mask
& LVIF_IMAGE
)
4275 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4277 if (lpLVItem
->mask
& LVIF_PARAM
)
4278 lpItem
->lParam
= lpLVItem
->lParam
;
4280 if (lpLVItem
->mask
& LVIF_INDENT
)
4281 lpItem
->iIndent
= lpLVItem
->iIndent
;
4283 if (uChanged
& LVIF_STATE
)
4285 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4287 lpItem
->state
&= ~stateMask
;
4288 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4290 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4292 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4293 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4295 else if (stateMask
& LVIS_SELECTED
)
4297 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4299 /* If we are asked to change focus, and we manage it, do it.
4300 It's important to have all new item data stored at this point,
4301 because changing existing focus could result in a redrawing operation,
4302 which in turn could ask for disp data, application should see all data
4303 for inserted item when processing LVN_GETDISPINFO.
4305 The way this works application will see nested item change notifications -
4306 changed item notifications interrupted by ones from item losing focus. */
4307 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4309 if (lpLVItem
->state
& LVIS_FOCUSED
)
4311 /* update selection mark */
4312 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4313 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4315 if (infoPtr
->nFocusedItem
!= -1)
4317 /* remove current focus */
4318 item
.mask
= LVIF_STATE
;
4320 item
.stateMask
= LVIS_FOCUSED
;
4322 /* recurse with redrawing an item */
4323 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4326 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4327 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4329 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4331 infoPtr
->nFocusedItem
= -1;
4336 /* if we're inserting the item, we're done */
4337 if (isNew
) return TRUE
;
4339 /* send LVN_ITEMCHANGED notification */
4340 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4341 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4348 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4351 * [I] infoPtr : valid pointer to the listview structure
4352 * [I] lpLVItem : valid pointer to new subitem attributes
4353 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4354 * [O] bChanged : will be set to TRUE if the item really changed
4360 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4363 SUBITEM_INFO
*lpSubItem
;
4365 /* we do not support subitems for virtual listviews */
4366 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4368 /* set subitem only if column is present */
4369 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4371 /* First do some sanity checks */
4372 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4373 particularly useful. We currently do not actually do anything with
4374 the flag on subitems.
4376 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4377 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4379 /* get the subitem structure, and create it if not there */
4380 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4381 assert (hdpaSubItems
);
4383 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4386 SUBITEM_INFO
*tmpSubItem
;
4389 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4390 if (!lpSubItem
) return FALSE
;
4391 /* we could binary search here, if need be...*/
4392 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4394 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4395 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4397 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4402 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4403 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4407 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4409 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4413 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4415 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4424 * Sets item attributes.
4427 * [I] infoPtr : valid pointer to the listview structure
4428 * [I] lpLVItem : new item attributes
4429 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4435 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4437 HWND hwndSelf
= infoPtr
->hwndSelf
;
4438 LPWSTR pszText
= NULL
;
4439 BOOL bResult
, bChanged
= FALSE
;
4442 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4444 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4447 /* Store old item area */
4448 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4450 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4451 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4453 pszText
= lpLVItem
->pszText
;
4454 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4457 /* actually set the fields */
4458 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4460 if (lpLVItem
->iSubItem
)
4461 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4463 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4464 if (!IsWindow(hwndSelf
))
4467 /* redraw item, if necessary */
4468 if (bChanged
&& !infoPtr
->bIsDrawing
)
4470 /* this little optimization eliminates some nasty flicker */
4471 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4472 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4473 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4474 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4477 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4478 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4484 textfreeT(lpLVItem
->pszText
, isW
);
4485 lpLVItem
->pszText
= pszText
;
4493 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4496 * [I] infoPtr : valid pointer to the listview structure
4501 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4504 SCROLLINFO scrollInfo
;
4506 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4507 scrollInfo
.fMask
= SIF_POS
;
4509 if (infoPtr
->uView
== LV_VIEW_LIST
)
4511 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4512 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4514 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4516 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4517 nItem
= scrollInfo
.nPos
;
4521 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4522 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4525 TRACE("nItem=%d\n", nItem
);
4533 * Erases the background of the given rectangle
4536 * [I] infoPtr : valid pointer to the listview structure
4537 * [I] hdc : device context handle
4538 * [I] lprcBox : clipping rectangle
4544 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4546 if (!infoPtr
->hBkBrush
) return FALSE
;
4548 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4550 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4558 * [I] infoPtr : valid pointer to the listview structure
4559 * [I] hdc : device context handle
4560 * [I] nItem : item index
4561 * [I] nSubItem : subitem index
4562 * [I] pos : item position in client coordinates
4563 * [I] cdmode : custom draw mode
4569 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
4572 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4573 static WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4574 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4576 RECT rcSelect
, rcBox
, rcIcon
, rcLabel
, rcStateIcon
;
4577 NMLVCUSTOMDRAW nmlvcd
;
4582 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, wine_dbgstr_point(&pos
));
4584 /* get information needed for drawing the item */
4585 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
4586 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
;
4587 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4588 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
;
4589 lvItem
.iItem
= nItem
;
4590 lvItem
.iSubItem
= nSubItem
;
4593 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4594 lvItem
.pszText
= szDispText
;
4595 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4596 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4597 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4598 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
4599 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4601 /* now check if we need to update the focus rectangle */
4602 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4604 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4605 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4606 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4607 OffsetRect(&rcSelect
, pos
.x
, pos
.y
);
4608 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
4609 OffsetRect(&rcStateIcon
, pos
.x
, pos
.y
);
4610 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
4611 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4612 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4613 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4615 /* fill in the custom draw structure */
4616 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4618 hOldFont
= GetCurrentObject(hdc
, OBJ_FONT
);
4619 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
4620 if (cdmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4621 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4622 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4623 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
4624 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4625 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
4626 if (nSubItem
== 0 && cdsubitemmode
== CDRF_NOTIFYITEMDRAW
)
4628 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4629 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4631 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4632 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4633 else if ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) == FALSE
)
4634 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4636 /* in full row select, subitems, will just use main item's colors */
4637 if (nSubItem
&& infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4638 nmlvcd
.clrTextBk
= CLR_NONE
;
4640 /* FIXME: temporary hack */
4641 rcSelect
.left
= rcLabel
.left
;
4643 /* draw the selection background, if we're drawing the main item */
4646 /* in icon mode, the label rect is really what we want to draw the
4648 if (infoPtr
->uView
== LV_VIEW_ICON
)
4651 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4653 /* we have to update left focus bound too if item isn't in leftmost column
4654 and reduce right box bound */
4655 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4659 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4661 INT Originx
= pos
.x
- LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
4662 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4663 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4665 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, index
)->rcHeader
.right
+ Originx
;
4666 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4670 rcSelect
.right
= rcBox
.right
;
4673 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
4674 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, NULL
, 0, NULL
);
4675 /* store new focus rectangle */
4676 if (infoPtr
->nFocusedItem
== nItem
) infoPtr
->rcFocus
= rcSelect
;
4680 if (infoPtr
->himlState
&& STATEIMAGEINDEX(lvItem
.state
) && (nSubItem
== 0))
4682 UINT uStateImage
= STATEIMAGEINDEX(lvItem
.state
);
4685 TRACE("uStateImage=%d\n", uStateImage
);
4686 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
,
4687 rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4692 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4693 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4697 TRACE("iImage=%d\n", lvItem
.iImage
);
4699 if (lvItem
.state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4700 style
= ILD_SELECTED
;
4704 ImageList_DrawEx(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
4705 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4706 lvItem
.state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4710 /* Don't bother painting item being edited */
4711 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
4713 /* figure out the text drawing flags */
4714 uFormat
= (infoPtr
->uView
== LV_VIEW_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4715 if (infoPtr
->uView
== LV_VIEW_ICON
)
4716 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4719 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4721 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
4722 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
4723 default: uFormat
|= DT_LEFT
;
4726 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
4728 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4729 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4731 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4733 /* for GRIDLINES reduce the bottom so the text formats correctly */
4734 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4737 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
4740 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4741 notify_postpaint(infoPtr
, &nmlvcd
);
4742 if (cdsubitemmode
& CDRF_NEWFONT
)
4743 SelectObject(hdc
, hOldFont
);
4749 * Draws listview items when in owner draw mode.
4752 * [I] infoPtr : valid pointer to the listview structure
4753 * [I] hdc : device context handle
4758 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4760 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4761 DWORD cditemmode
= CDRF_DODEFAULT
;
4762 NMLVCUSTOMDRAW nmlvcd
;
4763 POINT Origin
, Position
;
4769 ZeroMemory(&dis
, sizeof(dis
));
4771 /* Get scroll info once before loop */
4772 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4774 /* iterate through the invalidated rows */
4775 while(iterator_next(i
))
4777 item
.iItem
= i
->nItem
;
4779 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4780 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4781 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4783 dis
.CtlType
= ODT_LISTVIEW
;
4785 dis
.itemID
= item
.iItem
;
4786 dis
.itemAction
= ODA_DRAWENTIRE
;
4788 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4789 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4790 dis
.hwndItem
= infoPtr
->hwndSelf
;
4792 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4793 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4794 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4795 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4796 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4797 dis
.itemData
= item
.lParam
;
4799 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4802 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4803 * structure for the rest. of the paint cycle
4805 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4806 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4807 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4809 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4811 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4812 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4815 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4816 notify_postpaint(infoPtr
, &nmlvcd
);
4822 * Draws listview items when in report display mode.
4825 * [I] infoPtr : valid pointer to the listview structure
4826 * [I] hdc : device context handle
4827 * [I] cdmode : custom draw mode
4832 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4835 RECT rcClip
, rcItem
;
4836 POINT Origin
, Position
;
4843 /* figure out what to draw */
4844 rgntype
= GetClipBox(hdc
, &rcClip
);
4845 if (rgntype
== NULLREGION
) return;
4847 /* Get scroll info once before loop */
4848 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4850 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4852 /* narrow down the columns we need to paint */
4853 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4855 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4857 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4858 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4859 ranges_additem(colRanges
, index
);
4861 iterator_rangesitems(&j
, colRanges
);
4863 /* in full row select, we _have_ to draw the main item */
4864 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4867 /* iterate through the invalidated rows */
4868 while(iterator_next(i
))
4870 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4871 Position
.y
+= Origin
.y
;
4873 /* iterate through the invalidated columns */
4874 while(iterator_next(&j
))
4876 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4877 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4879 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4882 rcItem
.bottom
= infoPtr
->nItemHeight
;
4883 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4884 if (!RectVisible(hdc
, &rcItem
)) continue;
4887 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
4890 iterator_destroy(&j
);
4895 * Draws the gridlines if necessary when in report display mode.
4898 * [I] infoPtr : valid pointer to the listview structure
4899 * [I] hdc : device context handle
4904 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4910 RECT rcClip
, rcItem
= {0};
4918 /* figure out what to draw */
4919 rgntype
= GetClipBox(hdc
, &rcClip
);
4920 if (rgntype
== NULLREGION
) return;
4922 /* Get scroll info once before loop */
4923 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4925 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4927 /* narrow down the columns we need to paint */
4928 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4930 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4932 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4933 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4934 ranges_additem(colRanges
, index
);
4937 /* is right most vertical line visible? */
4938 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4940 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4941 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4942 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
4945 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
4947 hOldPen
= SelectObject ( hdc
, hPen
);
4949 /* draw the vertical lines for the columns */
4950 iterator_rangesitems(&j
, colRanges
);
4951 while(iterator_next(&j
))
4953 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4954 if (rcItem
.left
== 0) continue; /* skip leftmost column */
4955 rcItem
.left
+= Origin
.x
;
4956 rcItem
.right
+= Origin
.x
;
4957 rcItem
.top
= infoPtr
->rcList
.top
;
4958 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
4959 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
4960 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4961 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
4963 iterator_destroy(&j
);
4964 /* draw rightmost grid line if visible */
4967 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4968 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4969 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4971 rcItem
.right
+= Origin
.x
;
4973 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
4974 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
4977 /* draw the horizontal lines for the rows */
4978 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
4979 rcItem
.left
= infoPtr
->rcList
.left
;
4980 rcItem
.right
= infoPtr
->rcList
.right
;
4981 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
4983 rcItem
.bottom
= rcItem
.top
= y
;
4984 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
4985 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4986 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
4989 SelectObject( hdc
, hOldPen
);
4990 DeleteObject( hPen
);
4993 ranges_destroy(colRanges
);
4998 * Draws listview items when in list display mode.
5001 * [I] infoPtr : valid pointer to the listview structure
5002 * [I] hdc : device context handle
5003 * [I] cdmode : custom draw mode
5008 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5010 POINT Origin
, Position
;
5012 /* Get scroll info once before loop */
5013 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5015 while(iterator_prev(i
))
5017 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5018 Position
.x
+= Origin
.x
;
5019 Position
.y
+= Origin
.y
;
5021 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
5028 * Draws listview items.
5031 * [I] infoPtr : valid pointer to the listview structure
5032 * [I] hdc : device context handle
5033 * [I] prcErase : rect to be erased before refresh (may be NULL)
5038 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5040 COLORREF oldTextColor
= 0, oldBkColor
= 0, oldClrTextBk
, oldClrText
;
5041 NMLVCUSTOMDRAW nmlvcd
;
5048 HBITMAP hbmp
= NULL
;
5051 LISTVIEW_DUMP(infoPtr
);
5053 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5054 TRACE("double buffering\n");
5056 hdc
= CreateCompatibleDC(hdcOrig
);
5058 ERR("Failed to create DC for backbuffer\n");
5061 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5062 infoPtr
->rcList
.bottom
);
5064 ERR("Failed to create bitmap for backbuffer\n");
5069 SelectObject(hdc
, hbmp
);
5070 SelectObject(hdc
, infoPtr
->hFont
);
5072 if(GetClipBox(hdcOrig
, &rcClient
))
5073 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5075 /* Save dc values we're gonna trash while drawing
5076 * FIXME: Should be done in LISTVIEW_DrawItem() */
5077 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5078 oldBkMode
= GetBkMode(hdc
);
5079 oldBkColor
= GetBkColor(hdc
);
5080 oldTextColor
= GetTextColor(hdc
);
5083 infoPtr
->bIsDrawing
= TRUE
;
5086 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5087 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5088 /* If no erasing was done (usually because RedrawWindow was called
5089 * with RDW_INVALIDATE only) we need to copy the old contents into
5090 * the backbuffer before continuing. */
5091 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5092 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5093 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5094 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5097 /* FIXME: Shouldn't need to do this */
5098 oldClrTextBk
= infoPtr
->clrTextBk
;
5099 oldClrText
= infoPtr
->clrText
;
5101 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
5103 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5104 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5105 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5106 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5107 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
5109 /* Use these colors to draw the items */
5110 infoPtr
->clrTextBk
= nmlvcd
.clrTextBk
;
5111 infoPtr
->clrText
= nmlvcd
.clrText
;
5113 /* nothing to draw */
5114 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5116 /* figure out what we need to draw */
5117 iterator_visibleitems(&i
, infoPtr
, hdc
);
5118 range
= iterator_range(&i
);
5120 /* send cache hint notification */
5121 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5125 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5126 nmlv
.iFrom
= range
.lower
;
5127 nmlv
.iTo
= range
.upper
- 1;
5128 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5131 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5132 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5135 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5136 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5137 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5138 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5140 /* if we have a focus rect and it's visible, draw it */
5141 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5142 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5143 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5145 iterator_destroy(&i
);
5148 /* For LVS_EX_GRIDLINES go and draw lines */
5149 /* This includes the case where there were *no* items */
5150 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5151 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5153 /* Draw marquee rectangle if appropriate */
5154 if (infoPtr
->bMarqueeSelect
)
5155 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5157 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5158 notify_postpaint(infoPtr
, &nmlvcd
);
5160 infoPtr
->clrTextBk
= oldClrTextBk
;
5161 infoPtr
->clrText
= oldClrText
;
5164 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5165 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5166 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5167 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5172 SelectObject(hdc
, hOldFont
);
5173 SetBkMode(hdc
, oldBkMode
);
5174 SetBkColor(hdc
, oldBkColor
);
5175 SetTextColor(hdc
, oldTextColor
);
5178 infoPtr
->bIsDrawing
= FALSE
;
5184 * Calculates the approximate width and height of a given number of items.
5187 * [I] infoPtr : valid pointer to the listview structure
5188 * [I] nItemCount : number of items
5189 * [I] wWidth : width
5190 * [I] wHeight : height
5193 * Returns a DWORD. The width in the low word and the height in high word.
5195 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5196 WORD wWidth
, WORD wHeight
)
5198 DWORD dwViewRect
= 0;
5200 if (nItemCount
== -1)
5201 nItemCount
= infoPtr
->nItemCount
;
5203 if (infoPtr
->uView
== LV_VIEW_LIST
)
5205 INT nItemCountPerColumn
= 1;
5206 INT nColumnCount
= 0;
5208 if (wHeight
== 0xFFFF)
5210 /* use current height */
5211 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5214 if (wHeight
< infoPtr
->nItemHeight
)
5215 wHeight
= infoPtr
->nItemHeight
;
5219 if (infoPtr
->nItemHeight
> 0)
5221 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5222 if (nItemCountPerColumn
== 0)
5223 nItemCountPerColumn
= 1;
5225 if (nItemCount
% nItemCountPerColumn
!= 0)
5226 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5228 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5232 /* Microsoft padding magic */
5233 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5234 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5236 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5238 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5242 if (infoPtr
->nItemCount
> 0)
5244 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5245 wWidth
= rcBox
.right
- rcBox
.left
;
5246 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5250 /* use current height and width */
5251 if (wHeight
== 0xffff)
5252 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5253 if (wWidth
== 0xffff)
5254 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5257 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5259 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5265 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5266 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5268 if (wWidth
== 0xffff)
5269 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5271 if (wWidth
< nItemWidth
)
5272 wWidth
= nItemWidth
;
5274 cols
= wWidth
/ nItemWidth
;
5275 if (cols
> nItemCount
)
5282 rows
= nItemCount
/ cols
;
5283 if (nItemCount
% cols
)
5289 wHeight
= (nItemHeight
* rows
)+2;
5290 wWidth
= (nItemWidth
* cols
)+2;
5292 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5294 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5295 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5302 * Cancel edit label with saving item text.
5305 * [I] infoPtr : valid pointer to the listview structure
5308 * Always returns TRUE.
5310 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5312 if (infoPtr
->hwndEdit
)
5314 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5315 HWND edit
= infoPtr
->hwndEdit
;
5317 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5318 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5326 * Create a drag image list for the specified item.
5329 * [I] infoPtr : valid pointer to the listview structure
5330 * [I] iItem : index of item
5331 * [O] lppt : Upper-left corner of the image
5334 * Returns a handle to the image list if successful, NULL otherwise.
5336 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5342 HBITMAP hbmp
, hOldbmp
;
5343 HIMAGELIST dragList
= 0;
5344 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5346 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5349 rcItem
.left
= LVIR_BOUNDS
;
5350 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5353 lppt
->x
= rcItem
.left
;
5354 lppt
->y
= rcItem
.top
;
5356 size
.cx
= rcItem
.right
- rcItem
.left
;
5357 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5359 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5360 hdc
= CreateCompatibleDC(hdcOrig
);
5361 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5362 hOldbmp
= SelectObject(hdc
, hbmp
);
5364 rcItem
.left
= rcItem
.top
= 0;
5365 rcItem
.right
= size
.cx
;
5366 rcItem
.bottom
= size
.cy
;
5367 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5370 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
5372 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5373 SelectObject(hdc
, hOldbmp
);
5374 ImageList_Add(dragList
, hbmp
, 0);
5377 SelectObject(hdc
, hOldbmp
);
5381 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5383 TRACE("ret=%p\n", dragList
);
5391 * Removes all listview items and subitems.
5394 * [I] infoPtr : valid pointer to the listview structure
5400 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5403 HDPA hdpaSubItems
= NULL
;
5412 /* we do it directly, to avoid notifications */
5413 ranges_clear(infoPtr
->selectionRanges
);
5414 infoPtr
->nSelectionMark
= -1;
5415 infoPtr
->nFocusedItem
= -1;
5416 SetRectEmpty(&infoPtr
->rcFocus
);
5417 /* But we are supposed to leave nHotItem as is! */
5420 /* send LVN_DELETEALLITEMS notification */
5421 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
5423 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5425 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5427 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5429 /* send LVN_DELETEITEM notification, if not suppressed
5430 and if it is not a virtual listview */
5431 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
5432 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5433 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5434 /* free id struct */
5435 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5436 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5437 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5439 /* both item and subitem start with ITEMHDR header */
5440 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5442 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5443 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5446 DPA_Destroy(hdpaSubItems
);
5447 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5449 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5450 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5451 infoPtr
->nItemCount
--;
5456 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5457 LISTVIEW_UpdateScroll(infoPtr
);
5459 LISTVIEW_InvalidateList(infoPtr
);
5466 * Scrolls, and updates the columns, when a column is changing width.
5469 * [I] infoPtr : valid pointer to the listview structure
5470 * [I] nColumn : column to scroll
5471 * [I] dx : amount of scroll, in pixels
5476 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5478 COLUMN_INFO
*lpColumnInfo
;
5484 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5485 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5486 rcCol
= lpColumnInfo
->rcHeader
;
5487 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5488 rcCol
.left
= rcCol
.right
;
5490 /* adjust the other columns */
5491 hdi
.mask
= HDI_ORDER
;
5492 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5494 INT nOrder
= hdi
.iOrder
;
5495 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5497 hdi
.mask
= HDI_ORDER
;
5498 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5499 if (hdi
.iOrder
>= nOrder
) {
5500 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5501 lpColumnInfo
->rcHeader
.left
+= dx
;
5502 lpColumnInfo
->rcHeader
.right
+= dx
;
5507 /* do not update screen if not in report mode */
5508 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5510 /* Need to reset the item width when inserting a new column */
5511 infoPtr
->nItemWidth
+= dx
;
5513 LISTVIEW_UpdateScroll(infoPtr
);
5514 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5516 /* scroll to cover the deleted column, and invalidate for redraw */
5517 rcOld
= infoPtr
->rcList
;
5518 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5519 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5524 * Removes a column from the listview control.
5527 * [I] infoPtr : valid pointer to the listview structure
5528 * [I] nColumn : column index
5534 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5538 TRACE("nColumn=%d\n", nColumn
);
5540 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5541 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5543 /* While the MSDN specifically says that column zero should not be deleted,
5544 what actually happens is that the column itself is deleted but no items or subitems
5548 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5550 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5553 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5554 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5556 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5558 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5560 INT nItem
, nSubItem
, i
;
5562 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5564 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5567 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5569 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5570 if (lpSubItem
->iSubItem
== nColumn
)
5573 lpDelItem
= lpSubItem
;
5575 else if (lpSubItem
->iSubItem
> nColumn
)
5577 lpSubItem
->iSubItem
--;
5581 /* if we found our subitem, zap it */
5585 if (is_text(lpDelItem
->hdr
.pszText
))
5586 Free(lpDelItem
->hdr
.pszText
);
5591 /* free dpa memory */
5592 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5597 /* update the other column info */
5598 LISTVIEW_UpdateItemSize(infoPtr
);
5599 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5600 LISTVIEW_InvalidateList(infoPtr
);
5602 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5609 * Invalidates the listview after an item's insertion or deletion.
5612 * [I] infoPtr : valid pointer to the listview structure
5613 * [I] nItem : item index
5614 * [I] dir : -1 if deleting, 1 if inserting
5619 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5621 INT nPerCol
, nItemCol
, nItemRow
;
5625 /* if we don't refresh, what's the point of scrolling? */
5626 if (!is_redrawing(infoPtr
)) return;
5628 assert (abs(dir
) == 1);
5630 /* arrange icons if autoarrange is on */
5631 if (is_autoarrange(infoPtr
))
5633 BOOL arrange
= TRUE
;
5634 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5635 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5636 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5639 /* scrollbars need updating */
5640 LISTVIEW_UpdateScroll(infoPtr
);
5642 /* figure out the item's position */
5643 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5644 nPerCol
= infoPtr
->nItemCount
+ 1;
5645 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5646 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5647 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5650 nItemCol
= nItem
/ nPerCol
;
5651 nItemRow
= nItem
% nPerCol
;
5652 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5654 /* move the items below up a slot */
5655 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5656 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5657 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5658 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5659 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5660 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5661 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5663 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5664 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5667 /* report has only that column, so we're done */
5668 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5670 /* now for LISTs, we have to deal with the columns to the right */
5671 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5673 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5674 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5675 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5676 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5677 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5682 * Removes an item from the listview control.
5685 * [I] infoPtr : valid pointer to the listview structure
5686 * [I] nItem : item index
5692 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5695 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5696 INT focus
= infoPtr
->nFocusedItem
;
5698 TRACE("(nItem=%d)\n", nItem
);
5700 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5702 /* remove selection, and focus */
5704 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5705 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5707 /* send LVN_DELETEITEM notification. */
5708 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5710 /* we need to do this here, because we'll be deleting stuff */
5712 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5714 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5722 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5723 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5725 /* free id struct */
5726 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5727 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5728 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5730 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5732 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5733 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5736 DPA_Destroy(hdpaSubItems
);
5741 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5742 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5745 infoPtr
->nItemCount
--;
5746 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5747 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5749 /* now is the invalidation fun */
5751 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5758 * Callback implementation for editlabel control
5761 * [I] infoPtr : valid pointer to the listview structure
5762 * [I] storeText : store edit box text as item text
5763 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5769 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5771 HWND hwndSelf
= infoPtr
->hwndSelf
;
5772 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5773 NMLVDISPINFOW dispInfo
;
5774 INT editedItem
= infoPtr
->nEditLabelItem
;
5776 WCHAR
*pszText
= NULL
;
5781 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5785 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5787 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5788 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5793 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5795 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5796 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5797 dispInfo
.item
.iItem
= editedItem
;
5798 dispInfo
.item
.iSubItem
= 0;
5799 dispInfo
.item
.stateMask
= ~0;
5800 dispInfo
.item
.pszText
= szDispText
;
5801 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5802 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5809 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5812 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5813 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5814 textfreeT(tmp
, FALSE
);
5817 /* add the text from the edit in */
5818 dispInfo
.item
.mask
|= LVIF_TEXT
;
5819 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5820 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5822 /* Do we need to update the Item Text */
5823 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5825 infoPtr
->nEditLabelItem
= -1;
5826 infoPtr
->hwndEdit
= 0;
5828 if (!res
) goto cleanup
;
5830 if (!IsWindow(hwndSelf
))
5835 if (!pszText
) return TRUE
;
5842 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5844 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5845 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5846 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5848 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5854 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5855 dispInfo
.item
.mask
= LVIF_TEXT
;
5856 dispInfo
.item
.iItem
= editedItem
;
5857 dispInfo
.item
.iSubItem
= 0;
5858 dispInfo
.item
.pszText
= pszText
;
5859 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5860 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5870 * Subclassed edit control windproc function
5873 * [I] hwnd : the edit window handle
5874 * [I] uMsg : the message that is to be processed
5875 * [I] wParam : first message parameter
5876 * [I] lParam : second message parameter
5877 * [I] isW : TRUE if input is Unicode
5882 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5884 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5887 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5888 hwnd
, uMsg
, wParam
, lParam
, isW
);
5893 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5897 WNDPROC editProc
= infoPtr
->EditWndProc
;
5898 infoPtr
->EditWndProc
= 0;
5899 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5900 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5904 if (VK_ESCAPE
== (INT
)wParam
)
5909 else if (VK_RETURN
== (INT
)wParam
)
5913 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5917 if (infoPtr
->hwndEdit
)
5918 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
5920 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
5926 * Subclassed edit control Unicode windproc function
5929 * [I] hwnd : the edit window handle
5930 * [I] uMsg : the message that is to be processed
5931 * [I] wParam : first message parameter
5932 * [I] lParam : second message parameter
5936 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5938 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
5943 * Subclassed edit control ANSI windproc function
5946 * [I] hwnd : the edit window handle
5947 * [I] uMsg : the message that is to be processed
5948 * [I] wParam : first message parameter
5949 * [I] lParam : second message parameter
5953 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5955 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
5960 * Creates a subclassed edit control
5963 * [I] infoPtr : valid pointer to the listview structure
5964 * [I] text : initial text for the edit
5965 * [I] style : the window style
5966 * [I] isW : TRUE if input is Unicode
5970 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
5972 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
5973 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
5976 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
5978 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
5980 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5982 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5984 if (!hedit
) return 0;
5986 infoPtr
->EditWndProc
= (WNDPROC
)
5987 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
5988 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
5990 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
5991 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
5998 * Begin in place editing of specified list view item
6001 * [I] infoPtr : valid pointer to the listview structure
6002 * [I] nItem : item index
6003 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
6009 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
6011 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
6012 HWND hwndSelf
= infoPtr
->hwndSelf
;
6013 NMLVDISPINFOW dispInfo
;
6014 HFONT hOldFont
= NULL
;
6020 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6022 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6024 /* remove existing edit box */
6025 if (infoPtr
->hwndEdit
)
6027 SetFocus(infoPtr
->hwndSelf
);
6028 infoPtr
->hwndEdit
= 0;
6031 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6033 infoPtr
->nEditLabelItem
= nItem
;
6035 LISTVIEW_SetSelection(infoPtr
, nItem
);
6036 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6037 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6039 rect
.left
= LVIR_LABEL
;
6040 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6042 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6043 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6044 dispInfo
.item
.iItem
= nItem
;
6045 dispInfo
.item
.iSubItem
= 0;
6046 dispInfo
.item
.stateMask
= ~0;
6047 dispInfo
.item
.pszText
= disptextW
;
6048 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6049 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6051 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6052 if (!infoPtr
->hwndEdit
) return 0;
6054 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6056 if (!IsWindow(hwndSelf
))
6058 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6059 infoPtr
->hwndEdit
= 0;
6063 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6065 /* position and display edit box */
6066 hdc
= GetDC(infoPtr
->hwndSelf
);
6068 /* select the font to get appropriate metric dimensions */
6070 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6072 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6073 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6074 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6076 /* get string length in pixels */
6077 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6079 /* add extra spacing for the next character */
6080 GetTextMetricsW(hdc
, &tm
);
6081 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6084 SelectObject(hdc
, hOldFont
);
6086 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6088 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6091 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6092 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6093 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6094 SetFocus(infoPtr
->hwndEdit
);
6095 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6096 return infoPtr
->hwndEdit
;
6102 * Ensures the specified item is visible, scrolling into view if necessary.
6105 * [I] infoPtr : valid pointer to the listview structure
6106 * [I] nItem : item index
6107 * [I] bPartial : partially or entirely visible
6113 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6115 INT nScrollPosHeight
= 0;
6116 INT nScrollPosWidth
= 0;
6117 INT nHorzAdjust
= 0;
6118 INT nVertAdjust
= 0;
6121 RECT rcItem
, rcTemp
;
6123 rcItem
.left
= LVIR_BOUNDS
;
6124 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6126 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6128 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6130 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6131 if (infoPtr
->uView
== LV_VIEW_LIST
)
6132 nScrollPosWidth
= infoPtr
->nItemWidth
;
6133 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6134 nScrollPosWidth
= 1;
6136 if (rcItem
.left
< infoPtr
->rcList
.left
)
6139 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6144 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6148 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6150 /* scroll up/down, but not in LVS_LIST mode */
6151 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6152 nScrollPosHeight
= infoPtr
->nItemHeight
;
6153 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6154 nScrollPosHeight
= 1;
6156 if (rcItem
.top
< infoPtr
->rcList
.top
)
6159 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6164 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6168 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6170 if (nScrollPosWidth
)
6172 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6173 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6174 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6177 if (nScrollPosHeight
)
6179 INT diff
= nVertDiff
/ nScrollPosHeight
;
6180 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6181 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6189 * Searches for an item with specific characteristics.
6192 * [I] hwnd : window handle
6193 * [I] nStart : base item index
6194 * [I] lpFindInfo : item information to look for
6197 * SUCCESS : index of item
6200 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6201 const LVFINDINFOW
*lpFindInfo
)
6203 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6204 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6205 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6206 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6207 POINT Position
, Destination
;
6210 /* Search in virtual listviews should be done by application, not by
6211 listview control, so we just send LVN_ODFINDITEMW and return the result */
6212 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6216 nmlv
.iStart
= nStart
;
6217 nmlv
.lvfi
= *lpFindInfo
;
6218 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6221 if (!lpFindInfo
|| nItem
< 0) return -1;
6224 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6225 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6227 lvItem
.mask
|= LVIF_TEXT
;
6228 lvItem
.pszText
= szDispText
;
6229 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6232 if (lpFindInfo
->flags
& LVFI_WRAP
)
6235 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6236 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6241 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6242 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6243 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6244 switch(lpFindInfo
->vkDirection
)
6246 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6247 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6248 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6249 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6250 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6251 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6252 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6254 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6255 Destination
.x
= rcArea
.right
;
6256 Destination
.y
= rcArea
.bottom
;
6258 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6262 else Destination
.x
= Destination
.y
= 0;
6264 /* if LVFI_PARAM is specified, all other flags are ignored */
6265 if (lpFindInfo
->flags
& LVFI_PARAM
)
6267 lvItem
.mask
|= LVIF_PARAM
;
6269 lvItem
.mask
&= ~LVIF_TEXT
;
6273 for (; nItem
< nLast
; nItem
++)
6275 lvItem
.iItem
= nItem
;
6276 lvItem
.iSubItem
= 0;
6277 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6279 if (lvItem
.mask
& LVIF_PARAM
)
6281 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6287 if (lvItem
.mask
& LVIF_TEXT
)
6289 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6291 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6292 if (!p
|| p
!= lvItem
.pszText
) continue;
6296 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6300 if (!bNearest
) return nItem
;
6302 /* This is very inefficient. To do a good job here,
6303 * we need a sorted array of (x,y) item positions */
6304 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6306 /* compute the distance^2 to the destination */
6307 xdist
= Destination
.x
- Position
.x
;
6308 ydist
= Destination
.y
- Position
.y
;
6309 dist
= xdist
* xdist
+ ydist
* ydist
;
6311 /* remember the distance, and item if it's closer */
6315 nNearestItem
= nItem
;
6322 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6327 return nNearestItem
;
6332 * Searches for an item with specific characteristics.
6335 * [I] hwnd : window handle
6336 * [I] nStart : base item index
6337 * [I] lpFindInfo : item information to look for
6340 * SUCCESS : index of item
6343 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6344 const LVFINDINFOA
*lpFindInfo
)
6346 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6347 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6352 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6353 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6354 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6355 textfreeT(strW
, FALSE
);
6361 * Retrieves column attributes.
6364 * [I] infoPtr : valid pointer to the listview structure
6365 * [I] nColumn : column index
6366 * [IO] lpColumn : column information
6367 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6368 * otherwise it is in fact a LPLVCOLUMNA
6374 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6376 COLUMN_INFO
*lpColumnInfo
;
6379 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6380 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6382 /* initialize memory */
6383 ZeroMemory(&hdi
, sizeof(hdi
));
6385 if (lpColumn
->mask
& LVCF_TEXT
)
6387 hdi
.mask
|= HDI_TEXT
;
6388 hdi
.pszText
= lpColumn
->pszText
;
6389 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6392 if (lpColumn
->mask
& LVCF_IMAGE
)
6393 hdi
.mask
|= HDI_IMAGE
;
6395 if (lpColumn
->mask
& LVCF_ORDER
)
6396 hdi
.mask
|= HDI_ORDER
;
6398 if (lpColumn
->mask
& LVCF_SUBITEM
)
6399 hdi
.mask
|= HDI_LPARAM
;
6401 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6403 if (lpColumn
->mask
& LVCF_FMT
)
6404 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6406 if (lpColumn
->mask
& LVCF_WIDTH
)
6407 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6409 if (lpColumn
->mask
& LVCF_IMAGE
)
6410 lpColumn
->iImage
= hdi
.iImage
;
6412 if (lpColumn
->mask
& LVCF_ORDER
)
6413 lpColumn
->iOrder
= hdi
.iOrder
;
6415 if (lpColumn
->mask
& LVCF_SUBITEM
)
6416 lpColumn
->iSubItem
= hdi
.lParam
;
6418 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6419 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6425 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6427 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
6432 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6437 * Retrieves the column width.
6440 * [I] infoPtr : valid pointer to the listview structure
6441 * [I] int : column index
6444 * SUCCESS : column width
6447 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6449 INT nColumnWidth
= 0;
6452 TRACE("nColumn=%d\n", nColumn
);
6454 /* we have a 'column' in LIST and REPORT mode only */
6455 switch(infoPtr
->uView
)
6458 nColumnWidth
= infoPtr
->nItemWidth
;
6460 case LV_VIEW_DETAILS
:
6461 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6462 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6463 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6465 * TODO: should we do the same in LVM_GETCOLUMN?
6467 hdItem
.mask
= HDI_WIDTH
;
6468 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6470 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6473 nColumnWidth
= hdItem
.cxy
;
6477 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6478 return nColumnWidth
;
6483 * In list or report display mode, retrieves the number of items that can fit
6484 * vertically in the visible area. In icon or small icon display mode,
6485 * retrieves the total number of visible items.
6488 * [I] infoPtr : valid pointer to the listview structure
6491 * Number of fully visible items.
6493 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6495 switch (infoPtr
->uView
)
6498 case LV_VIEW_SMALLICON
:
6499 return infoPtr
->nItemCount
;
6500 case LV_VIEW_DETAILS
:
6501 return LISTVIEW_GetCountPerColumn(infoPtr
);
6503 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6511 * Retrieves an image list handle.
6514 * [I] infoPtr : valid pointer to the listview structure
6515 * [I] nImageList : image list identifier
6518 * SUCCESS : image list handle
6521 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6525 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6526 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6527 case LVSIL_STATE
: return infoPtr
->himlState
;
6528 case LVSIL_GROUPHEADER
:
6529 FIXME("LVSIL_GROUPHEADER not supported\n");
6532 WARN("got unknown imagelist index - %d\n", nImageList
);
6537 /* LISTVIEW_GetISearchString */
6541 * Retrieves item attributes.
6544 * [I] hwnd : window handle
6545 * [IO] lpLVItem : item info
6546 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6547 * if FALSE, then lpLVItem is a LPLVITEMA.
6550 * This is the internal 'GetItem' interface -- it tries to
6551 * be smart and avoid text copies, if possible, by modifying
6552 * lpLVItem->pszText to point to the text string. Please note
6553 * that this is not always possible (e.g. OWNERDATA), so on
6554 * entry you *must* supply valid values for pszText, and cchTextMax.
6555 * The only difference to the documented interface is that upon
6556 * return, you should use *only* the lpLVItem->pszText, rather than
6557 * the buffer pointer you provided on input. Most code already does
6558 * that, so it's not a problem.
6559 * For the two cases when the text must be copied (that is,
6560 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6566 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6568 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6569 NMLVDISPINFOW dispInfo
;
6575 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6577 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6580 if (lpLVItem
->mask
== 0) return TRUE
;
6581 TRACE("mask=%x\n", lpLVItem
->mask
);
6583 /* make a local copy */
6584 isubitem
= lpLVItem
->iSubItem
;
6586 /* a quick optimization if all we're asked is the focus state
6587 * these queries are worth optimising since they are common,
6588 * and can be answered in constant time, without the heavy accesses */
6589 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6590 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6592 lpLVItem
->state
= 0;
6593 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6594 lpLVItem
->state
|= LVIS_FOCUSED
;
6598 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6600 /* if the app stores all the data, handle it separately */
6601 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6603 dispInfo
.item
.state
= 0;
6605 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6606 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6607 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6609 UINT mask
= lpLVItem
->mask
;
6611 /* NOTE: copy only fields which we _know_ are initialized, some apps
6612 * depend on the uninitialized fields being 0 */
6613 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6614 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6615 dispInfo
.item
.iSubItem
= isubitem
;
6616 if (lpLVItem
->mask
& LVIF_TEXT
)
6618 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6620 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6623 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6624 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6627 if (lpLVItem
->mask
& LVIF_STATE
)
6628 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6629 /* could be zeroed on LVIF_NORECOMPUTE case */
6630 if (dispInfo
.item
.mask
)
6632 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6633 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6634 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6636 /* full size structure expected - _WIN32IE >= 0x560 */
6637 *lpLVItem
= dispInfo
.item
;
6639 else if (lpLVItem
->mask
& LVIF_INDENT
)
6641 /* indent member expected - _WIN32IE >= 0x300 */
6642 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6646 /* minimal structure expected */
6647 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6649 lpLVItem
->mask
= mask
;
6650 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6654 /* make sure lParam is zeroed out */
6655 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6657 /* callback marked pointer required here */
6658 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6659 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6661 /* we store only a little state, so if we're not asked, we're done */
6662 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6664 /* if focus is handled by us, report it */
6665 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6667 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6668 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6669 lpLVItem
->state
|= LVIS_FOCUSED
;
6672 /* and do the same for selection, if we handle it */
6673 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6675 lpLVItem
->state
&= ~LVIS_SELECTED
;
6676 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6677 lpLVItem
->state
|= LVIS_SELECTED
;
6683 /* find the item and subitem structures before we proceed */
6684 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6685 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6690 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6691 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6694 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6699 pItemHdr
= &lpItem
->hdr
;
6701 /* Do we need to query the state from the app? */
6702 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6704 dispInfo
.item
.mask
|= LVIF_STATE
;
6705 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6708 /* Do we need to enquire about the image? */
6709 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6710 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6712 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6713 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6716 /* Only items support indentation */
6717 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6720 dispInfo
.item
.mask
|= LVIF_INDENT
;
6721 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6724 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6725 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6726 !is_text(pItemHdr
->pszText
))
6728 dispInfo
.item
.mask
|= LVIF_TEXT
;
6729 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6730 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6731 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6732 *dispInfo
.item
.pszText
= '\0';
6735 /* If we don't have all the requested info, query the application */
6736 if (dispInfo
.item
.mask
)
6738 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6739 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6740 dispInfo
.item
.lParam
= lpItem
->lParam
;
6741 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6742 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6745 /* we should not store values for subitems */
6746 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6748 /* Now, handle the iImage field */
6749 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6751 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6752 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6753 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6755 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6757 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6758 lpLVItem
->iImage
= pItemHdr
->iImage
;
6760 lpLVItem
->iImage
= 0;
6763 /* The pszText field */
6764 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6766 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6767 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6769 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6771 else if (lpLVItem
->mask
& LVIF_TEXT
)
6773 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6774 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6775 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6778 /* Next is the lParam field */
6779 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6781 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6782 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6783 lpItem
->lParam
= dispInfo
.item
.lParam
;
6785 else if (lpLVItem
->mask
& LVIF_PARAM
)
6786 lpLVItem
->lParam
= lpItem
->lParam
;
6788 /* if this is a subitem, we're done */
6789 if (isubitem
) return TRUE
;
6791 /* ... the state field (this one is different due to uCallbackmask) */
6792 if (lpLVItem
->mask
& LVIF_STATE
)
6794 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6795 if (dispInfo
.item
.mask
& LVIF_STATE
)
6797 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6798 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6800 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6802 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6803 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6804 lpLVItem
->state
|= LVIS_FOCUSED
;
6806 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6808 lpLVItem
->state
&= ~LVIS_SELECTED
;
6809 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6810 lpLVItem
->state
|= LVIS_SELECTED
;
6814 /* and last, but not least, the indent field */
6815 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6817 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6818 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6819 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6821 else if (lpLVItem
->mask
& LVIF_INDENT
)
6823 lpLVItem
->iIndent
= lpItem
->iIndent
;
6831 * Retrieves item attributes.
6834 * [I] hwnd : window handle
6835 * [IO] lpLVItem : item info
6836 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6837 * if FALSE, then lpLVItem is a LPLVITEMA.
6840 * This is the external 'GetItem' interface -- it properly copies
6841 * the text in the provided buffer.
6847 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6852 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6855 pszText
= lpLVItem
->pszText
;
6856 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6857 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6859 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6860 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6862 pszText
= LPSTR_TEXTCALLBACKW
;
6864 lpLVItem
->pszText
= pszText
;
6872 * Retrieves the position (upper-left) of the listview control item.
6873 * Note that for LVS_ICON style, the upper-left is that of the icon
6874 * and not the bounding box.
6877 * [I] infoPtr : valid pointer to the listview structure
6878 * [I] nItem : item index
6879 * [O] lpptPosition : coordinate information
6885 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6889 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6891 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6893 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6894 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6896 if (infoPtr
->uView
== LV_VIEW_ICON
)
6898 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6899 lpptPosition
->y
+= ICON_TOP_PADDING
;
6901 lpptPosition
->x
+= Origin
.x
;
6902 lpptPosition
->y
+= Origin
.y
;
6904 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6911 * Retrieves the bounding rectangle for a listview control item.
6914 * [I] infoPtr : valid pointer to the listview structure
6915 * [I] nItem : item index
6916 * [IO] lprc : bounding rectangle coordinates
6917 * lprc->left specifies the portion of the item for which the bounding
6918 * rectangle will be retrieved.
6920 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6921 * including the icon and label.
6924 * * Experiment shows that native control returns:
6925 * * width = min (48, length of text line)
6926 * * .left = position.x - (width - iconsize.cx)/2
6927 * * .right = .left + width
6928 * * height = #lines of text * ntmHeight + icon height + 8
6929 * * .top = position.y - 2
6930 * * .bottom = .top + height
6931 * * separation between items .y = itemSpacing.cy - height
6932 * * .x = itemSpacing.cx - width
6933 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
6936 * * Experiment shows that native control returns:
6937 * * width = iconSize.cx + 16
6938 * * .left = position.x - (width - iconsize.cx)/2
6939 * * .right = .left + width
6940 * * height = iconSize.cy + 4
6941 * * .top = position.y - 2
6942 * * .bottom = .top + height
6943 * * separation between items .y = itemSpacing.cy - height
6944 * * .x = itemSpacing.cx - width
6945 * LVIR_LABEL Returns the bounding rectangle of the item text.
6948 * * Experiment shows that native control returns:
6949 * * width = text length
6950 * * .left = position.x - width/2
6951 * * .right = .left + width
6952 * * height = ntmH * linecount + 2
6953 * * .top = position.y + iconSize.cy + 6
6954 * * .bottom = .top + height
6955 * * separation between items .y = itemSpacing.cy - height
6956 * * .x = itemSpacing.cx - width
6957 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
6958 * rectangles, but excludes columns in report view.
6965 * Note that the bounding rectangle of the label in the LVS_ICON view depends
6966 * upon whether the window has the focus currently and on whether the item
6967 * is the one with the focus. Ensure that the control's record of which
6968 * item has the focus agrees with the items' records.
6970 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6972 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6973 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
6974 POINT Position
, Origin
;
6978 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
6980 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6982 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6983 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6985 /* Be smart and try to figure out the minimum we have to do */
6986 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
6987 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
6988 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
6989 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
6990 oversizedBox
= TRUE
;
6992 /* get what we need from the item before hand, so we make
6993 * only one request. This can speed up things, if data
6994 * is stored on the app side */
6996 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6997 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
6998 lvItem
.iItem
= nItem
;
6999 lvItem
.iSubItem
= 0;
7000 lvItem
.pszText
= szDispText
;
7001 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7002 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
7003 /* we got the state already up, simulate it here, to avoid a reget */
7004 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
7006 lvItem
.mask
|= LVIF_STATE
;
7007 lvItem
.stateMask
= LVIS_FOCUSED
;
7008 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
7011 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
7012 lprc
->left
= LVIR_BOUNDS
;
7018 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7022 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7026 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7029 case LVIR_SELECTBOUNDS
:
7030 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7034 WARN("Unknown value: %d\n", lprc
->left
);
7038 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7040 if (mode
!= LVIR_BOUNDS
)
7041 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7042 Position
.y
+ Origin
.y
);
7044 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7047 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7049 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7056 * Retrieves the spacing between listview control items.
7059 * [I] infoPtr : valid pointer to the listview structure
7060 * [IO] lprc : rectangle to receive the output
7061 * on input, lprc->top = nSubItem
7062 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7064 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7065 * not only those of the first column.
7071 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7073 RECT rect
= { 0, 0, 0, 0 };
7077 if (!lprc
) return FALSE
;
7079 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7080 /* Subitem of '0' means item itself, and this works for all control view modes */
7082 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7084 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7086 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7087 /* this works for any item index, no matter if it exists or not */
7088 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7090 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7093 rect
.bottom
= infoPtr
->nItemHeight
;
7097 /* Native implementation is broken for this case and garbage is left for left and right fields,
7098 we zero them to get predictable output */
7099 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7100 lprc
->bottom
= infoPtr
->nItemHeight
;
7101 OffsetRect(lprc
, origin
.x
, y
);
7102 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7110 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7111 if (infoPtr
->himlSmall
)
7112 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7114 rect
.right
= rect
.left
;
7116 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7124 ERR("Unknown bounds=%d\n", lprc
->left
);
7128 OffsetRect(&rect
, origin
.x
, y
);
7130 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7137 * Retrieves the spacing between listview control items.
7140 * [I] infoPtr : valid pointer to the listview structure
7141 * [I] bSmall : flag for small or large icon
7144 * Horizontal + vertical spacing
7146 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7152 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7156 if (infoPtr
->uView
== LV_VIEW_ICON
)
7157 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7159 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7166 * Retrieves the state of a listview control item.
7169 * [I] infoPtr : valid pointer to the listview structure
7170 * [I] nItem : item index
7171 * [I] uMask : state mask
7174 * State specified by the mask.
7176 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7180 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7182 lvItem
.iItem
= nItem
;
7183 lvItem
.iSubItem
= 0;
7184 lvItem
.mask
= LVIF_STATE
;
7185 lvItem
.stateMask
= uMask
;
7186 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7188 return lvItem
.state
& uMask
;
7193 * Retrieves the text of a listview control item or subitem.
7196 * [I] hwnd : window handle
7197 * [I] nItem : item index
7198 * [IO] lpLVItem : item information
7199 * [I] isW : TRUE if lpLVItem is Unicode
7202 * SUCCESS : string length
7205 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7207 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7209 lpLVItem
->mask
= LVIF_TEXT
;
7210 lpLVItem
->iItem
= nItem
;
7211 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7213 return textlenT(lpLVItem
->pszText
, isW
);
7218 * Searches for an item based on properties + relationships.
7221 * [I] infoPtr : valid pointer to the listview structure
7222 * [I] nItem : item index
7223 * [I] uFlags : relationship flag
7226 * SUCCESS : item index
7229 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7232 LVFINDINFOW lvFindInfo
;
7233 INT nCountPerColumn
;
7237 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7238 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7240 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7242 if (uFlags
& LVNI_CUT
)
7245 if (uFlags
& LVNI_DROPHILITED
)
7246 uMask
|= LVIS_DROPHILITED
;
7248 if (uFlags
& LVNI_FOCUSED
)
7249 uMask
|= LVIS_FOCUSED
;
7251 if (uFlags
& LVNI_SELECTED
)
7252 uMask
|= LVIS_SELECTED
;
7254 /* if we're asked for the focused item, that's only one,
7255 * so it's worth optimizing */
7256 if (uFlags
& LVNI_FOCUSED
)
7258 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7259 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7262 if (uFlags
& LVNI_ABOVE
)
7264 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7269 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7275 /* Special case for autoarrange - move 'til the top of a list */
7276 if (is_autoarrange(infoPtr
))
7278 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7279 while (nItem
- nCountPerRow
>= 0)
7281 nItem
-= nCountPerRow
;
7282 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7287 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7288 lvFindInfo
.vkDirection
= VK_UP
;
7289 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7290 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7292 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7297 else if (uFlags
& LVNI_BELOW
)
7299 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7301 while (nItem
< infoPtr
->nItemCount
)
7304 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7310 /* Special case for autoarrange - move 'til the bottom of a list */
7311 if (is_autoarrange(infoPtr
))
7313 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7314 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7316 nItem
+= nCountPerRow
;
7317 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7322 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7323 lvFindInfo
.vkDirection
= VK_DOWN
;
7324 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7325 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7327 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7332 else if (uFlags
& LVNI_TOLEFT
)
7334 if (infoPtr
->uView
== LV_VIEW_LIST
)
7336 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7337 while (nItem
- nCountPerColumn
>= 0)
7339 nItem
-= nCountPerColumn
;
7340 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7344 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7346 /* Special case for autoarrange - move 'til the beginning of a row */
7347 if (is_autoarrange(infoPtr
))
7349 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7350 while (nItem
% nCountPerRow
> 0)
7353 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7358 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7359 lvFindInfo
.vkDirection
= VK_LEFT
;
7360 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7361 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7363 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7368 else if (uFlags
& LVNI_TORIGHT
)
7370 if (infoPtr
->uView
== LV_VIEW_LIST
)
7372 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7373 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7375 nItem
+= nCountPerColumn
;
7376 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7380 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7382 /* Special case for autoarrange - move 'til the end of a row */
7383 if (is_autoarrange(infoPtr
))
7385 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7386 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7389 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7394 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7395 lvFindInfo
.vkDirection
= VK_RIGHT
;
7396 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7397 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7399 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7408 /* search by index */
7409 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7411 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7419 /* LISTVIEW_GetNumberOfWorkAreas */
7423 * Retrieves the origin coordinates when in icon or small icon display mode.
7426 * [I] infoPtr : valid pointer to the listview structure
7427 * [O] lpptOrigin : coordinate information
7432 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7434 INT nHorzPos
= 0, nVertPos
= 0;
7435 SCROLLINFO scrollInfo
;
7437 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7438 scrollInfo
.fMask
= SIF_POS
;
7440 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7441 nHorzPos
= scrollInfo
.nPos
;
7442 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7443 nVertPos
= scrollInfo
.nPos
;
7445 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7447 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7448 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7449 if (infoPtr
->uView
== LV_VIEW_LIST
)
7450 nHorzPos
*= infoPtr
->nItemWidth
;
7451 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7452 nVertPos
*= infoPtr
->nItemHeight
;
7454 lpptOrigin
->x
-= nHorzPos
;
7455 lpptOrigin
->y
-= nVertPos
;
7457 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7462 * Retrieves the width of a string.
7465 * [I] hwnd : window handle
7466 * [I] lpszText : text string to process
7467 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7470 * SUCCESS : string width (in pixels)
7473 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7478 if (is_text(lpszText
))
7480 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7481 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7482 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7485 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7487 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7488 SelectObject(hdc
, hOldFont
);
7489 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7491 return stringSize
.cx
;
7496 * Determines which listview item is located at the specified position.
7499 * [I] infoPtr : valid pointer to the listview structure
7500 * [IO] lpht : hit test information
7501 * [I] subitem : fill out iSubItem.
7502 * [I] select : return the index only if the hit selects the item
7505 * (mm 20001022): We must not allow iSubItem to be touched, for
7506 * an app might pass only a structure with space up to iItem!
7507 * (MS Office 97 does that for instance in the file open dialog)
7510 * SUCCESS : item index
7513 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7515 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7516 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7517 POINT Origin
, Position
, opt
;
7522 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7526 if (subitem
) lpht
->iSubItem
= 0;
7528 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7530 /* set whole list relation flags */
7531 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7533 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7534 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7535 lpht
->flags
|= LVHT_TOLEFT
;
7537 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7538 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7542 if (infoPtr
->rcList
.bottom
< opt
.y
)
7543 lpht
->flags
|= LVHT_BELOW
;
7547 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7548 lpht
->flags
|= LVHT_TOLEFT
;
7549 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7550 lpht
->flags
|= LVHT_TORIGHT
;
7552 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7553 lpht
->flags
|= LVHT_ABOVE
;
7554 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7555 lpht
->flags
|= LVHT_BELOW
;
7558 /* even if item is invalid try to find subitem */
7559 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7564 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7566 lpht
->iSubItem
= -1;
7567 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7569 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7571 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7577 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7579 /* if we're outside horizontal columns bounds there's nothing to test further */
7580 if (lpht
->iSubItem
== -1)
7583 lpht
->flags
= LVHT_NOWHERE
;
7588 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7589 if (lpht
->flags
) return -1;
7591 lpht
->flags
|= LVHT_NOWHERE
;
7593 /* first deal with the large items */
7594 rcSearch
.left
= lpht
->pt
.x
;
7595 rcSearch
.top
= lpht
->pt
.y
;
7596 rcSearch
.right
= rcSearch
.left
+ 1;
7597 rcSearch
.bottom
= rcSearch
.top
+ 1;
7599 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7600 iterator_next(&i
); /* go to first item in the sequence */
7602 iterator_destroy(&i
);
7604 TRACE("lpht->iItem=%d\n", iItem
);
7605 if (iItem
== -1) return -1;
7607 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7608 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7609 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7610 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7611 lvItem
.iItem
= iItem
;
7612 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7613 lvItem
.pszText
= szDispText
;
7614 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7615 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7616 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7618 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7619 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7620 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7622 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7623 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7625 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7627 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7630 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7631 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7635 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7636 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7638 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7639 if (!PtInRect(&rcBounds
, opt
)) return -1;
7641 if (PtInRect(&rcIcon
, opt
))
7642 lpht
->flags
|= LVHT_ONITEMICON
;
7643 else if (PtInRect(&rcLabel
, opt
))
7644 lpht
->flags
|= LVHT_ONITEMLABEL
;
7645 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7646 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7647 /* special case for LVS_EX_FULLROWSELECT */
7648 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
7649 !(lpht
->flags
& LVHT_ONITEM
))
7651 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7653 if (lpht
->flags
& LVHT_ONITEM
)
7654 lpht
->flags
&= ~LVHT_NOWHERE
;
7655 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7657 if (select
&& !(infoPtr
->uView
== LV_VIEW_DETAILS
&&
7658 ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) ||
7659 (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
))))
7661 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7663 /* get main item bounds */
7664 lvItem
.iSubItem
= 0;
7665 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7666 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7667 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7669 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7671 return lpht
->iItem
= iItem
;
7676 * Inserts a new item in the listview control.
7679 * [I] infoPtr : valid pointer to the listview structure
7680 * [I] lpLVItem : item information
7681 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7684 * SUCCESS : new item index
7687 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7694 BOOL is_sorted
, has_changed
;
7696 HWND hwndSelf
= infoPtr
->hwndSelf
;
7698 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7700 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7702 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7703 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7705 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7707 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7709 /* insert item in listview control data structure */
7710 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7711 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7713 /* link with id struct */
7714 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7716 lpID
->item
= hdpaSubItems
;
7717 lpID
->id
= get_next_itemid(infoPtr
);
7718 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7720 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7721 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7723 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7725 /* calculate new item index */
7732 while (i
< infoPtr
->nItemCount
)
7734 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7735 item_s
= DPA_GetPtr(hItem
, 0);
7737 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7738 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7740 if (cmpv
>= 0) break;
7746 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7748 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7749 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7750 if (nItem
== -1) goto fail
;
7751 infoPtr
->nItemCount
++;
7753 /* shift indices first so they don't get tangled */
7754 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7756 /* set the item attributes */
7757 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7759 /* full size structure expected - _WIN32IE >= 0x560 */
7762 else if (lpLVItem
->mask
& LVIF_INDENT
)
7764 /* indent member expected - _WIN32IE >= 0x300 */
7765 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7769 /* minimal structure expected */
7770 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7773 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7775 item
.mask
|= LVIF_STATE
;
7776 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7777 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7778 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7781 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7783 /* make room for the position, if we are in the right mode */
7784 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7786 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7788 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7790 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7795 /* send LVN_INSERTITEM notification */
7796 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7798 nmlv
.lParam
= lpItem
->lParam
;
7799 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7800 if (!IsWindow(hwndSelf
))
7803 /* align items (set position of each item) */
7804 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7808 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7809 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7811 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7813 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7816 /* now is the invalidation fun */
7817 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7821 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7822 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7823 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7824 infoPtr
->nItemCount
--;
7826 DPA_DeletePtr(hdpaSubItems
, 0);
7827 DPA_Destroy (hdpaSubItems
);
7834 * Checks item visibility.
7837 * [I] infoPtr : valid pointer to the listview structure
7838 * [I] nFirst : item index to check for
7841 * Item visible : TRUE
7842 * Item invisible or failure : FALSE
7844 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7846 POINT Origin
, Position
;
7851 TRACE("nItem=%d\n", nItem
);
7853 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7855 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7856 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7857 rcItem
.left
= Position
.x
+ Origin
.x
;
7858 rcItem
.top
= Position
.y
+ Origin
.y
;
7859 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7860 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7862 hdc
= GetDC(infoPtr
->hwndSelf
);
7863 if (!hdc
) return FALSE
;
7864 ret
= RectVisible(hdc
, &rcItem
);
7865 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7872 * Redraws a range of items.
7875 * [I] infoPtr : valid pointer to the listview structure
7876 * [I] nFirst : first item
7877 * [I] nLast : last item
7883 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7887 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7888 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7891 for (i
= nFirst
; i
<= nLast
; i
++)
7892 LISTVIEW_InvalidateItem(infoPtr
, i
);
7899 * Scroll the content of a listview.
7902 * [I] infoPtr : valid pointer to the listview structure
7903 * [I] dx : horizontal scroll amount in pixels
7904 * [I] dy : vertical scroll amount in pixels
7911 * If the control is in report view (LV_VIEW_DETAILS) the control can
7912 * be scrolled only in line increments. "dy" will be rounded to the
7913 * nearest number of pixels that are a whole line. Ex: if line height
7914 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7915 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7917 * For: (per experimentation with native control and CSpy ListView)
7918 * LV_VIEW_ICON scrolling in any direction is allowed
7919 * LV_VIEW_SMALLICON scrolling in any direction is allowed
7920 * LV_VIEW_LIST dx=1 = 1 column (horizontal only)
7921 * but will only scroll 1 column per message
7922 * no matter what the value.
7923 * dy must be 0 or FALSE returned.
7924 * LV_VIEW_DETAILS dx=1 = 1 pixel
7928 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7930 switch(infoPtr
->uView
) {
7931 case LV_VIEW_DETAILS
:
7932 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7933 dy
/= infoPtr
->nItemHeight
;
7936 if (dy
!= 0) return FALSE
;
7942 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
7943 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
7950 * Sets the background color.
7953 * [I] infoPtr : valid pointer to the listview structure
7954 * [I] color : background color
7960 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
7962 TRACE("(color=%x)\n", color
);
7964 if(infoPtr
->clrBk
!= color
) {
7965 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7966 infoPtr
->clrBk
= color
;
7967 if (color
== CLR_NONE
)
7968 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
7971 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
7972 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
7979 /* LISTVIEW_SetBkImage */
7981 /*** Helper for {Insert,Set}ColumnT *only* */
7982 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
7983 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7985 if (lpColumn
->mask
& LVCF_FMT
)
7987 /* format member is valid */
7988 lphdi
->mask
|= HDI_FORMAT
;
7990 /* set text alignment (leftmost column must be left-aligned) */
7991 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
7992 lphdi
->fmt
|= HDF_LEFT
;
7993 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
7994 lphdi
->fmt
|= HDF_RIGHT
;
7995 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
7996 lphdi
->fmt
|= HDF_CENTER
;
7998 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
7999 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
8001 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
8003 lphdi
->fmt
|= HDF_IMAGE
;
8004 lphdi
->iImage
= I_IMAGECALLBACK
;
8007 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
8008 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
8011 if (lpColumn
->mask
& LVCF_WIDTH
)
8013 lphdi
->mask
|= HDI_WIDTH
;
8014 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
8016 /* make it fill the remainder of the controls width */
8020 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
8022 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
8023 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8026 /* retrieve the layout of the header */
8027 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8028 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8030 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8033 lphdi
->cxy
= lpColumn
->cx
;
8036 if (lpColumn
->mask
& LVCF_TEXT
)
8038 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8039 lphdi
->fmt
|= HDF_STRING
;
8040 lphdi
->pszText
= lpColumn
->pszText
;
8041 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8044 if (lpColumn
->mask
& LVCF_IMAGE
)
8046 lphdi
->mask
|= HDI_IMAGE
;
8047 lphdi
->iImage
= lpColumn
->iImage
;
8050 if (lpColumn
->mask
& LVCF_ORDER
)
8052 lphdi
->mask
|= HDI_ORDER
;
8053 lphdi
->iOrder
= lpColumn
->iOrder
;
8060 * Inserts a new column.
8063 * [I] infoPtr : valid pointer to the listview structure
8064 * [I] nColumn : column index
8065 * [I] lpColumn : column information
8066 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8069 * SUCCESS : new column index
8072 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8073 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8075 COLUMN_INFO
*lpColumnInfo
;
8079 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8081 if (!lpColumn
|| nColumn
< 0) return -1;
8082 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8084 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8085 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8088 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8089 * (can be seen in SPY) otherwise column never gets added.
8091 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8092 hdi
.mask
|= HDI_WIDTH
;
8097 * when the iSubItem is available Windows copies it to the header lParam. It seems
8098 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8100 if (lpColumn
->mask
& LVCF_SUBITEM
)
8102 hdi
.mask
|= HDI_LPARAM
;
8103 hdi
.lParam
= lpColumn
->iSubItem
;
8106 /* create header if not present */
8107 LISTVIEW_CreateHeader(infoPtr
);
8108 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8109 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8111 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8114 /* insert item in header control */
8115 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8116 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8117 nColumn
, (LPARAM
)&hdi
);
8118 if (nNewColumn
== -1) return -1;
8119 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8121 /* create our own column info */
8122 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8123 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8125 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8126 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8127 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8130 /* now we have to actually adjust the data */
8131 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8133 SUBITEM_INFO
*lpSubItem
;
8139 item
.iSubItem
= nNewColumn
;
8140 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8141 item
.iImage
= I_IMAGECALLBACK
;
8142 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8144 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8146 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8147 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8149 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8150 if (lpSubItem
->iSubItem
>= nNewColumn
)
8151 lpSubItem
->iSubItem
++;
8154 /* add new subitem for each item */
8156 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8160 /* make space for the new column */
8161 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8162 LISTVIEW_UpdateItemSize(infoPtr
);
8167 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8170 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8178 * Sets the attributes of a header item.
8181 * [I] infoPtr : valid pointer to the listview structure
8182 * [I] nColumn : column index
8183 * [I] lpColumn : column attributes
8184 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8190 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8191 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8193 HDITEMW hdi
, hdiget
;
8196 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8198 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8200 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8201 if (lpColumn
->mask
& LVCF_FMT
)
8203 hdi
.mask
|= HDI_FORMAT
;
8204 hdiget
.mask
= HDI_FORMAT
;
8205 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8206 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8208 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8210 /* set header item attributes */
8211 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8212 if (!bResult
) return FALSE
;
8214 if (lpColumn
->mask
& LVCF_FMT
)
8216 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8217 INT oldFmt
= lpColumnInfo
->fmt
;
8219 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8220 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8222 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8226 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8227 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8234 * Sets the column order array
8237 * [I] infoPtr : valid pointer to the listview structure
8238 * [I] iCount : number of elements in column order array
8239 * [I] lpiArray : pointer to column order array
8245 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8247 TRACE("iCount %d lpiArray %p\n", iCount
, lpiArray
);
8249 if (!lpiArray
|| !IsWindow(infoPtr
->hwndHeader
)) return FALSE
;
8251 infoPtr
->colRectsDirty
= TRUE
;
8253 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8258 * Sets the width of a column
8261 * [I] infoPtr : valid pointer to the listview structure
8262 * [I] nColumn : column index
8263 * [I] cx : column width
8269 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8271 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8275 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
8277 /* set column width only if in report or list mode */
8278 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8280 /* take care of invalid cx values */
8281 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
8282 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
8284 /* resize all columns if in LV_VIEW_LIST mode */
8285 if(infoPtr
->uView
== LV_VIEW_LIST
)
8287 infoPtr
->nItemWidth
= cx
;
8288 LISTVIEW_InvalidateList(infoPtr
);
8292 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8294 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8299 lvItem
.mask
= LVIF_TEXT
;
8301 lvItem
.iSubItem
= nColumn
;
8302 lvItem
.pszText
= szDispText
;
8303 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8304 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8306 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8307 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8308 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8310 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8311 max_cx
+= infoPtr
->iconSize
.cx
;
8312 max_cx
+= TRAILING_LABEL_PADDING
;
8315 /* autosize based on listview items width */
8316 if(cx
== LVSCW_AUTOSIZE
)
8318 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8320 /* if iCol is the last column make it fill the remainder of the controls width */
8321 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8326 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8327 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8329 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8333 /* Despite what the MS docs say, if this is not the last
8334 column, then MS resizes the column to the width of the
8335 largest text string in the column, including headers
8336 and items. This is different from LVSCW_AUTOSIZE in that
8337 LVSCW_AUTOSIZE ignores the header string length. */
8340 /* retrieve header text */
8341 hdi
.mask
= HDI_TEXT
;
8342 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8343 hdi
.pszText
= szDispText
;
8344 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8346 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8347 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8350 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8351 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8352 /* FIXME: Take into account the header image, if one is present */
8353 SelectObject(hdc
, old_font
);
8354 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8356 cx
= max (cx
, max_cx
);
8360 if (cx
< 0) return FALSE
;
8362 /* call header to update the column change */
8363 hdi
.mask
= HDI_WIDTH
;
8364 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8365 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8366 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8370 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8373 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8376 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8378 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8379 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8382 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8383 ILC_COLOR
| ILC_MASK
, 2, 2);
8384 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8385 hdc
= CreateCompatibleDC(hdc_wnd
);
8386 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8387 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8388 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8390 rc
.left
= rc
.top
= 0;
8391 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
8392 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
8394 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8395 FillRect(hdc
, &rc
, hbr_white
);
8396 InflateRect(&rc
, -2, -2);
8397 FillRect(hdc
, &rc
, hbr_black
);
8399 SelectObject(hdc
, hbm_im
);
8400 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8401 SelectObject(hdc
, hbm_orig
);
8402 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8404 SelectObject(hdc
, hbm_im
);
8405 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8406 SelectObject(hdc
, hbm_orig
);
8407 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8409 DeleteObject(hbm_mask
);
8410 DeleteObject(hbm_im
);
8418 * Sets the extended listview style.
8421 * [I] infoPtr : valid pointer to the listview structure
8423 * [I] dwStyle : style
8426 * SUCCESS : previous style
8429 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8431 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8433 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8437 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8439 infoPtr
->dwLvExStyle
= ex_style
;
8441 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8443 HIMAGELIST himl
= 0;
8444 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8447 item
.mask
= LVIF_STATE
;
8448 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8449 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8450 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8452 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8453 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8454 ImageList_Destroy(infoPtr
->himlState
);
8456 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8457 /* checkbox list replaces previous custom list or... */
8458 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8459 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8460 /* ...previous was checkbox list */
8461 (old_ex_style
& LVS_EX_CHECKBOXES
))
8462 ImageList_Destroy(himl
);
8465 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8469 /* if not already created */
8470 LISTVIEW_CreateHeader(infoPtr
);
8472 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8473 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8474 style
|= HDS_DRAGDROP
;
8476 style
&= ~HDS_DRAGDROP
;
8477 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8480 /* GRIDLINES adds decoration at top so changes sizes */
8481 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8483 LISTVIEW_CreateHeader(infoPtr
);
8484 LISTVIEW_UpdateSize(infoPtr
);
8487 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8489 LISTVIEW_CreateHeader(infoPtr
);
8492 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8494 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8495 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8498 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8500 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8501 LISTVIEW_CreateHeader(infoPtr
);
8503 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8504 LISTVIEW_UpdateSize(infoPtr
);
8505 LISTVIEW_UpdateScroll(infoPtr
);
8508 LISTVIEW_InvalidateList(infoPtr
);
8509 return old_ex_style
;
8514 * Sets the new hot cursor used during hot tracking and hover selection.
8517 * [I] infoPtr : valid pointer to the listview structure
8518 * [I] hCursor : the new hot cursor handle
8521 * Returns the previous hot cursor
8523 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8525 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8527 infoPtr
->hHotCursor
= hCursor
;
8535 * Sets the hot item index.
8538 * [I] infoPtr : valid pointer to the listview structure
8539 * [I] iIndex : index
8542 * SUCCESS : previous hot item index
8543 * FAILURE : -1 (no hot item)
8545 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8547 INT iOldIndex
= infoPtr
->nHotItem
;
8549 infoPtr
->nHotItem
= iIndex
;
8557 * Sets the amount of time the cursor must hover over an item before it is selected.
8560 * [I] infoPtr : valid pointer to the listview structure
8561 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8564 * Returns the previous hover time
8566 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8568 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8570 infoPtr
->dwHoverTime
= dwHoverTime
;
8572 return oldHoverTime
;
8577 * Sets spacing for icons of LVS_ICON style.
8580 * [I] infoPtr : valid pointer to the listview structure
8581 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8582 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8585 * MAKELONG(oldcx, oldcy)
8587 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8589 INT iconWidth
= 0, iconHeight
= 0;
8590 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8592 TRACE("requested=(%d,%d)\n", cx
, cy
);
8594 /* set to defaults, if instructed to */
8595 if (cx
== -1 && cy
== -1)
8597 infoPtr
->autoSpacing
= TRUE
;
8598 if (infoPtr
->himlNormal
)
8599 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8600 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8601 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8604 infoPtr
->autoSpacing
= FALSE
;
8606 /* if 0 then keep width */
8608 infoPtr
->iconSpacing
.cx
= cx
;
8610 /* if 0 then keep height */
8612 infoPtr
->iconSpacing
.cy
= cy
;
8614 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8615 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8616 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8617 infoPtr
->ntmHeight
);
8619 /* these depend on the iconSpacing */
8620 LISTVIEW_UpdateItemSize(infoPtr
);
8625 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8629 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8636 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8637 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8646 * [I] infoPtr : valid pointer to the listview structure
8647 * [I] nType : image list type
8648 * [I] himl : image list handle
8651 * SUCCESS : old image list
8654 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8656 INT oldHeight
= infoPtr
->nItemHeight
;
8657 HIMAGELIST himlOld
= 0;
8659 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
8664 himlOld
= infoPtr
->himlNormal
;
8665 infoPtr
->himlNormal
= himl
;
8666 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8667 if (infoPtr
->autoSpacing
)
8668 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8672 himlOld
= infoPtr
->himlSmall
;
8673 infoPtr
->himlSmall
= himl
;
8674 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8675 if (infoPtr
->hwndHeader
)
8676 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8680 himlOld
= infoPtr
->himlState
;
8681 infoPtr
->himlState
= himl
;
8682 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8683 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8687 ERR("Unknown icon type=%d\n", nType
);
8691 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8692 if (infoPtr
->nItemHeight
!= oldHeight
)
8693 LISTVIEW_UpdateScroll(infoPtr
);
8700 * Preallocates memory (does *not* set the actual count of items !)
8703 * [I] infoPtr : valid pointer to the listview structure
8704 * [I] nItems : item count (projected number of items to allocate)
8705 * [I] dwFlags : update flags
8711 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8713 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8715 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8717 INT nOldCount
= infoPtr
->nItemCount
;
8719 if (nItems
< nOldCount
)
8721 RANGE range
= { nItems
, nOldCount
};
8722 ranges_del(infoPtr
->selectionRanges
, range
);
8723 if (infoPtr
->nFocusedItem
>= nItems
)
8725 LISTVIEW_SetItemFocus(infoPtr
, -1);
8726 SetRectEmpty(&infoPtr
->rcFocus
);
8730 infoPtr
->nItemCount
= nItems
;
8731 LISTVIEW_UpdateScroll(infoPtr
);
8733 /* the flags are valid only in ownerdata report and list modes */
8734 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8736 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8737 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8739 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8740 LISTVIEW_InvalidateList(infoPtr
);
8747 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8748 nFrom
= min(nOldCount
, nItems
);
8749 nTo
= max(nOldCount
, nItems
);
8751 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8754 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8755 rcErase
.right
= infoPtr
->nItemWidth
;
8756 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8757 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8758 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8759 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8761 else /* LV_VIEW_LIST */
8763 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8765 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8766 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8767 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8768 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8769 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8770 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8771 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8773 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8775 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8776 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8777 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8778 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8779 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8785 /* According to MSDN for non-LVS_OWNERDATA this is just
8786 * a performance issue. The control allocates its internal
8787 * data structures for the number of items specified. It
8788 * cuts down on the number of memory allocations. Therefore
8789 * we will just issue a WARN here
8791 WARN("for non-ownerdata performance option not implemented.\n");
8799 * Sets the position of an item.
8802 * [I] infoPtr : valid pointer to the listview structure
8803 * [I] nItem : item index
8804 * [I] pt : coordinate
8810 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8814 TRACE("(nItem=%d, pt=%s\n", nItem
, wine_dbgstr_point(pt
));
8816 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8817 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8820 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8822 /* This point value seems to be an undocumented feature.
8823 * The best guess is that it means either at the origin,
8824 * or at true beginning of the list. I will assume the origin. */
8825 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8828 if (infoPtr
->uView
== LV_VIEW_ICON
)
8830 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8831 Pt
.y
-= ICON_TOP_PADDING
;
8836 infoPtr
->bAutoarrange
= FALSE
;
8838 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8843 * Sets the state of one or many items.
8846 * [I] infoPtr : valid pointer to the listview structure
8847 * [I] nItem : item index
8848 * [I] item : item or subitem info
8854 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8859 if (!item
) return FALSE
;
8861 lvItem
.iItem
= nItem
;
8862 lvItem
.iSubItem
= 0;
8863 lvItem
.mask
= LVIF_STATE
;
8864 lvItem
.state
= item
->state
;
8865 lvItem
.stateMask
= item
->stateMask
;
8866 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8873 /* special case optimization for recurring attempt to deselect all */
8874 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8877 /* select all isn't allowed in LVS_SINGLESEL */
8878 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8881 /* focus all isn't allowed */
8882 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8884 notify
= infoPtr
->bDoChangeNotify
;
8885 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8887 infoPtr
->bDoChangeNotify
= FALSE
;
8888 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8889 oldstate
|= LVIS_SELECTED
;
8890 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
8893 /* apply to all items */
8894 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8895 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
8897 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8901 infoPtr
->bDoChangeNotify
= notify
;
8905 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
8906 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
8907 nmlv
.uChanged
= LVIF_STATE
;
8908 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
8911 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
8915 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8922 * Sets the text of an item or subitem.
8925 * [I] hwnd : window handle
8926 * [I] nItem : item index
8927 * [I] lpLVItem : item or subitem info
8928 * [I] isW : TRUE if input is Unicode
8934 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
8938 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
8939 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
8941 lvItem
.iItem
= nItem
;
8942 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
8943 lvItem
.mask
= LVIF_TEXT
;
8944 lvItem
.pszText
= lpLVItem
->pszText
;
8945 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
8947 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
8949 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
8954 * Set item index that marks the start of a multiple selection.
8957 * [I] infoPtr : valid pointer to the listview structure
8958 * [I] nIndex : index
8961 * Index number or -1 if there is no selection mark.
8963 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
8965 INT nOldIndex
= infoPtr
->nSelectionMark
;
8967 TRACE("(nIndex=%d)\n", nIndex
);
8969 infoPtr
->nSelectionMark
= nIndex
;
8976 * Sets the text background color.
8979 * [I] infoPtr : valid pointer to the listview structure
8980 * [I] color : text background color
8986 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8988 TRACE("(color=%x)\n", color
);
8990 infoPtr
->clrTextBk
= color
;
8996 * Sets the text foreground color.
8999 * [I] infoPtr : valid pointer to the listview structure
9000 * [I] color : text color
9006 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
9008 TRACE("(color=%x)\n", color
);
9010 infoPtr
->clrText
= color
;
9016 * Sets new ToolTip window to ListView control.
9019 * [I] infoPtr : valid pointer to the listview structure
9020 * [I] hwndNewToolTip : handle to new ToolTip
9025 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9027 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9028 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9029 return hwndOldToolTip
;
9034 * sets the Unicode character format flag for the control
9036 * [I] infoPtr :valid pointer to the listview structure
9037 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9040 * Old Unicode Format
9042 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9044 SHORT rc
= infoPtr
->notifyFormat
;
9045 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9046 return rc
== NFR_UNICODE
;
9051 * sets the control view mode
9053 * [I] infoPtr :valid pointer to the listview structure
9054 * [I] nView :new view mode value
9060 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9064 if (infoPtr
->uView
== nView
) return 1;
9066 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9067 if (nView
== LV_VIEW_TILE
)
9069 FIXME("View LV_VIEW_TILE unimplemented\n");
9073 infoPtr
->uView
= nView
;
9075 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9076 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9078 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9079 SetRectEmpty(&infoPtr
->rcFocus
);
9081 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9082 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9087 case LV_VIEW_SMALLICON
:
9088 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9090 case LV_VIEW_DETAILS
:
9095 LISTVIEW_CreateHeader( infoPtr
);
9097 hl
.prc
= &infoPtr
->rcList
;
9099 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9100 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9101 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9108 LISTVIEW_UpdateItemSize(infoPtr
);
9109 LISTVIEW_UpdateSize(infoPtr
);
9110 LISTVIEW_UpdateScroll(infoPtr
);
9111 LISTVIEW_InvalidateList(infoPtr
);
9113 TRACE("nView=%d\n", nView
);
9118 /* LISTVIEW_SetWorkAreas */
9122 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9125 * [I] first : pointer to first ITEM_INFO to compare
9126 * [I] second : pointer to second ITEM_INFO to compare
9127 * [I] lParam : HWND of control
9130 * if first comes before second : negative
9131 * if first comes after second : positive
9132 * if first and second are equivalent : zero
9134 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9136 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9137 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9138 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9140 /* Forward the call to the client defined callback */
9141 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9146 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9149 * [I] first : pointer to first ITEM_INFO to compare
9150 * [I] second : pointer to second ITEM_INFO to compare
9151 * [I] lParam : HWND of control
9154 * if first comes before second : negative
9155 * if first comes after second : positive
9156 * if first and second are equivalent : zero
9158 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9160 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9161 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9162 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9164 /* Forward the call to the client defined callback */
9165 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9170 * Sorts the listview items.
9173 * [I] infoPtr : valid pointer to the listview structure
9174 * [I] pfnCompare : application-defined value
9175 * [I] lParamSort : pointer to comparison callback
9176 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9182 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9183 LPARAM lParamSort
, BOOL IsEx
)
9187 LPVOID selectionMarkItem
= NULL
;
9188 LPVOID focusedItem
= NULL
;
9191 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9193 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9195 if (!pfnCompare
) return FALSE
;
9196 if (!infoPtr
->hdpaItems
) return FALSE
;
9198 /* if there are 0 or 1 items, there is no need to sort */
9199 if (infoPtr
->nItemCount
< 2) return TRUE
;
9201 /* clear selection */
9202 ranges_clear(infoPtr
->selectionRanges
);
9204 /* save selection mark and focused item */
9205 if (infoPtr
->nSelectionMark
>= 0)
9206 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9207 if (infoPtr
->nFocusedItem
>= 0)
9208 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9210 infoPtr
->pfnCompare
= pfnCompare
;
9211 infoPtr
->lParamSort
= lParamSort
;
9213 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9215 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9217 /* restore selection ranges */
9218 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9220 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9221 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9223 if (lpItem
->state
& LVIS_SELECTED
)
9224 ranges_additem(infoPtr
->selectionRanges
, i
);
9226 /* restore selection mark and focused item */
9227 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9228 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9230 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9232 /* refresh the display */
9233 LISTVIEW_InvalidateList(infoPtr
);
9239 * Update theme handle after a theme change.
9242 * [I] infoPtr : valid pointer to the listview structure
9246 * FAILURE : something else
9248 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9250 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9251 CloseThemeData(theme
);
9252 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9258 * Updates an items or rearranges the listview control.
9261 * [I] infoPtr : valid pointer to the listview structure
9262 * [I] nItem : item index
9268 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9270 TRACE("(nItem=%d)\n", nItem
);
9272 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9274 /* rearrange with default alignment style */
9275 if (is_autoarrange(infoPtr
))
9276 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9278 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9285 * Draw the track line at the place defined in the infoPtr structure.
9286 * The line is drawn with a XOR pen so drawing the line for the second time
9287 * in the same place erases the line.
9290 * [I] infoPtr : valid pointer to the listview structure
9296 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9300 if (infoPtr
->xTrackLine
== -1)
9303 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9305 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9306 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9307 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9313 * Called when an edit control should be displayed. This function is called after
9314 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9317 * [I] hwnd : Handle to the listview
9318 * [I] uMsg : WM_TIMER (ignored)
9319 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9320 * [I] dwTimer : The elapsed time (ignored)
9325 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9327 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9328 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9330 KillTimer(hwnd
, idEvent
);
9331 editItem
->fEnabled
= FALSE
;
9332 /* check if the item is still selected */
9333 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9334 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9339 * Creates the listview control - the WM_NCCREATE phase.
9342 * [I] hwnd : window handle
9343 * [I] lpcs : the create parameters
9349 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9351 LISTVIEW_INFO
*infoPtr
;
9354 TRACE("(lpcs=%p)\n", lpcs
);
9356 /* initialize info pointer */
9357 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9358 if (!infoPtr
) return FALSE
;
9360 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9362 infoPtr
->hwndSelf
= hwnd
;
9363 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9364 map_style_view(infoPtr
);
9365 /* determine the type of structures to use */
9366 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9367 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9369 /* initialize color information */
9370 infoPtr
->clrBk
= CLR_NONE
;
9371 infoPtr
->clrText
= CLR_DEFAULT
;
9372 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9373 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9375 /* set default values */
9376 infoPtr
->nFocusedItem
= -1;
9377 infoPtr
->nSelectionMark
= -1;
9378 infoPtr
->nHotItem
= -1;
9379 infoPtr
->bRedraw
= TRUE
;
9380 infoPtr
->bNoItemMetrics
= TRUE
;
9381 infoPtr
->bDoChangeNotify
= TRUE
;
9382 infoPtr
->autoSpacing
= TRUE
;
9383 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9384 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9385 infoPtr
->nEditLabelItem
= -1;
9386 infoPtr
->nLButtonDownItem
= -1;
9387 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9388 infoPtr
->nMeasureItemHeight
= 0;
9389 infoPtr
->xTrackLine
= -1; /* no track line */
9390 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9391 infoPtr
->iVersion
= COMCTL32_VERSION
;
9392 infoPtr
->colRectsDirty
= FALSE
;
9394 /* get default font (icon title) */
9395 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9396 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9397 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9398 LISTVIEW_SaveTextMetrics(infoPtr
);
9400 /* allocate memory for the data structure */
9401 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9402 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9403 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9404 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9405 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9406 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9410 DestroyWindow(infoPtr
->hwndHeader
);
9411 ranges_destroy(infoPtr
->selectionRanges
);
9412 DPA_Destroy(infoPtr
->hdpaItems
);
9413 DPA_Destroy(infoPtr
->hdpaItemIds
);
9414 DPA_Destroy(infoPtr
->hdpaPosX
);
9415 DPA_Destroy(infoPtr
->hdpaPosY
);
9416 DPA_Destroy(infoPtr
->hdpaColumns
);
9423 * Creates the listview control - the WM_CREATE phase. Most of the data is
9424 * already set up in LISTVIEW_NCCreate
9427 * [I] hwnd : window handle
9428 * [I] lpcs : the create parameters
9434 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9436 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9438 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9440 infoPtr
->dwStyle
= lpcs
->style
;
9441 map_style_view(infoPtr
);
9443 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9444 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9445 /* on error defaulting to ANSI notifications */
9446 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9447 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9449 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9451 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9454 infoPtr
->hwndHeader
= 0;
9456 /* init item size to avoid division by 0 */
9457 LISTVIEW_UpdateItemSize (infoPtr
);
9458 LISTVIEW_UpdateSize (infoPtr
);
9460 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9462 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9464 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9466 LISTVIEW_UpdateScroll(infoPtr
);
9467 /* send WM_MEASUREITEM notification */
9468 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9471 OpenThemeData(hwnd
, themeClass
);
9473 /* initialize the icon sizes */
9474 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9475 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9481 * Destroys the listview control.
9484 * [I] infoPtr : valid pointer to the listview structure
9490 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9492 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9493 CloseThemeData(theme
);
9495 /* delete all items */
9496 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9503 * Enables the listview control.
9506 * [I] infoPtr : valid pointer to the listview structure
9507 * [I] bEnable : specifies whether to enable or disable the window
9513 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9515 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9516 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9522 * Erases the background of the listview control.
9525 * [I] infoPtr : valid pointer to the listview structure
9526 * [I] hdc : device context handle
9532 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9536 TRACE("(hdc=%p)\n", hdc
);
9538 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9540 if (infoPtr
->clrBk
== CLR_NONE
)
9542 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9543 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9544 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9546 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9549 /* for double buffered controls we need to do this during refresh */
9550 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9552 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9558 * Helper function for LISTVIEW_[HV]Scroll *only*.
9559 * Performs vertical/horizontal scrolling by a give amount.
9562 * [I] infoPtr : valid pointer to the listview structure
9563 * [I] dx : amount of horizontal scroll
9564 * [I] dy : amount of vertical scroll
9566 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9568 /* now we can scroll the list */
9569 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9570 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9571 /* if we have focus, adjust rect */
9572 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9573 UpdateWindow(infoPtr
->hwndSelf
);
9578 * Performs vertical scrolling.
9581 * [I] infoPtr : valid pointer to the listview structure
9582 * [I] nScrollCode : scroll code
9583 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9584 * [I] hScrollWnd : scrollbar control window handle
9590 * SB_LINEUP/SB_LINEDOWN:
9591 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9592 * for LVS_REPORT is 1 line
9593 * for LVS_LIST cannot occur
9596 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9599 INT nOldScrollPos
, nNewScrollPos
;
9600 SCROLLINFO scrollInfo
;
9603 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9604 debugscrollcode(nScrollCode
), nScrollDiff
);
9606 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9608 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9609 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9611 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9613 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9615 nOldScrollPos
= scrollInfo
.nPos
;
9616 switch (nScrollCode
)
9622 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9626 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9630 nScrollDiff
= -scrollInfo
.nPage
;
9634 nScrollDiff
= scrollInfo
.nPage
;
9637 case SB_THUMBPOSITION
:
9639 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9646 /* quit right away if pos isn't changing */
9647 if (nScrollDiff
== 0) return 0;
9649 /* calculate new position, and handle overflows */
9650 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9651 if (nScrollDiff
> 0) {
9652 if (nNewScrollPos
< nOldScrollPos
||
9653 nNewScrollPos
> scrollInfo
.nMax
)
9654 nNewScrollPos
= scrollInfo
.nMax
;
9656 if (nNewScrollPos
> nOldScrollPos
||
9657 nNewScrollPos
< scrollInfo
.nMin
)
9658 nNewScrollPos
= scrollInfo
.nMin
;
9661 /* set the new position, and reread in case it changed */
9662 scrollInfo
.fMask
= SIF_POS
;
9663 scrollInfo
.nPos
= nNewScrollPos
;
9664 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9666 /* carry on only if it really changed */
9667 if (nNewScrollPos
== nOldScrollPos
) return 0;
9669 /* now adjust to client coordinates */
9670 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9671 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9673 /* and scroll the window */
9674 scroll_list(infoPtr
, 0, nScrollDiff
);
9681 * Performs horizontal scrolling.
9684 * [I] infoPtr : valid pointer to the listview structure
9685 * [I] nScrollCode : scroll code
9686 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9687 * [I] hScrollWnd : scrollbar control window handle
9693 * SB_LINELEFT/SB_LINERIGHT:
9694 * for LVS_ICON, LVS_SMALLICON 1 pixel
9695 * for LVS_REPORT is 1 pixel
9696 * for LVS_LIST is 1 column --> which is a 1 because the
9697 * scroll is based on columns not pixels
9700 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9703 INT nOldScrollPos
, nNewScrollPos
;
9704 SCROLLINFO scrollInfo
;
9707 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9708 debugscrollcode(nScrollCode
), nScrollDiff
);
9710 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9712 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9713 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9715 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9717 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9719 nOldScrollPos
= scrollInfo
.nPos
;
9721 switch (nScrollCode
)
9727 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9731 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9735 nScrollDiff
= -scrollInfo
.nPage
;
9739 nScrollDiff
= scrollInfo
.nPage
;
9742 case SB_THUMBPOSITION
:
9744 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9751 /* quit right away if pos isn't changing */
9752 if (nScrollDiff
== 0) return 0;
9754 /* calculate new position, and handle overflows */
9755 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9756 if (nScrollDiff
> 0) {
9757 if (nNewScrollPos
< nOldScrollPos
||
9758 nNewScrollPos
> scrollInfo
.nMax
)
9759 nNewScrollPos
= scrollInfo
.nMax
;
9761 if (nNewScrollPos
> nOldScrollPos
||
9762 nNewScrollPos
< scrollInfo
.nMin
)
9763 nNewScrollPos
= scrollInfo
.nMin
;
9766 /* set the new position, and reread in case it changed */
9767 scrollInfo
.fMask
= SIF_POS
;
9768 scrollInfo
.nPos
= nNewScrollPos
;
9769 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9771 /* carry on only if it really changed */
9772 if (nNewScrollPos
== nOldScrollPos
) return 0;
9774 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9776 /* now adjust to client coordinates */
9777 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9778 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9780 /* and scroll the window */
9781 scroll_list(infoPtr
, nScrollDiff
, 0);
9786 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9788 INT pulScrollLines
= 3;
9790 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9792 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9794 switch(infoPtr
->uView
)
9797 case LV_VIEW_SMALLICON
:
9799 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9800 * should be fixed in the future.
9802 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9803 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9806 case LV_VIEW_DETAILS
:
9807 if (abs(wheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
9809 int cLineScroll
= min(LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9810 cLineScroll
*= (-wheelDelta
/ WHEEL_DELTA
);
9811 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, cLineScroll
);
9816 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9827 * [I] infoPtr : valid pointer to the listview structure
9828 * [I] nVirtualKey : virtual key
9829 * [I] lKeyData : key data
9834 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9836 HWND hwndSelf
= infoPtr
->hwndSelf
;
9838 NMLVKEYDOWN nmKeyDown
;
9840 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9842 /* send LVN_KEYDOWN notification */
9843 nmKeyDown
.wVKey
= nVirtualKey
;
9844 nmKeyDown
.flags
= 0;
9845 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9846 if (!IsWindow(hwndSelf
))
9849 switch (nVirtualKey
)
9852 nItem
= infoPtr
->nFocusedItem
;
9853 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9854 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9858 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9860 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9861 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9866 if (infoPtr
->nItemCount
> 0)
9871 if (infoPtr
->nItemCount
> 0)
9872 nItem
= infoPtr
->nItemCount
- 1;
9876 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9880 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9884 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9888 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9892 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9894 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9895 if (infoPtr
->nFocusedItem
== topidx
)
9896 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9901 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9902 * LISTVIEW_GetCountPerRow(infoPtr
);
9903 if(nItem
< 0) nItem
= 0;
9907 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9909 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9910 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9911 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9912 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9914 nItem
= topidx
+ cnt
- 1;
9917 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9918 * LISTVIEW_GetCountPerRow(infoPtr
);
9919 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9923 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9924 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
9934 * [I] infoPtr : valid pointer to the listview structure
9939 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
9943 /* if we did not have the focus, there's nothing to do */
9944 if (!infoPtr
->bFocus
) return 0;
9946 /* send NM_KILLFOCUS notification */
9947 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
9949 /* if we have a focus rectangle, get rid of it */
9950 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
9952 /* if have a marquee selection, stop it */
9953 if (infoPtr
->bMarqueeSelect
)
9955 /* Remove the marquee rectangle and release our mouse capture */
9956 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
9959 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
9961 infoPtr
->bMarqueeSelect
= FALSE
;
9962 infoPtr
->bScrolling
= FALSE
;
9963 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
9966 /* set window focus flag */
9967 infoPtr
->bFocus
= FALSE
;
9969 /* invalidate the selected items before resetting focus flag */
9970 LISTVIEW_InvalidateSelectedItems(infoPtr
);
9977 * Processes double click messages (left mouse button).
9980 * [I] infoPtr : valid pointer to the listview structure
9981 * [I] wKey : key flag
9982 * [I] x,y : mouse coordinate
9987 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9989 LVHITTESTINFO htInfo
;
9991 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
9993 /* Cancel the item edition if any */
9994 if (infoPtr
->itemEdit
.fEnabled
)
9996 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
9997 infoPtr
->itemEdit
.fEnabled
= FALSE
;
10000 /* send NM_RELEASEDCAPTURE notification */
10001 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10006 /* send NM_DBLCLK notification */
10007 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
10008 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
10010 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
10011 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10016 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10021 r
.top
= r
.bottom
= pt
.y
;
10022 r
.left
= r
.right
= pt
.x
;
10024 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10026 SetCapture(infoPtr
->hwndSelf
);
10030 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10032 if (msg
.message
== WM_MOUSEMOVE
)
10034 pt
.x
= (short)LOWORD(msg
.lParam
);
10035 pt
.y
= (short)HIWORD(msg
.lParam
);
10036 if (PtInRect(&r
, pt
))
10044 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10045 msg
.message
<= WM_RBUTTONDBLCLK
)
10050 DispatchMessageW(&msg
);
10053 if (GetCapture() != infoPtr
->hwndSelf
)
10064 * Processes mouse down messages (left mouse button).
10067 * infoPtr [I ] valid pointer to the listview structure
10068 * wKey [I ] key flag
10069 * x,y [I ] mouse coordinate
10074 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10076 LVHITTESTINFO lvHitTestInfo
;
10077 static BOOL bGroupSelect
= TRUE
;
10078 POINT pt
= { x
, y
};
10081 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10083 /* send NM_RELEASEDCAPTURE notification */
10084 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10086 /* set left button down flag and record the click position */
10087 infoPtr
->bLButtonDown
= TRUE
;
10088 infoPtr
->ptClickPos
= pt
;
10089 infoPtr
->bDragging
= FALSE
;
10090 infoPtr
->bMarqueeSelect
= FALSE
;
10091 infoPtr
->bScrolling
= FALSE
;
10093 lvHitTestInfo
.pt
.x
= x
;
10094 lvHitTestInfo
.pt
.y
= y
;
10096 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10097 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10098 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10100 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10102 toggle_checkbox_state(infoPtr
, nItem
);
10106 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10108 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10109 infoPtr
->nEditLabelItem
= nItem
;
10111 LISTVIEW_SetSelection(infoPtr
, nItem
);
10115 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10119 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10120 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10121 infoPtr
->nSelectionMark
= nItem
;
10127 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10128 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10130 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10131 infoPtr
->nSelectionMark
= nItem
;
10134 else if (wKey
& MK_CONTROL
)
10138 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10140 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10141 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10142 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10143 infoPtr
->nSelectionMark
= nItem
;
10145 else if (wKey
& MK_SHIFT
)
10147 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10151 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10153 infoPtr
->nEditLabelItem
= nItem
;
10154 infoPtr
->nLButtonDownItem
= nItem
;
10156 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10159 /* set selection (clears other pre-existing selections) */
10160 LISTVIEW_SetSelection(infoPtr
, nItem
);
10164 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10165 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10169 if (!infoPtr
->bFocus
)
10170 SetFocus(infoPtr
->hwndSelf
);
10172 /* remove all selections */
10173 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10174 LISTVIEW_DeselectAll(infoPtr
);
10183 * Processes mouse up messages (left mouse button).
10186 * infoPtr [I ] valid pointer to the listview structure
10187 * wKey [I ] key flag
10188 * x,y [I ] mouse coordinate
10193 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10195 LVHITTESTINFO lvHitTestInfo
;
10197 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10199 if (!infoPtr
->bLButtonDown
) return 0;
10201 lvHitTestInfo
.pt
.x
= x
;
10202 lvHitTestInfo
.pt
.y
= y
;
10204 /* send NM_CLICK notification */
10205 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10206 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10208 /* set left button flag */
10209 infoPtr
->bLButtonDown
= FALSE
;
10211 /* set a single selection, reset others */
10212 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10213 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10214 infoPtr
->nLButtonDownItem
= -1;
10216 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10218 /* Remove the marquee rectangle and release our mouse capture */
10219 if (infoPtr
->bMarqueeSelect
)
10221 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10225 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10226 SetRect(&infoPtr
->marqueeDrawRect
, 0, 0, 0, 0);
10228 infoPtr
->bDragging
= FALSE
;
10229 infoPtr
->bMarqueeSelect
= FALSE
;
10230 infoPtr
->bScrolling
= FALSE
;
10232 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10236 /* if we clicked on a selected item, edit the label */
10237 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10239 /* we want to make sure the user doesn't want to do a double click. So we will
10240 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10242 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10243 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10244 SetTimer(infoPtr
->hwndSelf
,
10245 (UINT_PTR
)&infoPtr
->itemEdit
,
10246 GetDoubleClickTime(),
10247 LISTVIEW_DelayedEditItem
);
10250 if (!infoPtr
->bFocus
)
10251 SetFocus(infoPtr
->hwndSelf
);
10258 * Destroys the listview control (called after WM_DESTROY).
10261 * [I] infoPtr : valid pointer to the listview structure
10266 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10272 /* destroy data structure */
10273 DPA_Destroy(infoPtr
->hdpaItems
);
10274 DPA_Destroy(infoPtr
->hdpaItemIds
);
10275 DPA_Destroy(infoPtr
->hdpaPosX
);
10276 DPA_Destroy(infoPtr
->hdpaPosY
);
10278 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10279 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10280 DPA_Destroy(infoPtr
->hdpaColumns
);
10281 ranges_destroy(infoPtr
->selectionRanges
);
10283 /* destroy image lists */
10284 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10286 ImageList_Destroy(infoPtr
->himlNormal
);
10287 ImageList_Destroy(infoPtr
->himlSmall
);
10288 ImageList_Destroy(infoPtr
->himlState
);
10291 /* destroy font, bkgnd brush */
10292 infoPtr
->hFont
= 0;
10293 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10294 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10296 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10298 /* free listview info pointer*/
10306 * Handles notifications.
10309 * [I] infoPtr : valid pointer to the listview structure
10310 * [I] lpnmhdr : notification information
10315 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10319 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10321 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10323 /* remember: HDN_LAST < HDN_FIRST */
10324 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10325 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10327 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10329 switch (lpnmhdr
->code
)
10334 COLUMN_INFO
*lpColumnInfo
;
10338 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10341 /* remove the old line (if any) */
10342 LISTVIEW_DrawTrackLine(infoPtr
);
10344 /* compute & draw the new line */
10345 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10346 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10347 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10348 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10349 LISTVIEW_DrawTrackLine(infoPtr
);
10350 return notify_forward_header(infoPtr
, lpnmh
);
10353 case HDN_ENDTRACKA
:
10354 case HDN_ENDTRACKW
:
10355 /* remove the track line (if any) */
10356 LISTVIEW_DrawTrackLine(infoPtr
);
10357 infoPtr
->xTrackLine
= -1;
10358 return notify_forward_header(infoPtr
, lpnmh
);
10360 case HDN_BEGINDRAG
:
10361 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10362 return notify_forward_header(infoPtr
, lpnmh
);
10365 infoPtr
->colRectsDirty
= TRUE
;
10366 LISTVIEW_InvalidateList(infoPtr
);
10367 return notify_forward_header(infoPtr
, lpnmh
);
10369 case HDN_ITEMCHANGEDW
:
10370 case HDN_ITEMCHANGEDA
:
10372 COLUMN_INFO
*lpColumnInfo
;
10376 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10378 hdi
.mask
= HDI_WIDTH
;
10379 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10383 cxy
= lpnmh
->pitem
->cxy
;
10385 /* determine how much we change since the last know position */
10386 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10387 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10390 lpColumnInfo
->rcHeader
.right
+= dx
;
10392 hdi
.mask
= HDI_ORDER
;
10393 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10395 /* not the rightmost one */
10396 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10398 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10399 hdi
.iOrder
+ 1, 0);
10400 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10404 /* only needs to update the scrolls */
10405 infoPtr
->nItemWidth
+= dx
;
10406 LISTVIEW_UpdateScroll(infoPtr
);
10408 LISTVIEW_UpdateItemSize(infoPtr
);
10409 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10412 RECT rcCol
= lpColumnInfo
->rcHeader
;
10414 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10415 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10417 rcCol
.top
= infoPtr
->rcList
.top
;
10418 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10420 /* resizing left-aligned columns leaves most of the left side untouched */
10421 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10423 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10426 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10429 /* when shrinking the last column clear the now unused field */
10430 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10436 /* deal with right from rightmost column area */
10437 right
.left
= rcCol
.right
;
10438 right
.top
= rcCol
.top
;
10439 right
.bottom
= rcCol
.bottom
;
10440 right
.right
= infoPtr
->rcList
.right
;
10442 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10445 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10451 case HDN_ITEMCLICKW
:
10452 case HDN_ITEMCLICKA
:
10454 /* Handle sorting by Header Column */
10457 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10459 nmlv
.iSubItem
= lpnmh
->iItem
;
10460 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10461 return notify_forward_header(infoPtr
, lpnmh
);
10464 case HDN_DIVIDERDBLCLICKW
:
10465 case HDN_DIVIDERDBLCLICKA
:
10466 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10467 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10468 split needed for that */
10469 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10470 return notify_forward_header(infoPtr
, lpnmh
);
10477 * Paint non-client area of control.
10480 * [I] infoPtr : valid pointer to the listview structureof the sender
10481 * [I] region : update region
10484 * TRUE - frame was painted
10485 * FALSE - call default window proc
10487 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10489 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10493 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10494 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10497 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10499 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10501 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10502 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10503 if (region
!= (HRGN
)1)
10504 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10505 OffsetRect(&r
, -r
.left
, -r
.top
);
10507 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10508 OffsetRect(&r
, -r
.left
, -r
.top
);
10510 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10511 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10512 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10513 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10515 /* Call default proc to get the scrollbars etc. painted */
10516 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10523 * Determines the type of structure to use.
10526 * [I] infoPtr : valid pointer to the listview structureof the sender
10527 * [I] hwndFrom : listview window handle
10528 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10533 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10535 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10537 if (nCommand
== NF_REQUERY
)
10538 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10540 return infoPtr
->notifyFormat
;
10545 * Paints/Repaints the listview control. Internal use.
10548 * [I] infoPtr : valid pointer to the listview structure
10549 * [I] hdc : device context handle
10554 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10556 TRACE("(hdc=%p)\n", hdc
);
10558 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10560 infoPtr
->bNoItemMetrics
= FALSE
;
10561 LISTVIEW_UpdateItemSize(infoPtr
);
10562 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10563 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10564 LISTVIEW_UpdateScroll(infoPtr
);
10567 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10570 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10575 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10576 if (!hdc
) return 1;
10577 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10578 EndPaint(infoPtr
->hwndSelf
, &ps
);
10586 * Paints/Repaints the listview control, WM_PAINT handler.
10589 * [I] infoPtr : valid pointer to the listview structure
10590 * [I] hdc : device context handle
10595 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10597 TRACE("(hdc=%p)\n", hdc
);
10599 if (!is_redrawing(infoPtr
))
10600 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10602 return LISTVIEW_Paint(infoPtr
, hdc
);
10607 * Paints/Repaints the listview control.
10610 * [I] infoPtr : valid pointer to the listview structure
10611 * [I] hdc : device context handle
10612 * [I] options : drawing options
10617 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10619 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10621 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10624 if (options
& PRF_ERASEBKGND
)
10625 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10627 if (options
& PRF_CLIENT
)
10628 LISTVIEW_Paint(infoPtr
, hdc
);
10636 * Processes double click messages (right mouse button).
10639 * [I] infoPtr : valid pointer to the listview structure
10640 * [I] wKey : key flag
10641 * [I] x,y : mouse coordinate
10646 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10648 LVHITTESTINFO lvHitTestInfo
;
10650 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10652 /* send NM_RELEASEDCAPTURE notification */
10653 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10655 /* send NM_RDBLCLK notification */
10656 lvHitTestInfo
.pt
.x
= x
;
10657 lvHitTestInfo
.pt
.y
= y
;
10658 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10659 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10666 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10669 * [I] infoPtr : valid pointer to the listview structure
10670 * [I] wKey : key flag
10671 * [I] x, y : mouse coordinate
10676 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10681 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10683 /* send NM_RELEASEDCAPTURE notification */
10684 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10686 /* determine the index of the selected item */
10689 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10691 /* make sure the listview control window has the focus */
10692 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10694 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10696 LISTVIEW_SetItemFocus(infoPtr
, item
);
10697 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10698 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10699 LISTVIEW_SetSelection(infoPtr
, item
);
10702 LISTVIEW_DeselectAll(infoPtr
);
10704 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10706 if (ht
.iItem
!= -1)
10710 memset(&nmlv
, 0, sizeof(nmlv
));
10711 nmlv
.iItem
= ht
.iItem
;
10712 nmlv
.ptAction
= ht
.pt
;
10714 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10719 SetFocus(infoPtr
->hwndSelf
);
10723 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10725 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10727 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10728 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10729 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10741 * [I] infoPtr : valid pointer to the listview structure
10742 * [I] hwnd : window handle of window containing the cursor
10743 * [I] nHittest : hit-test code
10744 * [I] wMouseMsg : ideintifier of the mouse message
10747 * TRUE if cursor is set
10750 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10752 LVHITTESTINFO lvHitTestInfo
;
10754 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10756 if (!infoPtr
->hHotCursor
) goto forward
;
10758 GetCursorPos(&lvHitTestInfo
.pt
);
10759 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10761 SetCursor(infoPtr
->hHotCursor
);
10767 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10775 * [I] infoPtr : valid pointer to the listview structure
10776 * [I] hwndLoseFocus : handle of previously focused window
10781 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10783 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10785 /* if we have the focus already, there's nothing to do */
10786 if (infoPtr
->bFocus
) return 0;
10788 /* send NM_SETFOCUS notification */
10789 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10791 /* set window focus flag */
10792 infoPtr
->bFocus
= TRUE
;
10794 /* put the focus rect back on */
10795 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10797 /* redraw all visible selected items */
10798 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10808 * [I] infoPtr : valid pointer to the listview structure
10809 * [I] fRedraw : font handle
10810 * [I] fRedraw : redraw flag
10815 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10817 HFONT oldFont
= infoPtr
->hFont
;
10818 INT oldHeight
= infoPtr
->nItemHeight
;
10820 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10822 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10823 if (infoPtr
->hFont
== oldFont
) return 0;
10825 LISTVIEW_SaveTextMetrics(infoPtr
);
10827 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10829 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10831 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10832 LISTVIEW_UpdateSize(infoPtr
);
10833 LISTVIEW_UpdateScroll(infoPtr
);
10835 else if (infoPtr
->nItemHeight
!= oldHeight
)
10836 LISTVIEW_UpdateScroll(infoPtr
);
10838 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10845 * Message handling for WM_SETREDRAW.
10846 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10849 * [I] infoPtr : valid pointer to the listview structure
10850 * [I] bRedraw: state of redraw flag
10853 * DefWinProc return value
10855 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10857 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10859 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10860 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10862 infoPtr
->bRedraw
= bRedraw
;
10864 if(!bRedraw
) return 0;
10866 if (is_autoarrange(infoPtr
))
10867 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10868 LISTVIEW_UpdateScroll(infoPtr
);
10870 /* despite what the WM_SETREDRAW docs says, apps expect us
10871 * to invalidate the listview here... stupid! */
10872 LISTVIEW_InvalidateList(infoPtr
);
10879 * Resizes the listview control. This function processes WM_SIZE
10880 * messages. At this time, the width and height are not used.
10883 * [I] infoPtr : valid pointer to the listview structure
10884 * [I] Width : new width
10885 * [I] Height : new height
10890 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10892 RECT rcOld
= infoPtr
->rcList
;
10894 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10896 LISTVIEW_UpdateSize(infoPtr
);
10897 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10899 /* do not bother with display related stuff if we're not redrawing */
10900 if (!is_redrawing(infoPtr
)) return 0;
10902 if (is_autoarrange(infoPtr
))
10903 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10905 LISTVIEW_UpdateScroll(infoPtr
);
10907 /* refresh all only for lists whose height changed significantly */
10908 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10909 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10910 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10911 LISTVIEW_InvalidateList(infoPtr
);
10918 * Sets the size information.
10921 * [I] infoPtr : valid pointer to the listview structure
10926 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
10928 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
10930 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
10932 if (infoPtr
->uView
== LV_VIEW_LIST
)
10934 /* Apparently the "LIST" style is supposed to have the same
10935 * number of items in a column even if there is no scroll bar.
10936 * Since if a scroll bar already exists then the bottom is already
10937 * reduced, only reduce if the scroll bar does not currently exist.
10938 * The "2" is there to mimic the native control. I think it may be
10939 * related to either padding or edges. (GLA 7/2002)
10941 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
10942 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
10943 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
10946 /* if control created invisible header isn't created */
10947 if (infoPtr
->hwndHeader
)
10952 hl
.prc
= &infoPtr
->rcList
;
10954 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10955 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10957 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
10958 wp
.flags
|= SWP_SHOWWINDOW
;
10961 wp
.flags
|= SWP_HIDEWINDOW
;
10965 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
10966 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10968 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
10970 /* extra padding for grid */
10971 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
10972 infoPtr
->rcList
.top
+= 2;
10974 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
10979 * Processes WM_STYLECHANGED messages.
10982 * [I] infoPtr : valid pointer to the listview structure
10983 * [I] wStyleType : window style type (normal or extended)
10984 * [I] lpss : window style information
10989 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10990 const STYLESTRUCT
*lpss
)
10992 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
10993 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
10996 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10997 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10999 if (wStyleType
!= GWL_STYLE
) return 0;
11001 infoPtr
->dwStyle
= lpss
->styleNew
;
11002 map_style_view(infoPtr
);
11004 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
11005 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
11006 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
11008 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
11009 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
11010 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
11012 if (uNewView
!= uOldView
)
11016 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11017 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11019 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11020 SetRectEmpty(&infoPtr
->rcFocus
);
11022 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11023 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11025 if (uNewView
== LVS_REPORT
)
11030 LISTVIEW_CreateHeader( infoPtr
);
11032 hl
.prc
= &infoPtr
->rcList
;
11034 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11035 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11036 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11037 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11040 LISTVIEW_UpdateItemSize(infoPtr
);
11043 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11045 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11047 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11049 /* Turn off the header control */
11050 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11051 TRACE("Hide header control, was 0x%08x\n", style
);
11052 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11054 /* Turn on the header control */
11055 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11057 TRACE("Show header control, was 0x%08x\n", style
);
11058 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11064 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11065 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11066 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11068 /* update the size of the client area */
11069 LISTVIEW_UpdateSize(infoPtr
);
11071 /* add scrollbars if needed */
11072 LISTVIEW_UpdateScroll(infoPtr
);
11074 /* invalidate client area + erase background */
11075 LISTVIEW_InvalidateList(infoPtr
);
11082 * Processes WM_STYLECHANGING messages.
11085 * [I] wStyleType : window style type (normal or extended)
11086 * [I0] lpss : window style information
11091 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11094 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11095 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11097 /* don't forward LVS_OWNERDATA only if not already set to */
11098 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11100 if (lpss
->styleOld
& LVS_OWNERDATA
)
11101 lpss
->styleNew
|= LVS_OWNERDATA
;
11103 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11111 * Processes WM_SHOWWINDOW messages.
11114 * [I] infoPtr : valid pointer to the listview structure
11115 * [I] bShown : window is being shown (FALSE when hidden)
11116 * [I] iStatus : window show status
11121 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11123 /* header delayed creation */
11124 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11126 LISTVIEW_CreateHeader(infoPtr
);
11128 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11129 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11132 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11137 * Processes CCM_GETVERSION messages.
11140 * [I] infoPtr : valid pointer to the listview structure
11145 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11147 return infoPtr
->iVersion
;
11152 * Processes CCM_SETVERSION messages.
11155 * [I] infoPtr : valid pointer to the listview structure
11156 * [I] iVersion : version to be set
11159 * -1 when requested version is greater than DLL version;
11160 * previous version otherwise
11162 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11164 INT iOldVersion
= infoPtr
->iVersion
;
11166 if (iVersion
> COMCTL32_VERSION
)
11169 infoPtr
->iVersion
= iVersion
;
11171 TRACE("new version %d\n", iVersion
);
11173 return iOldVersion
;
11178 * Window procedure of the listview control.
11181 static LRESULT WINAPI
11182 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11184 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11186 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11188 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11189 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11193 case LVM_APPROXIMATEVIEWRECT
:
11194 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11195 LOWORD(lParam
), HIWORD(lParam
));
11197 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11199 case LVM_CANCELEDITLABEL
:
11200 return LISTVIEW_CancelEditLabel(infoPtr
);
11202 case LVM_CREATEDRAGIMAGE
:
11203 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11205 case LVM_DELETEALLITEMS
:
11206 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11208 case LVM_DELETECOLUMN
:
11209 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11211 case LVM_DELETEITEM
:
11212 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11214 case LVM_EDITLABELA
:
11215 case LVM_EDITLABELW
:
11216 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11217 uMsg
== LVM_EDITLABELW
);
11218 /* case LVM_ENABLEGROUPVIEW: */
11220 case LVM_ENSUREVISIBLE
:
11221 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11223 case LVM_FINDITEMW
:
11224 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11226 case LVM_FINDITEMA
:
11227 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11229 case LVM_GETBKCOLOR
:
11230 return infoPtr
->clrBk
;
11232 /* case LVM_GETBKIMAGE: */
11234 case LVM_GETCALLBACKMASK
:
11235 return infoPtr
->uCallbackMask
;
11237 case LVM_GETCOLUMNA
:
11238 case LVM_GETCOLUMNW
:
11239 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11240 uMsg
== LVM_GETCOLUMNW
);
11242 case LVM_GETCOLUMNORDERARRAY
:
11243 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11245 case LVM_GETCOLUMNWIDTH
:
11246 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11248 case LVM_GETCOUNTPERPAGE
:
11249 return LISTVIEW_GetCountPerPage(infoPtr
);
11251 case LVM_GETEDITCONTROL
:
11252 return (LRESULT
)infoPtr
->hwndEdit
;
11254 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11255 return infoPtr
->dwLvExStyle
;
11257 /* case LVM_GETGROUPINFO: */
11259 /* case LVM_GETGROUPMETRICS: */
11261 case LVM_GETHEADER
:
11262 return (LRESULT
)infoPtr
->hwndHeader
;
11264 case LVM_GETHOTCURSOR
:
11265 return (LRESULT
)infoPtr
->hHotCursor
;
11267 case LVM_GETHOTITEM
:
11268 return infoPtr
->nHotItem
;
11270 case LVM_GETHOVERTIME
:
11271 return infoPtr
->dwHoverTime
;
11273 case LVM_GETIMAGELIST
:
11274 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11276 /* case LVM_GETINSERTMARK: */
11278 /* case LVM_GETINSERTMARKCOLOR: */
11280 /* case LVM_GETINSERTMARKRECT: */
11282 case LVM_GETISEARCHSTRINGA
:
11283 case LVM_GETISEARCHSTRINGW
:
11284 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11289 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11291 case LVM_GETITEMCOUNT
:
11292 return infoPtr
->nItemCount
;
11294 case LVM_GETITEMPOSITION
:
11295 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11297 case LVM_GETITEMRECT
:
11298 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11300 case LVM_GETITEMSPACING
:
11301 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11303 case LVM_GETITEMSTATE
:
11304 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11306 case LVM_GETITEMTEXTA
:
11307 case LVM_GETITEMTEXTW
:
11308 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11309 uMsg
== LVM_GETITEMTEXTW
);
11311 case LVM_GETNEXTITEM
:
11312 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11314 case LVM_GETNUMBEROFWORKAREAS
:
11315 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11318 case LVM_GETORIGIN
:
11319 if (!lParam
) return FALSE
;
11320 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11321 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11322 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11325 /* case LVM_GETOUTLINECOLOR: */
11327 /* case LVM_GETSELECTEDCOLUMN: */
11329 case LVM_GETSELECTEDCOUNT
:
11330 return LISTVIEW_GetSelectedCount(infoPtr
);
11332 case LVM_GETSELECTIONMARK
:
11333 return infoPtr
->nSelectionMark
;
11335 case LVM_GETSTRINGWIDTHA
:
11336 case LVM_GETSTRINGWIDTHW
:
11337 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11338 uMsg
== LVM_GETSTRINGWIDTHW
);
11340 case LVM_GETSUBITEMRECT
:
11341 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11343 case LVM_GETTEXTBKCOLOR
:
11344 return infoPtr
->clrTextBk
;
11346 case LVM_GETTEXTCOLOR
:
11347 return infoPtr
->clrText
;
11349 /* case LVM_GETTILEINFO: */
11351 /* case LVM_GETTILEVIEWINFO: */
11353 case LVM_GETTOOLTIPS
:
11354 if( !infoPtr
->hwndToolTip
)
11355 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11356 return (LRESULT
)infoPtr
->hwndToolTip
;
11358 case LVM_GETTOPINDEX
:
11359 return LISTVIEW_GetTopIndex(infoPtr
);
11361 case LVM_GETUNICODEFORMAT
:
11362 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11365 return infoPtr
->uView
;
11367 case LVM_GETVIEWRECT
:
11368 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11370 case LVM_GETWORKAREAS
:
11371 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11374 /* case LVM_HASGROUP: */
11377 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11379 case LVM_INSERTCOLUMNA
:
11380 case LVM_INSERTCOLUMNW
:
11381 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11382 uMsg
== LVM_INSERTCOLUMNW
);
11384 /* case LVM_INSERTGROUP: */
11386 /* case LVM_INSERTGROUPSORTED: */
11388 case LVM_INSERTITEMA
:
11389 case LVM_INSERTITEMW
:
11390 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11392 /* case LVM_INSERTMARKHITTEST: */
11394 /* case LVM_ISGROUPVIEWENABLED: */
11396 case LVM_ISITEMVISIBLE
:
11397 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11399 case LVM_MAPIDTOINDEX
:
11400 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11402 case LVM_MAPINDEXTOID
:
11403 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11405 /* case LVM_MOVEGROUP: */
11407 /* case LVM_MOVEITEMTOGROUP: */
11409 case LVM_REDRAWITEMS
:
11410 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11412 /* case LVM_REMOVEALLGROUPS: */
11414 /* case LVM_REMOVEGROUP: */
11417 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11419 case LVM_SETBKCOLOR
:
11420 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11422 /* case LVM_SETBKIMAGE: */
11424 case LVM_SETCALLBACKMASK
:
11425 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11428 case LVM_SETCOLUMNA
:
11429 case LVM_SETCOLUMNW
:
11430 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11431 uMsg
== LVM_SETCOLUMNW
);
11433 case LVM_SETCOLUMNORDERARRAY
:
11434 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11436 case LVM_SETCOLUMNWIDTH
:
11437 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11439 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11440 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11442 /* case LVM_SETGROUPINFO: */
11444 /* case LVM_SETGROUPMETRICS: */
11446 case LVM_SETHOTCURSOR
:
11447 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11449 case LVM_SETHOTITEM
:
11450 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11452 case LVM_SETHOVERTIME
:
11453 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11455 case LVM_SETICONSPACING
:
11456 return LISTVIEW_SetIconSpacing(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
11458 case LVM_SETIMAGELIST
:
11459 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11461 /* case LVM_SETINFOTIP: */
11463 /* case LVM_SETINSERTMARK: */
11465 /* case LVM_SETINSERTMARKCOLOR: */
11470 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11471 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11474 case LVM_SETITEMCOUNT
:
11475 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11477 case LVM_SETITEMPOSITION
:
11480 pt
.x
= (short)LOWORD(lParam
);
11481 pt
.y
= (short)HIWORD(lParam
);
11482 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11485 case LVM_SETITEMPOSITION32
:
11486 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11488 case LVM_SETITEMSTATE
:
11489 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11491 case LVM_SETITEMTEXTA
:
11492 case LVM_SETITEMTEXTW
:
11493 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11494 uMsg
== LVM_SETITEMTEXTW
);
11496 /* case LVM_SETOUTLINECOLOR: */
11498 /* case LVM_SETSELECTEDCOLUMN: */
11500 case LVM_SETSELECTIONMARK
:
11501 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11503 case LVM_SETTEXTBKCOLOR
:
11504 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11506 case LVM_SETTEXTCOLOR
:
11507 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11509 /* case LVM_SETTILEINFO: */
11511 /* case LVM_SETTILEVIEWINFO: */
11513 /* case LVM_SETTILEWIDTH: */
11515 case LVM_SETTOOLTIPS
:
11516 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11518 case LVM_SETUNICODEFORMAT
:
11519 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11522 return LISTVIEW_SetView(infoPtr
, wParam
);
11524 /* case LVM_SETWORKAREAS: */
11526 /* case LVM_SORTGROUPS: */
11528 case LVM_SORTITEMS
:
11529 case LVM_SORTITEMSEX
:
11530 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11531 uMsg
== LVM_SORTITEMSEX
);
11532 case LVM_SUBITEMHITTEST
:
11533 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11536 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11538 case CCM_GETVERSION
:
11539 return LISTVIEW_GetVersion(infoPtr
);
11541 case CCM_SETVERSION
:
11542 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11545 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11548 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11551 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11554 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11557 return LISTVIEW_Destroy(infoPtr
);
11560 return LISTVIEW_Enable(infoPtr
);
11562 case WM_ERASEBKGND
:
11563 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11565 case WM_GETDLGCODE
:
11566 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11569 return (LRESULT
)infoPtr
->hFont
;
11572 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11575 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11578 return LISTVIEW_KillFocus(infoPtr
);
11580 case WM_LBUTTONDBLCLK
:
11581 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11583 case WM_LBUTTONDOWN
:
11584 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11587 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11590 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11592 case WM_MOUSEHOVER
:
11593 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11596 return LISTVIEW_NCDestroy(infoPtr
);
11599 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11602 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11604 case WM_NOTIFYFORMAT
:
11605 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11607 case WM_PRINTCLIENT
:
11608 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11611 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11613 case WM_RBUTTONDBLCLK
:
11614 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11616 case WM_RBUTTONDOWN
:
11617 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11620 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11623 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11626 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11629 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11631 case WM_SHOWWINDOW
:
11632 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11634 case WM_STYLECHANGED
:
11635 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11637 case WM_STYLECHANGING
:
11638 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11640 case WM_SYSCOLORCHANGE
:
11641 COMCTL32_RefreshSysColors();
11644 /* case WM_TIMER: */
11645 case WM_THEMECHANGED
:
11646 return LISTVIEW_ThemeChanged(infoPtr
);
11649 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11651 case WM_MOUSEWHEEL
:
11652 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11653 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11654 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11656 case WM_WINDOWPOSCHANGED
:
11657 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11659 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11660 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11662 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11664 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11666 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11668 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11670 /* case WM_WININICHANGE: */
11673 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11674 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11676 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11683 * Registers the window class.
11691 void LISTVIEW_Register(void)
11693 WNDCLASSW wndClass
;
11695 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11696 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11697 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11698 wndClass
.cbClsExtra
= 0;
11699 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11700 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11701 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11702 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11703 RegisterClassW(&wndClass
);
11708 * Unregisters the window class.
11716 void LISTVIEW_Unregister(void)
11718 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11723 * Handle any WM_COMMAND messages
11726 * [I] infoPtr : valid pointer to the listview structure
11727 * [I] wParam : the first message parameter
11728 * [I] lParam : the second message parameter
11733 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11736 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11738 if (!infoPtr
->hwndEdit
) return 0;
11740 switch (HIWORD(wParam
))
11745 * Adjust the edit window size
11747 WCHAR buffer
[1024];
11748 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11749 HFONT hFont
, hOldFont
= 0;
11753 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11754 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11755 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11757 /* Select font to get the right dimension of the string */
11758 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11761 hOldFont
= SelectObject(hdc
, hFont
);
11764 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11766 TEXTMETRICW textMetric
;
11768 /* Add Extra spacing for the next character */
11769 GetTextMetricsW(hdc
, &textMetric
);
11770 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11772 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11773 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11776 SelectObject(hdc
, hOldFont
);
11778 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11784 LISTVIEW_CancelEditLabel(infoPtr
);
11789 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);