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)
81 * -- LVS_NOSCROLL (see Q137520)
85 * -- LVS_EX_BORDERSELECT
89 * -- LVS_EX_MULTIWORKAREAS
91 * -- LVS_EX_SIMPLESELECT
92 * -- LVS_EX_TWOCLICKACTIVATE
93 * -- LVS_EX_UNDERLINECOLD
94 * -- LVS_EX_UNDERLINEHOT
97 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
103 * -- LVM_ENABLEGROUPVIEW
104 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
105 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
106 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
107 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
108 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
109 * -- LVM_GETINSERTMARKRECT
110 * -- LVM_GETNUMBEROFWORKAREAS
111 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
112 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
113 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
114 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
115 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
116 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
117 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
118 * -- LVM_INSERTGROUPSORTED
119 * -- LVM_INSERTMARKHITTEST
120 * -- LVM_ISGROUPVIEWENABLED
122 * -- LVM_MOVEITEMTOGROUP
124 * -- LVM_SETTILEWIDTH
128 * -- ListView_GetHoverTime, ListView_SetHoverTime
129 * -- ListView_GetISearchString
130 * -- ListView_GetNumberOfWorkAreas
131 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
138 #include "wine/port.h"
153 #include "commctrl.h"
154 #include "comctl32.h"
157 #include "wine/debug.h"
158 #include "wine/unicode.h"
160 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
162 typedef struct tagCOLUMN_INFO
164 RECT rcHeader
; /* tracks the header's rectangle */
165 INT fmt
; /* same as LVCOLUMN.fmt */
169 typedef struct tagITEMHDR
173 } ITEMHDR
, *LPITEMHDR
;
175 typedef struct tagSUBITEM_INFO
181 typedef struct tagITEM_ID ITEM_ID
;
183 typedef struct tagITEM_INFO
194 UINT id
; /* item id */
195 HDPA item
; /* link to item data */
198 typedef struct tagRANGE
204 typedef struct tagRANGES
209 typedef struct tagITERATOR
218 typedef struct tagDELAYED_ITEM_EDIT
224 typedef struct tagLISTVIEW_INFO
228 RECT rcList
; /* This rectangle is really the window
229 * client rectangle possibly reduced by the
230 * horizontal scroll bar and/or header - see
231 * LISTVIEW_UpdateSize. This rectangle offset
232 * by the LISTVIEW_GetOrigin value is in
233 * client coordinates */
235 /* notification window */
238 BOOL bDoChangeNotify
; /* send change notification messages? */
245 INT nItemCount
; /* the number of items in the list */
246 HDPA hdpaItems
; /* array ITEM_INFO pointers */
247 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
248 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
249 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
250 RANGES selectionRanges
;
251 INT nSelectionMark
; /* item to start next multiselection from */
253 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
256 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
257 BOOL colRectsDirty
; /* trigger column rectangles requery from header */
260 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
265 PFNLVCOMPARE pfnCompare
; /* sorting callback pointer */
269 DWORD dwStyle
; /* the cached window GWL_STYLE */
270 DWORD dwLvExStyle
; /* extended listview style */
271 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
277 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
280 HIMAGELIST himlNormal
;
281 HIMAGELIST himlSmall
;
282 HIMAGELIST himlState
;
287 POINT currIconPos
; /* this is the position next icon will be placed */
291 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
293 /* marquee selection */
294 BOOL bMarqueeSelect
; /* marquee selection/highlight underway */
296 RECT marqueeRect
; /* absolute coordinates of marquee selection */
297 RECT marqueeDrawRect
; /* relative coordinates for drawing marquee */
298 POINT marqueeOrigin
; /* absolute coordinates of marquee click origin */
301 BOOL bFocus
; /* control has focus */
303 RECT rcFocus
; /* focus bounds */
314 INT ntmHeight
; /* Some cached metrics of the font used */
315 INT ntmMaxCharWidth
; /* by the listview to draw items */
318 /* mouse operation */
321 POINT ptClickPos
; /* point where the user clicked */
322 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
327 /* keyboard operation */
328 DWORD lastKeyPressTimestamp
;
330 INT nSearchParamLength
;
331 WCHAR szSearchParam
[ MAX_PATH
];
334 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
335 BOOL bIsDrawing
; /* Drawing in progress */
336 INT nMeasureItemHeight
; /* WM_MEASUREITEM result */
337 BOOL bRedraw
; /* WM_SETREDRAW switch */
340 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
346 /* How many we debug buffer to allocate */
347 #define DEBUG_BUFFERS 20
348 /* The size of a single debug buffer */
349 #define DEBUG_BUFFER_SIZE 256
351 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
352 #define SB_INTERNAL -1
354 /* maximum size of a label */
355 #define DISP_TEXT_SIZE 260
357 /* padding for items in list and small icon display modes */
358 #define WIDTH_PADDING 12
360 /* padding for items in list, report and small icon display modes */
361 #define HEIGHT_PADDING 1
363 /* offset of items in report display mode */
364 #define REPORT_MARGINX 2
366 /* padding for icon in large icon display mode
367 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
368 * that HITTEST will see.
369 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
370 * ICON_TOP_PADDING - sum of the two above.
371 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
372 * LABEL_HOR_PADDING - between text and sides of box
373 * LABEL_VERT_PADDING - between bottom of text and end of box
375 * ICON_LR_PADDING - additional width above icon size.
376 * ICON_LR_HALF - half of the above value
378 #define ICON_TOP_PADDING_NOTHITABLE 2
379 #define ICON_TOP_PADDING_HITABLE 2
380 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
381 #define ICON_BOTTOM_PADDING 4
382 #define LABEL_HOR_PADDING 5
383 #define LABEL_VERT_PADDING 7
384 #define ICON_LR_PADDING 16
385 #define ICON_LR_HALF (ICON_LR_PADDING/2)
387 /* default label width for items in list and small icon display modes */
388 #define DEFAULT_LABEL_WIDTH 40
389 /* maximum select rectangle width for empty text item in LV_VIEW_DETAILS */
390 #define MAX_EMPTYTEXT_SELECT_WIDTH 80
392 /* default column width for items in list display mode */
393 #define DEFAULT_COLUMN_WIDTH 128
395 /* Size of "line" scroll for V & H scrolls */
396 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
398 /* Padding between image and label */
399 #define IMAGE_PADDING 2
401 /* Padding behind the label */
402 #define TRAILING_LABEL_PADDING 12
403 #define TRAILING_HEADER_PADDING 11
405 /* Border for the icon caption */
406 #define CAPTION_BORDER 2
408 /* Standard DrawText flags */
409 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
410 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
411 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
413 /* Image index from state */
414 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
416 /* The time in milliseconds to reset the search in the list */
417 #define KEY_DELAY 450
419 /* Dump the LISTVIEW_INFO structure to the debug channel */
420 #define LISTVIEW_DUMP(iP) do { \
421 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
422 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
423 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
424 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
425 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
426 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
427 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
428 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
429 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
430 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
433 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
436 * forward declarations
438 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
439 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
440 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
441 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
442 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
443 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
444 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
445 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
446 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
447 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
448 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
449 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
450 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
451 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
);
452 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
);
453 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
454 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
455 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
456 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
457 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*, INT
, INT
);
459 /******** Text handling functions *************************************/
461 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
462 * text string. The string may be ANSI or Unicode, in which case
463 * the boolean isW tells us the type of the string.
465 * The name of the function tell what type of strings it expects:
466 * W: Unicode, T: ANSI/Unicode - function of isW
469 static inline BOOL
is_text(LPCWSTR text
)
471 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
474 static inline int textlenT(LPCWSTR text
, BOOL isW
)
476 return !is_text(text
) ? 0 :
477 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
480 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
483 if (isSrcW
) lstrcpynW(dest
, src
, max
);
484 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
486 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
487 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
490 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
492 LPWSTR wstr
= (LPWSTR
)text
;
494 if (!isW
&& is_text(text
))
496 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
497 wstr
= Alloc(len
* sizeof(WCHAR
));
498 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
500 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
504 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
506 if (!isW
&& is_text(wstr
)) Free (wstr
);
510 * dest is a pointer to a Unicode string
511 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
513 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
517 if (src
== LPSTR_TEXTCALLBACKW
)
519 if (is_text(*dest
)) Free(*dest
);
520 *dest
= LPSTR_TEXTCALLBACKW
;
524 LPWSTR pszText
= textdupTtoW(src
, isW
);
525 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
526 bResult
= Str_SetPtrW(dest
, pszText
);
527 textfreeT(pszText
, isW
);
533 * compares a Unicode to a Unicode/ANSI text string
535 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
537 if (!aw
) return bt
? -1 : 0;
539 if (aw
== LPSTR_TEXTCALLBACKW
)
540 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
541 if (bt
!= LPSTR_TEXTCALLBACKW
)
543 LPWSTR bw
= textdupTtoW(bt
, isW
);
544 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
552 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
554 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
555 return CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
) - CSTR_EQUAL
;
558 /******** Debugging functions *****************************************/
560 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
562 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
563 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
566 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
568 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
569 n
= min(textlenT(text
, isW
), n
);
570 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
573 static char* debug_getbuf(void)
575 static int index
= 0;
576 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
577 return buffers
[index
++ % DEBUG_BUFFERS
];
580 static inline const char* debugrange(const RANGE
*lprng
)
582 if (!lprng
) return "(null)";
583 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
586 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
588 char* buf
= debug_getbuf(), *text
= buf
;
589 int len
, size
= DEBUG_BUFFER_SIZE
;
591 if (pScrollInfo
== NULL
) return "(null)";
592 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
593 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
594 if (pScrollInfo
->fMask
& SIF_RANGE
)
595 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
597 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
598 if (pScrollInfo
->fMask
& SIF_PAGE
)
599 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
601 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
602 if (pScrollInfo
->fMask
& SIF_POS
)
603 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
605 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
606 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
607 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
609 if (len
== -1) goto end
; buf
+= len
;
612 buf
= text
+ strlen(text
);
614 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
618 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
620 if (!plvnm
) return "(null)";
621 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
622 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
623 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
624 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
627 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
629 char* buf
= debug_getbuf(), *text
= buf
;
630 int len
, size
= DEBUG_BUFFER_SIZE
;
632 if (lpLVItem
== NULL
) return "(null)";
633 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
634 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
635 if (lpLVItem
->mask
& LVIF_STATE
)
636 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
638 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
639 if (lpLVItem
->mask
& LVIF_TEXT
)
640 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
642 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
643 if (lpLVItem
->mask
& LVIF_IMAGE
)
644 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
646 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
647 if (lpLVItem
->mask
& LVIF_PARAM
)
648 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
650 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
651 if (lpLVItem
->mask
& LVIF_INDENT
)
652 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
654 if (len
== -1) goto end
; buf
+= len
;
657 buf
= text
+ strlen(text
);
659 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
663 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
665 char* buf
= debug_getbuf(), *text
= buf
;
666 int len
, size
= DEBUG_BUFFER_SIZE
;
668 if (lpColumn
== NULL
) return "(null)";
669 len
= snprintf(buf
, size
, "{");
670 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
671 if (lpColumn
->mask
& LVCF_SUBITEM
)
672 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
674 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
675 if (lpColumn
->mask
& LVCF_FMT
)
676 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
678 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
679 if (lpColumn
->mask
& LVCF_WIDTH
)
680 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
682 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
683 if (lpColumn
->mask
& LVCF_TEXT
)
684 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
686 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
687 if (lpColumn
->mask
& LVCF_IMAGE
)
688 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
690 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
691 if (lpColumn
->mask
& LVCF_ORDER
)
692 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
694 if (len
== -1) goto end
; buf
+= len
;
697 buf
= text
+ strlen(text
);
699 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
703 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
705 if (!lpht
) return "(null)";
707 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
708 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
711 /* Return the corresponding text for a given scroll value */
712 static inline LPCSTR
debugscrollcode(int nScrollCode
)
716 case SB_LINELEFT
: return "SB_LINELEFT";
717 case SB_LINERIGHT
: return "SB_LINERIGHT";
718 case SB_PAGELEFT
: return "SB_PAGELEFT";
719 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
720 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
721 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
722 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
723 case SB_INTERNAL
: return "SB_INTERNAL";
724 default: return "unknown";
729 /******** Notification functions ************************************/
731 static int get_ansi_notification(UINT unicodeNotificationCode
)
733 switch (unicodeNotificationCode
)
735 case LVN_BEGINLABELEDITA
:
736 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
737 case LVN_ENDLABELEDITA
:
738 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
739 case LVN_GETDISPINFOA
:
740 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
741 case LVN_SETDISPINFOA
:
742 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
743 case LVN_ODFINDITEMA
:
744 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
745 case LVN_GETINFOTIPA
:
746 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
747 /* header forwards */
749 case HDN_TRACKW
: return HDN_TRACKA
;
751 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
752 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
753 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
754 case HDN_ITEMCHANGINGA
:
755 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
756 case HDN_ITEMCHANGEDA
:
757 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
759 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
760 case HDN_DIVIDERDBLCLICKA
:
761 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
764 FIXME("unknown notification %x\n", unicodeNotificationCode
);
765 return unicodeNotificationCode
;
768 /* forwards header notifications to listview parent */
769 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, NMHEADERW
*lpnmhW
)
771 LPCWSTR text
= NULL
, filter
= NULL
;
773 NMHEADERA
*lpnmh
= (NMHEADERA
*) lpnmhW
;
775 /* on unicode format exit earlier */
776 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
777 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
780 /* header always supplies unicode notifications,
781 all we have to do is to convert strings to ANSI */
784 /* convert item text */
785 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
787 text
= (LPCWSTR
)lpnmh
->pitem
->pszText
;
788 Str_SetPtrWtoA(&lpnmh
->pitem
->pszText
, text
);
790 /* convert filter text */
791 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
792 lpnmh
->pitem
->pvFilter
)
794 filter
= (LPCWSTR
)((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
;
795 Str_SetPtrWtoA(&((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
, filter
);
798 lpnmh
->hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
800 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, lpnmh
->hdr
.idFrom
,
806 Free(lpnmh
->pitem
->pszText
);
807 lpnmh
->pitem
->pszText
= (LPSTR
)text
;
811 Free(((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
);
812 ((HD_TEXTFILTERA
*)lpnmh
->pitem
->pvFilter
)->pszText
= (LPSTR
)filter
;
818 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
822 TRACE("(code=%d)\n", code
);
824 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
825 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
827 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
829 TRACE(" <= %ld\n", result
);
834 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
837 HWND hwnd
= infoPtr
->hwndSelf
;
838 notify_hdr(infoPtr
, code
, &nmh
);
839 return IsWindow(hwnd
);
842 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
853 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
854 item
.iItem
= htInfo
->iItem
;
856 item
.stateMask
= (UINT
)-1;
857 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
858 nmia
.lParam
= item
.lParam
;
859 nmia
.uOldState
= item
.state
;
860 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
861 nmia
.uChanged
= LVIF_STATE
;
864 nmia
.iItem
= htInfo
->iItem
;
865 nmia
.iSubItem
= htInfo
->iSubItem
;
866 nmia
.ptAction
= htInfo
->pt
;
868 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
869 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
870 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
872 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
875 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
877 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
878 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
881 /* Handles NM_DBLCLK, NM_CLICK, NM_RDBLCLK, NM_RCLICK. Only NM_RCLICK return value is used. */
882 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
886 HWND hwnd
= infoPtr
->hwndSelf
;
889 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
890 ZeroMemory(&nmia
, sizeof(nmia
));
891 nmia
.iItem
= lvht
->iItem
;
892 nmia
.iSubItem
= lvht
->iSubItem
;
893 nmia
.ptAction
= lvht
->pt
;
894 item
.mask
= LVIF_PARAM
;
895 item
.iItem
= lvht
->iItem
;
897 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
898 ret
= notify_hdr(infoPtr
, code
, (NMHDR
*)&nmia
);
899 return IsWindow(hwnd
) && (code
== NM_RCLICK
? !ret
: TRUE
);
902 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
906 HWND hwnd
= infoPtr
->hwndSelf
;
908 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
910 item
.mask
= LVIF_PARAM
;
913 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
914 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
915 return IsWindow(hwnd
);
919 Send notification. depends on dispinfoW having same
920 structure as dispinfoA.
921 infoPtr : listview struct
922 code : *Unicode* notification code
923 pdi : dispinfo structure (can be unicode or ansi)
924 isW : TRUE if dispinfo is Unicode
926 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT code
, LPNMLVDISPINFOW pdi
, BOOL isW
)
928 INT length
= 0, ret_length
;
929 LPWSTR buffer
= NULL
, ret_text
;
930 BOOL return_ansi
= FALSE
;
931 BOOL return_unicode
= FALSE
;
934 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_text(pdi
->item
.pszText
))
936 return_unicode
= ( isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
937 return_ansi
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
940 ret_length
= pdi
->item
.cchTextMax
;
941 ret_text
= pdi
->item
.pszText
;
943 if (return_unicode
|| return_ansi
)
945 if (code
!= LVN_GETDISPINFOW
)
947 length
= return_ansi
?
948 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
949 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
953 length
= pdi
->item
.cchTextMax
;
954 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
957 buffer
= Alloc( (return_ansi
? sizeof(WCHAR
) : sizeof(CHAR
)) * length
);
958 if (!buffer
) return FALSE
;
961 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
964 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
967 pdi
->item
.pszText
= buffer
;
968 pdi
->item
.cchTextMax
= length
;
971 if (infoPtr
->notifyFormat
== NFR_ANSI
)
972 code
= get_ansi_notification(code
);
974 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
975 ret
= notify_hdr(infoPtr
, code
, &pdi
->hdr
);
976 TRACE(" resulting code=%d\n", pdi
->hdr
.code
);
978 if (return_ansi
|| return_unicode
)
980 if (return_ansi
&& (pdi
->hdr
.code
== LVN_GETDISPINFOA
))
982 strcpy((char*)ret_text
, (char*)pdi
->item
.pszText
);
984 else if (return_unicode
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
))
986 strcpyW(ret_text
, pdi
->item
.pszText
);
988 else if (return_ansi
) /* note : pointer can be changed by app ! */
990 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) ret_text
,
991 ret_length
, NULL
, NULL
);
994 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
995 ret_text
, ret_length
);
997 pdi
->item
.pszText
= ret_text
; /* restores our buffer */
998 pdi
->item
.cchTextMax
= ret_length
;
1004 /* if dipsinfo holder changed notification code then convert */
1005 if (!isW
&& (pdi
->hdr
.code
== LVN_GETDISPINFOW
) && (pdi
->item
.mask
& LVIF_TEXT
))
1007 length
= WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
1009 buffer
= Alloc(length
* sizeof(CHAR
));
1010 if (!buffer
) return FALSE
;
1012 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) buffer
,
1013 ret_length
, NULL
, NULL
);
1015 strcpy((LPSTR
)pdi
->item
.pszText
, (LPSTR
)buffer
);
1022 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
1023 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
1025 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
1026 lpnmlvcd
->nmcd
.hdc
= hdc
;
1027 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
1028 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
1029 lpnmlvcd
->clrText
= infoPtr
->clrText
;
1030 if (!lplvItem
) return;
1031 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
1032 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
1033 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
1034 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
1035 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
1036 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
1039 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1041 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
1044 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
1045 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
1046 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
1047 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
1048 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
1049 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
1053 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
1055 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
1056 lpnmlvcd
->clrTextBk
= comctl32_color
.clrWindow
;
1057 if (lpnmlvcd
->clrText
== CLR_DEFAULT
)
1058 lpnmlvcd
->clrText
= comctl32_color
.clrWindowText
;
1060 /* apparently, for selected items, we have to override the returned values */
1063 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1065 if (infoPtr
->bFocus
)
1067 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1068 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1070 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1072 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1073 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1078 /* Set the text attributes */
1079 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
1081 SetBkMode(hdc
, OPAQUE
);
1082 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
1085 SetBkMode(hdc
, TRANSPARENT
);
1086 SetTextColor(hdc
, lpnmlvcd
->clrText
);
1089 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1091 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1094 /* returns TRUE when repaint needed, FALSE otherwise */
1095 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1097 MEASUREITEMSTRUCT mis
;
1098 mis
.CtlType
= ODT_LISTVIEW
;
1099 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1103 mis
.itemHeight
= infoPtr
->nItemHeight
;
1104 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1105 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1107 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1113 /******** Item iterator functions **********************************/
1115 static RANGES
ranges_create(int count
);
1116 static void ranges_destroy(RANGES ranges
);
1117 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1118 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1119 static void ranges_dump(RANGES ranges
);
1121 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1123 RANGE range
= { nItem
, nItem
+ 1 };
1125 return ranges_add(ranges
, range
);
1128 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1130 RANGE range
= { nItem
, nItem
+ 1 };
1132 return ranges_del(ranges
, range
);
1136 * ITERATOR DOCUMENTATION
1138 * The iterator functions allow for easy, and convenient iteration
1139 * over items of interest in the list. Typically, you create a
1140 * iterator, use it, and destroy it, as such:
1143 * iterator_xxxitems(&i, ...);
1144 * while (iterator_{prev,next}(&i)
1146 * //code which uses i.nItem
1148 * iterator_destroy(&i);
1150 * where xxx is either: framed, or visible.
1151 * Note that it is important that the code destroys the iterator
1152 * after it's done with it, as the creation of the iterator may
1153 * allocate memory, which thus needs to be freed.
1155 * You can iterate both forwards, and backwards through the list,
1156 * by using iterator_next or iterator_prev respectively.
1158 * Lower numbered items are draw on top of higher number items in
1159 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1160 * items may overlap). So, to test items, you should use
1162 * which lists the items top to bottom (in Z-order).
1163 * For drawing items, you should use
1165 * which lists the items bottom to top (in Z-order).
1166 * If you keep iterating over the items after the end-of-items
1167 * marker (-1) is returned, the iterator will start from the
1168 * beginning. Typically, you don't need to test for -1,
1169 * because iterator_{next,prev} will return TRUE if more items
1170 * are to be iterated over, or FALSE otherwise.
1172 * Note: the iterator is defined to be bidirectional. That is,
1173 * any number of prev followed by any number of next, or
1174 * five versa, should leave the iterator at the same item:
1175 * prev * n, next * n = next * n, prev * n
1177 * The iterator has a notion of an out-of-order, special item,
1178 * which sits at the start of the list. This is used in
1179 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1180 * which needs to be first, as it may overlap other items.
1182 * The code is a bit messy because we have:
1183 * - a special item to deal with
1184 * - simple range, or composite range
1186 * If you find bugs, or want to add features, please make sure you
1187 * always check/modify *both* iterator_prev, and iterator_next.
1191 * This function iterates through the items in increasing order,
1192 * but prefixed by the special item, then -1. That is:
1193 * special, 1, 2, 3, ..., n, -1.
1194 * Each item is listed only once.
1196 static inline BOOL
iterator_next(ITERATOR
* i
)
1200 i
->nItem
= i
->nSpecial
;
1201 if (i
->nItem
!= -1) return TRUE
;
1203 if (i
->nItem
== i
->nSpecial
)
1205 if (i
->ranges
) i
->index
= 0;
1211 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1212 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1217 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1218 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1221 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1223 i
->nItem
= i
->range
.lower
;
1224 if (i
->nItem
>= 0) goto testitem
;
1231 * This function iterates through the items in decreasing order,
1232 * followed by the special item, then -1. That is:
1233 * n, n-1, ..., 3, 2, 1, special, -1.
1234 * Each item is listed only once.
1236 static inline BOOL
iterator_prev(ITERATOR
* i
)
1243 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1246 if (i
->nItem
== i
->nSpecial
)
1254 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1255 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1261 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1264 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1266 i
->nItem
= i
->range
.upper
;
1267 if (i
->nItem
> 0) goto testitem
;
1269 return (i
->nItem
= i
->nSpecial
) != -1;
1272 static RANGE
iterator_range(const ITERATOR
*i
)
1276 if (!i
->ranges
) return i
->range
;
1278 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1280 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1281 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1283 else range
.lower
= range
.upper
= 0;
1289 * Releases resources associated with this iterator.
1291 static inline void iterator_destroy(const ITERATOR
*i
)
1293 ranges_destroy(i
->ranges
);
1297 * Create an empty iterator.
1299 static inline BOOL
iterator_empty(ITERATOR
* i
)
1301 ZeroMemory(i
, sizeof(*i
));
1302 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1307 * Create an iterator over a range.
1309 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1317 * Create an iterator over a bunch of ranges.
1318 * Please note that the iterator will take ownership of the ranges,
1319 * and will free them upon destruction.
1321 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1329 * Creates an iterator over the items which intersect frame.
1330 * Uses absolute coordinates rather than compensating for the current offset.
1332 static BOOL
iterator_frameditems_absolute(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*frame
)
1334 RECT rcItem
, rcTemp
;
1336 /* in case we fail, we want to return an empty iterator */
1337 if (!iterator_empty(i
)) return FALSE
;
1339 TRACE("(frame=%s)\n", wine_dbgstr_rect(frame
));
1341 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1345 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1347 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1348 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1349 i
->nSpecial
= infoPtr
->nFocusedItem
;
1351 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1352 /* to do better here, we need to have PosX, and PosY sorted */
1353 TRACE("building icon ranges:\n");
1354 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1356 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1357 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1358 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1359 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1360 if (IntersectRect(&rcTemp
, &rcItem
, frame
))
1361 ranges_additem(i
->ranges
, nItem
);
1365 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1369 if (frame
->left
>= infoPtr
->nItemWidth
) return TRUE
;
1370 if (frame
->top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1372 range
.lower
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1373 range
.upper
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1374 if (range
.upper
<= range
.lower
) return TRUE
;
1375 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1376 TRACE(" report=%s\n", debugrange(&i
->range
));
1380 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1381 INT nFirstRow
= max(frame
->top
/ infoPtr
->nItemHeight
, 0);
1382 INT nLastRow
= min((frame
->bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1389 if (infoPtr
->nItemWidth
)
1391 nFirstCol
= max(frame
->left
/ infoPtr
->nItemWidth
, 0);
1392 nLastCol
= min((frame
->right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1396 nFirstCol
= max(frame
->left
, 0);
1397 nLastCol
= min(frame
->right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1400 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1402 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1403 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1405 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1407 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1408 TRACE("building list ranges:\n");
1409 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1411 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1412 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1413 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1414 TRACE(" list=%s\n", debugrange(&item_range
));
1415 ranges_add(i
->ranges
, item_range
);
1423 * Creates an iterator over the items which intersect lprc.
1425 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1430 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1432 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1433 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1435 return iterator_frameditems_absolute(i
, infoPtr
, &frame
);
1439 * Creates an iterator over the items which intersect the visible region of hdc.
1441 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1443 POINT Origin
, Position
;
1444 RECT rcItem
, rcClip
;
1447 rgntype
= GetClipBox(hdc
, &rcClip
);
1448 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1449 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1450 if (rgntype
== SIMPLEREGION
) return TRUE
;
1452 /* first deal with the special item */
1453 if (i
->nSpecial
!= -1)
1455 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1456 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1459 /* if we can't deal with the region, we'll just go with the simple range */
1460 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1461 TRACE("building visible range:\n");
1462 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1464 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1465 if (!ranges_add(i
->ranges
, i
->range
))
1467 ranges_destroy(i
->ranges
);
1473 /* now delete the invisible items from the list */
1474 while(iterator_next(i
))
1476 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1477 rcItem
.left
= (infoPtr
->uView
== LV_VIEW_DETAILS
) ? Origin
.x
: Position
.x
+ Origin
.x
;
1478 rcItem
.top
= Position
.y
+ Origin
.y
;
1479 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1480 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1481 if (!RectVisible(hdc
, &rcItem
))
1482 ranges_delitem(i
->ranges
, i
->nItem
);
1484 /* the iterator should restart on the next iterator_next */
1490 /* Remove common elements from two iterators */
1491 /* Passed iterators have to point on the first elements */
1492 static BOOL
iterator_remove_common_items(ITERATOR
*iter1
, ITERATOR
*iter2
)
1494 if(!iter1
->ranges
|| !iter2
->ranges
) {
1497 if(iter1
->ranges
|| iter2
->ranges
||
1498 (iter1
->range
.lower
<iter2
->range
.lower
&& iter1
->range
.upper
>iter2
->range
.upper
) ||
1499 (iter1
->range
.lower
>iter2
->range
.lower
&& iter1
->range
.upper
<iter2
->range
.upper
)) {
1500 ERR("result is not a one range iterator\n");
1504 if(iter1
->range
.lower
==-1 || iter2
->range
.lower
==-1)
1507 lower
= iter1
->range
.lower
;
1508 upper
= iter1
->range
.upper
;
1510 if(lower
< iter2
->range
.lower
)
1511 iter1
->range
.upper
= iter2
->range
.lower
;
1512 else if(upper
> iter2
->range
.upper
)
1513 iter1
->range
.lower
= iter2
->range
.upper
;
1515 iter1
->range
.lower
= iter1
->range
.upper
= -1;
1517 if(iter2
->range
.lower
< lower
)
1518 iter2
->range
.upper
= lower
;
1519 else if(iter2
->range
.upper
> upper
)
1520 iter2
->range
.lower
= upper
;
1522 iter2
->range
.lower
= iter2
->range
.upper
= -1;
1527 iterator_next(iter1
);
1528 iterator_next(iter2
);
1531 if(iter1
->nItem
==-1 || iter2
->nItem
==-1)
1534 if(iter1
->nItem
== iter2
->nItem
) {
1535 int delete = iter1
->nItem
;
1537 iterator_prev(iter1
);
1538 iterator_prev(iter2
);
1539 ranges_delitem(iter1
->ranges
, delete);
1540 ranges_delitem(iter2
->ranges
, delete);
1541 iterator_next(iter1
);
1542 iterator_next(iter2
);
1543 } else if(iter1
->nItem
> iter2
->nItem
)
1544 iterator_next(iter2
);
1546 iterator_next(iter1
);
1549 iter1
->nItem
= iter1
->range
.lower
= iter1
->range
.upper
= -1;
1550 iter2
->nItem
= iter2
->range
.lower
= iter2
->range
.upper
= -1;
1554 /******** Misc helper functions ************************************/
1556 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1557 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1559 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1560 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1563 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1565 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1566 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1569 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1571 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1572 if(state
== 1 || state
== 2)
1576 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1577 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1578 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1582 /* this should be called after window style got updated,
1583 it used to reset view state to match current window style */
1584 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1586 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1589 infoPtr
->uView
= LV_VIEW_ICON
;
1592 infoPtr
->uView
= LV_VIEW_DETAILS
;
1595 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1598 infoPtr
->uView
= LV_VIEW_LIST
;
1602 /* computes next item id value */
1603 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1605 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1609 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1610 return lpID
->id
+ 1;
1615 /******** Internal API functions ************************************/
1617 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1619 static COLUMN_INFO mainItem
;
1621 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1622 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1624 /* update cached column rectangles */
1625 if (infoPtr
->colRectsDirty
)
1628 LISTVIEW_INFO
*Ptr
= (LISTVIEW_INFO
*)infoPtr
;
1631 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++) {
1632 info
= DPA_GetPtr(infoPtr
->hdpaColumns
, i
);
1633 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, i
, (LPARAM
)&info
->rcHeader
);
1635 Ptr
->colRectsDirty
= FALSE
;
1638 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1641 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1643 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1646 if (infoPtr
->hwndHeader
) return 0;
1648 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1650 /* setup creation flags */
1651 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1652 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1654 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1657 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1658 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1659 if (!infoPtr
->hwndHeader
) return -1;
1661 /* set header unicode format */
1662 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1664 /* set header font */
1665 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, TRUE
);
1667 /* set header image list */
1668 if (infoPtr
->himlSmall
)
1669 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)infoPtr
->himlSmall
);
1671 LISTVIEW_UpdateSize(infoPtr
);
1676 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1678 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1681 static inline BOOL
LISTVIEW_IsHeaderEnabled(const LISTVIEW_INFO
*infoPtr
)
1683 return (infoPtr
->uView
== LV_VIEW_DETAILS
||
1684 infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
) &&
1685 !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
);
1688 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1690 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1693 /* used to handle collapse main item column case */
1694 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1696 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1697 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1700 /* Listview invalidation functions: use _only_ these functions to invalidate */
1702 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1704 return infoPtr
->bRedraw
;
1707 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1709 if(!is_redrawing(infoPtr
)) return;
1710 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1711 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1714 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1718 if(!is_redrawing(infoPtr
)) return;
1719 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1720 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1723 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1725 POINT Origin
, Position
;
1728 if(!is_redrawing(infoPtr
)) return;
1729 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1730 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1731 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1732 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1734 rcBox
.bottom
= infoPtr
->nItemHeight
;
1735 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1736 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1739 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1741 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1744 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1748 if(!is_redrawing(infoPtr
)) return;
1749 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1750 rcCol
.top
= infoPtr
->rcList
.top
;
1751 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1752 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1757 * Retrieves the number of items that can fit vertically in the client area.
1760 * [I] infoPtr : valid pointer to the listview structure
1763 * Number of items per row.
1765 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1767 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1769 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1774 * Retrieves the number of items that can fit horizontally in the client
1778 * [I] infoPtr : valid pointer to the listview structure
1781 * Number of items per column.
1783 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1785 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1787 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1791 /*************************************************************************
1792 * LISTVIEW_ProcessLetterKeys
1794 * Processes keyboard messages generated by pressing the letter keys
1796 * What this does is perform a case insensitive search from the
1797 * current position with the following quirks:
1798 * - If two chars or more are pressed in quick succession we search
1799 * for the corresponding string (e.g. 'abc').
1800 * - If there is a delay we wipe away the current search string and
1801 * restart with just that char.
1802 * - If the user keeps pressing the same character, whether slowly or
1803 * fast, so that the search string is entirely composed of this
1804 * character ('aaaaa' for instance), then we search for first item
1805 * that starting with that character.
1806 * - If the user types the above character in quick succession, then
1807 * we must also search for the corresponding string ('aaaaa'), and
1808 * go to that string if there is a match.
1811 * [I] hwnd : handle to the window
1812 * [I] charCode : the character code, the actual character
1813 * [I] keyData : key data
1821 * - The current implementation has a list of characters it will
1822 * accept and it ignores everything else. In particular it will
1823 * ignore accentuated characters which seems to match what
1824 * Windows does. But I'm not sure it makes sense to follow
1826 * - We don't sound a beep when the search fails.
1830 * TREEVIEW_ProcessLetterKeys
1832 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1834 WCHAR buffer
[MAX_PATH
];
1841 /* simple parameter checking */
1842 if (!charCode
|| !keyData
|| infoPtr
->nItemCount
== 0) return 0;
1844 /* only allow the valid WM_CHARs through */
1845 if (!isalnumW(charCode
) &&
1846 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1847 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1848 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1849 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1850 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1851 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1852 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1853 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1854 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1857 /* update the search parameters */
1858 prevTime
= infoPtr
->lastKeyPressTimestamp
;
1859 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1860 diff
= infoPtr
->lastKeyPressTimestamp
- prevTime
;
1862 if (diff
>= 0 && diff
< KEY_DELAY
)
1864 if (infoPtr
->nSearchParamLength
< MAX_PATH
- 1)
1865 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++] = charCode
;
1867 if (infoPtr
->charCode
!= charCode
)
1868 infoPtr
->charCode
= charCode
= 0;
1872 infoPtr
->charCode
= charCode
;
1873 infoPtr
->szSearchParam
[0] = charCode
;
1874 infoPtr
->nSearchParamLength
= 1;
1877 /* should start from next after focused item, so next item that matches
1878 will be selected, if there isn't any and focused matches it will be selected
1879 on second search stage from beginning of the list */
1880 if (infoPtr
->nFocusedItem
>= 0 && infoPtr
->nItemCount
> 1)
1882 /* with some accumulated search data available start with current focus, otherwise
1883 it's excluded from search */
1884 startidx
= infoPtr
->nSearchParamLength
> 1 ? infoPtr
->nFocusedItem
: infoPtr
->nFocusedItem
+ 1;
1885 if (startidx
== infoPtr
->nItemCount
) startidx
= 0;
1890 /* let application handle this for virtual listview */
1891 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1895 memset(&nmlv
.lvfi
, 0, sizeof(nmlv
.lvfi
));
1896 nmlv
.lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1897 nmlv
.lvfi
.psz
= infoPtr
->szSearchParam
;
1898 nmlv
.iStart
= startidx
;
1900 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = 0;
1902 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1906 int i
= startidx
, endidx
;
1908 /* and search from the current position */
1910 endidx
= infoPtr
->nItemCount
;
1912 /* first search in [startidx, endidx), on failure continue in [0, startidx) */
1915 /* start from first item if not found with >= startidx */
1916 if (i
== infoPtr
->nItemCount
&& startidx
> 0)
1922 for (i
= startidx
; i
< endidx
; i
++)
1925 item
.mask
= LVIF_TEXT
;
1928 item
.pszText
= buffer
;
1929 item
.cchTextMax
= MAX_PATH
;
1930 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1932 if (!lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, infoPtr
->nSearchParamLength
))
1937 /* this is used to find first char match when search string is not available yet,
1938 otherwise every WM_CHAR will search to next item by first char, ignoring that we're
1939 already waiting for user to complete a string */
1940 else if (nItem
== -1 && infoPtr
->nSearchParamLength
== 1 && !lstrncmpiW(item
.pszText
, infoPtr
->szSearchParam
, 1))
1942 /* this would work but we must keep looking for a longer match */
1947 if ( nItem
!= -1 || /* found something */
1948 endidx
!= infoPtr
->nItemCount
|| /* second search done */
1949 (startidx
== 0 && endidx
== infoPtr
->nItemCount
) /* full range for first search */ )
1955 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1960 /*************************************************************************
1961 * LISTVIEW_UpdateHeaderSize [Internal]
1963 * Function to resize the header control
1966 * [I] hwnd : handle to a window
1967 * [I] nNewScrollPos : scroll pos to set
1972 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1977 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1979 if (!infoPtr
->hwndHeader
) return;
1981 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1982 point
[0].x
= winRect
.left
;
1983 point
[0].y
= winRect
.top
;
1984 point
[1].x
= winRect
.right
;
1985 point
[1].y
= winRect
.bottom
;
1987 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1988 point
[0].x
= -nNewScrollPos
;
1989 point
[1].x
+= nNewScrollPos
;
1991 SetWindowPos(infoPtr
->hwndHeader
,0,
1992 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1993 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1994 SWP_NOZORDER
| SWP_NOACTIVATE
);
1999 * Update the scrollbars. This functions should be called whenever
2000 * the content, size or view changes.
2003 * [I] infoPtr : valid pointer to the listview structure
2008 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
2010 SCROLLINFO horzInfo
, vertInfo
;
2013 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
2015 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
2016 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
2017 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2019 /* for now, we'll set info.nMax to the _count_, and adjust it later */
2020 if (infoPtr
->uView
== LV_VIEW_LIST
)
2022 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
2023 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
2025 /* scroll by at least one column per page */
2026 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
2027 horzInfo
.nPage
= infoPtr
->nItemWidth
;
2029 if (infoPtr
->nItemWidth
)
2030 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
2032 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2034 horzInfo
.nMax
= infoPtr
->nItemWidth
;
2036 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2040 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
2043 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
2045 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
))
2050 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2051 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2053 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2054 horzInfo
.nMax
= rcHeader
.right
;
2055 TRACE("horzInfo.nMax=%d\n", horzInfo
.nMax
);
2059 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2060 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
2061 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
2062 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
2063 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
2065 /* Setting the horizontal scroll can change the listview size
2066 * (and potentially everything else) so we need to recompute
2067 * everything again for the vertical scroll
2070 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
2071 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
2072 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2074 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2076 vertInfo
.nMax
= infoPtr
->nItemCount
;
2078 /* scroll by at least one page */
2079 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
2080 vertInfo
.nPage
= infoPtr
->nItemHeight
;
2082 if (infoPtr
->nItemHeight
> 0)
2083 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
2085 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
2089 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
2092 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
2093 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
2094 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
2095 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
2096 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
2098 /* Change of the range may have changed the scroll pos. If so move the content */
2099 if (dx
!= 0 || dy
!= 0)
2102 listRect
= infoPtr
->rcList
;
2103 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
2104 SW_ERASE
| SW_INVALIDATE
);
2107 /* Update the Header Control */
2108 if (infoPtr
->hwndHeader
)
2110 horzInfo
.fMask
= SIF_POS
;
2111 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
2112 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
2119 * Shows/hides the focus rectangle.
2122 * [I] infoPtr : valid pointer to the listview structure
2123 * [I] fShow : TRUE to show the focus, FALSE to hide it.
2128 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
2132 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
2134 if (infoPtr
->nFocusedItem
< 0) return;
2136 /* we need some gymnastics in ICON mode to handle large items */
2137 if (infoPtr
->uView
== LV_VIEW_ICON
)
2141 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
2142 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
2144 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
2149 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
2151 /* for some reason, owner draw should work only in report mode */
2152 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
2157 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2158 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2160 item
.iItem
= infoPtr
->nFocusedItem
;
2162 item
.mask
= LVIF_PARAM
;
2163 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
2165 ZeroMemory(&dis
, sizeof(dis
));
2166 dis
.CtlType
= ODT_LISTVIEW
;
2167 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
2168 dis
.itemID
= item
.iItem
;
2169 dis
.itemAction
= ODA_FOCUS
;
2170 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
2171 dis
.hwndItem
= infoPtr
->hwndSelf
;
2173 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
2174 dis
.itemData
= item
.lParam
;
2176 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
2178 SelectObject(hdc
, hOldFont
);
2182 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
2185 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2189 * Invalidates all visible selected items.
2191 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
2195 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
2196 while(iterator_next(&i
))
2198 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2199 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2201 iterator_destroy(&i
);
2206 * DESCRIPTION: [INTERNAL]
2207 * Computes an item's (left,top) corner, relative to rcView.
2208 * That is, the position has NOT been made relative to the Origin.
2209 * This is deliberate, to avoid computing the Origin over, and
2210 * over again, when this function is called in a loop. Instead,
2211 * one can factor the computation of the Origin before the loop,
2212 * and offset the value returned by this function, on every iteration.
2215 * [I] infoPtr : valid pointer to the listview structure
2216 * [I] nItem : item number
2217 * [O] lpptOrig : item top, left corner
2222 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2224 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2226 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2228 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2229 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2231 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2233 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2234 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2235 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2237 else /* LV_VIEW_DETAILS */
2239 lpptPosition
->x
= REPORT_MARGINX
;
2240 /* item is always at zero indexed column */
2241 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2242 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2243 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2248 * DESCRIPTION: [INTERNAL]
2249 * Compute the rectangles of an item. This is to localize all
2250 * the computations in one place. If you are not interested in some
2251 * of these values, simply pass in a NULL -- the function is smart
2252 * enough to compute only what's necessary. The function computes
2253 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2254 * one, the BOX rectangle. This rectangle is very cheap to compute,
2255 * and is guaranteed to contain all the other rectangles. Computing
2256 * the ICON rect is also cheap, but all the others are potentially
2257 * expensive. This gives an easy and effective optimization when
2258 * searching (like point inclusion, or rectangle intersection):
2259 * first test against the BOX, and if TRUE, test against the desired
2261 * If the function does not have all the necessary information
2262 * to computed the requested rectangles, will crash with a
2263 * failed assertion. This is done so we catch all programming
2264 * errors, given that the function is called only from our code.
2266 * We have the following 'special' meanings for a few fields:
2267 * * If LVIS_FOCUSED is set, we assume the item has the focus
2268 * This is important in ICON mode, where it might get a larger
2269 * then usual rectangle
2271 * Please note that subitem support works only in REPORT mode.
2274 * [I] infoPtr : valid pointer to the listview structure
2275 * [I] lpLVItem : item to compute the measures for
2276 * [O] lprcBox : ptr to Box rectangle
2277 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2278 * [0] lprcSelectBox : ptr to select box rectangle
2279 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2280 * [O] lprcIcon : ptr to Icon rectangle
2281 * Same as LVM_GETITEMRECT with LVIR_ICON
2282 * [O] lprcStateIcon: ptr to State Icon rectangle
2283 * [O] lprcLabel : ptr to Label rectangle
2284 * Same as LVM_GETITEMRECT with LVIR_LABEL
2289 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2290 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2291 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2293 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2294 RECT Box
, SelectBox
, Icon
, Label
;
2295 COLUMN_INFO
*lpColumnInfo
= NULL
;
2296 SIZE labelSize
= { 0, 0 };
2298 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2300 /* Be smart and try to figure out the minimum we have to do */
2301 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2302 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2304 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2305 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2307 if (lprcSelectBox
) doSelectBox
= TRUE
;
2308 if (lprcLabel
) doLabel
= TRUE
;
2309 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2316 /************************************************************/
2317 /* compute the box rectangle (it should be cheap to do) */
2318 /************************************************************/
2319 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2320 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2322 if (lpLVItem
->iSubItem
)
2324 Box
= lpColumnInfo
->rcHeader
;
2329 Box
.right
= infoPtr
->nItemWidth
;
2332 Box
.bottom
= infoPtr
->nItemHeight
;
2334 /******************************************************************/
2335 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2336 /******************************************************************/
2339 LONG state_width
= 0;
2341 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2342 state_width
= infoPtr
->iconStateSize
.cx
;
2344 if (infoPtr
->uView
== LV_VIEW_ICON
)
2346 Icon
.left
= Box
.left
+ state_width
;
2347 if (infoPtr
->himlNormal
)
2348 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2349 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2350 Icon
.right
= Icon
.left
;
2351 Icon
.bottom
= Icon
.top
;
2352 if (infoPtr
->himlNormal
)
2354 Icon
.right
+= infoPtr
->iconSize
.cx
;
2355 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2358 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2360 Icon
.left
= Box
.left
+ state_width
;
2362 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2364 /* we need the indent in report mode */
2365 assert(lpLVItem
->mask
& LVIF_INDENT
);
2366 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2370 Icon
.right
= Icon
.left
;
2371 if (infoPtr
->himlSmall
&&
2372 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 ||
2373 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2374 Icon
.right
+= infoPtr
->iconSize
.cx
;
2375 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2377 if(lprcIcon
) *lprcIcon
= Icon
;
2378 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2380 /* TODO: is this correct? */
2383 lprcStateIcon
->left
= Icon
.left
- state_width
;
2384 lprcStateIcon
->right
= Icon
.left
;
2385 lprcStateIcon
->top
= Icon
.top
;
2386 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2387 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2390 else Icon
.right
= 0;
2392 /************************************************************/
2393 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2394 /************************************************************/
2397 /* calculate how far to the right can the label stretch */
2398 Label
.right
= Box
.right
;
2399 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2401 if (lpLVItem
->iSubItem
== 0)
2403 /* we need a zero based rect here */
2404 Label
= lpColumnInfo
->rcHeader
;
2405 OffsetRect(&Label
, -Label
.left
, 0);
2409 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2411 labelSize
.cx
= infoPtr
->nItemWidth
;
2412 labelSize
.cy
= infoPtr
->nItemHeight
;
2416 /* we need the text in non owner draw mode */
2417 assert(lpLVItem
->mask
& LVIF_TEXT
);
2418 if (is_text(lpLVItem
->pszText
))
2420 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2421 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2422 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2426 /* compute rough rectangle where the label will go */
2427 SetRectEmpty(&rcText
);
2428 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2429 rcText
.bottom
= infoPtr
->nItemHeight
;
2430 if (infoPtr
->uView
== LV_VIEW_ICON
)
2431 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2433 /* now figure out the flags */
2434 if (infoPtr
->uView
== LV_VIEW_ICON
)
2435 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2437 uFormat
= LV_SL_DT_FLAGS
;
2439 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2441 if (rcText
.right
!= rcText
.left
)
2442 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2444 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2446 SelectObject(hdc
, hOldFont
);
2447 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2451 if (infoPtr
->uView
== LV_VIEW_ICON
)
2453 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2454 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2455 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2456 Label
.right
= Label
.left
+ labelSize
.cx
;
2457 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2458 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2460 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2461 labelSize
.cy
/= infoPtr
->ntmHeight
;
2462 labelSize
.cy
= max(labelSize
.cy
, 1);
2463 labelSize
.cy
*= infoPtr
->ntmHeight
;
2465 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2467 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2469 Label
.left
= Icon
.right
;
2470 Label
.top
= Box
.top
;
2471 Label
.right
= lpLVItem
->iSubItem
? lpColumnInfo
->rcHeader
.right
:
2472 lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
2473 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2475 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2477 Label
.left
= Icon
.right
;
2478 Label
.top
= Box
.top
;
2479 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2480 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2483 if (lprcLabel
) *lprcLabel
= Label
;
2484 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2487 /************************************************************/
2488 /* compute SELECT bounding box */
2489 /************************************************************/
2492 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2494 SelectBox
.left
= Icon
.left
;
2495 SelectBox
.top
= Box
.top
;
2496 SelectBox
.bottom
= Box
.bottom
;
2499 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2501 SelectBox
.right
= min(Label
.left
+ MAX_EMPTYTEXT_SELECT_WIDTH
, Label
.right
);
2505 UnionRect(&SelectBox
, &Icon
, &Label
);
2507 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2508 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2511 /* Fix the Box if necessary */
2514 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2515 else *lprcBox
= Box
;
2517 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2521 * DESCRIPTION: [INTERNAL]
2524 * [I] infoPtr : valid pointer to the listview structure
2525 * [I] nItem : item number
2526 * [O] lprcBox : ptr to Box rectangle
2531 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2533 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2534 POINT Position
, Origin
;
2537 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2538 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2540 /* Be smart and try to figure out the minimum we have to do */
2542 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2543 lvItem
.mask
|= LVIF_TEXT
;
2544 lvItem
.iItem
= nItem
;
2545 lvItem
.iSubItem
= 0;
2546 lvItem
.pszText
= szDispText
;
2547 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2548 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2549 if (infoPtr
->uView
== LV_VIEW_ICON
)
2551 lvItem
.mask
|= LVIF_STATE
;
2552 lvItem
.stateMask
= LVIS_FOCUSED
;
2553 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2555 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2557 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2558 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2560 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2563 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2566 /* LISTVIEW_MapIdToIndex helper */
2567 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2569 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2570 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2572 if (id1
->id
== id2
->id
) return 0;
2574 return (id1
->id
< id2
->id
) ? -1 : 1;
2579 * Returns the item index for id specified.
2582 * [I] infoPtr : valid pointer to the listview structure
2583 * [I] iID : item id to get index for
2586 * Item index, or -1 on failure.
2588 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2593 TRACE("iID=%d\n", iID
);
2595 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2596 if (infoPtr
->nItemCount
== 0) return -1;
2599 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, MapIdSearchCompare
, 0, DPAS_SORTED
);
2603 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2604 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2612 * Returns the item id for index given.
2615 * [I] infoPtr : valid pointer to the listview structure
2616 * [I] iItem : item index to get id for
2621 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2626 TRACE("iItem=%d\n", iItem
);
2628 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2629 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2631 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2632 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2634 return lpItem
->id
->id
;
2639 * Returns the current icon position, and advances it along the top.
2640 * The returned position is not offset by Origin.
2643 * [I] infoPtr : valid pointer to the listview structure
2644 * [O] lpPos : will get the current icon position
2649 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2651 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2653 *lpPos
= infoPtr
->currIconPos
;
2655 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2656 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2658 infoPtr
->currIconPos
.x
= 0;
2659 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2665 * Returns the current icon position, and advances it down the left edge.
2666 * The returned position is not offset by Origin.
2669 * [I] infoPtr : valid pointer to the listview structure
2670 * [O] lpPos : will get the current icon position
2675 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2677 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2679 *lpPos
= infoPtr
->currIconPos
;
2681 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2682 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2684 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2685 infoPtr
->currIconPos
.y
= 0;
2691 * Moves an icon to the specified position.
2692 * It takes care of invalidating the item, etc.
2695 * [I] infoPtr : valid pointer to the listview structure
2696 * [I] nItem : the item to move
2697 * [I] lpPos : the new icon position
2698 * [I] isNew : flags the item as being new
2704 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2710 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2711 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2713 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2714 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2717 /* Allocating a POINTER for every item is too resource intensive,
2718 * so we'll keep the (x,y) in different arrays */
2719 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2720 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2722 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2729 * Arranges listview items in icon display mode.
2732 * [I] infoPtr : valid pointer to the listview structure
2733 * [I] nAlignCode : alignment code
2739 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2741 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2745 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2747 TRACE("nAlignCode=%d\n", nAlignCode
);
2749 if (nAlignCode
== LVA_DEFAULT
)
2751 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2752 else nAlignCode
= LVA_ALIGNTOP
;
2757 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2758 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2759 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2760 default: return FALSE
;
2763 infoPtr
->bAutoarrange
= TRUE
;
2764 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2765 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2767 next_pos(infoPtr
, &pos
);
2768 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2776 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2777 * For LVS_REPORT always returns empty rectangle.
2780 * [I] infoPtr : valid pointer to the listview structure
2781 * [O] lprcView : bounding rectangle
2787 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2791 SetRectEmpty(lprcView
);
2793 switch (infoPtr
->uView
)
2796 case LV_VIEW_SMALLICON
:
2797 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2799 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2800 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2801 lprcView
->right
= max(lprcView
->right
, x
);
2802 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2804 if (infoPtr
->nItemCount
> 0)
2806 lprcView
->right
+= infoPtr
->nItemWidth
;
2807 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2812 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2813 x
= infoPtr
->nItemCount
/ y
;
2814 if (infoPtr
->nItemCount
% y
) x
++;
2815 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2816 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2823 * Retrieves the bounding rectangle of all the items.
2826 * [I] infoPtr : valid pointer to the listview structure
2827 * [O] lprcView : bounding rectangle
2833 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2837 TRACE("(lprcView=%p)\n", lprcView
);
2839 if (!lprcView
) return FALSE
;
2841 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2843 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2845 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2846 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2849 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2856 * Retrieves the subitem pointer associated with the subitem index.
2859 * [I] hdpaSubItems : DPA handle for a specific item
2860 * [I] nSubItem : index of subitem
2863 * SUCCESS : subitem pointer
2866 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2868 SUBITEM_INFO
*lpSubItem
;
2871 /* we should binary search here if need be */
2872 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2874 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2875 if (lpSubItem
->iSubItem
== nSubItem
)
2885 * Calculates the desired item width.
2888 * [I] infoPtr : valid pointer to the listview structure
2891 * The desired item width.
2893 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2897 TRACE("uView=%d\n", infoPtr
->uView
);
2899 if (infoPtr
->uView
== LV_VIEW_ICON
)
2900 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2901 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2903 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2908 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2909 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2911 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2912 nItemWidth
= rcHeader
.right
;
2915 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2917 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2921 lvItem
.mask
= LVIF_TEXT
;
2922 lvItem
.iSubItem
= 0;
2924 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2927 lvItem
.pszText
= szDispText
;
2928 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2929 if (LISTVIEW_GetItemW(infoPtr
, &lvItem
))
2930 nItemWidth
= max(LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
),
2934 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2935 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2937 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2945 * Calculates the desired item height.
2948 * [I] infoPtr : valid pointer to the listview structure
2951 * The desired item height.
2953 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2957 TRACE("uView=%d\n", infoPtr
->uView
);
2959 if (infoPtr
->uView
== LV_VIEW_ICON
)
2960 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2963 nItemHeight
= infoPtr
->ntmHeight
;
2964 if (infoPtr
->himlState
)
2965 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2966 if (infoPtr
->himlSmall
)
2967 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2968 nItemHeight
+= HEIGHT_PADDING
;
2969 if (infoPtr
->nMeasureItemHeight
> 0)
2970 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2973 return max(nItemHeight
, 1);
2978 * Updates the width, and height of an item.
2981 * [I] infoPtr : valid pointer to the listview structure
2986 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2988 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2989 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2995 * Retrieves and saves important text metrics info for the current
2999 * [I] infoPtr : valid pointer to the listview structure
3002 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
3004 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
3005 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
3006 HFONT hOldFont
= SelectObject(hdc
, hFont
);
3010 if (GetTextMetricsW(hdc
, &tm
))
3012 infoPtr
->ntmHeight
= tm
.tmHeight
;
3013 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
3016 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
3017 infoPtr
->nEllipsisWidth
= sz
.cx
;
3019 SelectObject(hdc
, hOldFont
);
3020 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
3022 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
3027 * A compare function for ranges
3030 * [I] range1 : pointer to range 1;
3031 * [I] range2 : pointer to range 2;
3035 * > 0 : if range 1 > range 2
3036 * < 0 : if range 2 > range 1
3037 * = 0 : if range intersects range 2
3039 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
3043 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
3045 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
3050 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
3055 #define ranges_check(ranges, desc) if (TRACE_ON(listview)) ranges_assert(ranges, desc, __FILE__, __LINE__)
3057 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *file
, int line
)
3062 TRACE("*** Checking %s:%d:%s ***\n", file
, line
, desc
);
3064 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
3065 ranges_dump(ranges
);
3066 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
3068 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
3069 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
3070 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3072 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
3073 assert (prev
->upper
<= curr
->lower
);
3074 assert (curr
->lower
< curr
->upper
);
3078 TRACE("--- Done checking---\n");
3081 static RANGES
ranges_create(int count
)
3083 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
3084 if (!ranges
) return NULL
;
3085 ranges
->hdpa
= DPA_Create(count
);
3086 if (ranges
->hdpa
) return ranges
;
3091 static void ranges_clear(RANGES ranges
)
3095 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3096 Free(DPA_GetPtr(ranges
->hdpa
, i
));
3097 DPA_DeleteAllPtrs(ranges
->hdpa
);
3101 static void ranges_destroy(RANGES ranges
)
3103 if (!ranges
) return;
3104 ranges_clear(ranges
);
3105 DPA_Destroy(ranges
->hdpa
);
3109 static RANGES
ranges_clone(RANGES ranges
)
3114 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
3116 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3118 RANGE
*newrng
= Alloc(sizeof(RANGE
));
3119 if (!newrng
) goto fail
;
3120 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
3121 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
3126 TRACE ("clone failed\n");
3127 ranges_destroy(clone
);
3131 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
3135 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
3136 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
3141 static void ranges_dump(RANGES ranges
)
3145 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3146 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
3149 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
3151 RANGE srchrng
= { nItem
, nItem
+ 1 };
3153 TRACE("(nItem=%d)\n", nItem
);
3154 ranges_check(ranges
, "before contain");
3155 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
3158 static INT
ranges_itemcount(RANGES ranges
)
3162 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
3164 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
3165 count
+= sel
->upper
- sel
->lower
;
3171 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
3173 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
3176 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3177 if (index
== -1) return TRUE
;
3179 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
3181 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
3182 if (chkrng
->lower
>= nItem
)
3183 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
3184 if (chkrng
->upper
> nItem
)
3185 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
3190 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
3195 TRACE("(%s)\n", debugrange(&range
));
3196 ranges_check(ranges
, "before add");
3198 /* try find overlapping regions first */
3199 srchrgn
.lower
= range
.lower
- 1;
3200 srchrgn
.upper
= range
.upper
+ 1;
3201 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
3207 TRACE("Adding new range\n");
3209 /* create the brand new range to insert */
3210 newrgn
= Alloc(sizeof(RANGE
));
3211 if(!newrgn
) goto fail
;
3214 /* figure out where to insert it */
3215 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3216 TRACE("index=%d\n", index
);
3217 if (index
== -1) index
= 0;
3219 /* and get it over with */
3220 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3228 RANGE
*chkrgn
, *mrgrgn
;
3229 INT fromindex
, mergeindex
;
3231 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3232 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3234 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3235 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3237 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3239 /* merge now common ranges */
3241 srchrgn
.lower
= chkrgn
->lower
- 1;
3242 srchrgn
.upper
= chkrgn
->upper
+ 1;
3246 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3247 if (mergeindex
== -1) break;
3248 if (mergeindex
== index
)
3250 fromindex
= index
+ 1;
3254 TRACE("Merge with index %i\n", mergeindex
);
3256 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3257 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3258 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3260 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3261 if (mergeindex
< index
) index
--;
3265 ranges_check(ranges
, "after add");
3269 ranges_check(ranges
, "failed add");
3273 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3278 TRACE("(%s)\n", debugrange(&range
));
3279 ranges_check(ranges
, "before del");
3281 /* we don't use DPAS_SORTED here, since we need *
3282 * to find the first overlapping range */
3283 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3286 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3288 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3290 /* case 1: Same range */
3291 if ( (chkrgn
->upper
== range
.upper
) &&
3292 (chkrgn
->lower
== range
.lower
) )
3294 DPA_DeletePtr(ranges
->hdpa
, index
);
3298 /* case 2: engulf */
3299 else if ( (chkrgn
->upper
<= range
.upper
) &&
3300 (chkrgn
->lower
>= range
.lower
) )
3302 DPA_DeletePtr(ranges
->hdpa
, index
);
3305 /* case 3: overlap upper */
3306 else if ( (chkrgn
->upper
<= range
.upper
) &&
3307 (chkrgn
->lower
< range
.lower
) )
3309 chkrgn
->upper
= range
.lower
;
3311 /* case 4: overlap lower */
3312 else if ( (chkrgn
->upper
> range
.upper
) &&
3313 (chkrgn
->lower
>= range
.lower
) )
3315 chkrgn
->lower
= range
.upper
;
3318 /* case 5: fully internal */
3323 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3324 newrgn
->lower
= chkrgn
->lower
;
3325 newrgn
->upper
= range
.lower
;
3326 chkrgn
->lower
= range
.upper
;
3327 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3335 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3338 ranges_check(ranges
, "after del");
3342 ranges_check(ranges
, "failed del");
3348 * Removes all selection ranges
3351 * [I] infoPtr : valid pointer to the listview structure
3352 * [I] toSkip : item range to skip removing the selection
3358 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3367 lvItem
.stateMask
= LVIS_SELECTED
;
3369 /* need to clone the DPA because callbacks can change it */
3370 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3371 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3372 while(iterator_next(&i
))
3373 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3374 /* note that the iterator destructor will free the cloned range */
3375 iterator_destroy(&i
);
3380 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3384 if (!(toSkip
= ranges_create(1))) return FALSE
;
3385 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3386 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3387 ranges_destroy(toSkip
);
3391 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3393 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3398 * Retrieves the number of items that are marked as selected.
3401 * [I] infoPtr : valid pointer to the listview structure
3404 * Number of items selected.
3406 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3408 INT nSelectedCount
= 0;
3410 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3413 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3415 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3420 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3422 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3423 return nSelectedCount
;
3428 * Manages the item focus.
3431 * [I] infoPtr : valid pointer to the listview structure
3432 * [I] nItem : item index
3435 * TRUE : focused item changed
3436 * FALSE : focused item has NOT changed
3438 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3440 INT oldFocus
= infoPtr
->nFocusedItem
;
3443 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3445 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3446 lvItem
.stateMask
= LVIS_FOCUSED
;
3447 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3449 return oldFocus
!= infoPtr
->nFocusedItem
;
3452 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3454 if (nShiftItem
< nItem
) return nShiftItem
;
3456 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3458 if (direction
> 0) return nShiftItem
+ direction
;
3460 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3463 /* This function updates focus index.
3466 focus : current focus index
3467 item : index of item to be added/removed
3468 direction : add/remove flag
3470 static void LISTVIEW_ShiftFocus(LISTVIEW_INFO
*infoPtr
, INT focus
, INT item
, INT direction
)
3472 BOOL old_change
= infoPtr
->bDoChangeNotify
;
3474 infoPtr
->bDoChangeNotify
= FALSE
;
3475 focus
= shift_item(infoPtr
, focus
, item
, direction
);
3476 if (focus
!= infoPtr
->nFocusedItem
)
3477 LISTVIEW_SetItemFocus(infoPtr
, focus
);
3478 infoPtr
->bDoChangeNotify
= old_change
;
3483 * Updates the various indices after an item has been inserted or deleted.
3486 * [I] infoPtr : valid pointer to the listview structure
3487 * [I] nItem : item index
3488 * [I] direction : Direction of shift, +1 or -1.
3493 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3495 TRACE("Shifting %i, %i steps\n", nItem
, direction
);
3497 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3498 assert(abs(direction
) == 1);
3499 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3501 /* But we are not supposed to modify nHotItem! */
3506 * Adds a block of selections.
3509 * [I] infoPtr : valid pointer to the listview structure
3510 * [I] nItem : item index
3513 * Whether the window is still valid.
3515 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3517 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3518 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3519 HWND hwndSelf
= infoPtr
->hwndSelf
;
3520 NMLVODSTATECHANGE nmlv
;
3525 /* Temporarily disable change notification
3526 * If the control is LVS_OWNERDATA, we need to send
3527 * only one LVN_ODSTATECHANGED notification.
3528 * See MSDN documentation for LVN_ITEMCHANGED.
3530 bOldChange
= infoPtr
->bDoChangeNotify
;
3531 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3533 if (nFirst
== -1) nFirst
= nItem
;
3535 item
.state
= LVIS_SELECTED
;
3536 item
.stateMask
= LVIS_SELECTED
;
3538 for (i
= nFirst
; i
<= nLast
; i
++)
3539 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3541 ZeroMemory(&nmlv
, sizeof(nmlv
));
3542 nmlv
.iFrom
= nFirst
;
3545 nmlv
.uNewState
= item
.state
;
3547 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3548 if (!IsWindow(hwndSelf
))
3550 infoPtr
->bDoChangeNotify
= bOldChange
;
3557 * Sets a single group selection.
3560 * [I] infoPtr : valid pointer to the listview structure
3561 * [I] nItem : item index
3566 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3573 if (!(selection
= ranges_create(100))) return;
3575 item
.state
= LVIS_SELECTED
;
3576 item
.stateMask
= LVIS_SELECTED
;
3578 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3580 if (infoPtr
->nSelectionMark
== -1)
3582 infoPtr
->nSelectionMark
= nItem
;
3583 ranges_additem(selection
, nItem
);
3589 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3590 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3591 ranges_add(selection
, sel
);
3596 RECT rcItem
, rcSel
, rcSelMark
;
3599 rcItem
.left
= LVIR_BOUNDS
;
3600 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) {
3601 ranges_destroy (selection
);
3604 rcSelMark
.left
= LVIR_BOUNDS
;
3605 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) {
3606 ranges_destroy (selection
);
3609 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3610 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3611 while(iterator_next(&i
))
3613 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3614 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3616 iterator_destroy(&i
);
3619 /* disable per item notifications on LVS_OWNERDATA style
3620 FIXME: single LVN_ODSTATECHANGED should be used */
3621 bOldChange
= infoPtr
->bDoChangeNotify
;
3622 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3624 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3627 iterator_rangesitems(&i
, selection
);
3628 while(iterator_next(&i
))
3629 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3630 /* this will also destroy the selection */
3631 iterator_destroy(&i
);
3633 infoPtr
->bDoChangeNotify
= bOldChange
;
3635 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3640 * Sets a single selection.
3643 * [I] infoPtr : valid pointer to the listview structure
3644 * [I] nItem : item index
3649 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3653 TRACE("nItem=%d\n", nItem
);
3655 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3657 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3658 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3659 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3661 infoPtr
->nSelectionMark
= nItem
;
3666 * Set selection(s) with keyboard.
3669 * [I] infoPtr : valid pointer to the listview structure
3670 * [I] nItem : item index
3671 * [I] space : VK_SPACE code sent
3674 * SUCCESS : TRUE (needs to be repainted)
3675 * FAILURE : FALSE (nothing has changed)
3677 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3679 /* FIXME: pass in the state */
3680 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
3681 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
3682 BOOL bResult
= FALSE
;
3684 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3685 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3689 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3690 LISTVIEW_SetSelection(infoPtr
, nItem
);
3694 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3698 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3699 lvItem
.stateMask
= LVIS_SELECTED
;
3702 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3703 if (lvItem
.state
& LVIS_SELECTED
)
3704 infoPtr
->nSelectionMark
= nItem
;
3706 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3709 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3712 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3716 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3718 LVHITTESTINFO lvHitTestInfo
;
3720 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3721 lvHitTestInfo
.pt
.x
= pt
.x
;
3722 lvHitTestInfo
.pt
.y
= pt
.y
;
3724 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3726 lpLVItem
->mask
= LVIF_PARAM
;
3727 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3728 lpLVItem
->iSubItem
= 0;
3730 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3733 static inline BOOL
LISTVIEW_IsHotTracking(const LISTVIEW_INFO
*infoPtr
)
3735 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3736 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3737 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3742 * Called when the mouse is being actively tracked and has hovered for a specified
3746 * [I] infoPtr : valid pointer to the listview structure
3747 * [I] fwKeys : key indicator
3748 * [I] x,y : mouse position
3751 * 0 if the message was processed, non-zero if there was an error
3754 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3755 * over the item for a certain period of time.
3758 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, INT x
, INT y
)
3762 if (notify_hdr(infoPtr
, NM_HOVER
, &hdr
)) return 0;
3764 if (LISTVIEW_IsHotTracking(infoPtr
))
3772 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3773 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3775 SetFocus(infoPtr
->hwndSelf
);
3781 #define SCROLL_LEFT 0x1
3782 #define SCROLL_RIGHT 0x2
3783 #define SCROLL_UP 0x4
3784 #define SCROLL_DOWN 0x8
3788 * Utility routine to draw and highlight items within a marquee selection rectangle.
3791 * [I] infoPtr : valid pointer to the listview structure
3792 * [I] coords_orig : original co-ordinates of the cursor
3793 * [I] coords_offs : offsetted coordinates of the cursor
3794 * [I] offset : offset amount
3795 * [I] scroll : Bitmask of which directions we should scroll, if at all
3800 static void LISTVIEW_MarqueeHighlight(LISTVIEW_INFO
*infoPtr
, const POINT
*coords_orig
,
3801 const POINT
*coords_offs
, const POINT
*offset
,
3804 BOOL controlDown
= FALSE
;
3806 ITERATOR old_elems
, new_elems
;
3809 if (coords_offs
->x
> infoPtr
->marqueeOrigin
.x
)
3811 rect
.left
= infoPtr
->marqueeOrigin
.x
;
3812 rect
.right
= coords_offs
->x
;
3816 rect
.left
= coords_offs
->x
;
3817 rect
.right
= infoPtr
->marqueeOrigin
.x
;
3820 if (coords_offs
->y
> infoPtr
->marqueeOrigin
.y
)
3822 rect
.top
= infoPtr
->marqueeOrigin
.y
;
3823 rect
.bottom
= coords_offs
->y
;
3827 rect
.top
= coords_offs
->y
;
3828 rect
.bottom
= infoPtr
->marqueeOrigin
.y
;
3831 /* Cancel out the old marquee rectangle and draw the new one */
3832 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3834 /* Scroll by the appropriate distance if applicable - speed up scrolling as
3835 the cursor is further away */
3837 if ((scroll
& SCROLL_LEFT
) && (coords_orig
->x
<= 0))
3838 LISTVIEW_Scroll(infoPtr
, coords_orig
->x
, 0);
3840 if ((scroll
& SCROLL_RIGHT
) && (coords_orig
->x
>= infoPtr
->rcList
.right
))
3841 LISTVIEW_Scroll(infoPtr
, (coords_orig
->x
- infoPtr
->rcList
.right
), 0);
3843 if ((scroll
& SCROLL_UP
) && (coords_orig
->y
<= 0))
3844 LISTVIEW_Scroll(infoPtr
, 0, coords_orig
->y
);
3846 if ((scroll
& SCROLL_DOWN
) && (coords_orig
->y
>= infoPtr
->rcList
.bottom
))
3847 LISTVIEW_Scroll(infoPtr
, 0, (coords_orig
->y
- infoPtr
->rcList
.bottom
));
3849 iterator_frameditems_absolute(&old_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3851 CopyRect(&infoPtr
->marqueeRect
, &rect
);
3853 CopyRect(&infoPtr
->marqueeDrawRect
, &rect
);
3854 OffsetRect(&infoPtr
->marqueeDrawRect
, offset
->x
, offset
->y
);
3856 iterator_frameditems_absolute(&new_elems
, infoPtr
, &infoPtr
->marqueeRect
);
3857 iterator_remove_common_items(&old_elems
, &new_elems
);
3859 /* Iterate over no longer selected items */
3860 while (iterator_next(&old_elems
))
3862 if (old_elems
.nItem
> -1)
3864 if (LISTVIEW_GetItemState(infoPtr
, old_elems
.nItem
, LVIS_SELECTED
) == LVIS_SELECTED
)
3867 item
.state
= LVIS_SELECTED
;
3869 item
.stateMask
= LVIS_SELECTED
;
3871 LISTVIEW_SetItemState(infoPtr
, old_elems
.nItem
, &item
);
3874 iterator_destroy(&old_elems
);
3877 /* Iterate over newly selected items */
3878 if (GetKeyState(VK_CONTROL
) & 0x8000)
3881 while (iterator_next(&new_elems
))
3883 if (new_elems
.nItem
> -1)
3885 /* If CTRL is pressed, invert. If not, always select the item. */
3886 if ((controlDown
) && (LISTVIEW_GetItemState(infoPtr
, new_elems
.nItem
, LVIS_SELECTED
)))
3889 item
.state
= LVIS_SELECTED
;
3891 item
.stateMask
= LVIS_SELECTED
;
3893 LISTVIEW_SetItemState(infoPtr
, new_elems
.nItem
, &item
);
3896 iterator_destroy(&new_elems
);
3898 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
3903 * Called when we are in a marquee selection that involves scrolling the listview (ie,
3904 * the cursor is outside the bounds of the client area). This is a TIMERPROC.
3907 * [I] hwnd : Handle to the listview
3908 * [I] uMsg : WM_TIMER (ignored)
3909 * [I] idEvent : The timer ID interpreted as a pointer to a LISTVIEW_INFO struct
3910 * [I] dwTimer : The elapsed time (ignored)
3915 static VOID CALLBACK
LISTVIEW_ScrollTimer(HWND hWnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
3917 LISTVIEW_INFO
*infoPtr
;
3918 SCROLLINFO scrollInfo
;
3924 infoPtr
= (LISTVIEW_INFO
*) idEvent
;
3929 /* Get the current cursor position and convert to client coordinates */
3930 GetCursorPos(&coords_orig
);
3931 ScreenToClient(hWnd
, &coords_orig
);
3933 /* Ensure coordinates are within client bounds */
3934 coords_offs
.x
= max(min(coords_orig
.x
, infoPtr
->rcList
.right
), 0);
3935 coords_offs
.y
= max(min(coords_orig
.y
, infoPtr
->rcList
.bottom
), 0);
3938 LISTVIEW_GetOrigin(infoPtr
, &offset
);
3940 /* Offset coordinates by the appropriate amount */
3941 coords_offs
.x
-= offset
.x
;
3942 coords_offs
.y
-= offset
.y
;
3944 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3945 scrollInfo
.fMask
= SIF_ALL
;
3947 /* Work out in which directions we can scroll */
3948 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3950 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3951 scroll
|= SCROLL_UP
;
3953 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3954 scroll
|= SCROLL_DOWN
;
3957 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3959 if (scrollInfo
.nPos
!= scrollInfo
.nMin
)
3960 scroll
|= SCROLL_LEFT
;
3962 if (((scrollInfo
.nPage
+ scrollInfo
.nPos
) - 1) != scrollInfo
.nMax
)
3963 scroll
|= SCROLL_RIGHT
;
3966 if (((coords_orig
.x
<= 0) && (scroll
& SCROLL_LEFT
)) ||
3967 ((coords_orig
.y
<= 0) && (scroll
& SCROLL_UP
)) ||
3968 ((coords_orig
.x
>= infoPtr
->rcList
.right
) && (scroll
& SCROLL_RIGHT
)) ||
3969 ((coords_orig
.y
>= infoPtr
->rcList
.bottom
) && (scroll
& SCROLL_DOWN
)))
3971 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, scroll
);
3977 * Called whenever WM_MOUSEMOVE is received.
3980 * [I] infoPtr : valid pointer to the listview structure
3981 * [I] fwKeys : key indicator
3982 * [I] x,y : mouse position
3985 * 0 if the message is processed, non-zero if there was an error
3987 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3993 if (!(fwKeys
& MK_LBUTTON
))
3994 infoPtr
->bLButtonDown
= FALSE
;
3996 if (infoPtr
->bLButtonDown
)
3998 rect
.left
= rect
.right
= infoPtr
->ptClickPos
.x
;
3999 rect
.top
= rect
.bottom
= infoPtr
->ptClickPos
.y
;
4001 InflateRect(&rect
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
4004 if (infoPtr
->bLButtonDown
)
4006 if (infoPtr
->bMarqueeSelect
)
4016 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4018 /* Ensure coordinates are within client bounds */
4019 coords_offs
.x
= max(min(x
, infoPtr
->rcList
.right
), 0);
4020 coords_offs
.y
= max(min(y
, infoPtr
->rcList
.bottom
), 0);
4022 /* Offset coordinates by the appropriate amount */
4023 coords_offs
.x
-= offset
.x
;
4024 coords_offs
.y
-= offset
.y
;
4026 /* Enable the timer if we're going outside our bounds, in case the user doesn't
4027 move the mouse again */
4029 if ((x
<= 0) || (y
<= 0) || (x
>= infoPtr
->rcList
.right
) ||
4030 (y
>= infoPtr
->rcList
.bottom
))
4032 if (!infoPtr
->bScrolling
)
4034 infoPtr
->bScrolling
= TRUE
;
4035 SetTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
, 1, LISTVIEW_ScrollTimer
);
4040 infoPtr
->bScrolling
= FALSE
;
4041 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
4044 LISTVIEW_MarqueeHighlight(infoPtr
, &coords_orig
, &coords_offs
, &offset
, 0);
4052 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4054 /* reset item marker */
4055 if (infoPtr
->nLButtonDownItem
!= ht
.iItem
)
4056 infoPtr
->nLButtonDownItem
= -1;
4058 if (!PtInRect(&rect
, pt
))
4060 /* this path covers the following:
4061 1. WM_LBUTTONDOWN over selected item (sets focus on it)
4062 2. change focus with keys
4063 3. move mouse over item from step 1 selects it and moves focus on it */
4064 if (infoPtr
->nLButtonDownItem
!= -1 &&
4065 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
4069 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
4070 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
4072 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
4073 infoPtr
->nLButtonDownItem
= -1;
4076 if (!infoPtr
->bDragging
)
4078 ht
.pt
= infoPtr
->ptClickPos
;
4079 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
4081 /* If the click is outside the range of an item, begin a
4082 highlight. If not, begin an item drag. */
4087 /* If we're allowing multiple selections, send notification.
4088 If return value is non-zero, cancel. */
4089 if (!(infoPtr
->dwStyle
& LVS_SINGLESEL
) && (notify_hdr(infoPtr
, LVN_MARQUEEBEGIN
, &hdr
) == 0))
4091 /* Store the absolute coordinates of the click */
4093 LISTVIEW_GetOrigin(infoPtr
, &offset
);
4095 infoPtr
->marqueeOrigin
.x
= infoPtr
->ptClickPos
.x
- offset
.x
;
4096 infoPtr
->marqueeOrigin
.y
= infoPtr
->ptClickPos
.y
- offset
.y
;
4098 /* Begin selection and capture mouse */
4099 infoPtr
->bMarqueeSelect
= TRUE
;
4100 SetCapture(infoPtr
->hwndSelf
);
4107 ZeroMemory(&nmlv
, sizeof(nmlv
));
4108 nmlv
.iItem
= ht
.iItem
;
4109 nmlv
.ptAction
= infoPtr
->ptClickPos
;
4111 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
4112 infoPtr
->bDragging
= TRUE
;
4120 /* see if we are supposed to be tracking mouse hovering */
4121 if (LISTVIEW_IsHotTracking(infoPtr
)) {
4122 TRACKMOUSEEVENT trackinfo
;
4124 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
4125 trackinfo
.dwFlags
= TME_QUERY
;
4127 /* see if we are already tracking this hwnd */
4128 _TrackMouseEvent(&trackinfo
);
4130 if(!(trackinfo
.dwFlags
& TME_HOVER
) || trackinfo
.hwndTrack
!= infoPtr
->hwndSelf
) {
4131 trackinfo
.dwFlags
= TME_HOVER
;
4132 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
4133 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
4135 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
4136 _TrackMouseEvent(&trackinfo
);
4145 * Tests whether the item is assignable to a list with style lStyle
4147 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
4149 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
4150 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
4151 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
4159 * Helper for LISTVIEW_SetItemT and LISTVIEW_InsertItemT: sets item attributes.
4162 * [I] infoPtr : valid pointer to the listview structure
4163 * [I] lpLVItem : valid pointer to new item attributes
4164 * [I] isNew : the item being set is being inserted
4165 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4166 * [O] bChanged : will be set to TRUE if the item really changed
4172 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
4178 /* stateMask is ignored for LVM_INSERTITEM */
4179 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
4183 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
4185 if (lpLVItem
->mask
== 0) return TRUE
;
4187 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4189 /* a virtual listview only stores selection and focus */
4190 if (lpLVItem
->mask
& ~LVIF_STATE
)
4196 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4197 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
4201 /* we need to get the lParam and state of the item */
4202 item
.iItem
= lpLVItem
->iItem
;
4203 item
.iSubItem
= lpLVItem
->iSubItem
;
4204 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
4205 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
4209 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
4211 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
4212 /* determine what fields will change */
4213 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
4214 uChanged
|= LVIF_STATE
;
4216 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4217 uChanged
|= LVIF_IMAGE
;
4219 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
4220 uChanged
|= LVIF_PARAM
;
4222 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
4223 uChanged
|= LVIF_INDENT
;
4225 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4226 uChanged
|= LVIF_TEXT
;
4228 TRACE("change mask=0x%x\n", uChanged
);
4230 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
4231 nmlv
.iItem
= lpLVItem
->iItem
;
4232 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
4233 nmlv
.uOldState
= item
.state
;
4234 nmlv
.uChanged
= uChanged
? uChanged
: lpLVItem
->mask
;
4235 nmlv
.lParam
= item
.lParam
;
4237 /* Send LVN_ITEMCHANGING notification, if the item is not being inserted
4238 and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications
4239 are enabled. Even nothing really changed we still need to send this,
4240 in this case uChanged mask is just set to passed item mask. */
4241 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
4243 HWND hwndSelf
= infoPtr
->hwndSelf
;
4245 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
4247 if (!IsWindow(hwndSelf
))
4251 /* When item is inserted we need to shift existing focus index if new item has lower index. */
4252 if (isNew
&& (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
) &&
4253 /* this means we won't hit a focus change path later */
4254 ((uChanged
& LVIF_STATE
) == 0 || (!(lpLVItem
->state
& LVIS_FOCUSED
) && (infoPtr
->nFocusedItem
!= lpLVItem
->iItem
))))
4256 if (infoPtr
->nFocusedItem
!= -1 && (lpLVItem
->iItem
<= infoPtr
->nFocusedItem
))
4257 infoPtr
->nFocusedItem
++;
4260 if (!uChanged
) return TRUE
;
4263 /* copy information */
4264 if (lpLVItem
->mask
& LVIF_TEXT
)
4265 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4267 if (lpLVItem
->mask
& LVIF_IMAGE
)
4268 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
4270 if (lpLVItem
->mask
& LVIF_PARAM
)
4271 lpItem
->lParam
= lpLVItem
->lParam
;
4273 if (lpLVItem
->mask
& LVIF_INDENT
)
4274 lpItem
->iIndent
= lpLVItem
->iIndent
;
4276 if (uChanged
& LVIF_STATE
)
4278 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
4280 lpItem
->state
&= ~stateMask
;
4281 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
4283 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
4285 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
4286 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4288 else if (stateMask
& LVIS_SELECTED
)
4290 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
4292 /* If we are asked to change focus, and we manage it, do it.
4293 It's important to have all new item data stored at this point,
4294 because changing existing focus could result in a redrawing operation,
4295 which in turn could ask for disp data, application should see all data
4296 for inserted item when processing LVN_GETDISPINFO.
4298 The way this works application will see nested item change notifications -
4299 changed item notifications interrupted by ones from item losing focus. */
4300 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
4302 if (lpLVItem
->state
& LVIS_FOCUSED
)
4304 /* update selection mark */
4305 if (infoPtr
->nFocusedItem
== -1 && infoPtr
->nSelectionMark
== -1)
4306 infoPtr
->nSelectionMark
= lpLVItem
->iItem
;
4308 if (infoPtr
->nFocusedItem
!= -1)
4310 /* remove current focus */
4311 item
.mask
= LVIF_STATE
;
4313 item
.stateMask
= LVIS_FOCUSED
;
4315 /* recurse with redrawing an item */
4316 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
4319 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
4320 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
4322 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
4324 infoPtr
->nFocusedItem
= -1;
4329 /* if we're inserting the item, we're done */
4330 if (isNew
) return TRUE
;
4332 /* send LVN_ITEMCHANGED notification */
4333 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
4334 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
4341 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
4344 * [I] infoPtr : valid pointer to the listview structure
4345 * [I] lpLVItem : valid pointer to new subitem attributes
4346 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4347 * [O] bChanged : will be set to TRUE if the item really changed
4353 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
4356 SUBITEM_INFO
*lpSubItem
;
4358 /* we do not support subitems for virtual listviews */
4359 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
4361 /* set subitem only if column is present */
4362 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4364 /* First do some sanity checks */
4365 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
4366 particularly useful. We currently do not actually do anything with
4367 the flag on subitems.
4369 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
| LVIF_DI_SETITEM
)) return FALSE
;
4370 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
4372 /* get the subitem structure, and create it if not there */
4373 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
4374 assert (hdpaSubItems
);
4376 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
4379 SUBITEM_INFO
*tmpSubItem
;
4382 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
4383 if (!lpSubItem
) return FALSE
;
4384 /* we could binary search here, if need be...*/
4385 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4387 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4388 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
4390 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
4395 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
4396 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
4400 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
))
4402 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
4406 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
4408 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
4417 * Sets item attributes.
4420 * [I] infoPtr : valid pointer to the listview structure
4421 * [I] lpLVItem : new item attributes
4422 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
4428 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
4430 HWND hwndSelf
= infoPtr
->hwndSelf
;
4431 LPWSTR pszText
= NULL
;
4432 BOOL bResult
, bChanged
= FALSE
;
4435 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
4437 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
4440 /* Store old item area */
4441 LISTVIEW_GetItemBox(infoPtr
, lpLVItem
->iItem
, &oldItemArea
);
4443 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
4444 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_text(lpLVItem
->pszText
))
4446 pszText
= lpLVItem
->pszText
;
4447 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
4450 /* actually set the fields */
4451 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
4453 if (lpLVItem
->iSubItem
)
4454 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
4456 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
4457 if (!IsWindow(hwndSelf
))
4460 /* redraw item, if necessary */
4461 if (bChanged
&& !infoPtr
->bIsDrawing
)
4463 /* this little optimization eliminates some nasty flicker */
4464 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
4465 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
4466 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
4467 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
4470 LISTVIEW_InvalidateRect(infoPtr
, &oldItemArea
);
4471 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
4477 textfreeT(lpLVItem
->pszText
, isW
);
4478 lpLVItem
->pszText
= pszText
;
4486 * Retrieves the index of the item at coordinate (0, 0) of the client area.
4489 * [I] infoPtr : valid pointer to the listview structure
4494 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
4497 SCROLLINFO scrollInfo
;
4499 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
4500 scrollInfo
.fMask
= SIF_POS
;
4502 if (infoPtr
->uView
== LV_VIEW_LIST
)
4504 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
4505 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
4507 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4509 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4510 nItem
= scrollInfo
.nPos
;
4514 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
4515 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4518 TRACE("nItem=%d\n", nItem
);
4526 * Erases the background of the given rectangle
4529 * [I] infoPtr : valid pointer to the listview structure
4530 * [I] hdc : device context handle
4531 * [I] lprcBox : clipping rectangle
4537 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4539 if (!infoPtr
->hBkBrush
) return FALSE
;
4541 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4543 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4551 * [I] infoPtr : valid pointer to the listview structure
4552 * [I] hdc : device context handle
4553 * [I] nItem : item index
4554 * [I] nSubItem : subitem index
4555 * [I] pos : item position in client coordinates
4556 * [I] cdmode : custom draw mode
4562 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
4565 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4566 static WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4567 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4569 RECT rcSelect
, rcBox
, rcIcon
, rcLabel
, rcStateIcon
;
4570 NMLVCUSTOMDRAW nmlvcd
;
4574 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, wine_dbgstr_point(&pos
));
4576 /* get information needed for drawing the item */
4577 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
4578 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
;
4579 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4580 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
| LVIS_CUT
| LVIS_OVERLAYMASK
;
4581 lvItem
.iItem
= nItem
;
4582 lvItem
.iSubItem
= nSubItem
;
4585 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4586 lvItem
.pszText
= szDispText
;
4587 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4588 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4589 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4590 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
4591 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4593 /* now check if we need to update the focus rectangle */
4594 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4596 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4597 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4598 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4599 OffsetRect(&rcSelect
, pos
.x
, pos
.y
);
4600 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
4601 OffsetRect(&rcStateIcon
, pos
.x
, pos
.y
);
4602 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
4603 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4604 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4605 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4607 /* fill in the custom draw structure */
4608 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4610 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
4611 if (cdmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4612 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4613 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4614 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
4615 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4616 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
4617 if (nSubItem
== 0 && (cdsubitemmode
& CDRF_NOTIFYITEMDRAW
) != 0)
4619 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4620 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4622 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4623 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4624 else if ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) == FALSE
)
4625 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4627 /* FIXME: temporary hack */
4628 rcSelect
.left
= rcLabel
.left
;
4630 /* in icon mode, the label rect is really what we want to draw the
4632 /* in detail mode, we want to paint background for label rect when
4633 * item is not selected or listview has full row select; otherwise paint
4634 * background for text only */
4635 if (infoPtr
->uView
== LV_VIEW_ICON
||
4636 (infoPtr
->uView
== LV_VIEW_DETAILS
&&
4637 (!(lvItem
.state
& LVIS_SELECTED
) ||
4638 (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) != 0)))
4641 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
4642 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, NULL
, 0, NULL
);
4644 if(nSubItem
== 0 && infoPtr
->nFocusedItem
== nItem
)
4646 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4648 /* we have to update left focus bound too if item isn't in leftmost column
4649 and reduce right box bound */
4650 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4654 if ((leftmost
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0)))
4656 INT Originx
= pos
.x
- LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
4657 INT index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4658 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4660 rcBox
.right
= LISTVIEW_GetColumnInfo(infoPtr
, index
)->rcHeader
.right
+ Originx
;
4661 rcSelect
.left
= LISTVIEW_GetColumnInfo(infoPtr
, leftmost
)->rcHeader
.left
+ Originx
;
4665 rcSelect
.right
= rcBox
.right
;
4668 /* store new focus rectangle */
4669 infoPtr
->rcFocus
= rcSelect
;
4673 if (infoPtr
->himlState
&& STATEIMAGEINDEX(lvItem
.state
) && (nSubItem
== 0))
4675 UINT uStateImage
= STATEIMAGEINDEX(lvItem
.state
);
4678 TRACE("uStateImage=%d\n", uStateImage
);
4679 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
,
4680 rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4685 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4686 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4690 TRACE("iImage=%d\n", lvItem
.iImage
);
4692 if (lvItem
.state
& (LVIS_SELECTED
| LVIS_CUT
) && infoPtr
->bFocus
)
4693 style
= ILD_SELECTED
;
4697 ImageList_DrawEx(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
4698 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
,
4699 lvItem
.state
& LVIS_CUT
? RGB(255, 255, 255) : CLR_DEFAULT
,
4700 style
| (lvItem
.state
& LVIS_OVERLAYMASK
));
4703 /* Don't bother painting item being edited */
4704 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
4706 /* figure out the text drawing flags */
4707 uFormat
= (infoPtr
->uView
== LV_VIEW_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4708 if (infoPtr
->uView
== LV_VIEW_ICON
)
4709 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4712 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4714 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
4715 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
4716 default: uFormat
|= DT_LEFT
;
4719 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
4721 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4722 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4724 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4726 /* for GRIDLINES reduce the bottom so the text formats correctly */
4727 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4730 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
4733 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4734 notify_postpaint(infoPtr
, &nmlvcd
);
4740 * Draws listview items when in owner draw mode.
4743 * [I] infoPtr : valid pointer to the listview structure
4744 * [I] hdc : device context handle
4749 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4751 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4752 DWORD cditemmode
= CDRF_DODEFAULT
;
4753 NMLVCUSTOMDRAW nmlvcd
;
4754 POINT Origin
, Position
;
4760 ZeroMemory(&dis
, sizeof(dis
));
4762 /* Get scroll info once before loop */
4763 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4765 /* iterate through the invalidated rows */
4766 while(iterator_next(i
))
4768 item
.iItem
= i
->nItem
;
4770 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4771 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4772 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4774 dis
.CtlType
= ODT_LISTVIEW
;
4776 dis
.itemID
= item
.iItem
;
4777 dis
.itemAction
= ODA_DRAWENTIRE
;
4779 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4780 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4781 dis
.hwndItem
= infoPtr
->hwndSelf
;
4783 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4784 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4785 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4786 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4787 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4788 dis
.itemData
= item
.lParam
;
4790 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4793 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4794 * structure for the rest. of the paint cycle
4796 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4797 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4798 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4800 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4802 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4803 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4806 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4807 notify_postpaint(infoPtr
, &nmlvcd
);
4813 * Draws listview items when in report display mode.
4816 * [I] infoPtr : valid pointer to the listview structure
4817 * [I] hdc : device context handle
4818 * [I] cdmode : custom draw mode
4823 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4826 RECT rcClip
, rcItem
;
4827 POINT Origin
, Position
;
4834 /* figure out what to draw */
4835 rgntype
= GetClipBox(hdc
, &rcClip
);
4836 if (rgntype
== NULLREGION
) return;
4838 /* Get scroll info once before loop */
4839 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4841 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4843 /* narrow down the columns we need to paint */
4844 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4846 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4848 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4849 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4850 ranges_additem(colRanges
, index
);
4852 iterator_rangesitems(&j
, colRanges
);
4854 /* in full row select, we _have_ to draw the main item */
4855 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4858 /* iterate through the invalidated rows */
4859 while(iterator_next(i
))
4861 SelectObject(hdc
, infoPtr
->hFont
);
4862 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4863 Position
.y
+= Origin
.y
;
4865 /* iterate through the invalidated columns */
4866 while(iterator_next(&j
))
4868 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4869 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4871 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4874 rcItem
.bottom
= infoPtr
->nItemHeight
;
4875 OffsetRect(&rcItem
, Origin
.x
, Position
.y
);
4876 if (!RectVisible(hdc
, &rcItem
)) continue;
4879 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
4882 iterator_destroy(&j
);
4887 * Draws the gridlines if necessary when in report display mode.
4890 * [I] infoPtr : valid pointer to the listview structure
4891 * [I] hdc : device context handle
4896 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4902 RECT rcClip
, rcItem
= {0};
4910 /* figure out what to draw */
4911 rgntype
= GetClipBox(hdc
, &rcClip
);
4912 if (rgntype
== NULLREGION
) return;
4914 /* Get scroll info once before loop */
4915 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4917 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4919 /* narrow down the columns we need to paint */
4920 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4922 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4924 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4925 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4926 ranges_additem(colRanges
, index
);
4929 /* is right most vertical line visible? */
4930 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4932 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4933 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4934 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
4937 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
4939 hOldPen
= SelectObject ( hdc
, hPen
);
4941 /* draw the vertical lines for the columns */
4942 iterator_rangesitems(&j
, colRanges
);
4943 while(iterator_next(&j
))
4945 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4946 if (rcItem
.left
== 0) continue; /* skip leftmost column */
4947 rcItem
.left
+= Origin
.x
;
4948 rcItem
.right
+= Origin
.x
;
4949 rcItem
.top
= infoPtr
->rcList
.top
;
4950 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
4951 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
4952 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4953 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
4955 iterator_destroy(&j
);
4956 /* draw rightmost grid line if visible */
4959 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4960 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4961 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4963 rcItem
.right
+= Origin
.x
;
4965 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
4966 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
4969 /* draw the horizontal lines for the rows */
4970 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
4971 rcItem
.left
= infoPtr
->rcList
.left
;
4972 rcItem
.right
= infoPtr
->rcList
.right
;
4973 for(y
= Origin
.y
> 1 ? Origin
.y
- 1 : itemheight
- 1 + Origin
.y
% itemheight
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
4975 rcItem
.bottom
= rcItem
.top
= y
;
4976 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
4977 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4978 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
4981 SelectObject( hdc
, hOldPen
);
4982 DeleteObject( hPen
);
4985 ranges_destroy(colRanges
);
4990 * Draws listview items when in list display mode.
4993 * [I] infoPtr : valid pointer to the listview structure
4994 * [I] hdc : device context handle
4995 * [I] cdmode : custom draw mode
5000 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
5002 POINT Origin
, Position
;
5004 /* Get scroll info once before loop */
5005 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5007 while(iterator_prev(i
))
5009 SelectObject(hdc
, infoPtr
->hFont
);
5010 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
5011 Position
.x
+= Origin
.x
;
5012 Position
.y
+= Origin
.y
;
5014 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
5021 * Draws listview items.
5024 * [I] infoPtr : valid pointer to the listview structure
5025 * [I] hdc : device context handle
5026 * [I] prcErase : rect to be erased before refresh (may be NULL)
5031 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
5033 COLORREF oldTextColor
= 0, oldBkColor
= 0;
5034 NMLVCUSTOMDRAW nmlvcd
;
5041 HBITMAP hbmp
= NULL
;
5044 LISTVIEW_DUMP(infoPtr
);
5046 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5047 TRACE("double buffering\n");
5049 hdc
= CreateCompatibleDC(hdcOrig
);
5051 ERR("Failed to create DC for backbuffer\n");
5054 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
5055 infoPtr
->rcList
.bottom
);
5057 ERR("Failed to create bitmap for backbuffer\n");
5062 SelectObject(hdc
, hbmp
);
5063 SelectObject(hdc
, infoPtr
->hFont
);
5065 if(GetClipBox(hdcOrig
, &rcClient
))
5066 IntersectClipRect(hdc
, rcClient
.left
, rcClient
.top
, rcClient
.right
, rcClient
.bottom
);
5068 /* Save dc values we're gonna trash while drawing
5069 * FIXME: Should be done in LISTVIEW_DrawItem() */
5070 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5071 oldBkMode
= GetBkMode(hdc
);
5072 oldBkColor
= GetBkColor(hdc
);
5073 oldTextColor
= GetTextColor(hdc
);
5076 infoPtr
->bIsDrawing
= TRUE
;
5079 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
5080 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
5081 /* If no erasing was done (usually because RedrawWindow was called
5082 * with RDW_INVALIDATE only) we need to copy the old contents into
5083 * the backbuffer before continuing. */
5084 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5085 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5086 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5087 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5090 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
5092 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
5093 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
5094 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
5095 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
5097 /* nothing to draw */
5098 if(infoPtr
->nItemCount
== 0) goto enddraw
;
5100 /* figure out what we need to draw */
5101 iterator_visibleitems(&i
, infoPtr
, hdc
);
5102 range
= iterator_range(&i
);
5104 /* send cache hint notification */
5105 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5109 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
5110 nmlv
.iFrom
= range
.lower
;
5111 nmlv
.iTo
= range
.upper
- 1;
5112 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
5115 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
5116 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
5119 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5120 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
5121 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
5122 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
5124 /* if we have a focus rect and it's visible, draw it */
5125 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
5126 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
5127 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
5129 iterator_destroy(&i
);
5132 /* For LVS_EX_GRIDLINES go and draw lines */
5133 /* This includes the case where there were *no* items */
5134 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
5135 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
5137 /* Draw marquee rectangle if appropriate */
5138 if (infoPtr
->bMarqueeSelect
)
5139 DrawFocusRect(hdc
, &infoPtr
->marqueeDrawRect
);
5141 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
5142 notify_postpaint(infoPtr
, &nmlvcd
);
5145 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
5146 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
5147 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
5148 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
5153 SelectObject(hdc
, hOldFont
);
5154 SetBkMode(hdc
, oldBkMode
);
5155 SetBkColor(hdc
, oldBkColor
);
5156 SetTextColor(hdc
, oldTextColor
);
5159 infoPtr
->bIsDrawing
= FALSE
;
5165 * Calculates the approximate width and height of a given number of items.
5168 * [I] infoPtr : valid pointer to the listview structure
5169 * [I] nItemCount : number of items
5170 * [I] wWidth : width
5171 * [I] wHeight : height
5174 * Returns a DWORD. The width in the low word and the height in high word.
5176 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
5177 WORD wWidth
, WORD wHeight
)
5179 DWORD dwViewRect
= 0;
5181 if (nItemCount
== -1)
5182 nItemCount
= infoPtr
->nItemCount
;
5184 if (infoPtr
->uView
== LV_VIEW_LIST
)
5186 INT nItemCountPerColumn
= 1;
5187 INT nColumnCount
= 0;
5189 if (wHeight
== 0xFFFF)
5191 /* use current height */
5192 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5195 if (wHeight
< infoPtr
->nItemHeight
)
5196 wHeight
= infoPtr
->nItemHeight
;
5200 if (infoPtr
->nItemHeight
> 0)
5202 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
5203 if (nItemCountPerColumn
== 0)
5204 nItemCountPerColumn
= 1;
5206 if (nItemCount
% nItemCountPerColumn
!= 0)
5207 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
5209 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
5213 /* Microsoft padding magic */
5214 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
5215 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
5217 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5219 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5223 if (infoPtr
->nItemCount
> 0)
5225 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
5226 wWidth
= rcBox
.right
- rcBox
.left
;
5227 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
5231 /* use current height and width */
5232 if (wHeight
== 0xffff)
5233 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
5234 if (wWidth
== 0xffff)
5235 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5238 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5240 else if (infoPtr
->uView
== LV_VIEW_ICON
)
5246 nItemWidth
= infoPtr
->iconSpacing
.cx
;
5247 nItemHeight
= infoPtr
->iconSpacing
.cy
;
5249 if (wWidth
== 0xffff)
5250 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
5252 if (wWidth
< nItemWidth
)
5253 wWidth
= nItemWidth
;
5255 cols
= wWidth
/ nItemWidth
;
5256 if (cols
> nItemCount
)
5263 rows
= nItemCount
/ cols
;
5264 if (nItemCount
% cols
)
5270 wHeight
= (nItemHeight
* rows
)+2;
5271 wWidth
= (nItemWidth
* cols
)+2;
5273 dwViewRect
= MAKELONG(wWidth
, wHeight
);
5275 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
5276 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
5283 * Cancel edit label with saving item text.
5286 * [I] infoPtr : valid pointer to the listview structure
5289 * Always returns TRUE.
5291 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
5293 if (infoPtr
->hwndEdit
)
5295 /* handle value will be lost after LISTVIEW_EndEditLabelT */
5296 HWND edit
= infoPtr
->hwndEdit
;
5298 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
5299 SendMessageW(edit
, WM_CLOSE
, 0, 0);
5307 * Create a drag image list for the specified item.
5310 * [I] infoPtr : valid pointer to the listview structure
5311 * [I] iItem : index of item
5312 * [O] lppt : Upper-left corner of the image
5315 * Returns a handle to the image list if successful, NULL otherwise.
5317 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
5323 HBITMAP hbmp
, hOldbmp
;
5325 HIMAGELIST dragList
= 0;
5326 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
5328 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
|| !lppt
)
5331 rcItem
.left
= LVIR_BOUNDS
;
5332 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
5335 lppt
->x
= rcItem
.left
;
5336 lppt
->y
= rcItem
.top
;
5338 size
.cx
= rcItem
.right
- rcItem
.left
;
5339 size
.cy
= rcItem
.bottom
- rcItem
.top
;
5341 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
5342 hdc
= CreateCompatibleDC(hdcOrig
);
5343 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
5344 hOldbmp
= SelectObject(hdc
, hbmp
);
5345 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5347 rcItem
.left
= rcItem
.top
= 0;
5348 rcItem
.right
= size
.cx
;
5349 rcItem
.bottom
= size
.cy
;
5350 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
5353 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
5355 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
5356 SelectObject(hdc
, hOldbmp
);
5357 ImageList_Add(dragList
, hbmp
, 0);
5360 SelectObject(hdc
, hOldbmp
);
5362 SelectObject(hdc
, hOldFont
);
5365 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
5367 TRACE("ret=%p\n", dragList
);
5375 * Removes all listview items and subitems.
5378 * [I] infoPtr : valid pointer to the listview structure
5384 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
5387 HDPA hdpaSubItems
= NULL
;
5396 /* we do it directly, to avoid notifications */
5397 ranges_clear(infoPtr
->selectionRanges
);
5398 infoPtr
->nSelectionMark
= -1;
5399 infoPtr
->nFocusedItem
= -1;
5400 SetRectEmpty(&infoPtr
->rcFocus
);
5401 /* But we are supposed to leave nHotItem as is! */
5404 /* send LVN_DELETEALLITEMS notification */
5405 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
5407 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
5409 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
5411 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5413 /* send LVN_DELETEITEM notification, if not suppressed
5414 and if it is not a virtual listview */
5415 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
5416 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
5417 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5418 /* free id struct */
5419 j
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5420 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, j
);
5421 DPA_DeletePtr(infoPtr
->hdpaItemIds
, j
);
5423 /* both item and subitem start with ITEMHDR header */
5424 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
5426 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
5427 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5430 DPA_Destroy(hdpaSubItems
);
5431 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
5433 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
5434 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
5435 infoPtr
->nItemCount
--;
5440 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5441 LISTVIEW_UpdateScroll(infoPtr
);
5443 LISTVIEW_InvalidateList(infoPtr
);
5450 * Scrolls, and updates the columns, when a column is changing width.
5453 * [I] infoPtr : valid pointer to the listview structure
5454 * [I] nColumn : column to scroll
5455 * [I] dx : amount of scroll, in pixels
5460 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
5462 COLUMN_INFO
*lpColumnInfo
;
5468 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
5469 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
5470 rcCol
= lpColumnInfo
->rcHeader
;
5471 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
5472 rcCol
.left
= rcCol
.right
;
5474 /* adjust the other columns */
5475 hdi
.mask
= HDI_ORDER
;
5476 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
5478 INT nOrder
= hdi
.iOrder
;
5479 for (nCol
= 0; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
5481 hdi
.mask
= HDI_ORDER
;
5482 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nCol
, (LPARAM
)&hdi
);
5483 if (hdi
.iOrder
>= nOrder
) {
5484 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
5485 lpColumnInfo
->rcHeader
.left
+= dx
;
5486 lpColumnInfo
->rcHeader
.right
+= dx
;
5491 /* do not update screen if not in report mode */
5492 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
5494 /* Need to reset the item width when inserting a new column */
5495 infoPtr
->nItemWidth
+= dx
;
5497 LISTVIEW_UpdateScroll(infoPtr
);
5498 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
5500 /* scroll to cover the deleted column, and invalidate for redraw */
5501 rcOld
= infoPtr
->rcList
;
5502 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
5503 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5508 * Removes a column from the listview control.
5511 * [I] infoPtr : valid pointer to the listview structure
5512 * [I] nColumn : column index
5518 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5522 TRACE("nColumn=%d\n", nColumn
);
5524 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
5525 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5527 /* While the MSDN specifically says that column zero should not be deleted,
5528 what actually happens is that the column itself is deleted but no items or subitems
5532 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
5534 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
5537 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
5538 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
5540 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
5542 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
5544 INT nItem
, nSubItem
, i
;
5546 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
5548 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
5551 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5553 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
5554 if (lpSubItem
->iSubItem
== nColumn
)
5557 lpDelItem
= lpSubItem
;
5559 else if (lpSubItem
->iSubItem
> nColumn
)
5561 lpSubItem
->iSubItem
--;
5565 /* if we found our subitem, zap it */
5569 if (is_text(lpDelItem
->hdr
.pszText
))
5570 Free(lpDelItem
->hdr
.pszText
);
5575 /* free dpa memory */
5576 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
5581 /* update the other column info */
5582 LISTVIEW_UpdateItemSize(infoPtr
);
5583 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
5584 LISTVIEW_InvalidateList(infoPtr
);
5586 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
5593 * Invalidates the listview after an item's insertion or deletion.
5596 * [I] infoPtr : valid pointer to the listview structure
5597 * [I] nItem : item index
5598 * [I] dir : -1 if deleting, 1 if inserting
5603 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5605 INT nPerCol
, nItemCol
, nItemRow
;
5609 /* if we don't refresh, what's the point of scrolling? */
5610 if (!is_redrawing(infoPtr
)) return;
5612 assert (abs(dir
) == 1);
5614 /* arrange icons if autoarrange is on */
5615 if (is_autoarrange(infoPtr
))
5617 BOOL arrange
= TRUE
;
5618 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5619 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5620 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5623 /* scrollbars need updating */
5624 LISTVIEW_UpdateScroll(infoPtr
);
5626 /* figure out the item's position */
5627 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5628 nPerCol
= infoPtr
->nItemCount
+ 1;
5629 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5630 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5631 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5634 nItemCol
= nItem
/ nPerCol
;
5635 nItemRow
= nItem
% nPerCol
;
5636 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5638 /* move the items below up a slot */
5639 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5640 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5641 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5642 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5643 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5644 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5645 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5647 TRACE("Invalidating rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5648 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5651 /* report has only that column, so we're done */
5652 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5654 /* now for LISTs, we have to deal with the columns to the right */
5655 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5657 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5658 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5659 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5660 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5661 InvalidateRect(infoPtr
->hwndSelf
, &rcScroll
, TRUE
);
5666 * Removes an item from the listview control.
5669 * [I] infoPtr : valid pointer to the listview structure
5670 * [I] nItem : item index
5676 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5679 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5680 INT focus
= infoPtr
->nFocusedItem
;
5682 TRACE("(nItem=%d)\n", nItem
);
5684 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5686 /* remove selection, and focus */
5688 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5689 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5691 /* send LVN_DELETEITEM notification. */
5692 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5694 /* we need to do this here, because we'll be deleting stuff */
5696 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5698 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5706 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5707 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5709 /* free id struct */
5710 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5711 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5712 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5714 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5716 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5717 if (is_text(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5720 DPA_Destroy(hdpaSubItems
);
5725 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5726 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5729 infoPtr
->nItemCount
--;
5730 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5731 LISTVIEW_ShiftFocus(infoPtr
, focus
, nItem
, -1);
5733 /* now is the invalidation fun */
5735 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5742 * Callback implementation for editlabel control
5745 * [I] infoPtr : valid pointer to the listview structure
5746 * [I] storeText : store edit box text as item text
5747 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5753 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5755 HWND hwndSelf
= infoPtr
->hwndSelf
;
5756 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5757 NMLVDISPINFOW dispInfo
;
5758 INT editedItem
= infoPtr
->nEditLabelItem
;
5760 WCHAR
*pszText
= NULL
;
5765 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5769 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5771 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5772 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5777 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5779 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5780 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5781 dispInfo
.item
.iItem
= editedItem
;
5782 dispInfo
.item
.iSubItem
= 0;
5783 dispInfo
.item
.stateMask
= ~0;
5784 dispInfo
.item
.pszText
= szDispText
;
5785 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5786 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
))
5793 same
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5796 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5797 same
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5798 textfreeT(tmp
, FALSE
);
5801 /* add the text from the edit in */
5802 dispInfo
.item
.mask
|= LVIF_TEXT
;
5803 dispInfo
.item
.pszText
= same
? NULL
: pszText
;
5804 dispInfo
.item
.cchTextMax
= textlenT(dispInfo
.item
.pszText
, isW
);
5806 /* Do we need to update the Item Text */
5807 res
= notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
);
5809 infoPtr
->nEditLabelItem
= -1;
5810 infoPtr
->hwndEdit
= 0;
5812 if (!res
) goto cleanup
;
5814 if (!IsWindow(hwndSelf
))
5819 if (!pszText
) return TRUE
;
5826 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5828 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5829 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5830 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5832 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5838 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5839 dispInfo
.item
.mask
= LVIF_TEXT
;
5840 dispInfo
.item
.iItem
= editedItem
;
5841 dispInfo
.item
.iSubItem
= 0;
5842 dispInfo
.item
.pszText
= pszText
;
5843 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5844 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5854 * Subclassed edit control windproc function
5857 * [I] hwnd : the edit window handle
5858 * [I] uMsg : the message that is to be processed
5859 * [I] wParam : first message parameter
5860 * [I] lParam : second message parameter
5861 * [I] isW : TRUE if input is Unicode
5866 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
5868 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
5871 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
5872 hwnd
, uMsg
, wParam
, lParam
, isW
);
5877 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
5881 WNDPROC editProc
= infoPtr
->EditWndProc
;
5882 infoPtr
->EditWndProc
= 0;
5883 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
5884 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5888 if (VK_ESCAPE
== (INT
)wParam
)
5893 else if (VK_RETURN
== (INT
)wParam
)
5897 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
5901 if (infoPtr
->hwndEdit
)
5902 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
5904 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
5910 * Subclassed edit control Unicode windproc function
5913 * [I] hwnd : the edit window handle
5914 * [I] uMsg : the message that is to be processed
5915 * [I] wParam : first message parameter
5916 * [I] lParam : second message parameter
5920 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5922 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
5927 * Subclassed edit control ANSI windproc function
5930 * [I] hwnd : the edit window handle
5931 * [I] uMsg : the message that is to be processed
5932 * [I] wParam : first message parameter
5933 * [I] lParam : second message parameter
5937 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
5939 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
5944 * Creates a subclassed edit control
5947 * [I] infoPtr : valid pointer to the listview structure
5948 * [I] text : initial text for the edit
5949 * [I] style : the window style
5950 * [I] isW : TRUE if input is Unicode
5954 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, BOOL isW
)
5956 static const DWORD style
= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
|WS_VISIBLE
;
5957 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
5960 TRACE("(%p, text=%s, isW=%d)\n", infoPtr
, debugtext_t(text
, isW
), isW
);
5962 /* window will be resized and positioned after LVN_BEGINLABELEDIT */
5964 hedit
= CreateWindowW(WC_EDITW
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5966 hedit
= CreateWindowA(WC_EDITA
, (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
5968 if (!hedit
) return 0;
5970 infoPtr
->EditWndProc
= (WNDPROC
)
5971 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
5972 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
5974 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);
5975 SendMessageW(hedit
, EM_SETLIMITTEXT
, DISP_TEXT_SIZE
-1, 0);
5982 * Begin in place editing of specified list view item
5985 * [I] infoPtr : valid pointer to the listview structure
5986 * [I] nItem : item index
5987 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
5993 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
5995 WCHAR disptextW
[DISP_TEXT_SIZE
] = { 0 };
5996 HWND hwndSelf
= infoPtr
->hwndSelf
;
5997 NMLVDISPINFOW dispInfo
;
5998 HFONT hOldFont
= NULL
;
6004 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
6006 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
6008 /* remove existing edit box */
6009 if (infoPtr
->hwndEdit
)
6011 SetFocus(infoPtr
->hwndSelf
);
6012 infoPtr
->hwndEdit
= 0;
6015 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6017 infoPtr
->nEditLabelItem
= nItem
;
6019 LISTVIEW_SetSelection(infoPtr
, nItem
);
6020 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
6021 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
6023 rect
.left
= LVIR_LABEL
;
6024 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
6026 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6027 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
6028 dispInfo
.item
.iItem
= nItem
;
6029 dispInfo
.item
.iSubItem
= 0;
6030 dispInfo
.item
.stateMask
= ~0;
6031 dispInfo
.item
.pszText
= disptextW
;
6032 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
6033 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
6035 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, isW
);
6036 if (!infoPtr
->hwndEdit
) return 0;
6038 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
6040 if (!IsWindow(hwndSelf
))
6042 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
6043 infoPtr
->hwndEdit
= 0;
6047 TRACE("disp text=%s\n", debugtext_t(dispInfo
.item
.pszText
, isW
));
6049 /* position and display edit box */
6050 hdc
= GetDC(infoPtr
->hwndSelf
);
6052 /* select the font to get appropriate metric dimensions */
6054 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
6056 /* use real edit box content, it could be altered during LVN_BEGINLABELEDIT notification */
6057 GetWindowTextW(infoPtr
->hwndEdit
, disptextW
, DISP_TEXT_SIZE
);
6058 TRACE("edit box text=%s\n", debugstr_w(disptextW
));
6060 /* get string length in pixels */
6061 GetTextExtentPoint32W(hdc
, disptextW
, lstrlenW(disptextW
), &sz
);
6063 /* add extra spacing for the next character */
6064 GetTextMetricsW(hdc
, &tm
);
6065 sz
.cx
+= tm
.tmMaxCharWidth
* 2;
6068 SelectObject(hdc
, hOldFont
);
6070 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6072 sz
.cy
= rect
.bottom
- rect
.top
+ 2;
6075 TRACE("moving edit=(%d,%d)-(%d,%d)\n", rect
.left
, rect
.top
, sz
.cx
, sz
.cy
);
6076 MoveWindow(infoPtr
->hwndEdit
, rect
.left
, rect
.top
, sz
.cx
, sz
.cy
, FALSE
);
6077 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
6078 SetFocus(infoPtr
->hwndEdit
);
6079 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
6080 return infoPtr
->hwndEdit
;
6086 * Ensures the specified item is visible, scrolling into view if necessary.
6089 * [I] infoPtr : valid pointer to the listview structure
6090 * [I] nItem : item index
6091 * [I] bPartial : partially or entirely visible
6097 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
6099 INT nScrollPosHeight
= 0;
6100 INT nScrollPosWidth
= 0;
6101 INT nHorzAdjust
= 0;
6102 INT nVertAdjust
= 0;
6105 RECT rcItem
, rcTemp
;
6107 rcItem
.left
= LVIR_BOUNDS
;
6108 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
6110 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
6112 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
6114 /* scroll left/right, but in LV_VIEW_DETAILS mode */
6115 if (infoPtr
->uView
== LV_VIEW_LIST
)
6116 nScrollPosWidth
= infoPtr
->nItemWidth
;
6117 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6118 nScrollPosWidth
= 1;
6120 if (rcItem
.left
< infoPtr
->rcList
.left
)
6123 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
6128 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
6132 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
6134 /* scroll up/down, but not in LVS_LIST mode */
6135 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6136 nScrollPosHeight
= infoPtr
->nItemHeight
;
6137 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
6138 nScrollPosHeight
= 1;
6140 if (rcItem
.top
< infoPtr
->rcList
.top
)
6143 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
6148 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
6152 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
6154 if (nScrollPosWidth
)
6156 INT diff
= nHorzDiff
/ nScrollPosWidth
;
6157 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
6158 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
);
6161 if (nScrollPosHeight
)
6163 INT diff
= nVertDiff
/ nScrollPosHeight
;
6164 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
6165 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
);
6173 * Searches for an item with specific characteristics.
6176 * [I] hwnd : window handle
6177 * [I] nStart : base item index
6178 * [I] lpFindInfo : item information to look for
6181 * SUCCESS : index of item
6184 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6185 const LVFINDINFOW
*lpFindInfo
)
6187 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6188 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
6189 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
6190 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
6191 POINT Position
, Destination
;
6194 /* Search in virtual listviews should be done by application, not by
6195 listview control, so we just send LVN_ODFINDITEMW and return the result */
6196 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6200 nmlv
.iStart
= nStart
;
6201 nmlv
.lvfi
= *lpFindInfo
;
6202 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
6205 if (!lpFindInfo
|| nItem
< 0) return -1;
6208 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6209 lpFindInfo
->flags
& LVFI_SUBSTRING
)
6211 lvItem
.mask
|= LVIF_TEXT
;
6212 lvItem
.pszText
= szDispText
;
6213 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6216 if (lpFindInfo
->flags
& LVFI_WRAP
)
6219 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
6220 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
6225 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6226 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
6227 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
6228 switch(lpFindInfo
->vkDirection
)
6230 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
6231 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
6232 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
6233 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
6234 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
6235 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6236 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
6238 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
6239 Destination
.x
= rcArea
.right
;
6240 Destination
.y
= rcArea
.bottom
;
6242 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
6246 else Destination
.x
= Destination
.y
= 0;
6248 /* if LVFI_PARAM is specified, all other flags are ignored */
6249 if (lpFindInfo
->flags
& LVFI_PARAM
)
6251 lvItem
.mask
|= LVIF_PARAM
;
6253 lvItem
.mask
&= ~LVIF_TEXT
;
6257 for (; nItem
< nLast
; nItem
++)
6259 lvItem
.iItem
= nItem
;
6260 lvItem
.iSubItem
= 0;
6261 lvItem
.pszText
= szDispText
;
6262 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6264 if (lvItem
.mask
& LVIF_PARAM
)
6266 if (lpFindInfo
->lParam
== lvItem
.lParam
)
6272 if (lvItem
.mask
& LVIF_TEXT
)
6274 if (lpFindInfo
->flags
& (LVFI_PARTIAL
| LVFI_SUBSTRING
))
6276 WCHAR
*p
= strstrW(lvItem
.pszText
, lpFindInfo
->psz
);
6277 if (!p
|| p
!= lvItem
.pszText
) continue;
6281 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
6285 if (!bNearest
) return nItem
;
6287 /* This is very inefficient. To do a good job here,
6288 * we need a sorted array of (x,y) item positions */
6289 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6291 /* compute the distance^2 to the destination */
6292 xdist
= Destination
.x
- Position
.x
;
6293 ydist
= Destination
.y
- Position
.y
;
6294 dist
= xdist
* xdist
+ ydist
* ydist
;
6296 /* remember the distance, and item if it's closer */
6300 nNearestItem
= nItem
;
6307 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
6312 return nNearestItem
;
6317 * Searches for an item with specific characteristics.
6320 * [I] hwnd : window handle
6321 * [I] nStart : base item index
6322 * [I] lpFindInfo : item information to look for
6325 * SUCCESS : index of item
6328 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
6329 const LVFINDINFOA
*lpFindInfo
)
6331 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
) ||
6332 lpFindInfo
->flags
& LVFI_SUBSTRING
;
6337 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
6338 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
6339 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
6340 textfreeT(strW
, FALSE
);
6346 * Retrieves column attributes.
6349 * [I] infoPtr : valid pointer to the listview structure
6350 * [I] nColumn : column index
6351 * [IO] lpColumn : column information
6352 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
6353 * otherwise it is in fact a LPLVCOLUMNA
6359 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
6361 COLUMN_INFO
*lpColumnInfo
;
6364 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6365 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6367 /* initialize memory */
6368 ZeroMemory(&hdi
, sizeof(hdi
));
6370 if (lpColumn
->mask
& LVCF_TEXT
)
6372 hdi
.mask
|= HDI_TEXT
;
6373 hdi
.pszText
= lpColumn
->pszText
;
6374 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
6377 if (lpColumn
->mask
& LVCF_IMAGE
)
6378 hdi
.mask
|= HDI_IMAGE
;
6380 if (lpColumn
->mask
& LVCF_ORDER
)
6381 hdi
.mask
|= HDI_ORDER
;
6383 if (lpColumn
->mask
& LVCF_SUBITEM
)
6384 hdi
.mask
|= HDI_LPARAM
;
6386 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
6388 if (lpColumn
->mask
& LVCF_FMT
)
6389 lpColumn
->fmt
= lpColumnInfo
->fmt
;
6391 if (lpColumn
->mask
& LVCF_WIDTH
)
6392 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
6394 if (lpColumn
->mask
& LVCF_IMAGE
)
6395 lpColumn
->iImage
= hdi
.iImage
;
6397 if (lpColumn
->mask
& LVCF_ORDER
)
6398 lpColumn
->iOrder
= hdi
.iOrder
;
6400 if (lpColumn
->mask
& LVCF_SUBITEM
)
6401 lpColumn
->iSubItem
= hdi
.lParam
;
6403 if (lpColumn
->mask
& LVCF_MINWIDTH
)
6404 lpColumn
->cxMin
= lpColumnInfo
->cxMin
;
6410 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
6412 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
6417 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
6422 * Retrieves the column width.
6425 * [I] infoPtr : valid pointer to the listview structure
6426 * [I] int : column index
6429 * SUCCESS : column width
6432 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
6434 INT nColumnWidth
= 0;
6437 TRACE("nColumn=%d\n", nColumn
);
6439 /* we have a 'column' in LIST and REPORT mode only */
6440 switch(infoPtr
->uView
)
6443 nColumnWidth
= infoPtr
->nItemWidth
;
6445 case LV_VIEW_DETAILS
:
6446 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDN_ITEMCHANGED.
6447 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
6448 * HDN_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
6450 * TODO: should we do the same in LVM_GETCOLUMN?
6452 hdItem
.mask
= HDI_WIDTH
;
6453 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
6455 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
6458 nColumnWidth
= hdItem
.cxy
;
6462 TRACE("nColumnWidth=%d\n", nColumnWidth
);
6463 return nColumnWidth
;
6468 * In list or report display mode, retrieves the number of items that can fit
6469 * vertically in the visible area. In icon or small icon display mode,
6470 * retrieves the total number of visible items.
6473 * [I] infoPtr : valid pointer to the listview structure
6476 * Number of fully visible items.
6478 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
6480 switch (infoPtr
->uView
)
6483 case LV_VIEW_SMALLICON
:
6484 return infoPtr
->nItemCount
;
6485 case LV_VIEW_DETAILS
:
6486 return LISTVIEW_GetCountPerColumn(infoPtr
);
6488 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
6496 * Retrieves an image list handle.
6499 * [I] infoPtr : valid pointer to the listview structure
6500 * [I] nImageList : image list identifier
6503 * SUCCESS : image list handle
6506 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
6510 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
6511 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
6512 case LVSIL_STATE
: return infoPtr
->himlState
;
6513 case LVSIL_GROUPHEADER
:
6514 FIXME("LVSIL_GROUPHEADER not supported\n");
6517 WARN("got unknown imagelist index - %d\n", nImageList
);
6522 /* LISTVIEW_GetISearchString */
6526 * Retrieves item attributes.
6529 * [I] hwnd : window handle
6530 * [IO] lpLVItem : item info
6531 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6532 * if FALSE, then lpLVItem is a LPLVITEMA.
6535 * This is the internal 'GetItem' interface -- it tries to
6536 * be smart and avoid text copies, if possible, by modifying
6537 * lpLVItem->pszText to point to the text string. Please note
6538 * that this is not always possible (e.g. OWNERDATA), so on
6539 * entry you *must* supply valid values for pszText, and cchTextMax.
6540 * The only difference to the documented interface is that upon
6541 * return, you should use *only* the lpLVItem->pszText, rather than
6542 * the buffer pointer you provided on input. Most code already does
6543 * that, so it's not a problem.
6544 * For the two cases when the text must be copied (that is,
6545 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
6551 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6553 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
6554 NMLVDISPINFOW dispInfo
;
6560 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6562 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6565 if (lpLVItem
->mask
== 0) return TRUE
;
6566 TRACE("mask=%x\n", lpLVItem
->mask
);
6568 /* make a local copy */
6569 isubitem
= lpLVItem
->iSubItem
;
6571 /* a quick optimization if all we're asked is the focus state
6572 * these queries are worth optimising since they are common,
6573 * and can be answered in constant time, without the heavy accesses */
6574 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
6575 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
6577 lpLVItem
->state
= 0;
6578 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6579 lpLVItem
->state
|= LVIS_FOCUSED
;
6583 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
6585 /* if the app stores all the data, handle it separately */
6586 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
6588 dispInfo
.item
.state
= 0;
6590 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
6591 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
6592 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
6594 UINT mask
= lpLVItem
->mask
;
6596 /* NOTE: copy only fields which we _know_ are initialized, some apps
6597 * depend on the uninitialized fields being 0 */
6598 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
6599 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6600 dispInfo
.item
.iSubItem
= isubitem
;
6601 if (lpLVItem
->mask
& LVIF_TEXT
)
6603 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
6605 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
6608 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6609 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6612 if (lpLVItem
->mask
& LVIF_STATE
)
6613 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
6614 /* could be zeroed on LVIF_NORECOMPUTE case */
6615 if (dispInfo
.item
.mask
)
6617 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6618 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
6619 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6621 /* full size structure expected - _WIN32IE >= 0x560 */
6622 *lpLVItem
= dispInfo
.item
;
6624 else if (lpLVItem
->mask
& LVIF_INDENT
)
6626 /* indent member expected - _WIN32IE >= 0x300 */
6627 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
6631 /* minimal structure expected */
6632 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
6634 lpLVItem
->mask
= mask
;
6635 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
6639 /* make sure lParam is zeroed out */
6640 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
6642 /* callback marked pointer required here */
6643 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
6644 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
6646 /* we store only a little state, so if we're not asked, we're done */
6647 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
6649 /* if focus is handled by us, report it */
6650 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6652 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6653 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6654 lpLVItem
->state
|= LVIS_FOCUSED
;
6657 /* and do the same for selection, if we handle it */
6658 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6660 lpLVItem
->state
&= ~LVIS_SELECTED
;
6661 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6662 lpLVItem
->state
|= LVIS_SELECTED
;
6668 /* find the item and subitem structures before we proceed */
6669 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
6670 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
6675 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
6676 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
6679 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
6684 pItemHdr
= &lpItem
->hdr
;
6686 /* Do we need to query the state from the app? */
6687 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
6689 dispInfo
.item
.mask
|= LVIF_STATE
;
6690 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
6693 /* Do we need to enquire about the image? */
6694 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
6695 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
6697 dispInfo
.item
.mask
|= LVIF_IMAGE
;
6698 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
6701 /* Only items support indentation */
6702 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
6705 dispInfo
.item
.mask
|= LVIF_INDENT
;
6706 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
6709 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
6710 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
6711 !is_text(pItemHdr
->pszText
))
6713 dispInfo
.item
.mask
|= LVIF_TEXT
;
6714 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
6715 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
6716 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
6717 *dispInfo
.item
.pszText
= '\0';
6720 /* If we don't have all the requested info, query the application */
6721 if (dispInfo
.item
.mask
)
6723 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
6724 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
6725 dispInfo
.item
.lParam
= lpItem
->lParam
;
6726 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
6727 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
6730 /* we should not store values for subitems */
6731 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6733 /* Now, handle the iImage field */
6734 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6736 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6737 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6738 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6740 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6742 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6743 lpLVItem
->iImage
= pItemHdr
->iImage
;
6745 lpLVItem
->iImage
= 0;
6748 /* The pszText field */
6749 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6751 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6752 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6754 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6756 else if (lpLVItem
->mask
& LVIF_TEXT
)
6758 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6759 if (isW
|| !is_text(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6760 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6763 /* Next is the lParam field */
6764 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6766 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6767 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6768 lpItem
->lParam
= dispInfo
.item
.lParam
;
6770 else if (lpLVItem
->mask
& LVIF_PARAM
)
6771 lpLVItem
->lParam
= lpItem
->lParam
;
6773 /* if this is a subitem, we're done */
6774 if (isubitem
) return TRUE
;
6776 /* ... the state field (this one is different due to uCallbackmask) */
6777 if (lpLVItem
->mask
& LVIF_STATE
)
6779 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6780 if (dispInfo
.item
.mask
& LVIF_STATE
)
6782 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6783 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6785 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6787 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6788 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6789 lpLVItem
->state
|= LVIS_FOCUSED
;
6791 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6793 lpLVItem
->state
&= ~LVIS_SELECTED
;
6794 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6795 lpLVItem
->state
|= LVIS_SELECTED
;
6799 /* and last, but not least, the indent field */
6800 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6802 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6803 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6804 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6806 else if (lpLVItem
->mask
& LVIF_INDENT
)
6808 lpLVItem
->iIndent
= lpItem
->iIndent
;
6816 * Retrieves item attributes.
6819 * [I] hwnd : window handle
6820 * [IO] lpLVItem : item info
6821 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6822 * if FALSE, then lpLVItem is a LPLVITEMA.
6825 * This is the external 'GetItem' interface -- it properly copies
6826 * the text in the provided buffer.
6832 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6837 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6840 pszText
= lpLVItem
->pszText
;
6841 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6842 if (bResult
&& (lpLVItem
->mask
& LVIF_TEXT
) && lpLVItem
->pszText
!= pszText
)
6844 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6845 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6847 pszText
= LPSTR_TEXTCALLBACKW
;
6849 lpLVItem
->pszText
= pszText
;
6857 * Retrieves the position (upper-left) of the listview control item.
6858 * Note that for LVS_ICON style, the upper-left is that of the icon
6859 * and not the bounding box.
6862 * [I] infoPtr : valid pointer to the listview structure
6863 * [I] nItem : item index
6864 * [O] lpptPosition : coordinate information
6870 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6874 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6876 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6878 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6879 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6881 if (infoPtr
->uView
== LV_VIEW_ICON
)
6883 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6884 lpptPosition
->y
+= ICON_TOP_PADDING
;
6886 lpptPosition
->x
+= Origin
.x
;
6887 lpptPosition
->y
+= Origin
.y
;
6889 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6896 * Retrieves the bounding rectangle for a listview control item.
6899 * [I] infoPtr : valid pointer to the listview structure
6900 * [I] nItem : item index
6901 * [IO] lprc : bounding rectangle coordinates
6902 * lprc->left specifies the portion of the item for which the bounding
6903 * rectangle will be retrieved.
6905 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6906 * including the icon and label.
6909 * * Experiment shows that native control returns:
6910 * * width = min (48, length of text line)
6911 * * .left = position.x - (width - iconsize.cx)/2
6912 * * .right = .left + width
6913 * * height = #lines of text * ntmHeight + icon height + 8
6914 * * .top = position.y - 2
6915 * * .bottom = .top + height
6916 * * separation between items .y = itemSpacing.cy - height
6917 * * .x = itemSpacing.cx - width
6918 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
6921 * * Experiment shows that native control returns:
6922 * * width = iconSize.cx + 16
6923 * * .left = position.x - (width - iconsize.cx)/2
6924 * * .right = .left + width
6925 * * height = iconSize.cy + 4
6926 * * .top = position.y - 2
6927 * * .bottom = .top + height
6928 * * separation between items .y = itemSpacing.cy - height
6929 * * .x = itemSpacing.cx - width
6930 * LVIR_LABEL Returns the bounding rectangle of the item text.
6933 * * Experiment shows that native control returns:
6934 * * width = text length
6935 * * .left = position.x - width/2
6936 * * .right = .left + width
6937 * * height = ntmH * linecount + 2
6938 * * .top = position.y + iconSize.cy + 6
6939 * * .bottom = .top + height
6940 * * separation between items .y = itemSpacing.cy - height
6941 * * .x = itemSpacing.cx - width
6942 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
6943 * rectangles, but excludes columns in report view.
6950 * Note that the bounding rectangle of the label in the LVS_ICON view depends
6951 * upon whether the window has the focus currently and on whether the item
6952 * is the one with the focus. Ensure that the control's record of which
6953 * item has the focus agrees with the items' records.
6955 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6957 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6958 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
6959 POINT Position
, Origin
;
6963 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
6965 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6967 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6968 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6970 /* Be smart and try to figure out the minimum we have to do */
6971 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
6972 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
6973 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
6974 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
6975 oversizedBox
= TRUE
;
6977 /* get what we need from the item before hand, so we make
6978 * only one request. This can speed up things, if data
6979 * is stored on the app side */
6981 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6982 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
6983 lvItem
.iItem
= nItem
;
6984 lvItem
.iSubItem
= 0;
6985 lvItem
.pszText
= szDispText
;
6986 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6987 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6988 /* we got the state already up, simulate it here, to avoid a reget */
6989 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
6991 lvItem
.mask
|= LVIF_STATE
;
6992 lvItem
.stateMask
= LVIS_FOCUSED
;
6993 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
6996 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
6997 lprc
->left
= LVIR_BOUNDS
;
7003 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
7007 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
7011 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
7014 case LVIR_SELECTBOUNDS
:
7015 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
7019 WARN("Unknown value: %d\n", lprc
->left
);
7023 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7025 if (mode
!= LVIR_BOUNDS
)
7026 OffsetRect(lprc
, Origin
.x
+ LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
,
7027 Position
.y
+ Origin
.y
);
7029 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
7032 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
7034 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
7041 * Retrieves the spacing between listview control items.
7044 * [I] infoPtr : valid pointer to the listview structure
7045 * [IO] lprc : rectangle to receive the output
7046 * on input, lprc->top = nSubItem
7047 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
7049 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
7050 * not only those of the first column.
7056 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT item
, LPRECT lprc
)
7058 RECT rect
= { 0, 0, 0, 0 };
7062 if (!lprc
) return FALSE
;
7064 TRACE("(item=%d, subitem=%d, type=%d)\n", item
, lprc
->top
, lprc
->left
);
7065 /* Subitem of '0' means item itself, and this works for all control view modes */
7067 return LISTVIEW_GetItemRect(infoPtr
, item
, lprc
);
7069 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
7071 LISTVIEW_GetOrigin(infoPtr
, &origin
);
7072 /* this works for any item index, no matter if it exists or not */
7073 y
= item
* infoPtr
->nItemHeight
+ origin
.y
;
7075 if (infoPtr
->hwndHeader
&& SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)&rect
))
7078 rect
.bottom
= infoPtr
->nItemHeight
;
7082 /* Native implementation is broken for this case and garbage is left for left and right fields,
7083 we zero them to get predictable output */
7084 lprc
->left
= lprc
->right
= lprc
->top
= 0;
7085 lprc
->bottom
= infoPtr
->nItemHeight
;
7086 OffsetRect(lprc
, origin
.x
, y
);
7087 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7095 /* it doesn't matter if main item actually has an icon, if imagelist is set icon width is returned */
7096 if (infoPtr
->himlSmall
)
7097 rect
.right
= rect
.left
+ infoPtr
->iconSize
.cx
;
7099 rect
.right
= rect
.left
;
7101 rect
.bottom
= rect
.top
+ infoPtr
->iconSize
.cy
;
7109 ERR("Unknown bounds=%d\n", lprc
->left
);
7113 OffsetRect(&rect
, origin
.x
, y
);
7115 TRACE("return rect %s\n", wine_dbgstr_rect(lprc
));
7122 * Retrieves the spacing between listview control items.
7125 * [I] infoPtr : valid pointer to the listview structure
7126 * [I] bSmall : flag for small or large icon
7129 * Horizontal + vertical spacing
7131 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
7137 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7141 if (infoPtr
->uView
== LV_VIEW_ICON
)
7142 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
7144 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
7151 * Retrieves the state of a listview control item.
7154 * [I] infoPtr : valid pointer to the listview structure
7155 * [I] nItem : item index
7156 * [I] uMask : state mask
7159 * State specified by the mask.
7161 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
7165 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7167 lvItem
.iItem
= nItem
;
7168 lvItem
.iSubItem
= 0;
7169 lvItem
.mask
= LVIF_STATE
;
7170 lvItem
.stateMask
= uMask
;
7171 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
7173 return lvItem
.state
& uMask
;
7178 * Retrieves the text of a listview control item or subitem.
7181 * [I] hwnd : window handle
7182 * [I] nItem : item index
7183 * [IO] lpLVItem : item information
7184 * [I] isW : TRUE if lpLVItem is Unicode
7187 * SUCCESS : string length
7190 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
7192 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
7194 lpLVItem
->mask
= LVIF_TEXT
;
7195 lpLVItem
->iItem
= nItem
;
7196 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
7198 return textlenT(lpLVItem
->pszText
, isW
);
7203 * Searches for an item based on properties + relationships.
7206 * [I] infoPtr : valid pointer to the listview structure
7207 * [I] nItem : item index
7208 * [I] uFlags : relationship flag
7211 * SUCCESS : item index
7214 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
7217 LVFINDINFOW lvFindInfo
;
7218 INT nCountPerColumn
;
7222 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
7223 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
7225 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
7227 if (uFlags
& LVNI_CUT
)
7230 if (uFlags
& LVNI_DROPHILITED
)
7231 uMask
|= LVIS_DROPHILITED
;
7233 if (uFlags
& LVNI_FOCUSED
)
7234 uMask
|= LVIS_FOCUSED
;
7236 if (uFlags
& LVNI_SELECTED
)
7237 uMask
|= LVIS_SELECTED
;
7239 /* if we're asked for the focused item, that's only one,
7240 * so it's worth optimizing */
7241 if (uFlags
& LVNI_FOCUSED
)
7243 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
7244 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
7247 if (uFlags
& LVNI_ABOVE
)
7249 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7254 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7260 /* Special case for autoarrange - move 'til the top of a list */
7261 if (is_autoarrange(infoPtr
))
7263 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7264 while (nItem
- nCountPerRow
>= 0)
7266 nItem
-= nCountPerRow
;
7267 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7272 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7273 lvFindInfo
.vkDirection
= VK_UP
;
7274 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7275 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7277 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7282 else if (uFlags
& LVNI_BELOW
)
7284 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
7286 while (nItem
< infoPtr
->nItemCount
)
7289 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7295 /* Special case for autoarrange - move 'til the bottom of a list */
7296 if (is_autoarrange(infoPtr
))
7298 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7299 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
7301 nItem
+= nCountPerRow
;
7302 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7307 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7308 lvFindInfo
.vkDirection
= VK_DOWN
;
7309 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7310 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7312 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7317 else if (uFlags
& LVNI_TOLEFT
)
7319 if (infoPtr
->uView
== LV_VIEW_LIST
)
7321 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7322 while (nItem
- nCountPerColumn
>= 0)
7324 nItem
-= nCountPerColumn
;
7325 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7329 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7331 /* Special case for autoarrange - move 'til the beginning of a row */
7332 if (is_autoarrange(infoPtr
))
7334 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7335 while (nItem
% nCountPerRow
> 0)
7338 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7343 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7344 lvFindInfo
.vkDirection
= VK_LEFT
;
7345 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7346 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7348 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7353 else if (uFlags
& LVNI_TORIGHT
)
7355 if (infoPtr
->uView
== LV_VIEW_LIST
)
7357 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
7358 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
7360 nItem
+= nCountPerColumn
;
7361 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7365 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7367 /* Special case for autoarrange - move 'til the end of a row */
7368 if (is_autoarrange(infoPtr
))
7370 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
7371 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
7374 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7379 lvFindInfo
.flags
= LVFI_NEARESTXY
;
7380 lvFindInfo
.vkDirection
= VK_RIGHT
;
7381 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
7382 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
7384 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
7393 /* search by index */
7394 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
7396 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
7404 /* LISTVIEW_GetNumberOfWorkAreas */
7408 * Retrieves the origin coordinates when in icon or small icon display mode.
7411 * [I] infoPtr : valid pointer to the listview structure
7412 * [O] lpptOrigin : coordinate information
7417 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
7419 INT nHorzPos
= 0, nVertPos
= 0;
7420 SCROLLINFO scrollInfo
;
7422 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7423 scrollInfo
.fMask
= SIF_POS
;
7425 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
7426 nHorzPos
= scrollInfo
.nPos
;
7427 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
7428 nVertPos
= scrollInfo
.nPos
;
7430 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
7432 lpptOrigin
->x
= infoPtr
->rcList
.left
;
7433 lpptOrigin
->y
= infoPtr
->rcList
.top
;
7434 if (infoPtr
->uView
== LV_VIEW_LIST
)
7435 nHorzPos
*= infoPtr
->nItemWidth
;
7436 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7437 nVertPos
*= infoPtr
->nItemHeight
;
7439 lpptOrigin
->x
-= nHorzPos
;
7440 lpptOrigin
->y
-= nVertPos
;
7442 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
7447 * Retrieves the width of a string.
7450 * [I] hwnd : window handle
7451 * [I] lpszText : text string to process
7452 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
7455 * SUCCESS : string width (in pixels)
7458 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
7463 if (is_text(lpszText
))
7465 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
7466 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7467 HFONT hOldFont
= SelectObject(hdc
, hFont
);
7470 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
7472 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
7473 SelectObject(hdc
, hOldFont
);
7474 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7476 return stringSize
.cx
;
7481 * Determines which listview item is located at the specified position.
7484 * [I] infoPtr : valid pointer to the listview structure
7485 * [IO] lpht : hit test information
7486 * [I] subitem : fill out iSubItem.
7487 * [I] select : return the index only if the hit selects the item
7490 * (mm 20001022): We must not allow iSubItem to be touched, for
7491 * an app might pass only a structure with space up to iItem!
7492 * (MS Office 97 does that for instance in the file open dialog)
7495 * SUCCESS : item index
7498 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
7500 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
7501 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
7502 POINT Origin
, Position
, opt
;
7507 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
7511 if (subitem
) lpht
->iSubItem
= 0;
7513 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7515 /* set whole list relation flags */
7516 if (subitem
&& infoPtr
->uView
== LV_VIEW_DETAILS
)
7518 /* LVM_SUBITEMHITTEST checks left bound of possible client area */
7519 if (infoPtr
->rcList
.left
> lpht
->pt
.x
&& Origin
.x
< lpht
->pt
.x
)
7520 lpht
->flags
|= LVHT_TOLEFT
;
7522 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7523 opt
.y
= lpht
->pt
.y
+ infoPtr
->rcList
.top
;
7527 if (infoPtr
->rcList
.bottom
< opt
.y
)
7528 lpht
->flags
|= LVHT_BELOW
;
7532 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
7533 lpht
->flags
|= LVHT_TOLEFT
;
7534 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
7535 lpht
->flags
|= LVHT_TORIGHT
;
7537 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
7538 lpht
->flags
|= LVHT_ABOVE
;
7539 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
7540 lpht
->flags
|= LVHT_BELOW
;
7543 /* even if item is invalid try to find subitem */
7544 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
7549 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7551 lpht
->iSubItem
= -1;
7552 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
7554 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
7556 if ((opt
.x
>= pRect
->left
) && (opt
.x
< pRect
->right
))
7562 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
7564 /* if we're outside horizontal columns bounds there's nothing to test further */
7565 if (lpht
->iSubItem
== -1)
7568 lpht
->flags
= LVHT_NOWHERE
;
7573 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7574 if (lpht
->flags
) return -1;
7576 lpht
->flags
|= LVHT_NOWHERE
;
7578 /* first deal with the large items */
7579 rcSearch
.left
= lpht
->pt
.x
;
7580 rcSearch
.top
= lpht
->pt
.y
;
7581 rcSearch
.right
= rcSearch
.left
+ 1;
7582 rcSearch
.bottom
= rcSearch
.top
+ 1;
7584 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
7585 iterator_next(&i
); /* go to first item in the sequence */
7587 iterator_destroy(&i
);
7589 TRACE("lpht->iItem=%d\n", iItem
);
7590 if (iItem
== -1) return -1;
7592 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
7593 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
7594 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
7595 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
7596 lvItem
.iItem
= iItem
;
7597 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
7598 lvItem
.pszText
= szDispText
;
7599 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7600 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
7601 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
7603 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7604 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
7605 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
7607 if (lpht
->pt
.y
< infoPtr
->rcList
.top
&& lpht
->pt
.y
>= 0)
7608 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
+ infoPtr
->rcList
.top
;
7610 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
7612 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7615 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
7616 opt
.x
= lpht
->pt
.x
- Origin
.x
;
7620 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7621 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7623 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
7624 if (!PtInRect(&rcBounds
, opt
)) return -1;
7626 if (PtInRect(&rcIcon
, opt
))
7627 lpht
->flags
|= LVHT_ONITEMICON
;
7628 else if (PtInRect(&rcLabel
, opt
))
7629 lpht
->flags
|= LVHT_ONITEMLABEL
;
7630 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
7631 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
7632 /* special case for LVS_EX_FULLROWSELECT */
7633 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
7634 !(lpht
->flags
& LVHT_ONITEM
))
7636 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
7638 if (lpht
->flags
& LVHT_ONITEM
)
7639 lpht
->flags
&= ~LVHT_NOWHERE
;
7640 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
7642 if (select
&& !(infoPtr
->uView
== LV_VIEW_DETAILS
&&
7643 ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) ||
7644 (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
))))
7646 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7648 /* get main item bounds */
7649 lvItem
.iSubItem
= 0;
7650 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
7651 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
7652 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
7654 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
7656 return lpht
->iItem
= iItem
;
7661 * Inserts a new item in the listview control.
7664 * [I] infoPtr : valid pointer to the listview structure
7665 * [I] lpLVItem : item information
7666 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
7669 * SUCCESS : new item index
7672 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
7679 BOOL is_sorted
, has_changed
;
7681 HWND hwndSelf
= infoPtr
->hwndSelf
;
7683 TRACE("(item=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
7685 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
7687 /* make sure it's an item, and not a subitem; cannot insert a subitem */
7688 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
7690 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
7692 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
7694 /* insert item in listview control data structure */
7695 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
7696 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
7698 /* link with id struct */
7699 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
7701 lpID
->item
= hdpaSubItems
;
7702 lpID
->id
= get_next_itemid(infoPtr
);
7703 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
7705 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
7706 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
7708 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
7710 /* calculate new item index */
7717 while (i
< infoPtr
->nItemCount
)
7719 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
7720 item_s
= DPA_GetPtr(hItem
, 0);
7722 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
7723 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
7725 if (cmpv
>= 0) break;
7731 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
7733 TRACE("inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
7734 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
7735 if (nItem
== -1) goto fail
;
7736 infoPtr
->nItemCount
++;
7738 /* shift indices first so they don't get tangled */
7739 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7741 /* set the item attributes */
7742 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7744 /* full size structure expected - _WIN32IE >= 0x560 */
7747 else if (lpLVItem
->mask
& LVIF_INDENT
)
7749 /* indent member expected - _WIN32IE >= 0x300 */
7750 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7754 /* minimal structure expected */
7755 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7758 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7760 item
.mask
|= LVIF_STATE
;
7761 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7762 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7763 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7766 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7768 /* make room for the position, if we are in the right mode */
7769 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7771 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7773 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7775 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7780 /* send LVN_INSERTITEM notification */
7781 memset(&nmlv
, 0, sizeof(NMLISTVIEW
));
7783 nmlv
.lParam
= lpItem
->lParam
;
7784 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7785 if (!IsWindow(hwndSelf
))
7788 /* align items (set position of each item) */
7789 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7793 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7794 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7796 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7798 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7801 /* now is the invalidation fun */
7802 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7806 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7807 LISTVIEW_ShiftFocus(infoPtr
, infoPtr
->nFocusedItem
, nItem
, -1);
7808 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7809 infoPtr
->nItemCount
--;
7811 DPA_DeletePtr(hdpaSubItems
, 0);
7812 DPA_Destroy (hdpaSubItems
);
7819 * Checks item visibility.
7822 * [I] infoPtr : valid pointer to the listview structure
7823 * [I] nFirst : item index to check for
7826 * Item visible : TRUE
7827 * Item invisible or failure : FALSE
7829 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7831 POINT Origin
, Position
;
7836 TRACE("nItem=%d\n", nItem
);
7838 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7840 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7841 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7842 rcItem
.left
= Position
.x
+ Origin
.x
;
7843 rcItem
.top
= Position
.y
+ Origin
.y
;
7844 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7845 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7847 hdc
= GetDC(infoPtr
->hwndSelf
);
7848 if (!hdc
) return FALSE
;
7849 ret
= RectVisible(hdc
, &rcItem
);
7850 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7857 * Redraws a range of items.
7860 * [I] infoPtr : valid pointer to the listview structure
7861 * [I] nFirst : first item
7862 * [I] nLast : last item
7868 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7872 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7873 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7876 for (i
= nFirst
; i
<= nLast
; i
++)
7877 LISTVIEW_InvalidateItem(infoPtr
, i
);
7884 * Scroll the content of a listview.
7887 * [I] infoPtr : valid pointer to the listview structure
7888 * [I] dx : horizontal scroll amount in pixels
7889 * [I] dy : vertical scroll amount in pixels
7896 * If the control is in report view (LV_VIEW_DETAILS) the control can
7897 * be scrolled only in line increments. "dy" will be rounded to the
7898 * nearest number of pixels that are a whole line. Ex: if line height
7899 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7900 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7902 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7904 switch(infoPtr
->uView
) {
7905 case LV_VIEW_DETAILS
:
7906 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7907 dy
/= infoPtr
->nItemHeight
;
7910 if (dy
!= 0) return FALSE
;
7916 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
);
7917 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
);
7924 * Sets the background color.
7927 * [I] infoPtr : valid pointer to the listview structure
7928 * [I] color : background color
7934 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
7936 TRACE("(color=%x)\n", color
);
7938 if(infoPtr
->clrBk
!= color
) {
7939 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7940 infoPtr
->clrBk
= color
;
7941 if (color
== CLR_NONE
)
7942 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
7945 infoPtr
->hBkBrush
= CreateSolidBrush(color
);
7946 infoPtr
->dwLvExStyle
&= ~LVS_EX_TRANSPARENTBKGND
;
7953 /* LISTVIEW_SetBkImage */
7955 /*** Helper for {Insert,Set}ColumnT *only* */
7956 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
7957 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7959 if (lpColumn
->mask
& LVCF_FMT
)
7961 /* format member is valid */
7962 lphdi
->mask
|= HDI_FORMAT
;
7964 /* set text alignment (leftmost column must be left-aligned) */
7965 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
7966 lphdi
->fmt
|= HDF_LEFT
;
7967 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
7968 lphdi
->fmt
|= HDF_RIGHT
;
7969 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
7970 lphdi
->fmt
|= HDF_CENTER
;
7972 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
7973 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
7975 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
7977 lphdi
->fmt
|= HDF_IMAGE
;
7978 lphdi
->iImage
= I_IMAGECALLBACK
;
7981 if (lpColumn
->fmt
& LVCFMT_FIXED_WIDTH
)
7982 lphdi
->fmt
|= HDF_FIXEDWIDTH
;
7985 if (lpColumn
->mask
& LVCF_WIDTH
)
7987 lphdi
->mask
|= HDI_WIDTH
;
7988 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
7990 /* make it fill the remainder of the controls width */
7994 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
7996 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
7997 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
8000 /* retrieve the layout of the header */
8001 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
8002 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
8004 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
8007 lphdi
->cxy
= lpColumn
->cx
;
8010 if (lpColumn
->mask
& LVCF_TEXT
)
8012 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
8013 lphdi
->fmt
|= HDF_STRING
;
8014 lphdi
->pszText
= lpColumn
->pszText
;
8015 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
8018 if (lpColumn
->mask
& LVCF_IMAGE
)
8020 lphdi
->mask
|= HDI_IMAGE
;
8021 lphdi
->iImage
= lpColumn
->iImage
;
8024 if (lpColumn
->mask
& LVCF_ORDER
)
8026 lphdi
->mask
|= HDI_ORDER
;
8027 lphdi
->iOrder
= lpColumn
->iOrder
;
8034 * Inserts a new column.
8037 * [I] infoPtr : valid pointer to the listview structure
8038 * [I] nColumn : column index
8039 * [I] lpColumn : column information
8040 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
8043 * SUCCESS : new column index
8046 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8047 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8049 COLUMN_INFO
*lpColumnInfo
;
8053 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8055 if (!lpColumn
|| nColumn
< 0) return -1;
8056 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
8058 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8059 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8062 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
8063 * (can be seen in SPY) otherwise column never gets added.
8065 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
8066 hdi
.mask
|= HDI_WIDTH
;
8071 * when the iSubItem is available Windows copies it to the header lParam. It seems
8072 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
8074 if (lpColumn
->mask
& LVCF_SUBITEM
)
8076 hdi
.mask
|= HDI_LPARAM
;
8077 hdi
.lParam
= lpColumn
->iSubItem
;
8080 /* create header if not present */
8081 LISTVIEW_CreateHeader(infoPtr
);
8082 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
8083 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
8085 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8088 /* insert item in header control */
8089 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
8090 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
8091 nColumn
, (LPARAM
)&hdi
);
8092 if (nNewColumn
== -1) return -1;
8093 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
8095 /* create our own column info */
8096 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
8097 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
8099 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
8100 if (lpColumn
->mask
& LVCF_MINWIDTH
) lpColumnInfo
->cxMin
= lpColumn
->cxMin
;
8101 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
8104 /* now we have to actually adjust the data */
8105 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
8107 SUBITEM_INFO
*lpSubItem
;
8113 item
.iSubItem
= nNewColumn
;
8114 item
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
8115 item
.iImage
= I_IMAGECALLBACK
;
8116 item
.pszText
= LPSTR_TEXTCALLBACKW
;
8118 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
8120 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
8121 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
8123 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
8124 if (lpSubItem
->iSubItem
>= nNewColumn
)
8125 lpSubItem
->iSubItem
++;
8128 /* add new subitem for each item */
8130 set_sub_item(infoPtr
, &item
, isW
, &changed
);
8134 /* make space for the new column */
8135 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8136 LISTVIEW_UpdateItemSize(infoPtr
);
8141 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
8144 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
8152 * Sets the attributes of a header item.
8155 * [I] infoPtr : valid pointer to the listview structure
8156 * [I] nColumn : column index
8157 * [I] lpColumn : column attributes
8158 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
8164 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
8165 const LVCOLUMNW
*lpColumn
, BOOL isW
)
8167 HDITEMW hdi
, hdiget
;
8170 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
8172 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8174 ZeroMemory(&hdi
, sizeof(HDITEMW
));
8175 if (lpColumn
->mask
& LVCF_FMT
)
8177 hdi
.mask
|= HDI_FORMAT
;
8178 hdiget
.mask
= HDI_FORMAT
;
8179 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
8180 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
8182 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
8184 /* set header item attributes */
8185 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, nColumn
, (LPARAM
)&hdi
);
8186 if (!bResult
) return FALSE
;
8188 if (lpColumn
->mask
& LVCF_FMT
)
8190 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
8191 INT oldFmt
= lpColumnInfo
->fmt
;
8193 lpColumnInfo
->fmt
= lpColumn
->fmt
;
8194 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
8196 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
8200 if (lpColumn
->mask
& LVCF_MINWIDTH
)
8201 LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
= lpColumn
->cxMin
;
8208 * Sets the column order array
8211 * [I] infoPtr : valid pointer to the listview structure
8212 * [I] iCount : number of elements in column order array
8213 * [I] lpiArray : pointer to column order array
8219 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
8221 TRACE("iCount %d lpiArray %p\n", iCount
, lpiArray
);
8223 if (!lpiArray
|| !IsWindow(infoPtr
->hwndHeader
)) return FALSE
;
8225 infoPtr
->colRectsDirty
= TRUE
;
8227 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
8232 * Sets the width of a column
8235 * [I] infoPtr : valid pointer to the listview structure
8236 * [I] nColumn : column index
8237 * [I] cx : column width
8243 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
8245 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
8249 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
8251 /* set column width only if in report or list mode */
8252 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
8254 /* take care of invalid cx values */
8255 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
8256 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
8258 /* resize all columns if in LV_VIEW_LIST mode */
8259 if(infoPtr
->uView
== LV_VIEW_LIST
)
8261 infoPtr
->nItemWidth
= cx
;
8262 LISTVIEW_InvalidateList(infoPtr
);
8266 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
8268 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
8273 lvItem
.mask
= LVIF_TEXT
;
8275 lvItem
.iSubItem
= nColumn
;
8276 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
8277 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8279 lvItem
.pszText
= szDispText
;
8280 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
8281 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
8282 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
8284 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
8285 max_cx
+= infoPtr
->iconSize
.cx
;
8286 max_cx
+= TRAILING_LABEL_PADDING
;
8289 /* autosize based on listview items width */
8290 if(cx
== LVSCW_AUTOSIZE
)
8292 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
8294 /* if iCol is the last column make it fill the remainder of the controls width */
8295 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
8300 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8301 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
8303 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
8307 /* Despite what the MS docs say, if this is not the last
8308 column, then MS resizes the column to the width of the
8309 largest text string in the column, including headers
8310 and items. This is different from LVSCW_AUTOSIZE in that
8311 LVSCW_AUTOSIZE ignores the header string length. */
8314 /* retrieve header text */
8315 hdi
.mask
= HDI_TEXT
;
8316 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
8317 hdi
.pszText
= szDispText
;
8318 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
8320 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
8321 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
8324 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
8325 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
8326 /* FIXME: Take into account the header image, if one is present */
8327 SelectObject(hdc
, old_font
);
8328 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8330 cx
= max (cx
, max_cx
);
8334 if (cx
< 0) return FALSE
;
8336 /* call header to update the column change */
8337 hdi
.mask
= HDI_WIDTH
;
8338 hdi
.cxy
= max(cx
, LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->cxMin
);
8339 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
8340 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
8344 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
8347 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
8350 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
8352 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
8353 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
8356 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
8357 ILC_COLOR
| ILC_MASK
, 2, 2);
8358 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
8359 hdc
= CreateCompatibleDC(hdc_wnd
);
8360 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
8361 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
8362 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
8364 rc
.left
= rc
.top
= 0;
8365 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
8366 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
8368 hbm_orig
= SelectObject(hdc
, hbm_mask
);
8369 FillRect(hdc
, &rc
, hbr_white
);
8370 InflateRect(&rc
, -2, -2);
8371 FillRect(hdc
, &rc
, hbr_black
);
8373 SelectObject(hdc
, hbm_im
);
8374 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
8375 SelectObject(hdc
, hbm_orig
);
8376 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8378 SelectObject(hdc
, hbm_im
);
8379 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
8380 SelectObject(hdc
, hbm_orig
);
8381 ImageList_Add(himl
, hbm_im
, hbm_mask
);
8383 DeleteObject(hbm_mask
);
8384 DeleteObject(hbm_im
);
8392 * Sets the extended listview style.
8395 * [I] infoPtr : valid pointer to the listview structure
8397 * [I] dwStyle : style
8400 * SUCCESS : previous style
8403 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD mask
, DWORD ex_style
)
8405 DWORD old_ex_style
= infoPtr
->dwLvExStyle
;
8407 TRACE("mask=0x%08x, ex_style=0x%08x\n", mask
, ex_style
);
8411 infoPtr
->dwLvExStyle
= (old_ex_style
& ~mask
) | (ex_style
& mask
);
8413 infoPtr
->dwLvExStyle
= ex_style
;
8415 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_CHECKBOXES
)
8417 HIMAGELIST himl
= 0;
8418 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
8421 item
.mask
= LVIF_STATE
;
8422 item
.stateMask
= LVIS_STATEIMAGEMASK
;
8423 item
.state
= INDEXTOSTATEIMAGEMASK(1);
8424 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
8426 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
8427 if(!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8428 ImageList_Destroy(infoPtr
->himlState
);
8430 himl
= LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
8431 /* checkbox list replaces previous custom list or... */
8432 if(((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) &&
8433 !(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
)) ||
8434 /* ...previous was checkbox list */
8435 (old_ex_style
& LVS_EX_CHECKBOXES
))
8436 ImageList_Destroy(himl
);
8439 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERDRAGDROP
)
8443 /* if not already created */
8444 LISTVIEW_CreateHeader(infoPtr
);
8446 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
8447 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
8448 style
|= HDS_DRAGDROP
;
8450 style
&= ~HDS_DRAGDROP
;
8451 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
);
8454 /* GRIDLINES adds decoration at top so changes sizes */
8455 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_GRIDLINES
)
8457 LISTVIEW_CreateHeader(infoPtr
);
8458 LISTVIEW_UpdateSize(infoPtr
);
8461 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_FULLROWSELECT
)
8463 LISTVIEW_CreateHeader(infoPtr
);
8466 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_TRANSPARENTBKGND
)
8468 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
8469 LISTVIEW_SetBkColor(infoPtr
, CLR_NONE
);
8472 if((infoPtr
->dwLvExStyle
^ old_ex_style
) & LVS_EX_HEADERINALLVIEWS
)
8474 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
8475 LISTVIEW_CreateHeader(infoPtr
);
8477 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8478 LISTVIEW_UpdateSize(infoPtr
);
8479 LISTVIEW_UpdateScroll(infoPtr
);
8482 LISTVIEW_InvalidateList(infoPtr
);
8483 return old_ex_style
;
8488 * Sets the new hot cursor used during hot tracking and hover selection.
8491 * [I] infoPtr : valid pointer to the listview structure
8492 * [I] hCursor : the new hot cursor handle
8495 * Returns the previous hot cursor
8497 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
8499 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
8501 infoPtr
->hHotCursor
= hCursor
;
8509 * Sets the hot item index.
8512 * [I] infoPtr : valid pointer to the listview structure
8513 * [I] iIndex : index
8516 * SUCCESS : previous hot item index
8517 * FAILURE : -1 (no hot item)
8519 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
8521 INT iOldIndex
= infoPtr
->nHotItem
;
8523 infoPtr
->nHotItem
= iIndex
;
8531 * Sets the amount of time the cursor must hover over an item before it is selected.
8534 * [I] infoPtr : valid pointer to the listview structure
8535 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
8538 * Returns the previous hover time
8540 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
8542 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
8544 infoPtr
->dwHoverTime
= dwHoverTime
;
8546 return oldHoverTime
;
8551 * Sets spacing for icons of LVS_ICON style.
8554 * [I] infoPtr : valid pointer to the listview structure
8555 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
8556 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
8559 * MAKELONG(oldcx, oldcy)
8561 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
8563 INT iconWidth
= 0, iconHeight
= 0;
8564 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
8566 TRACE("requested=(%d,%d)\n", cx
, cy
);
8568 /* set to defaults, if instructed to */
8569 if (cx
== -1 && cy
== -1)
8571 infoPtr
->autoSpacing
= TRUE
;
8572 if (infoPtr
->himlNormal
)
8573 ImageList_GetIconSize(infoPtr
->himlNormal
, &iconWidth
, &iconHeight
);
8574 cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
) + iconWidth
;
8575 cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
) + iconHeight
;
8578 infoPtr
->autoSpacing
= FALSE
;
8580 /* if 0 then keep width */
8582 infoPtr
->iconSpacing
.cx
= cx
;
8584 /* if 0 then keep height */
8586 infoPtr
->iconSpacing
.cy
= cy
;
8588 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
8589 LOWORD(oldspacing
), HIWORD(oldspacing
), infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
,
8590 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
8591 infoPtr
->ntmHeight
);
8593 /* these depend on the iconSpacing */
8594 LISTVIEW_UpdateItemSize(infoPtr
);
8599 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
8603 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
8610 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
8611 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
8620 * [I] infoPtr : valid pointer to the listview structure
8621 * [I] nType : image list type
8622 * [I] himl : image list handle
8625 * SUCCESS : old image list
8628 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
8630 INT oldHeight
= infoPtr
->nItemHeight
;
8631 HIMAGELIST himlOld
= 0;
8633 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
8638 himlOld
= infoPtr
->himlNormal
;
8639 infoPtr
->himlNormal
= himl
;
8640 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
8641 if (infoPtr
->autoSpacing
)
8642 LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
8646 himlOld
= infoPtr
->himlSmall
;
8647 infoPtr
->himlSmall
= himl
;
8648 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
8649 if (infoPtr
->hwndHeader
)
8650 SendMessageW(infoPtr
->hwndHeader
, HDM_SETIMAGELIST
, 0, (LPARAM
)himl
);
8654 himlOld
= infoPtr
->himlState
;
8655 infoPtr
->himlState
= himl
;
8656 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
8657 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
8661 ERR("Unknown icon type=%d\n", nType
);
8665 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
8666 if (infoPtr
->nItemHeight
!= oldHeight
)
8667 LISTVIEW_UpdateScroll(infoPtr
);
8674 * Preallocates memory (does *not* set the actual count of items !)
8677 * [I] infoPtr : valid pointer to the listview structure
8678 * [I] nItems : item count (projected number of items to allocate)
8679 * [I] dwFlags : update flags
8685 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
8687 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
8689 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8691 INT nOldCount
= infoPtr
->nItemCount
;
8693 if (nItems
< nOldCount
)
8695 RANGE range
= { nItems
, nOldCount
};
8696 ranges_del(infoPtr
->selectionRanges
, range
);
8697 if (infoPtr
->nFocusedItem
>= nItems
)
8699 LISTVIEW_SetItemFocus(infoPtr
, -1);
8700 SetRectEmpty(&infoPtr
->rcFocus
);
8704 infoPtr
->nItemCount
= nItems
;
8705 LISTVIEW_UpdateScroll(infoPtr
);
8707 /* the flags are valid only in ownerdata report and list modes */
8708 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
8710 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
8711 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
8713 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
8714 LISTVIEW_InvalidateList(infoPtr
);
8721 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8722 nFrom
= min(nOldCount
, nItems
);
8723 nTo
= max(nOldCount
, nItems
);
8725 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8728 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
8729 rcErase
.right
= infoPtr
->nItemWidth
;
8730 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
8731 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8732 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8733 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8735 else /* LV_VIEW_LIST */
8737 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
8739 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
8740 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
8741 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
8742 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8743 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8744 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8745 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8747 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8749 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
8750 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
8751 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
8752 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
8753 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
8759 /* According to MSDN for non-LVS_OWNERDATA this is just
8760 * a performance issue. The control allocates its internal
8761 * data structures for the number of items specified. It
8762 * cuts down on the number of memory allocations. Therefore
8763 * we will just issue a WARN here
8765 WARN("for non-ownerdata performance option not implemented.\n");
8773 * Sets the position of an item.
8776 * [I] infoPtr : valid pointer to the listview structure
8777 * [I] nItem : item index
8778 * [I] pt : coordinate
8784 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*pt
)
8788 TRACE("(nItem=%d, pt=%s\n", nItem
, wine_dbgstr_point(pt
));
8790 if (!pt
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8791 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8794 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8796 /* This point value seems to be an undocumented feature.
8797 * The best guess is that it means either at the origin,
8798 * or at true beginning of the list. I will assume the origin. */
8799 if ((Pt
.x
== -1) && (Pt
.y
== -1))
8802 if (infoPtr
->uView
== LV_VIEW_ICON
)
8804 Pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8805 Pt
.y
-= ICON_TOP_PADDING
;
8810 infoPtr
->bAutoarrange
= FALSE
;
8812 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &Pt
, FALSE
);
8817 * Sets the state of one or many items.
8820 * [I] infoPtr : valid pointer to the listview structure
8821 * [I] nItem : item index
8822 * [I] item : item or subitem info
8828 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*item
)
8833 if (!item
) return FALSE
;
8835 lvItem
.iItem
= nItem
;
8836 lvItem
.iSubItem
= 0;
8837 lvItem
.mask
= LVIF_STATE
;
8838 lvItem
.state
= item
->state
;
8839 lvItem
.stateMask
= item
->stateMask
;
8840 TRACE("item=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8847 /* special case optimization for recurring attempt to deselect all */
8848 if (lvItem
.state
== 0 && lvItem
.stateMask
== LVIS_SELECTED
&& !LISTVIEW_GetSelectedCount(infoPtr
))
8851 /* select all isn't allowed in LVS_SINGLESEL */
8852 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8855 /* focus all isn't allowed */
8856 if (lvItem
.state
& lvItem
.stateMask
& LVIS_FOCUSED
) return FALSE
;
8858 notify
= infoPtr
->bDoChangeNotify
;
8859 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8861 infoPtr
->bDoChangeNotify
= FALSE
;
8862 if (!(lvItem
.state
& LVIS_SELECTED
) && LISTVIEW_GetSelectedCount(infoPtr
))
8863 oldstate
|= LVIS_SELECTED
;
8864 if (infoPtr
->nFocusedItem
!= -1) oldstate
|= LVIS_FOCUSED
;
8867 /* apply to all items */
8868 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8869 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) ret
= FALSE
;
8871 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
8875 infoPtr
->bDoChangeNotify
= notify
;
8879 nmlv
.uNewState
= lvItem
.state
& lvItem
.stateMask
;
8880 nmlv
.uOldState
= oldstate
& lvItem
.stateMask
;
8881 nmlv
.uChanged
= LVIF_STATE
;
8882 nmlv
.ptAction
.x
= nmlv
.ptAction
.y
= 0;
8885 notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
8889 ret
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8896 * Sets the text of an item or subitem.
8899 * [I] hwnd : window handle
8900 * [I] nItem : item index
8901 * [I] lpLVItem : item or subitem info
8902 * [I] isW : TRUE if input is Unicode
8908 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
8912 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
8913 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
8915 lvItem
.iItem
= nItem
;
8916 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
8917 lvItem
.mask
= LVIF_TEXT
;
8918 lvItem
.pszText
= lpLVItem
->pszText
;
8919 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
8921 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
8923 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
8928 * Set item index that marks the start of a multiple selection.
8931 * [I] infoPtr : valid pointer to the listview structure
8932 * [I] nIndex : index
8935 * Index number or -1 if there is no selection mark.
8937 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
8939 INT nOldIndex
= infoPtr
->nSelectionMark
;
8941 TRACE("(nIndex=%d)\n", nIndex
);
8943 infoPtr
->nSelectionMark
= nIndex
;
8950 * Sets the text background color.
8953 * [I] infoPtr : valid pointer to the listview structure
8954 * [I] color : text background color
8960 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8962 TRACE("(color=%x)\n", color
);
8964 infoPtr
->clrTextBk
= color
;
8970 * Sets the text foreground color.
8973 * [I] infoPtr : valid pointer to the listview structure
8974 * [I] color : text color
8980 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF color
)
8982 TRACE("(color=%x)\n", color
);
8984 infoPtr
->clrText
= color
;
8990 * Sets new ToolTip window to ListView control.
8993 * [I] infoPtr : valid pointer to the listview structure
8994 * [I] hwndNewToolTip : handle to new ToolTip
8999 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
9001 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
9002 infoPtr
->hwndToolTip
= hwndNewToolTip
;
9003 return hwndOldToolTip
;
9008 * sets the Unicode character format flag for the control
9010 * [I] infoPtr :valid pointer to the listview structure
9011 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
9014 * Old Unicode Format
9016 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL unicode
)
9018 SHORT rc
= infoPtr
->notifyFormat
;
9019 infoPtr
->notifyFormat
= (unicode
) ? NFR_UNICODE
: NFR_ANSI
;
9020 return rc
== NFR_UNICODE
;
9025 * sets the control view mode
9027 * [I] infoPtr :valid pointer to the listview structure
9028 * [I] nView :new view mode value
9034 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
9038 if (infoPtr
->uView
== nView
) return 1;
9040 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
9041 if (nView
== LV_VIEW_TILE
)
9043 FIXME("View LV_VIEW_TILE unimplemented\n");
9047 infoPtr
->uView
= nView
;
9049 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9050 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
9052 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
9053 SetRectEmpty(&infoPtr
->rcFocus
);
9055 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9056 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
9061 case LV_VIEW_SMALLICON
:
9062 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9064 case LV_VIEW_DETAILS
:
9069 LISTVIEW_CreateHeader( infoPtr
);
9071 hl
.prc
= &infoPtr
->rcList
;
9073 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
9074 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
9075 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
9082 LISTVIEW_UpdateItemSize(infoPtr
);
9083 LISTVIEW_UpdateSize(infoPtr
);
9084 LISTVIEW_UpdateScroll(infoPtr
);
9085 LISTVIEW_InvalidateList(infoPtr
);
9087 TRACE("nView=%d\n", nView
);
9092 /* LISTVIEW_SetWorkAreas */
9096 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
9099 * [I] first : pointer to first ITEM_INFO to compare
9100 * [I] second : pointer to second ITEM_INFO to compare
9101 * [I] lParam : HWND of control
9104 * if first comes before second : negative
9105 * if first comes after second : positive
9106 * if first and second are equivalent : zero
9108 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
9110 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9111 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
9112 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
9114 /* Forward the call to the client defined callback */
9115 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
9120 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
9123 * [I] first : pointer to first ITEM_INFO to compare
9124 * [I] second : pointer to second ITEM_INFO to compare
9125 * [I] lParam : HWND of control
9128 * if first comes before second : negative
9129 * if first comes after second : positive
9130 * if first and second are equivalent : zero
9132 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
9134 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
9135 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
9136 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
9138 /* Forward the call to the client defined callback */
9139 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
9144 * Sorts the listview items.
9147 * [I] infoPtr : valid pointer to the listview structure
9148 * [I] pfnCompare : application-defined value
9149 * [I] lParamSort : pointer to comparison callback
9150 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
9156 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
9157 LPARAM lParamSort
, BOOL IsEx
)
9161 LPVOID selectionMarkItem
= NULL
;
9162 LPVOID focusedItem
= NULL
;
9165 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
9167 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
9169 if (!pfnCompare
) return FALSE
;
9170 if (!infoPtr
->hdpaItems
) return FALSE
;
9172 /* if there are 0 or 1 items, there is no need to sort */
9173 if (infoPtr
->nItemCount
< 2) return TRUE
;
9175 /* clear selection */
9176 ranges_clear(infoPtr
->selectionRanges
);
9178 /* save selection mark and focused item */
9179 if (infoPtr
->nSelectionMark
>= 0)
9180 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
9181 if (infoPtr
->nFocusedItem
>= 0)
9182 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
9184 infoPtr
->pfnCompare
= pfnCompare
;
9185 infoPtr
->lParamSort
= lParamSort
;
9187 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
9189 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
9191 /* restore selection ranges */
9192 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
9194 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
9195 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
9197 if (lpItem
->state
& LVIS_SELECTED
)
9198 ranges_additem(infoPtr
->selectionRanges
, i
);
9200 /* restore selection mark and focused item */
9201 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
9202 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
9204 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
9206 /* refresh the display */
9207 LISTVIEW_InvalidateList(infoPtr
);
9213 * Update theme handle after a theme change.
9216 * [I] infoPtr : valid pointer to the listview structure
9220 * FAILURE : something else
9222 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
9224 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9225 CloseThemeData(theme
);
9226 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
9232 * Updates an items or rearranges the listview control.
9235 * [I] infoPtr : valid pointer to the listview structure
9236 * [I] nItem : item index
9242 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
9244 TRACE("(nItem=%d)\n", nItem
);
9246 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
9248 /* rearrange with default alignment style */
9249 if (is_autoarrange(infoPtr
))
9250 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9252 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
9259 * Draw the track line at the place defined in the infoPtr structure.
9260 * The line is drawn with a XOR pen so drawing the line for the second time
9261 * in the same place erases the line.
9264 * [I] infoPtr : valid pointer to the listview structure
9270 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
9274 if (infoPtr
->xTrackLine
== -1)
9277 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
9279 PatBlt( hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
,
9280 1, infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
, DSTINVERT
);
9281 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9287 * Called when an edit control should be displayed. This function is called after
9288 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
9291 * [I] hwnd : Handle to the listview
9292 * [I] uMsg : WM_TIMER (ignored)
9293 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
9294 * [I] dwTimer : The elapsed time (ignored)
9299 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
9301 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
9302 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9304 KillTimer(hwnd
, idEvent
);
9305 editItem
->fEnabled
= FALSE
;
9306 /* check if the item is still selected */
9307 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
9308 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
9313 * Creates the listview control - the WM_NCCREATE phase.
9316 * [I] hwnd : window handle
9317 * [I] lpcs : the create parameters
9323 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9325 LISTVIEW_INFO
*infoPtr
;
9328 TRACE("(lpcs=%p)\n", lpcs
);
9330 /* initialize info pointer */
9331 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
9332 if (!infoPtr
) return FALSE
;
9334 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
9336 infoPtr
->hwndSelf
= hwnd
;
9337 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
9338 map_style_view(infoPtr
);
9339 /* determine the type of structures to use */
9340 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
9341 /* infoPtr->notifyFormat will be filled in WM_CREATE */
9343 /* initialize color information */
9344 infoPtr
->clrBk
= CLR_NONE
;
9345 infoPtr
->clrText
= CLR_DEFAULT
;
9346 infoPtr
->clrTextBk
= CLR_DEFAULT
;
9347 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
9349 /* set default values */
9350 infoPtr
->nFocusedItem
= -1;
9351 infoPtr
->nSelectionMark
= -1;
9352 infoPtr
->nHotItem
= -1;
9353 infoPtr
->bRedraw
= TRUE
;
9354 infoPtr
->bNoItemMetrics
= TRUE
;
9355 infoPtr
->bDoChangeNotify
= TRUE
;
9356 infoPtr
->autoSpacing
= TRUE
;
9357 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
) - GetSystemMetrics(SM_CXICON
);
9358 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
) - GetSystemMetrics(SM_CYICON
);
9359 infoPtr
->nEditLabelItem
= -1;
9360 infoPtr
->nLButtonDownItem
= -1;
9361 infoPtr
->dwHoverTime
= HOVER_DEFAULT
; /* default system hover time */
9362 infoPtr
->cWheelRemainder
= 0;
9363 infoPtr
->nMeasureItemHeight
= 0;
9364 infoPtr
->xTrackLine
= -1; /* no track line */
9365 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9366 infoPtr
->iVersion
= COMCTL32_VERSION
;
9367 infoPtr
->colRectsDirty
= FALSE
;
9369 /* get default font (icon title) */
9370 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
9371 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
9372 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
9373 LISTVIEW_SaveTextMetrics(infoPtr
);
9375 /* allocate memory for the data structure */
9376 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
9377 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
9378 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
9379 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
9380 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
9381 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
9385 DestroyWindow(infoPtr
->hwndHeader
);
9386 ranges_destroy(infoPtr
->selectionRanges
);
9387 DPA_Destroy(infoPtr
->hdpaItems
);
9388 DPA_Destroy(infoPtr
->hdpaItemIds
);
9389 DPA_Destroy(infoPtr
->hdpaPosX
);
9390 DPA_Destroy(infoPtr
->hdpaPosY
);
9391 DPA_Destroy(infoPtr
->hdpaColumns
);
9398 * Creates the listview control - the WM_CREATE phase. Most of the data is
9399 * already set up in LISTVIEW_NCCreate
9402 * [I] hwnd : window handle
9403 * [I] lpcs : the create parameters
9409 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
9411 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9413 TRACE("(lpcs=%p, style=0x%08x)\n", lpcs
, lpcs
->style
);
9415 infoPtr
->dwStyle
= lpcs
->style
;
9416 map_style_view(infoPtr
);
9418 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
9419 (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9420 /* on error defaulting to ANSI notifications */
9421 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
9422 TRACE("notify format=%d\n", infoPtr
->notifyFormat
);
9424 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
9426 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
9429 infoPtr
->hwndHeader
= 0;
9431 /* init item size to avoid division by 0 */
9432 LISTVIEW_UpdateItemSize (infoPtr
);
9433 LISTVIEW_UpdateSize (infoPtr
);
9435 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9437 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
9439 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
9441 LISTVIEW_UpdateScroll(infoPtr
);
9442 /* send WM_MEASUREITEM notification */
9443 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
9446 OpenThemeData(hwnd
, themeClass
);
9448 /* initialize the icon sizes */
9449 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
9450 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
9456 * Destroys the listview control.
9459 * [I] infoPtr : valid pointer to the listview structure
9465 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
9467 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
9468 CloseThemeData(theme
);
9470 /* delete all items */
9471 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9478 * Enables the listview control.
9481 * [I] infoPtr : valid pointer to the listview structure
9482 * [I] bEnable : specifies whether to enable or disable the window
9488 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
)
9490 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
9491 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
9497 * Erases the background of the listview control.
9500 * [I] infoPtr : valid pointer to the listview structure
9501 * [I] hdc : device context handle
9507 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9511 TRACE("(hdc=%p)\n", hdc
);
9513 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
9515 if (infoPtr
->clrBk
== CLR_NONE
)
9517 if (infoPtr
->dwLvExStyle
& LVS_EX_TRANSPARENTBKGND
)
9518 return SendMessageW(infoPtr
->hwndNotify
, WM_PRINTCLIENT
,
9519 (WPARAM
)hdc
, PRF_ERASEBKGND
);
9521 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
9524 /* for double buffered controls we need to do this during refresh */
9525 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
9527 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
9533 * Helper function for LISTVIEW_[HV]Scroll *only*.
9534 * Performs vertical/horizontal scrolling by a give amount.
9537 * [I] infoPtr : valid pointer to the listview structure
9538 * [I] dx : amount of horizontal scroll
9539 * [I] dy : amount of vertical scroll
9541 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
9543 /* now we can scroll the list */
9544 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
9545 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
9546 /* if we have focus, adjust rect */
9547 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
9548 UpdateWindow(infoPtr
->hwndSelf
);
9553 * Performs vertical scrolling.
9556 * [I] infoPtr : valid pointer to the listview structure
9557 * [I] nScrollCode : scroll code
9558 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9559 * [I] hScrollWnd : scrollbar control window handle
9565 * SB_LINEUP/SB_LINEDOWN:
9566 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
9567 * for LVS_REPORT is 1 line
9568 * for LVS_LIST cannot occur
9571 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9574 INT nOldScrollPos
, nNewScrollPos
;
9575 SCROLLINFO scrollInfo
;
9578 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9579 debugscrollcode(nScrollCode
), nScrollDiff
);
9581 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9583 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9584 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9586 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9588 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
9590 nOldScrollPos
= scrollInfo
.nPos
;
9591 switch (nScrollCode
)
9597 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9601 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9605 nScrollDiff
= -scrollInfo
.nPage
;
9609 nScrollDiff
= scrollInfo
.nPage
;
9612 case SB_THUMBPOSITION
:
9614 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9621 /* quit right away if pos isn't changing */
9622 if (nScrollDiff
== 0) return 0;
9624 /* calculate new position, and handle overflows */
9625 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9626 if (nScrollDiff
> 0) {
9627 if (nNewScrollPos
< nOldScrollPos
||
9628 nNewScrollPos
> scrollInfo
.nMax
)
9629 nNewScrollPos
= scrollInfo
.nMax
;
9631 if (nNewScrollPos
> nOldScrollPos
||
9632 nNewScrollPos
< scrollInfo
.nMin
)
9633 nNewScrollPos
= scrollInfo
.nMin
;
9636 /* set the new position, and reread in case it changed */
9637 scrollInfo
.fMask
= SIF_POS
;
9638 scrollInfo
.nPos
= nNewScrollPos
;
9639 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
9641 /* carry on only if it really changed */
9642 if (nNewScrollPos
== nOldScrollPos
) return 0;
9644 /* now adjust to client coordinates */
9645 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9646 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
9648 /* and scroll the window */
9649 scroll_list(infoPtr
, 0, nScrollDiff
);
9656 * Performs horizontal scrolling.
9659 * [I] infoPtr : valid pointer to the listview structure
9660 * [I] nScrollCode : scroll code
9661 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
9662 * [I] hScrollWnd : scrollbar control window handle
9668 * SB_LINELEFT/SB_LINERIGHT:
9669 * for LVS_ICON, LVS_SMALLICON 1 pixel
9670 * for LVS_REPORT is 1 pixel
9671 * for LVS_LIST is 1 column --> which is a 1 because the
9672 * scroll is based on columns not pixels
9675 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
9678 INT nOldScrollPos
, nNewScrollPos
;
9679 SCROLLINFO scrollInfo
;
9682 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
9683 debugscrollcode(nScrollCode
), nScrollDiff
);
9685 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
9687 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
9688 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
9690 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
9692 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
9694 nOldScrollPos
= scrollInfo
.nPos
;
9696 switch (nScrollCode
)
9702 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
9706 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
9710 nScrollDiff
= -scrollInfo
.nPage
;
9714 nScrollDiff
= scrollInfo
.nPage
;
9717 case SB_THUMBPOSITION
:
9719 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
9726 /* quit right away if pos isn't changing */
9727 if (nScrollDiff
== 0) return 0;
9729 /* calculate new position, and handle overflows */
9730 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
9731 if (nScrollDiff
> 0) {
9732 if (nNewScrollPos
< nOldScrollPos
||
9733 nNewScrollPos
> scrollInfo
.nMax
)
9734 nNewScrollPos
= scrollInfo
.nMax
;
9736 if (nNewScrollPos
> nOldScrollPos
||
9737 nNewScrollPos
< scrollInfo
.nMin
)
9738 nNewScrollPos
= scrollInfo
.nMin
;
9741 /* set the new position, and reread in case it changed */
9742 scrollInfo
.fMask
= SIF_POS
;
9743 scrollInfo
.nPos
= nNewScrollPos
;
9744 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
9746 /* carry on only if it really changed */
9747 if (nNewScrollPos
== nOldScrollPos
) return 0;
9749 if (infoPtr
->hwndHeader
) LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
9751 /* now adjust to client coordinates */
9752 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
9753 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
9755 /* and scroll the window */
9756 scroll_list(infoPtr
, nScrollDiff
, 0);
9761 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
9763 UINT pulScrollLines
= 3;
9765 TRACE("(wheelDelta=%d)\n", wheelDelta
);
9767 switch(infoPtr
->uView
)
9770 case LV_VIEW_SMALLICON
:
9772 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9773 * should be fixed in the future.
9775 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (wheelDelta
> 0) ?
9776 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
);
9779 case LV_VIEW_DETAILS
:
9780 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
9782 /* if scrolling changes direction, ignore left overs */
9783 if ((wheelDelta
< 0 && infoPtr
->cWheelRemainder
< 0) ||
9784 (wheelDelta
> 0 && infoPtr
->cWheelRemainder
> 0))
9785 infoPtr
->cWheelRemainder
+= wheelDelta
;
9787 infoPtr
->cWheelRemainder
= wheelDelta
;
9788 if (infoPtr
->cWheelRemainder
&& pulScrollLines
)
9791 pulScrollLines
= min((UINT
)LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9792 cLineScroll
= pulScrollLines
* (float)infoPtr
->cWheelRemainder
/ WHEEL_DELTA
;
9793 infoPtr
->cWheelRemainder
-= WHEEL_DELTA
* cLineScroll
/ (int)pulScrollLines
;
9794 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, -cLineScroll
);
9799 LISTVIEW_HScroll(infoPtr
, (wheelDelta
> 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0);
9810 * [I] infoPtr : valid pointer to the listview structure
9811 * [I] nVirtualKey : virtual key
9812 * [I] lKeyData : key data
9817 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9819 HWND hwndSelf
= infoPtr
->hwndSelf
;
9821 NMLVKEYDOWN nmKeyDown
;
9823 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9825 /* send LVN_KEYDOWN notification */
9826 nmKeyDown
.wVKey
= nVirtualKey
;
9827 nmKeyDown
.flags
= 0;
9828 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9829 if (!IsWindow(hwndSelf
))
9832 switch (nVirtualKey
)
9835 nItem
= infoPtr
->nFocusedItem
;
9836 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9837 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9841 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9843 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9844 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9849 if (infoPtr
->nItemCount
> 0)
9854 if (infoPtr
->nItemCount
> 0)
9855 nItem
= infoPtr
->nItemCount
- 1;
9859 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9863 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9867 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9871 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9875 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9877 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9878 if (infoPtr
->nFocusedItem
== topidx
)
9879 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9884 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9885 * LISTVIEW_GetCountPerRow(infoPtr
);
9886 if(nItem
< 0) nItem
= 0;
9890 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9892 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9893 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9894 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9895 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9897 nItem
= topidx
+ cnt
- 1;
9900 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9901 * LISTVIEW_GetCountPerRow(infoPtr
);
9902 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9906 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9907 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
9917 * [I] infoPtr : valid pointer to the listview structure
9922 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
9926 /* drop any left over scroll amount */
9927 infoPtr
->cWheelRemainder
= 0;
9929 /* if we did not have the focus, there's nothing more to do */
9930 if (!infoPtr
->bFocus
) return 0;
9932 /* send NM_KILLFOCUS notification */
9933 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
9935 /* if we have a focus rectangle, get rid of it */
9936 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
9938 /* if have a marquee selection, stop it */
9939 if (infoPtr
->bMarqueeSelect
)
9941 /* Remove the marquee rectangle and release our mouse capture */
9942 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeRect
);
9945 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
9947 infoPtr
->bMarqueeSelect
= FALSE
;
9948 infoPtr
->bScrolling
= FALSE
;
9949 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
9952 /* set window focus flag */
9953 infoPtr
->bFocus
= FALSE
;
9955 /* invalidate the selected items before resetting focus flag */
9956 LISTVIEW_InvalidateSelectedItems(infoPtr
);
9963 * Processes double click messages (left mouse button).
9966 * [I] infoPtr : valid pointer to the listview structure
9967 * [I] wKey : key flag
9968 * [I] x,y : mouse coordinate
9973 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9975 LVHITTESTINFO htInfo
;
9977 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
9979 /* Cancel the item edition if any */
9980 if (infoPtr
->itemEdit
.fEnabled
)
9982 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
9983 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9986 /* send NM_RELEASEDCAPTURE notification */
9987 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9992 /* send NM_DBLCLK notification */
9993 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
9994 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
9996 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
9997 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
10002 static LRESULT
LISTVIEW_TrackMouse(const LISTVIEW_INFO
*infoPtr
, POINT pt
)
10007 r
.top
= r
.bottom
= pt
.y
;
10008 r
.left
= r
.right
= pt
.x
;
10010 InflateRect(&r
, GetSystemMetrics(SM_CXDRAG
), GetSystemMetrics(SM_CYDRAG
));
10012 SetCapture(infoPtr
->hwndSelf
);
10016 if (PeekMessageW(&msg
, 0, 0, 0, PM_REMOVE
| PM_NOYIELD
))
10018 if (msg
.message
== WM_MOUSEMOVE
)
10020 pt
.x
= (short)LOWORD(msg
.lParam
);
10021 pt
.y
= (short)HIWORD(msg
.lParam
);
10022 if (PtInRect(&r
, pt
))
10030 else if (msg
.message
>= WM_LBUTTONDOWN
&&
10031 msg
.message
<= WM_RBUTTONDBLCLK
)
10036 DispatchMessageW(&msg
);
10039 if (GetCapture() != infoPtr
->hwndSelf
)
10050 * Processes mouse down messages (left mouse button).
10053 * infoPtr [I ] valid pointer to the listview structure
10054 * wKey [I ] key flag
10055 * x,y [I ] mouse coordinate
10060 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10062 LVHITTESTINFO lvHitTestInfo
;
10063 static BOOL bGroupSelect
= TRUE
;
10064 POINT pt
= { x
, y
};
10067 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10069 /* send NM_RELEASEDCAPTURE notification */
10070 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10072 /* set left button down flag and record the click position */
10073 infoPtr
->bLButtonDown
= TRUE
;
10074 infoPtr
->ptClickPos
= pt
;
10075 infoPtr
->bDragging
= FALSE
;
10076 infoPtr
->bMarqueeSelect
= FALSE
;
10077 infoPtr
->bScrolling
= FALSE
;
10079 lvHitTestInfo
.pt
.x
= x
;
10080 lvHitTestInfo
.pt
.y
= y
;
10082 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
10083 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
10084 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
10086 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
10088 toggle_checkbox_state(infoPtr
, nItem
);
10092 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
10094 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10095 infoPtr
->nEditLabelItem
= nItem
;
10097 LISTVIEW_SetSelection(infoPtr
, nItem
);
10101 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
10105 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
10106 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10107 infoPtr
->nSelectionMark
= nItem
;
10113 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
10114 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10116 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
10117 infoPtr
->nSelectionMark
= nItem
;
10120 else if (wKey
& MK_CONTROL
)
10124 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
10126 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
10127 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
10128 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
10129 infoPtr
->nSelectionMark
= nItem
;
10131 else if (wKey
& MK_SHIFT
)
10133 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
10137 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
10139 infoPtr
->nEditLabelItem
= nItem
;
10140 infoPtr
->nLButtonDownItem
= nItem
;
10142 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
10145 /* set selection (clears other pre-existing selections) */
10146 LISTVIEW_SetSelection(infoPtr
, nItem
);
10150 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
10151 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
10155 if (!infoPtr
->bFocus
)
10156 SetFocus(infoPtr
->hwndSelf
);
10158 /* remove all selections */
10159 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
10160 LISTVIEW_DeselectAll(infoPtr
);
10169 * Processes mouse up messages (left mouse button).
10172 * infoPtr [I ] valid pointer to the listview structure
10173 * wKey [I ] key flag
10174 * x,y [I ] mouse coordinate
10179 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10181 LVHITTESTINFO lvHitTestInfo
;
10183 TRACE("(key=%hu, X=%u, Y=%u)\n", wKey
, x
, y
);
10185 if (!infoPtr
->bLButtonDown
) return 0;
10187 lvHitTestInfo
.pt
.x
= x
;
10188 lvHitTestInfo
.pt
.y
= y
;
10190 /* send NM_CLICK notification */
10191 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10192 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
10194 /* set left button flag */
10195 infoPtr
->bLButtonDown
= FALSE
;
10197 /* set a single selection, reset others */
10198 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
10199 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
10200 infoPtr
->nLButtonDownItem
= -1;
10202 if (infoPtr
->bDragging
|| infoPtr
->bMarqueeSelect
)
10204 /* Remove the marquee rectangle and release our mouse capture */
10205 if (infoPtr
->bMarqueeSelect
)
10207 LISTVIEW_InvalidateRect(infoPtr
, &infoPtr
->marqueeDrawRect
);
10211 SetRect(&infoPtr
->marqueeRect
, 0, 0, 0, 0);
10212 SetRect(&infoPtr
->marqueeDrawRect
, 0, 0, 0, 0);
10214 infoPtr
->bDragging
= FALSE
;
10215 infoPtr
->bMarqueeSelect
= FALSE
;
10216 infoPtr
->bScrolling
= FALSE
;
10218 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
) infoPtr
);
10222 /* if we clicked on a selected item, edit the label */
10223 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
10225 /* we want to make sure the user doesn't want to do a double click. So we will
10226 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
10228 infoPtr
->itemEdit
.fEnabled
= TRUE
;
10229 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
10230 SetTimer(infoPtr
->hwndSelf
,
10231 (UINT_PTR
)&infoPtr
->itemEdit
,
10232 GetDoubleClickTime(),
10233 LISTVIEW_DelayedEditItem
);
10236 if (!infoPtr
->bFocus
)
10237 SetFocus(infoPtr
->hwndSelf
);
10244 * Destroys the listview control (called after WM_DESTROY).
10247 * [I] infoPtr : valid pointer to the listview structure
10252 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
10258 /* destroy data structure */
10259 DPA_Destroy(infoPtr
->hdpaItems
);
10260 DPA_Destroy(infoPtr
->hdpaItemIds
);
10261 DPA_Destroy(infoPtr
->hdpaPosX
);
10262 DPA_Destroy(infoPtr
->hdpaPosY
);
10264 for (i
= 0; i
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); i
++)
10265 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, i
));
10266 DPA_Destroy(infoPtr
->hdpaColumns
);
10267 ranges_destroy(infoPtr
->selectionRanges
);
10269 /* destroy image lists */
10270 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
10272 ImageList_Destroy(infoPtr
->himlNormal
);
10273 ImageList_Destroy(infoPtr
->himlSmall
);
10274 ImageList_Destroy(infoPtr
->himlState
);
10277 /* destroy font, bkgnd brush */
10278 infoPtr
->hFont
= 0;
10279 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
10280 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
10282 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
10284 /* free listview info pointer*/
10292 * Handles notifications.
10295 * [I] infoPtr : valid pointer to the listview structure
10296 * [I] lpnmhdr : notification information
10301 static LRESULT
LISTVIEW_Notify(LISTVIEW_INFO
*infoPtr
, NMHDR
*lpnmhdr
)
10305 TRACE("(lpnmhdr=%p)\n", lpnmhdr
);
10307 if (!lpnmhdr
|| lpnmhdr
->hwndFrom
!= infoPtr
->hwndHeader
) return 0;
10309 /* remember: HDN_LAST < HDN_FIRST */
10310 if (lpnmhdr
->code
> HDN_FIRST
|| lpnmhdr
->code
< HDN_LAST
) return 0;
10311 lpnmh
= (NMHEADERW
*)lpnmhdr
;
10313 if (lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
10315 switch (lpnmhdr
->code
)
10320 COLUMN_INFO
*lpColumnInfo
;
10324 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10327 /* remove the old line (if any) */
10328 LISTVIEW_DrawTrackLine(infoPtr
);
10330 /* compute & draw the new line */
10331 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10332 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
10333 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10334 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
10335 LISTVIEW_DrawTrackLine(infoPtr
);
10336 return notify_forward_header(infoPtr
, lpnmh
);
10339 case HDN_ENDTRACKA
:
10340 case HDN_ENDTRACKW
:
10341 /* remove the track line (if any) */
10342 LISTVIEW_DrawTrackLine(infoPtr
);
10343 infoPtr
->xTrackLine
= -1;
10344 return notify_forward_header(infoPtr
, lpnmh
);
10346 case HDN_BEGINDRAG
:
10347 if ((infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0) return 1;
10348 return notify_forward_header(infoPtr
, lpnmh
);
10351 infoPtr
->colRectsDirty
= TRUE
;
10352 LISTVIEW_InvalidateList(infoPtr
);
10353 return notify_forward_header(infoPtr
, lpnmh
);
10355 case HDN_ITEMCHANGEDW
:
10356 case HDN_ITEMCHANGEDA
:
10358 COLUMN_INFO
*lpColumnInfo
;
10362 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
10364 hdi
.mask
= HDI_WIDTH
;
10365 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
10369 cxy
= lpnmh
->pitem
->cxy
;
10371 /* determine how much we change since the last know position */
10372 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
10373 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
10376 lpColumnInfo
->rcHeader
.right
+= dx
;
10378 hdi
.mask
= HDI_ORDER
;
10379 SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
);
10381 /* not the rightmost one */
10382 if (hdi
.iOrder
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
10384 INT nIndex
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
10385 hdi
.iOrder
+ 1, 0);
10386 LISTVIEW_ScrollColumns(infoPtr
, nIndex
, dx
);
10390 /* only needs to update the scrolls */
10391 infoPtr
->nItemWidth
+= dx
;
10392 LISTVIEW_UpdateScroll(infoPtr
);
10394 LISTVIEW_UpdateItemSize(infoPtr
);
10395 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
10398 RECT rcCol
= lpColumnInfo
->rcHeader
;
10400 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
10401 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
10403 rcCol
.top
= infoPtr
->rcList
.top
;
10404 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
10406 /* resizing left-aligned columns leaves most of the left side untouched */
10407 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
10409 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
10412 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
10415 /* when shrinking the last column clear the now unused field */
10416 if (hdi
.iOrder
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
10422 /* deal with right from rightmost column area */
10423 right
.left
= rcCol
.right
;
10424 right
.top
= rcCol
.top
;
10425 right
.bottom
= rcCol
.bottom
;
10426 right
.right
= infoPtr
->rcList
.right
;
10428 LISTVIEW_InvalidateRect(infoPtr
, &right
);
10431 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
10437 case HDN_ITEMCLICKW
:
10438 case HDN_ITEMCLICKA
:
10440 /* Handle sorting by Header Column */
10443 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
10445 nmlv
.iSubItem
= lpnmh
->iItem
;
10446 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
10447 return notify_forward_header(infoPtr
, lpnmh
);
10450 case HDN_DIVIDERDBLCLICKW
:
10451 case HDN_DIVIDERDBLCLICKA
:
10452 /* FIXME: for LVS_EX_HEADERINALLVIEWS and not LV_VIEW_DETAILS
10453 we should use LVSCW_AUTOSIZE_USEHEADER, helper rework or
10454 split needed for that */
10455 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
10456 return notify_forward_header(infoPtr
, lpnmh
);
10463 * Paint non-client area of control.
10466 * [I] infoPtr : valid pointer to the listview structureof the sender
10467 * [I] region : update region
10470 * TRUE - frame was painted
10471 * FALSE - call default window proc
10473 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
10475 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
10479 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
10480 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
10483 return DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)region
, 0);
10485 GetWindowRect(infoPtr
->hwndSelf
, &r
);
10487 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
10488 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
10489 if (region
!= (HRGN
)1)
10490 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
10491 OffsetRect(&r
, -r
.left
, -r
.top
);
10493 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
10494 OffsetRect(&r
, -r
.left
, -r
.top
);
10496 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
10497 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
10498 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
10499 ReleaseDC(infoPtr
->hwndSelf
, dc
);
10501 /* Call default proc to get the scrollbars etc. painted */
10502 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
10509 * Determines the type of structure to use.
10512 * [I] infoPtr : valid pointer to the listview structureof the sender
10513 * [I] hwndFrom : listview window handle
10514 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
10519 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
10521 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
10523 if (nCommand
== NF_REQUERY
)
10524 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
10526 return infoPtr
->notifyFormat
;
10531 * Paints/Repaints the listview control. Internal use.
10534 * [I] infoPtr : valid pointer to the listview structure
10535 * [I] hdc : device context handle
10540 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10542 TRACE("(hdc=%p)\n", hdc
);
10544 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
10546 infoPtr
->bNoItemMetrics
= FALSE
;
10547 LISTVIEW_UpdateItemSize(infoPtr
);
10548 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
10549 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10550 LISTVIEW_UpdateScroll(infoPtr
);
10553 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
10556 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
10561 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
10562 if (!hdc
) return 1;
10563 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
10564 EndPaint(infoPtr
->hwndSelf
, &ps
);
10572 * Paints/Repaints the listview control, WM_PAINT handler.
10575 * [I] infoPtr : valid pointer to the listview structure
10576 * [I] hdc : device context handle
10581 static inline LRESULT
LISTVIEW_WMPaint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
10583 TRACE("(hdc=%p)\n", hdc
);
10585 if (!is_redrawing(infoPtr
))
10586 return DefWindowProcW (infoPtr
->hwndSelf
, WM_PAINT
, (WPARAM
)hdc
, 0);
10588 return LISTVIEW_Paint(infoPtr
, hdc
);
10593 * Paints/Repaints the listview control.
10596 * [I] infoPtr : valid pointer to the listview structure
10597 * [I] hdc : device context handle
10598 * [I] options : drawing options
10603 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
10605 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
10607 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
10610 if (options
& PRF_ERASEBKGND
)
10611 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
10613 if (options
& PRF_CLIENT
)
10614 LISTVIEW_Paint(infoPtr
, hdc
);
10622 * Processes double click messages (right mouse button).
10625 * [I] infoPtr : valid pointer to the listview structure
10626 * [I] wKey : key flag
10627 * [I] x,y : mouse coordinate
10632 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10634 LVHITTESTINFO lvHitTestInfo
;
10636 TRACE("(key=%hu,X=%u,Y=%u)\n", wKey
, x
, y
);
10638 /* send NM_RELEASEDCAPTURE notification */
10639 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10641 /* send NM_RDBLCLK notification */
10642 lvHitTestInfo
.pt
.x
= x
;
10643 lvHitTestInfo
.pt
.y
= y
;
10644 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
10645 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
10652 * Processes WM_RBUTTONDOWN message and corresponding drag operation.
10655 * [I] infoPtr : valid pointer to the listview structure
10656 * [I] wKey : key flag
10657 * [I] x, y : mouse coordinate
10662 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
10667 TRACE("(key=%hu, x=%d, y=%d)\n", wKey
, x
, y
);
10669 /* send NM_RELEASEDCAPTURE notification */
10670 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
10672 /* determine the index of the selected item */
10675 item
= LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, TRUE
);
10677 /* make sure the listview control window has the focus */
10678 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
10680 if ((item
>= 0) && (item
< infoPtr
->nItemCount
))
10682 LISTVIEW_SetItemFocus(infoPtr
, item
);
10683 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
10684 !LISTVIEW_GetItemState(infoPtr
, item
, LVIS_SELECTED
))
10685 LISTVIEW_SetSelection(infoPtr
, item
);
10688 LISTVIEW_DeselectAll(infoPtr
);
10690 if (LISTVIEW_TrackMouse(infoPtr
, ht
.pt
))
10692 if (ht
.iItem
!= -1)
10696 memset(&nmlv
, 0, sizeof(nmlv
));
10697 nmlv
.iItem
= ht
.iItem
;
10698 nmlv
.ptAction
= ht
.pt
;
10700 notify_listview(infoPtr
, LVN_BEGINRDRAG
, &nmlv
);
10705 SetFocus(infoPtr
->hwndSelf
);
10709 LISTVIEW_HitTest(infoPtr
, &ht
, TRUE
, FALSE
);
10711 if (notify_click(infoPtr
, NM_RCLICK
, &ht
))
10713 /* Send a WM_CONTEXTMENU message in response to the WM_RBUTTONUP */
10714 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
10715 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)GetMessagePos());
10727 * [I] infoPtr : valid pointer to the listview structure
10728 * [I] hwnd : window handle of window containing the cursor
10729 * [I] nHittest : hit-test code
10730 * [I] wMouseMsg : ideintifier of the mouse message
10733 * TRUE if cursor is set
10736 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10738 LVHITTESTINFO lvHitTestInfo
;
10740 if (!LISTVIEW_IsHotTracking(infoPtr
)) goto forward
;
10742 if (!infoPtr
->hHotCursor
) goto forward
;
10744 GetCursorPos(&lvHitTestInfo
.pt
);
10745 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) goto forward
;
10747 SetCursor(infoPtr
->hHotCursor
);
10753 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SETCURSOR
, wParam
, lParam
);
10761 * [I] infoPtr : valid pointer to the listview structure
10762 * [I] hwndLoseFocus : handle of previously focused window
10767 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
10769 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
10771 /* if we have the focus already, there's nothing to do */
10772 if (infoPtr
->bFocus
) return 0;
10774 /* send NM_SETFOCUS notification */
10775 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
10777 /* set window focus flag */
10778 infoPtr
->bFocus
= TRUE
;
10780 /* put the focus rect back on */
10781 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
10783 /* redraw all visible selected items */
10784 LISTVIEW_InvalidateSelectedItems(infoPtr
);
10794 * [I] infoPtr : valid pointer to the listview structure
10795 * [I] fRedraw : font handle
10796 * [I] fRedraw : redraw flag
10801 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
10803 HFONT oldFont
= infoPtr
->hFont
;
10804 INT oldHeight
= infoPtr
->nItemHeight
;
10806 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
10808 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
10809 if (infoPtr
->hFont
== oldFont
) return 0;
10811 LISTVIEW_SaveTextMetrics(infoPtr
);
10813 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
10815 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10817 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
10818 LISTVIEW_UpdateSize(infoPtr
);
10819 LISTVIEW_UpdateScroll(infoPtr
);
10821 else if (infoPtr
->nItemHeight
!= oldHeight
)
10822 LISTVIEW_UpdateScroll(infoPtr
);
10824 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
10831 * Message handling for WM_SETREDRAW.
10832 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
10835 * [I] infoPtr : valid pointer to the listview structure
10836 * [I] bRedraw: state of redraw flag
10839 * DefWinProc return value
10841 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
10843 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
10845 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
10846 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
10848 infoPtr
->bRedraw
= bRedraw
;
10850 if(!bRedraw
) return 0;
10852 if (is_autoarrange(infoPtr
))
10853 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10854 LISTVIEW_UpdateScroll(infoPtr
);
10856 /* despite what the WM_SETREDRAW docs says, apps expect us
10857 * to invalidate the listview here... stupid! */
10858 LISTVIEW_InvalidateList(infoPtr
);
10865 * Resizes the listview control. This function processes WM_SIZE
10866 * messages. At this time, the width and height are not used.
10869 * [I] infoPtr : valid pointer to the listview structure
10870 * [I] Width : new width
10871 * [I] Height : new height
10876 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10878 RECT rcOld
= infoPtr
->rcList
;
10880 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10882 LISTVIEW_UpdateSize(infoPtr
);
10883 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10885 /* do not bother with display related stuff if we're not redrawing */
10886 if (!is_redrawing(infoPtr
)) return 0;
10888 if (is_autoarrange(infoPtr
))
10889 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10891 LISTVIEW_UpdateScroll(infoPtr
);
10893 /* refresh all only for lists whose height changed significantly */
10894 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10895 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10896 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10897 LISTVIEW_InvalidateList(infoPtr
);
10904 * Sets the size information.
10907 * [I] infoPtr : valid pointer to the listview structure
10912 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
10914 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
10916 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
10918 if (infoPtr
->uView
== LV_VIEW_LIST
)
10920 /* Apparently the "LIST" style is supposed to have the same
10921 * number of items in a column even if there is no scroll bar.
10922 * Since if a scroll bar already exists then the bottom is already
10923 * reduced, only reduce if the scroll bar does not currently exist.
10924 * The "2" is there to mimic the native control. I think it may be
10925 * related to either padding or edges. (GLA 7/2002)
10927 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
10928 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
10929 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
10932 /* if control created invisible header isn't created */
10933 if (infoPtr
->hwndHeader
)
10938 hl
.prc
= &infoPtr
->rcList
;
10940 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10941 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10943 if (LISTVIEW_IsHeaderEnabled(infoPtr
))
10944 wp
.flags
|= SWP_SHOWWINDOW
;
10947 wp
.flags
|= SWP_HIDEWINDOW
;
10951 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
10952 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10954 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
10956 /* extra padding for grid */
10957 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
10958 infoPtr
->rcList
.top
+= 2;
10960 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
10965 * Processes WM_STYLECHANGED messages.
10968 * [I] infoPtr : valid pointer to the listview structure
10969 * [I] wStyleType : window style type (normal or extended)
10970 * [I] lpss : window style information
10975 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10976 const STYLESTRUCT
*lpss
)
10978 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
10979 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
10982 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10983 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10985 if (wStyleType
!= GWL_STYLE
) return 0;
10987 infoPtr
->dwStyle
= lpss
->styleNew
;
10988 map_style_view(infoPtr
);
10990 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
10991 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
10992 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
10994 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
10995 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
10996 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
10998 if (uNewView
!= uOldView
)
11002 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
11003 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
11005 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
11006 SetRectEmpty(&infoPtr
->rcFocus
);
11008 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
11009 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
11011 if (uNewView
== LVS_REPORT
)
11016 LISTVIEW_CreateHeader( infoPtr
);
11018 hl
.prc
= &infoPtr
->rcList
;
11020 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
11021 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
11022 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
11023 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
11026 LISTVIEW_UpdateItemSize(infoPtr
);
11029 if (uNewView
== LVS_REPORT
|| infoPtr
->dwLvExStyle
& LVS_EX_HEADERINALLVIEWS
)
11031 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
11033 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
11035 /* Turn off the header control */
11036 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
11037 TRACE("Hide header control, was 0x%08x\n", style
);
11038 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
11040 /* Turn on the header control */
11041 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
11043 TRACE("Show header control, was 0x%08x\n", style
);
11044 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
11050 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
11051 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
11052 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
11054 /* update the size of the client area */
11055 LISTVIEW_UpdateSize(infoPtr
);
11057 /* add scrollbars if needed */
11058 LISTVIEW_UpdateScroll(infoPtr
);
11060 /* invalidate client area + erase background */
11061 LISTVIEW_InvalidateList(infoPtr
);
11068 * Processes WM_STYLECHANGING messages.
11071 * [I] wStyleType : window style type (normal or extended)
11072 * [I0] lpss : window style information
11077 static INT
LISTVIEW_StyleChanging(WPARAM wStyleType
,
11080 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
11081 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
11083 /* don't forward LVS_OWNERDATA only if not already set to */
11084 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
11086 if (lpss
->styleOld
& LVS_OWNERDATA
)
11087 lpss
->styleNew
|= LVS_OWNERDATA
;
11089 lpss
->styleNew
&= ~LVS_OWNERDATA
;
11097 * Processes WM_SHOWWINDOW messages.
11100 * [I] infoPtr : valid pointer to the listview structure
11101 * [I] bShown : window is being shown (FALSE when hidden)
11102 * [I] iStatus : window show status
11107 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, WPARAM bShown
, LPARAM iStatus
)
11109 /* header delayed creation */
11110 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
11112 LISTVIEW_CreateHeader(infoPtr
);
11114 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
11115 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
11118 return DefWindowProcW(infoPtr
->hwndSelf
, WM_SHOWWINDOW
, bShown
, iStatus
);
11123 * Processes CCM_GETVERSION messages.
11126 * [I] infoPtr : valid pointer to the listview structure
11131 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
11133 return infoPtr
->iVersion
;
11138 * Processes CCM_SETVERSION messages.
11141 * [I] infoPtr : valid pointer to the listview structure
11142 * [I] iVersion : version to be set
11145 * -1 when requested version is greater than DLL version;
11146 * previous version otherwise
11148 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
11150 INT iOldVersion
= infoPtr
->iVersion
;
11152 if (iVersion
> COMCTL32_VERSION
)
11155 infoPtr
->iVersion
= iVersion
;
11157 TRACE("new version %d\n", iVersion
);
11159 return iOldVersion
;
11164 * Window procedure of the listview control.
11167 static LRESULT WINAPI
11168 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11170 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
11172 TRACE("(hwnd=%p uMsg=%x wParam=%lx lParam=%lx)\n", hwnd
, uMsg
, wParam
, lParam
);
11174 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
11175 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11179 case LVM_APPROXIMATEVIEWRECT
:
11180 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
11181 LOWORD(lParam
), HIWORD(lParam
));
11183 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
11185 case LVM_CANCELEDITLABEL
:
11186 return LISTVIEW_CancelEditLabel(infoPtr
);
11188 case LVM_CREATEDRAGIMAGE
:
11189 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11191 case LVM_DELETEALLITEMS
:
11192 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
11194 case LVM_DELETECOLUMN
:
11195 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
11197 case LVM_DELETEITEM
:
11198 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
11200 case LVM_EDITLABELA
:
11201 case LVM_EDITLABELW
:
11202 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
,
11203 uMsg
== LVM_EDITLABELW
);
11204 /* case LVM_ENABLEGROUPVIEW: */
11206 case LVM_ENSUREVISIBLE
:
11207 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
11209 case LVM_FINDITEMW
:
11210 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
11212 case LVM_FINDITEMA
:
11213 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
11215 case LVM_GETBKCOLOR
:
11216 return infoPtr
->clrBk
;
11218 /* case LVM_GETBKIMAGE: */
11220 case LVM_GETCALLBACKMASK
:
11221 return infoPtr
->uCallbackMask
;
11223 case LVM_GETCOLUMNA
:
11224 case LVM_GETCOLUMNW
:
11225 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11226 uMsg
== LVM_GETCOLUMNW
);
11228 case LVM_GETCOLUMNORDERARRAY
:
11229 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11231 case LVM_GETCOLUMNWIDTH
:
11232 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
11234 case LVM_GETCOUNTPERPAGE
:
11235 return LISTVIEW_GetCountPerPage(infoPtr
);
11237 case LVM_GETEDITCONTROL
:
11238 return (LRESULT
)infoPtr
->hwndEdit
;
11240 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
11241 return infoPtr
->dwLvExStyle
;
11243 /* case LVM_GETGROUPINFO: */
11245 /* case LVM_GETGROUPMETRICS: */
11247 case LVM_GETHEADER
:
11248 return (LRESULT
)infoPtr
->hwndHeader
;
11250 case LVM_GETHOTCURSOR
:
11251 return (LRESULT
)infoPtr
->hHotCursor
;
11253 case LVM_GETHOTITEM
:
11254 return infoPtr
->nHotItem
;
11256 case LVM_GETHOVERTIME
:
11257 return infoPtr
->dwHoverTime
;
11259 case LVM_GETIMAGELIST
:
11260 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
11262 /* case LVM_GETINSERTMARK: */
11264 /* case LVM_GETINSERTMARKCOLOR: */
11266 /* case LVM_GETINSERTMARKRECT: */
11268 case LVM_GETISEARCHSTRINGA
:
11269 case LVM_GETISEARCHSTRINGW
:
11270 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
11275 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_GETITEMW
);
11277 case LVM_GETITEMCOUNT
:
11278 return infoPtr
->nItemCount
;
11280 case LVM_GETITEMPOSITION
:
11281 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
11283 case LVM_GETITEMRECT
:
11284 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
11286 case LVM_GETITEMSPACING
:
11287 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
11289 case LVM_GETITEMSTATE
:
11290 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
11292 case LVM_GETITEMTEXTA
:
11293 case LVM_GETITEMTEXTW
:
11294 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11295 uMsg
== LVM_GETITEMTEXTW
);
11297 case LVM_GETNEXTITEM
:
11298 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
11300 case LVM_GETNUMBEROFWORKAREAS
:
11301 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
11304 case LVM_GETORIGIN
:
11305 if (!lParam
) return FALSE
;
11306 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
11307 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
11308 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
11311 /* case LVM_GETOUTLINECOLOR: */
11313 /* case LVM_GETSELECTEDCOLUMN: */
11315 case LVM_GETSELECTEDCOUNT
:
11316 return LISTVIEW_GetSelectedCount(infoPtr
);
11318 case LVM_GETSELECTIONMARK
:
11319 return infoPtr
->nSelectionMark
;
11321 case LVM_GETSTRINGWIDTHA
:
11322 case LVM_GETSTRINGWIDTHW
:
11323 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
,
11324 uMsg
== LVM_GETSTRINGWIDTHW
);
11326 case LVM_GETSUBITEMRECT
:
11327 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
11329 case LVM_GETTEXTBKCOLOR
:
11330 return infoPtr
->clrTextBk
;
11332 case LVM_GETTEXTCOLOR
:
11333 return infoPtr
->clrText
;
11335 /* case LVM_GETTILEINFO: */
11337 /* case LVM_GETTILEVIEWINFO: */
11339 case LVM_GETTOOLTIPS
:
11340 if( !infoPtr
->hwndToolTip
)
11341 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
11342 return (LRESULT
)infoPtr
->hwndToolTip
;
11344 case LVM_GETTOPINDEX
:
11345 return LISTVIEW_GetTopIndex(infoPtr
);
11347 case LVM_GETUNICODEFORMAT
:
11348 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
11351 return infoPtr
->uView
;
11353 case LVM_GETVIEWRECT
:
11354 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
11356 case LVM_GETWORKAREAS
:
11357 FIXME("LVM_GETWORKAREAS: unimplemented\n");
11360 /* case LVM_HASGROUP: */
11363 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
11365 case LVM_INSERTCOLUMNA
:
11366 case LVM_INSERTCOLUMNW
:
11367 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11368 uMsg
== LVM_INSERTCOLUMNW
);
11370 /* case LVM_INSERTGROUP: */
11372 /* case LVM_INSERTGROUPSORTED: */
11374 case LVM_INSERTITEMA
:
11375 case LVM_INSERTITEMW
:
11376 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, uMsg
== LVM_INSERTITEMW
);
11378 /* case LVM_INSERTMARKHITTEST: */
11380 /* case LVM_ISGROUPVIEWENABLED: */
11382 case LVM_ISITEMVISIBLE
:
11383 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
11385 case LVM_MAPIDTOINDEX
:
11386 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
11388 case LVM_MAPINDEXTOID
:
11389 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
11391 /* case LVM_MOVEGROUP: */
11393 /* case LVM_MOVEITEMTOGROUP: */
11395 case LVM_REDRAWITEMS
:
11396 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11398 /* case LVM_REMOVEALLGROUPS: */
11400 /* case LVM_REMOVEGROUP: */
11403 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
11405 case LVM_SETBKCOLOR
:
11406 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
11408 /* case LVM_SETBKIMAGE: */
11410 case LVM_SETCALLBACKMASK
:
11411 infoPtr
->uCallbackMask
= (UINT
)wParam
;
11414 case LVM_SETCOLUMNA
:
11415 case LVM_SETCOLUMNW
:
11416 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
,
11417 uMsg
== LVM_SETCOLUMNW
);
11419 case LVM_SETCOLUMNORDERARRAY
:
11420 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
11422 case LVM_SETCOLUMNWIDTH
:
11423 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
11425 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
11426 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
11428 /* case LVM_SETGROUPINFO: */
11430 /* case LVM_SETGROUPMETRICS: */
11432 case LVM_SETHOTCURSOR
:
11433 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
11435 case LVM_SETHOTITEM
:
11436 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
11438 case LVM_SETHOVERTIME
:
11439 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)lParam
);
11441 case LVM_SETICONSPACING
:
11443 return LISTVIEW_SetIconSpacing(infoPtr
, -1, -1);
11444 return LISTVIEW_SetIconSpacing(infoPtr
, LOWORD(lParam
), HIWORD(lParam
));
11446 case LVM_SETIMAGELIST
:
11447 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
11449 /* case LVM_SETINFOTIP: */
11451 /* case LVM_SETINSERTMARK: */
11453 /* case LVM_SETINSERTMARKCOLOR: */
11458 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
11459 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
11462 case LVM_SETITEMCOUNT
:
11463 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
11465 case LVM_SETITEMPOSITION
:
11468 pt
.x
= (short)LOWORD(lParam
);
11469 pt
.y
= (short)HIWORD(lParam
);
11470 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, &pt
);
11473 case LVM_SETITEMPOSITION32
:
11474 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, (POINT
*)lParam
);
11476 case LVM_SETITEMSTATE
:
11477 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
11479 case LVM_SETITEMTEXTA
:
11480 case LVM_SETITEMTEXTW
:
11481 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
,
11482 uMsg
== LVM_SETITEMTEXTW
);
11484 /* case LVM_SETOUTLINECOLOR: */
11486 /* case LVM_SETSELECTEDCOLUMN: */
11488 case LVM_SETSELECTIONMARK
:
11489 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
11491 case LVM_SETTEXTBKCOLOR
:
11492 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
11494 case LVM_SETTEXTCOLOR
:
11495 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
11497 /* case LVM_SETTILEINFO: */
11499 /* case LVM_SETTILEVIEWINFO: */
11501 /* case LVM_SETTILEWIDTH: */
11503 case LVM_SETTOOLTIPS
:
11504 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
11506 case LVM_SETUNICODEFORMAT
:
11507 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
11510 return LISTVIEW_SetView(infoPtr
, wParam
);
11512 /* case LVM_SETWORKAREAS: */
11514 /* case LVM_SORTGROUPS: */
11516 case LVM_SORTITEMS
:
11517 case LVM_SORTITEMSEX
:
11518 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, wParam
,
11519 uMsg
== LVM_SORTITEMSEX
);
11520 case LVM_SUBITEMHITTEST
:
11521 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
11524 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
11526 case CCM_GETVERSION
:
11527 return LISTVIEW_GetVersion(infoPtr
);
11529 case CCM_SETVERSION
:
11530 return LISTVIEW_SetVersion(infoPtr
, wParam
);
11533 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
11536 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
11539 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
11542 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
11545 return LISTVIEW_Destroy(infoPtr
);
11548 return LISTVIEW_Enable(infoPtr
);
11550 case WM_ERASEBKGND
:
11551 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
11553 case WM_GETDLGCODE
:
11554 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
11557 return (LRESULT
)infoPtr
->hFont
;
11560 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11563 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
11566 return LISTVIEW_KillFocus(infoPtr
);
11568 case WM_LBUTTONDBLCLK
:
11569 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11571 case WM_LBUTTONDOWN
:
11572 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11575 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11578 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11580 case WM_MOUSEHOVER
:
11581 return LISTVIEW_MouseHover(infoPtr
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11584 return LISTVIEW_NCDestroy(infoPtr
);
11587 return LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
);
11590 return LISTVIEW_Notify(infoPtr
, (LPNMHDR
)lParam
);
11592 case WM_NOTIFYFORMAT
:
11593 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
11595 case WM_PRINTCLIENT
:
11596 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
11599 return LISTVIEW_WMPaint(infoPtr
, (HDC
)wParam
);
11601 case WM_RBUTTONDBLCLK
:
11602 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11604 case WM_RBUTTONDOWN
:
11605 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
11608 return LISTVIEW_SetCursor(infoPtr
, wParam
, lParam
);
11611 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
11614 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
11617 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
11619 case WM_SHOWWINDOW
:
11620 return LISTVIEW_ShowWindow(infoPtr
, wParam
, lParam
);
11622 case WM_STYLECHANGED
:
11623 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
11625 case WM_STYLECHANGING
:
11626 return LISTVIEW_StyleChanging(wParam
, (LPSTYLESTRUCT
)lParam
);
11628 case WM_SYSCOLORCHANGE
:
11629 COMCTL32_RefreshSysColors();
11632 /* case WM_TIMER: */
11633 case WM_THEMECHANGED
:
11634 return LISTVIEW_ThemeChanged(infoPtr
);
11637 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0);
11639 case WM_MOUSEWHEEL
:
11640 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
11641 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11642 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
11644 case WM_WINDOWPOSCHANGED
:
11645 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
11647 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
11648 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
11650 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
11652 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
11654 LISTVIEW_Size(infoPtr
, ((WINDOWPOS
*)lParam
)->cx
, ((WINDOWPOS
*)lParam
)->cy
);
11656 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11658 /* case WM_WININICHANGE: */
11661 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
11662 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
11664 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
11671 * Registers the window class.
11679 void LISTVIEW_Register(void)
11681 WNDCLASSW wndClass
;
11683 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
11684 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
11685 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
11686 wndClass
.cbClsExtra
= 0;
11687 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
11688 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
11689 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
11690 wndClass
.lpszClassName
= WC_LISTVIEWW
;
11691 RegisterClassW(&wndClass
);
11696 * Unregisters the window class.
11704 void LISTVIEW_Unregister(void)
11706 UnregisterClassW(WC_LISTVIEWW
, NULL
);
11711 * Handle any WM_COMMAND messages
11714 * [I] infoPtr : valid pointer to the listview structure
11715 * [I] wParam : the first message parameter
11716 * [I] lParam : the second message parameter
11721 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
11724 TRACE("(%p %x %x %lx)\n", infoPtr
, HIWORD(wParam
), LOWORD(wParam
), lParam
);
11726 if (!infoPtr
->hwndEdit
) return 0;
11728 switch (HIWORD(wParam
))
11733 * Adjust the edit window size
11735 WCHAR buffer
[1024];
11736 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
11737 HFONT hFont
, hOldFont
= 0;
11741 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
11742 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
11743 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
11745 /* Select font to get the right dimension of the string */
11746 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
11749 hOldFont
= SelectObject(hdc
, hFont
);
11752 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
11754 TEXTMETRICW textMetric
;
11756 /* Add Extra spacing for the next character */
11757 GetTextMetricsW(hdc
, &textMetric
);
11758 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
11760 SetWindowPos(infoPtr
->hwndEdit
, NULL
, 0, 0, sz
.cx
,
11761 rect
.bottom
- rect
.top
, SWP_DRAWFRAME
| SWP_NOMOVE
| SWP_NOZORDER
);
11764 SelectObject(hdc
, hOldFont
);
11766 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
11772 LISTVIEW_CancelEditLabel(infoPtr
);
11777 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);