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 Nikolay Sivov
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with this library; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
27 * This code was audited for completeness against the documented features
28 * of Comctl32.dll version 6.0 on May. 20, 2005, by James Hawkins.
30 * Unless otherwise noted, we believe this code to be complete, as per
31 * the specification mentioned above.
32 * If you discover missing features, or bugs, please note them below.
36 * Default Message Processing
37 * -- WM_CREATE: create the icon and small icon image lists at this point only if
38 * the LVS_SHAREIMAGELISTS style is not specified.
39 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
40 * or small icon and the LVS_AUTOARRANGE style is specified.
45 * -- Hot item handling, mouse hovering
46 * -- Workareas support
51 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
52 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
53 * -- LVA_SNAPTOGRID not implemented
54 * -- LISTVIEW_ApproximateViewRect partially implemented
55 * -- LISTVIEW_[GS]etColumnOrderArray stubs
56 * -- LISTVIEW_SetColumnWidth ignores header images & bitmap
57 * -- LISTVIEW_SetIconSpacing is incomplete
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)
83 * -- LVS_NOSCROLL (see Q137520)
87 * -- LVS_EX_BORDERSELECT
89 * -- LVS_EX_HEADERDRAGDROP
92 * -- LVS_EX_MULTIWORKAREAS
94 * -- LVS_EX_SIMPLESELECT
95 * -- LVS_EX_TWOCLICKACTIVATE
96 * -- LVS_EX_UNDERLINECOLD
97 * -- LVS_EX_UNDERLINEHOT
100 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
103 * -- LVN_MARQUEEBEGIN
109 * -- LVM_ENABLEGROUPVIEW
110 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
111 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
112 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
113 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
114 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
115 * -- LVM_GETINSERTMARKRECT
116 * -- LVM_GETNUMBEROFWORKAREAS
117 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
118 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
119 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
120 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
121 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
122 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
123 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
124 * -- LVM_INSERTGROUPSORTED
125 * -- LVM_INSERTMARKHITTEST
126 * -- LVM_ISGROUPVIEWENABLED
128 * -- LVM_MOVEITEMTOGROUP
130 * -- LVM_SETTILEWIDTH
134 * -- ListView_GetHoverTime, ListView_SetHoverTime
135 * -- ListView_GetISearchString
136 * -- ListView_GetNumberOfWorkAreas
137 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
142 * Known differences in message stream from native control (not known if
143 * these differences cause problems):
144 * LVM_INSERTITEM issues LVM_SETITEMSTATE and LVM_SETITEM in certain cases.
145 * LVM_SETITEM does not always issue LVN_ITEMCHANGING/LVN_ITEMCHANGED.
146 * WM_CREATE does not issue WM_QUERYUISTATE and associated registry
147 * processing for "USEDOUBLECLICKTIME".
151 #include "wine/port.h"
166 #include "commctrl.h"
167 #include "comctl32.h"
170 #include "wine/debug.h"
171 #include "wine/unicode.h"
173 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
175 /* make sure you set this to 0 for production use! */
176 #define DEBUG_RANGES 1
178 typedef struct tagCOLUMN_INFO
180 RECT rcHeader
; /* tracks the header's rectangle */
181 int fmt
; /* same as LVCOLUMN.fmt */
184 typedef struct tagITEMHDR
188 } ITEMHDR
, *LPITEMHDR
;
190 typedef struct tagSUBITEM_INFO
196 typedef struct tagITEM_ID ITEM_ID
;
198 typedef struct tagITEM_INFO
209 UINT id
; /* item id */
210 HDPA item
; /* link to item data */
213 typedef struct tagRANGE
219 typedef struct tagRANGES
224 typedef struct tagITERATOR
233 typedef struct tagDELAYED_ITEM_EDIT
239 typedef struct tagLISTVIEW_INFO
246 HIMAGELIST himlNormal
;
247 HIMAGELIST himlSmall
;
248 HIMAGELIST himlState
;
252 POINT ptClickPos
; /* point where the user clicked */
253 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
256 RANGES selectionRanges
;
261 RECT rcList
; /* This rectangle is really the window
262 * client rectangle possibly reduced by the
263 * horizontal scroll bar and/or header - see
264 * LISTVIEW_UpdateSize. This rectangle offset
265 * by the LISTVIEW_GetOrigin value is in
266 * client coordinates */
275 INT ntmHeight
; /* Some cached metrics of the font used */
276 INT ntmMaxCharWidth
; /* by the listview to draw items */
278 BOOL bRedraw
; /* Turns on/off repaints & invalidations */
279 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
281 BOOL bDoChangeNotify
; /* send change notification messages? */
284 DWORD dwStyle
; /* the cached window GWL_STYLE */
285 DWORD dwLvExStyle
; /* extended listview style */
286 DWORD uView
; /* current view available through LVM_[G,S]ETVIEW */
287 INT nItemCount
; /* the number of items in the list */
288 HDPA hdpaItems
; /* array ITEM_INFO pointers */
289 HDPA hdpaItemIds
; /* array of ITEM_ID pointers */
290 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
291 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
292 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
293 POINT currIconPos
; /* this is the position next icon will be placed */
294 PFNLVCOMPARE pfnCompare
;
299 INT nLButtonDownItem
; /* tracks item to reset multiselection on WM_LBUTTONUP */
303 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
305 DWORD lastKeyPressTimestamp
;
307 INT nSearchParamLength
;
308 WCHAR szSearchParam
[ MAX_PATH
];
310 INT nMeasureItemHeight
;
311 INT xTrackLine
; /* The x coefficient of the track line or -1 if none */
312 DELAYED_ITEM_EDIT itemEdit
; /* Pointer to this structure will be the timer ID */
314 DWORD iVersion
; /* CCM_[G,S]ETVERSION */
320 /* How many we debug buffer to allocate */
321 #define DEBUG_BUFFERS 20
322 /* The size of a single debug bbuffer */
323 #define DEBUG_BUFFER_SIZE 256
325 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
326 #define SB_INTERNAL -1
328 /* maximum size of a label */
329 #define DISP_TEXT_SIZE 512
331 /* padding for items in list and small icon display modes */
332 #define WIDTH_PADDING 12
334 /* padding for items in list, report and small icon display modes */
335 #define HEIGHT_PADDING 1
337 /* offset of items in report display mode */
338 #define REPORT_MARGINX 2
340 /* padding for icon in large icon display mode
341 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
342 * that HITTEST will see.
343 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
344 * ICON_TOP_PADDING - sum of the two above.
345 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
346 * LABEL_HOR_PADDING - between text and sides of box
347 * LABEL_VERT_PADDING - between bottom of text and end of box
349 * ICON_LR_PADDING - additional width above icon size.
350 * ICON_LR_HALF - half of the above value
352 #define ICON_TOP_PADDING_NOTHITABLE 2
353 #define ICON_TOP_PADDING_HITABLE 2
354 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
355 #define ICON_BOTTOM_PADDING 4
356 #define LABEL_HOR_PADDING 5
357 #define LABEL_VERT_PADDING 7
358 #define ICON_LR_PADDING 16
359 #define ICON_LR_HALF (ICON_LR_PADDING/2)
361 /* default label width for items in list and small icon display modes */
362 #define DEFAULT_LABEL_WIDTH 40
364 /* default column width for items in list display mode */
365 #define DEFAULT_COLUMN_WIDTH 128
367 /* Size of "line" scroll for V & H scrolls */
368 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
370 /* Padding between image and label */
371 #define IMAGE_PADDING 2
373 /* Padding behind the label */
374 #define TRAILING_LABEL_PADDING 12
375 #define TRAILING_HEADER_PADDING 11
377 /* Border for the icon caption */
378 #define CAPTION_BORDER 2
380 /* Standard DrawText flags */
381 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
382 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
383 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
385 /* Image index from state */
386 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
388 /* The time in milliseconds to reset the search in the list */
389 #define KEY_DELAY 450
391 /* Dump the LISTVIEW_INFO structure to the debug channel */
392 #define LISTVIEW_DUMP(iP) do { \
393 TRACE("hwndSelf=%p, clrBk=0x%06x, clrText=0x%06x, clrTextBk=0x%06x, ItemHeight=%d, ItemWidth=%d, Style=0x%08x\n", \
394 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
395 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
396 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08x, Focus=%d\n", \
397 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
398 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
399 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%d, icSz.cy=%d, icSp.cx=%d, icSp.cy=%d, notifyFmt=%d\n", \
400 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
401 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
402 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, wine_dbgstr_rect(&iP->rcList)); \
405 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
408 * forward declarations
410 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
411 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*, INT
, LPRECT
);
412 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*, INT
, LPPOINT
);
413 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*, INT
, LPPOINT
);
414 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*, INT
, LPRECT
);
415 static INT
LISTVIEW_GetLabelWidth(const LISTVIEW_INFO
*, INT
);
416 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*, LPPOINT
);
417 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*, LPRECT
);
418 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
419 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
420 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
421 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
, BOOL
);
422 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*, INT
, UINT
);
423 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
424 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
425 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
426 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
427 static HWND
CreateEditLabelT(LISTVIEW_INFO
*, LPCWSTR
, DWORD
, BOOL
);
428 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
429 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
430 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*, BOOL
, BOOL
);
432 /******** Text handling functions *************************************/
434 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
435 * text string. The string may be ANSI or Unicode, in which case
436 * the boolean isW tells us the type of the string.
438 * The name of the function tell what type of strings it expects:
439 * W: Unicode, T: ANSI/Unicode - function of isW
442 static inline BOOL
is_textW(LPCWSTR text
)
444 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
447 static inline BOOL
is_textT(LPCWSTR text
, BOOL isW
)
449 /* we can ignore isW since LPSTR_TEXTCALLBACKW == LPSTR_TEXTCALLBACKA */
450 return is_textW(text
);
453 static inline int textlenT(LPCWSTR text
, BOOL isW
)
455 return !is_textT(text
, isW
) ? 0 :
456 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
459 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
462 if (isSrcW
) lstrcpynW(dest
, src
, max
);
463 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
465 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
466 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
469 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
471 LPWSTR wstr
= (LPWSTR
)text
;
473 if (!isW
&& is_textT(text
, isW
))
475 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
476 wstr
= Alloc(len
* sizeof(WCHAR
));
477 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
479 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
483 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
485 if (!isW
&& is_textT(wstr
, isW
)) Free (wstr
);
489 * dest is a pointer to a Unicode string
490 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
492 static BOOL
textsetptrT(LPWSTR
*dest
, LPCWSTR src
, BOOL isW
)
496 if (src
== LPSTR_TEXTCALLBACKW
)
498 if (is_textW(*dest
)) Free(*dest
);
499 *dest
= LPSTR_TEXTCALLBACKW
;
503 LPWSTR pszText
= textdupTtoW(src
, isW
);
504 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
505 bResult
= Str_SetPtrW(dest
, pszText
);
506 textfreeT(pszText
, isW
);
512 * compares a Unicode to a Unicode/ANSI text string
514 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
516 if (!aw
) return bt
? -1 : 0;
517 if (!bt
) return aw
? 1 : 0;
518 if (aw
== LPSTR_TEXTCALLBACKW
)
519 return bt
== LPSTR_TEXTCALLBACKW
? 1 : -1;
520 if (bt
!= LPSTR_TEXTCALLBACKW
)
522 LPWSTR bw
= textdupTtoW(bt
, isW
);
523 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
531 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
535 n
= min(min(n
, lstrlenW(s1
)), lstrlenW(s2
));
536 res
= CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
);
537 return res
? res
- sizeof(WCHAR
) : res
;
540 /******** Debugging functions *****************************************/
542 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
544 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
545 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
548 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
550 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
551 n
= min(textlenT(text
, isW
), n
);
552 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
555 static char* debug_getbuf(void)
557 static int index
= 0;
558 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
559 return buffers
[index
++ % DEBUG_BUFFERS
];
562 static inline const char* debugrange(const RANGE
*lprng
)
564 if (!lprng
) return "(null)";
565 return wine_dbg_sprintf("[%d, %d]", lprng
->lower
, lprng
->upper
);
568 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
570 char* buf
= debug_getbuf(), *text
= buf
;
571 int len
, size
= DEBUG_BUFFER_SIZE
;
573 if (pScrollInfo
== NULL
) return "(null)";
574 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
575 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
576 if (pScrollInfo
->fMask
& SIF_RANGE
)
577 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
579 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
580 if (pScrollInfo
->fMask
& SIF_PAGE
)
581 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
583 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
584 if (pScrollInfo
->fMask
& SIF_POS
)
585 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
587 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
588 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
589 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
591 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
594 buf
= text
+ strlen(text
);
596 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
600 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
602 if (!plvnm
) return "(null)";
603 return wine_dbg_sprintf("iItem=%d, iSubItem=%d, uNewState=0x%x,"
604 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld",
605 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
606 plvnm
->uChanged
, wine_dbgstr_point(&plvnm
->ptAction
), plvnm
->lParam
);
609 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
611 char* buf
= debug_getbuf(), *text
= buf
;
612 int len
, size
= DEBUG_BUFFER_SIZE
;
614 if (lpLVItem
== NULL
) return "(null)";
615 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
616 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
617 if (lpLVItem
->mask
& LVIF_STATE
)
618 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
620 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
621 if (lpLVItem
->mask
& LVIF_TEXT
)
622 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
624 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
625 if (lpLVItem
->mask
& LVIF_IMAGE
)
626 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
628 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
629 if (lpLVItem
->mask
& LVIF_PARAM
)
630 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
632 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
633 if (lpLVItem
->mask
& LVIF_INDENT
)
634 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
636 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
639 buf
= text
+ strlen(text
);
641 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
645 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
647 char* buf
= debug_getbuf(), *text
= buf
;
648 int len
, size
= DEBUG_BUFFER_SIZE
;
650 if (lpColumn
== NULL
) return "(null)";
651 len
= snprintf(buf
, size
, "{");
652 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
653 if (lpColumn
->mask
& LVCF_SUBITEM
)
654 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
656 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
657 if (lpColumn
->mask
& LVCF_FMT
)
658 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
660 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
661 if (lpColumn
->mask
& LVCF_WIDTH
)
662 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
664 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
665 if (lpColumn
->mask
& LVCF_TEXT
)
666 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
668 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
669 if (lpColumn
->mask
& LVCF_IMAGE
)
670 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
672 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
673 if (lpColumn
->mask
& LVCF_ORDER
)
674 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
676 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
679 buf
= text
+ strlen(text
);
681 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
685 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
687 if (!lpht
) return "(null)";
689 return wine_dbg_sprintf("{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
690 wine_dbgstr_point(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
693 /* Return the corresponding text for a given scroll value */
694 static inline LPCSTR
debugscrollcode(int nScrollCode
)
698 case SB_LINELEFT
: return "SB_LINELEFT";
699 case SB_LINERIGHT
: return "SB_LINERIGHT";
700 case SB_PAGELEFT
: return "SB_PAGELEFT";
701 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
702 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
703 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
704 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
705 case SB_INTERNAL
: return "SB_INTERNAL";
706 default: return "unknown";
711 /******** Notification functions ************************************/
713 static int get_ansi_notification(UINT unicodeNotificationCode
)
715 switch (unicodeNotificationCode
)
717 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
718 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
719 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
720 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
721 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
722 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
723 /* header forwards */
724 case HDN_TRACKW
: return HDN_TRACKA
;
725 case HDN_ENDTRACKW
: return HDN_ENDTRACKA
;
726 case HDN_BEGINDRAG
: return HDN_BEGINDRAG
;
727 case HDN_ENDDRAG
: return HDN_ENDDRAG
;
728 case HDN_ITEMCHANGINGW
: return HDN_ITEMCHANGINGA
;
729 case HDN_ITEMCHANGEDW
: return HDN_ITEMCHANGEDA
;
730 case HDN_ITEMCLICKW
: return HDN_ITEMCLICKA
;
731 case HDN_DIVIDERDBLCLICKW
: return HDN_DIVIDERDBLCLICKA
;
733 ERR("unknown notification %x\n", unicodeNotificationCode
);
738 /* forwards header notifications to listview parent */
739 static LRESULT
notify_forward_header(const LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
743 HD_TEXTFILTERA textfilter
;
744 LPSTR text
= NULL
, filter
= NULL
;
747 /* on unicode format exit earlier */
748 if (infoPtr
->notifyFormat
== NFR_UNICODE
)
749 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
750 (WPARAM
)lpnmh
->hdr
.idFrom
, (LPARAM
)lpnmh
);
752 /* header always supplies unicode notifications,
753 all we have to do is to convert strings to ANSI */
754 nmhA
= *(NMHEADERA
*)lpnmh
;
757 hditema
= *(HDITEMA
*)lpnmh
->pitem
;
758 nmhA
.pitem
= &hditema
;
759 /* convert item text */
760 if (lpnmh
->pitem
->mask
& HDI_TEXT
)
762 hditema
.pszText
= NULL
;
763 Str_SetPtrWtoA(&hditema
.pszText
, lpnmh
->pitem
->pszText
);
764 text
= hditema
.pszText
;
766 /* convert filter text */
767 if ((lpnmh
->pitem
->mask
& HDI_FILTER
) && (lpnmh
->pitem
->type
== HDFT_ISSTRING
) &&
768 lpnmh
->pitem
->pvFilter
)
770 hditema
.pvFilter
= &textfilter
;
771 textfilter
= *(HD_TEXTFILTERA
*)(lpnmh
->pitem
->pvFilter
);
772 textfilter
.pszText
= NULL
;
773 Str_SetPtrWtoA(&textfilter
.pszText
, ((HD_TEXTFILTERW
*)lpnmh
->pitem
->pvFilter
)->pszText
);
774 filter
= textfilter
.pszText
;
777 nmhA
.hdr
.code
= get_ansi_notification(lpnmh
->hdr
.code
);
779 ret
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
780 (WPARAM
)nmhA
.hdr
.idFrom
, (LPARAM
)&nmhA
);
789 static LRESULT
notify_hdr(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
793 TRACE("(code=%d)\n", code
);
795 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
796 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
798 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
, pnmh
->idFrom
, (LPARAM
)pnmh
);
800 TRACE(" <= %ld\n", result
);
805 static inline BOOL
notify(const LISTVIEW_INFO
*infoPtr
, INT code
)
808 HWND hwnd
= infoPtr
->hwndSelf
;
809 notify_hdr(infoPtr
, code
, &nmh
);
810 return IsWindow(hwnd
);
813 static inline void notify_itemactivate(const LISTVIEW_INFO
*infoPtr
, const LVHITTESTINFO
*htInfo
)
824 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
825 item
.iItem
= htInfo
->iItem
;
827 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
828 nmia
.lParam
= item
.lParam
;
829 nmia
.uOldState
= item
.state
;
830 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
831 nmia
.uChanged
= LVIF_STATE
;
834 nmia
.iItem
= htInfo
->iItem
;
835 nmia
.iSubItem
= htInfo
->iSubItem
;
836 nmia
.ptAction
= htInfo
->pt
;
838 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
839 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
840 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
842 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
845 static inline LRESULT
notify_listview(const LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
847 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
848 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
851 static BOOL
notify_click(const LISTVIEW_INFO
*infoPtr
, INT code
, const LVHITTESTINFO
*lvht
)
855 HWND hwnd
= infoPtr
->hwndSelf
;
857 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
858 ZeroMemory(&nmia
, sizeof(nmia
));
859 nmia
.iItem
= lvht
->iItem
;
860 nmia
.iSubItem
= lvht
->iSubItem
;
861 nmia
.ptAction
= lvht
->pt
;
862 item
.mask
= LVIF_PARAM
;
863 item
.iItem
= lvht
->iItem
;
865 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmia
.lParam
= item
.lParam
;
866 notify_hdr(infoPtr
, code
, (LPNMHDR
)&nmia
);
867 return IsWindow(hwnd
);
870 static BOOL
notify_deleteitem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
874 HWND hwnd
= infoPtr
->hwndSelf
;
876 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
878 item
.mask
= LVIF_PARAM
;
881 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
882 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
883 return IsWindow(hwnd
);
887 Send notification. depends on dispinfoW having same
888 structure as dispinfoA.
889 infoPtr : listview struct
890 notificationCode : *Unicode* notification code
891 pdi : dispinfo structure (can be unicode or ansi)
892 isW : TRUE if dispinfo is Unicode
894 static BOOL
notify_dispinfoT(const LISTVIEW_INFO
*infoPtr
, UINT notificationCode
, LPNMLVDISPINFOW pdi
, BOOL isW
)
896 BOOL bResult
= FALSE
;
897 BOOL convertToAnsi
= FALSE
, convertToUnicode
= FALSE
;
898 INT cchTempBufMax
= 0, savCchTextMax
= 0;
900 LPWSTR pszTempBuf
= NULL
, savPszText
= NULL
;
902 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_textT(pdi
->item
.pszText
, isW
))
904 convertToAnsi
= (isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
905 convertToUnicode
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
908 if (convertToAnsi
|| convertToUnicode
)
910 if (notificationCode
!= LVN_GETDISPINFOW
)
912 cchTempBufMax
= convertToUnicode
?
913 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
914 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
918 cchTempBufMax
= pdi
->item
.cchTextMax
;
919 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
922 pszTempBuf
= Alloc( (convertToUnicode
? sizeof(WCHAR
) : sizeof(CHAR
)) * cchTempBufMax
);
923 if (!pszTempBuf
) return FALSE
;
925 if (convertToUnicode
)
926 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
927 pszTempBuf
, cchTempBufMax
);
929 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) pszTempBuf
,
930 cchTempBufMax
, NULL
, NULL
);
932 savCchTextMax
= pdi
->item
.cchTextMax
;
933 savPszText
= pdi
->item
.pszText
;
934 pdi
->item
.pszText
= pszTempBuf
;
935 pdi
->item
.cchTextMax
= cchTempBufMax
;
938 if (infoPtr
->notifyFormat
== NFR_ANSI
)
939 realNotifCode
= get_ansi_notification(notificationCode
);
941 realNotifCode
= notificationCode
;
942 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
943 bResult
= notify_hdr(infoPtr
, realNotifCode
, &pdi
->hdr
);
945 if (convertToUnicode
|| convertToAnsi
)
947 if (convertToUnicode
) /* note : pointer can be changed by app ! */
948 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) savPszText
,
949 savCchTextMax
, NULL
, NULL
);
951 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
952 savPszText
, savCchTextMax
);
953 pdi
->item
.pszText
= savPszText
; /* restores our buffer */
954 pdi
->item
.cchTextMax
= savCchTextMax
;
960 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
,
961 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
963 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
964 lpnmlvcd
->nmcd
.hdc
= hdc
;
965 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
966 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
967 lpnmlvcd
->clrText
= infoPtr
->clrText
;
968 if (!lplvItem
) return;
969 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
970 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
971 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
972 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
973 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
974 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
977 static inline DWORD
notify_customdraw (const LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
979 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
982 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
983 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
984 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
985 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
986 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
987 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
991 static void prepaint_setup (const LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
, BOOL SubItem
)
993 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
994 lpnmlvcd
->clrTextBk
= comctl32_color
.clrWindow
;
995 if (lpnmlvcd
->clrText
== CLR_DEFAULT
)
996 lpnmlvcd
->clrText
= comctl32_color
.clrWindowText
;
998 /* apparently, for selected items, we have to override the returned values */
1001 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
1003 if (infoPtr
->bFocus
)
1005 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
1006 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
1008 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
1010 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
1011 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
1016 /* Set the text attributes */
1017 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
1019 SetBkMode(hdc
, OPAQUE
);
1020 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
1023 SetBkMode(hdc
, TRANSPARENT
);
1024 SetTextColor(hdc
, lpnmlvcd
->clrText
);
1027 static inline DWORD
notify_postpaint (const LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1029 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1032 /* returns TRUE when repaint needed, FALSE otherwise */
1033 static BOOL
notify_measureitem(LISTVIEW_INFO
*infoPtr
)
1035 MEASUREITEMSTRUCT mis
;
1036 mis
.CtlType
= ODT_LISTVIEW
;
1037 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1041 mis
.itemHeight
= infoPtr
->nItemHeight
;
1042 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
1043 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
1045 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
1051 /******** Item iterator functions **********************************/
1053 static RANGES
ranges_create(int count
);
1054 static void ranges_destroy(RANGES ranges
);
1055 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1056 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1057 static void ranges_dump(RANGES ranges
);
1059 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1061 RANGE range
= { nItem
, nItem
+ 1 };
1063 return ranges_add(ranges
, range
);
1066 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1068 RANGE range
= { nItem
, nItem
+ 1 };
1070 return ranges_del(ranges
, range
);
1074 * ITERATOR DOCUMENTATION
1076 * The iterator functions allow for easy, and convenient iteration
1077 * over items of interest in the list. Typically, you create a
1078 * iterator, use it, and destroy it, as such:
1081 * iterator_xxxitems(&i, ...);
1082 * while (iterator_{prev,next}(&i)
1084 * //code which uses i.nItem
1086 * iterator_destroy(&i);
1088 * where xxx is either: framed, or visible.
1089 * Note that it is important that the code destroys the iterator
1090 * after it's done with it, as the creation of the iterator may
1091 * allocate memory, which thus needs to be freed.
1093 * You can iterate both forwards, and backwards through the list,
1094 * by using iterator_next or iterator_prev respectively.
1096 * Lower numbered items are draw on top of higher number items in
1097 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1098 * items may overlap). So, to test items, you should use
1100 * which lists the items top to bottom (in Z-order).
1101 * For drawing items, you should use
1103 * which lists the items bottom to top (in Z-order).
1104 * If you keep iterating over the items after the end-of-items
1105 * marker (-1) is returned, the iterator will start from the
1106 * beginning. Typically, you don't need to test for -1,
1107 * because iterator_{next,prev} will return TRUE if more items
1108 * are to be iterated over, or FALSE otherwise.
1110 * Note: the iterator is defined to be bidirectional. That is,
1111 * any number of prev followed by any number of next, or
1112 * five versa, should leave the iterator at the same item:
1113 * prev * n, next * n = next * n, prev * n
1115 * The iterator has a notion of an out-of-order, special item,
1116 * which sits at the start of the list. This is used in
1117 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1118 * which needs to be first, as it may overlap other items.
1120 * The code is a bit messy because we have:
1121 * - a special item to deal with
1122 * - simple range, or composite range
1124 * If you find bugs, or want to add features, please make sure you
1125 * always check/modify *both* iterator_prev, and iterator_next.
1129 * This function iterates through the items in increasing order,
1130 * but prefixed by the special item, then -1. That is:
1131 * special, 1, 2, 3, ..., n, -1.
1132 * Each item is listed only once.
1134 static inline BOOL
iterator_next(ITERATOR
* i
)
1138 i
->nItem
= i
->nSpecial
;
1139 if (i
->nItem
!= -1) return TRUE
;
1141 if (i
->nItem
== i
->nSpecial
)
1143 if (i
->ranges
) i
->index
= 0;
1149 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1150 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1155 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1156 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1159 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1161 i
->nItem
= i
->range
.lower
;
1162 if (i
->nItem
>= 0) goto testitem
;
1169 * This function iterates through the items in decreasing order,
1170 * followed by the special item, then -1. That is:
1171 * n, n-1, ..., 3, 2, 1, special, -1.
1172 * Each item is listed only once.
1174 static inline BOOL
iterator_prev(ITERATOR
* i
)
1181 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1184 if (i
->nItem
== i
->nSpecial
)
1192 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1193 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1199 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1202 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1204 i
->nItem
= i
->range
.upper
;
1205 if (i
->nItem
> 0) goto testitem
;
1207 return (i
->nItem
= i
->nSpecial
) != -1;
1210 static RANGE
iterator_range(const ITERATOR
*i
)
1214 if (!i
->ranges
) return i
->range
;
1216 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1218 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1219 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1221 else range
.lower
= range
.upper
= 0;
1227 * Releases resources associated with this ierator.
1229 static inline void iterator_destroy(const ITERATOR
*i
)
1231 ranges_destroy(i
->ranges
);
1235 * Create an empty iterator.
1237 static inline BOOL
iterator_empty(ITERATOR
* i
)
1239 ZeroMemory(i
, sizeof(*i
));
1240 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1245 * Create an iterator over a range.
1247 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1255 * Create an iterator over a bunch of ranges.
1256 * Please note that the iterator will take ownership of the ranges,
1257 * and will free them upon destruction.
1259 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1267 * Creates an iterator over the items which intersect lprc.
1269 static BOOL
iterator_frameditems(ITERATOR
* i
, const LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1271 RECT frame
= *lprc
, rcItem
, rcTemp
;
1274 /* in case we fail, we want to return an empty iterator */
1275 if (!iterator_empty(i
)) return FALSE
;
1277 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1279 TRACE("(lprc=%s)\n", wine_dbgstr_rect(lprc
));
1280 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1282 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
1286 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->nFocusedItem
!= -1)
1288 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1289 if (IntersectRect(&rcTemp
, &rcItem
, lprc
))
1290 i
->nSpecial
= infoPtr
->nFocusedItem
;
1292 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1293 /* to do better here, we need to have PosX, and PosY sorted */
1294 TRACE("building icon ranges:\n");
1295 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1297 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1298 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1299 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1300 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1301 if (IntersectRect(&rcTemp
, &rcItem
, &frame
))
1302 ranges_additem(i
->ranges
, nItem
);
1306 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1310 if (frame
.left
>= infoPtr
->nItemWidth
) return TRUE
;
1311 if (frame
.top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1313 range
.lower
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1314 range
.upper
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1315 if (range
.upper
<= range
.lower
) return TRUE
;
1316 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1317 TRACE(" report=%s\n", debugrange(&i
->range
));
1321 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1322 INT nFirstRow
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1323 INT nLastRow
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1330 if (infoPtr
->nItemWidth
)
1332 nFirstCol
= max(frame
.left
/ infoPtr
->nItemWidth
, 0);
1333 nLastCol
= min((frame
.right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1337 nFirstCol
= max(frame
.left
, 0);
1338 nLastCol
= min(frame
.right
- 1, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1341 lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1343 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1344 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1346 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1348 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1349 TRACE("building list ranges:\n");
1350 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1352 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1353 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1354 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1355 TRACE(" list=%s\n", debugrange(&item_range
));
1356 ranges_add(i
->ranges
, item_range
);
1364 * Creates an iterator over the items which intersect the visible region of hdc.
1366 static BOOL
iterator_visibleitems(ITERATOR
*i
, const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1368 POINT Origin
, Position
;
1369 RECT rcItem
, rcClip
;
1372 rgntype
= GetClipBox(hdc
, &rcClip
);
1373 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1374 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1375 if (rgntype
== SIMPLEREGION
) return TRUE
;
1377 /* first deal with the special item */
1378 if (i
->nSpecial
!= -1)
1380 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1381 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1384 /* if we can't deal with the region, we'll just go with the simple range */
1385 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1386 TRACE("building visible range:\n");
1387 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1389 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1390 if (!ranges_add(i
->ranges
, i
->range
))
1392 ranges_destroy(i
->ranges
);
1398 /* now delete the invisible items from the list */
1399 while(iterator_next(i
))
1401 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1402 rcItem
.left
= Position
.x
+ Origin
.x
;
1403 rcItem
.top
= Position
.y
+ Origin
.y
;
1404 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1405 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1406 if (!RectVisible(hdc
, &rcItem
))
1407 ranges_delitem(i
->ranges
, i
->nItem
);
1409 /* the iterator should restart on the next iterator_next */
1415 /******** Misc helper functions ************************************/
1417 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1418 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1420 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1421 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1424 static inline BOOL
is_autoarrange(const LISTVIEW_INFO
*infoPtr
)
1426 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1427 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
);
1430 static void toggle_checkbox_state(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1432 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
1433 if(state
== 1 || state
== 2)
1437 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
1438 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
1439 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
1443 /* this should be called after window style got updated,
1444 it used to reset view state to match current window style */
1445 static inline void map_style_view(LISTVIEW_INFO
*infoPtr
)
1447 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
1450 infoPtr
->uView
= LV_VIEW_ICON
;
1453 infoPtr
->uView
= LV_VIEW_DETAILS
;
1456 infoPtr
->uView
= LV_VIEW_SMALLICON
;
1459 infoPtr
->uView
= LV_VIEW_LIST
;
1463 /* computes next item id value */
1464 static DWORD
get_next_itemid(const LISTVIEW_INFO
*infoPtr
)
1466 INT count
= DPA_GetPtrCount(infoPtr
->hdpaItemIds
);
1470 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, count
- 1);
1471 return lpID
->id
+ 1;
1476 /******** Internal API functions ************************************/
1478 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1480 static COLUMN_INFO mainItem
;
1482 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1483 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1484 return DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1487 static INT
LISTVIEW_CreateHeader(LISTVIEW_INFO
*infoPtr
)
1489 DWORD dFlags
= WS_CHILD
| HDS_HORZ
| HDS_FULLDRAG
| HDS_DRAGDROP
;
1492 if (infoPtr
->hwndHeader
) return 0;
1494 TRACE("Creating header for list %p\n", infoPtr
->hwndSelf
);
1496 /* setup creation flags */
1497 dFlags
|= (LVS_NOSORTHEADER
& infoPtr
->dwStyle
) ? 0 : HDS_BUTTONS
;
1498 dFlags
|= (LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) ? HDS_HIDDEN
: 0;
1500 hInst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
1503 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
, dFlags
,
1504 0, 0, 0, 0, infoPtr
->hwndSelf
, NULL
, hInst
, NULL
);
1505 if (!infoPtr
->hwndHeader
) return -1;
1507 /* set header unicode format */
1508 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, TRUE
, 0);
1510 /* set header font */
1511 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, (LPARAM
)TRUE
);
1513 LISTVIEW_UpdateSize(infoPtr
);
1518 static inline void LISTVIEW_GetHeaderRect(const LISTVIEW_INFO
*infoPtr
, INT nSubItem
, LPRECT lprc
)
1520 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1523 static inline BOOL
LISTVIEW_GetItemW(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1525 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1528 /* used to handle collapse main item column case */
1529 static inline BOOL
LISTVIEW_DrawFocusRect(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1531 return (infoPtr
->rcFocus
.left
< infoPtr
->rcFocus
.right
) ?
1532 DrawFocusRect(hdc
, &infoPtr
->rcFocus
) : FALSE
;
1535 /* Listview invalidation functions: use _only_ these functions to invalidate */
1537 static inline BOOL
is_redrawing(const LISTVIEW_INFO
*infoPtr
)
1539 return infoPtr
->bRedraw
;
1542 static inline void LISTVIEW_InvalidateRect(const LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1544 if(!is_redrawing(infoPtr
)) return;
1545 TRACE(" invalidating rect=%s\n", wine_dbgstr_rect(rect
));
1546 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1549 static inline void LISTVIEW_InvalidateItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
1553 if(!is_redrawing(infoPtr
)) return;
1554 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1555 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1558 static inline void LISTVIEW_InvalidateSubItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1560 POINT Origin
, Position
;
1563 if(!is_redrawing(infoPtr
)) return;
1564 assert (infoPtr
->uView
== LV_VIEW_DETAILS
);
1565 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1566 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1567 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1569 rcBox
.bottom
= infoPtr
->nItemHeight
;
1570 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1571 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1574 static inline void LISTVIEW_InvalidateList(const LISTVIEW_INFO
*infoPtr
)
1576 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1579 static inline void LISTVIEW_InvalidateColumn(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1583 if(!is_redrawing(infoPtr
)) return;
1584 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1585 rcCol
.top
= infoPtr
->rcList
.top
;
1586 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1587 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1592 * Retrieves the number of items that can fit vertically in the client area.
1595 * [I] infoPtr : valid pointer to the listview structure
1598 * Number of items per row.
1600 static inline INT
LISTVIEW_GetCountPerRow(const LISTVIEW_INFO
*infoPtr
)
1602 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1604 return max(nListWidth
/(infoPtr
->nItemWidth
? infoPtr
->nItemWidth
: 1), 1);
1609 * Retrieves the number of items that can fit horizontally in the client
1613 * [I] infoPtr : valid pointer to the listview structure
1616 * Number of items per column.
1618 static inline INT
LISTVIEW_GetCountPerColumn(const LISTVIEW_INFO
*infoPtr
)
1620 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1622 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1626 /*************************************************************************
1627 * LISTVIEW_ProcessLetterKeys
1629 * Processes keyboard messages generated by pressing the letter keys
1631 * What this does is perform a case insensitive search from the
1632 * current position with the following quirks:
1633 * - If two chars or more are pressed in quick succession we search
1634 * for the corresponding string (e.g. 'abc').
1635 * - If there is a delay we wipe away the current search string and
1636 * restart with just that char.
1637 * - If the user keeps pressing the same character, whether slowly or
1638 * fast, so that the search string is entirely composed of this
1639 * character ('aaaaa' for instance), then we search for first item
1640 * that starting with that character.
1641 * - If the user types the above character in quick succession, then
1642 * we must also search for the corresponding string ('aaaaa'), and
1643 * go to that string if there is a match.
1646 * [I] hwnd : handle to the window
1647 * [I] charCode : the character code, the actual character
1648 * [I] keyData : key data
1656 * - The current implementation has a list of characters it will
1657 * accept and it ignores everything else. In particular it will
1658 * ignore accentuated characters which seems to match what
1659 * Windows does. But I'm not sure it makes sense to follow
1661 * - We don't sound a beep when the search fails.
1665 * TREEVIEW_ProcessLetterKeys
1667 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1672 WCHAR buffer
[MAX_PATH
];
1673 DWORD lastKeyPressTimestamp
= infoPtr
->lastKeyPressTimestamp
;
1675 /* simple parameter checking */
1676 if (!charCode
|| !keyData
) return 0;
1678 /* only allow the valid WM_CHARs through */
1679 if (!isalnumW(charCode
) &&
1680 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1681 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1682 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1683 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1684 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1685 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1686 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1687 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1688 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1691 /* if there's one item or less, there is no where to go */
1692 if (infoPtr
->nItemCount
<= 1) return 0;
1694 /* update the search parameters */
1695 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1696 if (infoPtr
->lastKeyPressTimestamp
- lastKeyPressTimestamp
< KEY_DELAY
) {
1697 if (infoPtr
->nSearchParamLength
< MAX_PATH
-1)
1698 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
1699 if (infoPtr
->charCode
!= charCode
)
1700 infoPtr
->charCode
= charCode
= 0;
1702 infoPtr
->charCode
=charCode
;
1703 infoPtr
->szSearchParam
[0]=charCode
;
1704 infoPtr
->nSearchParamLength
=1;
1705 /* Redundant with the 1 char string */
1709 /* and search from the current position */
1711 if (infoPtr
->nFocusedItem
>= 0) {
1712 endidx
=infoPtr
->nFocusedItem
;
1714 /* if looking for single character match,
1715 * then we must always move forward
1717 if (infoPtr
->nSearchParamLength
== 1)
1720 endidx
=infoPtr
->nItemCount
;
1724 /* Let application handle this for virtual listview */
1725 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
1730 ZeroMemory(&lvfi
, sizeof(lvfi
));
1731 lvfi
.flags
= (LVFI_WRAP
| LVFI_PARTIAL
);
1732 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
] = '\0';
1733 lvfi
.psz
= infoPtr
->szSearchParam
;
1737 nItem
= notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
1740 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1746 if (idx
== infoPtr
->nItemCount
) {
1747 if (endidx
== infoPtr
->nItemCount
|| endidx
== 0)
1753 item
.mask
= LVIF_TEXT
;
1756 item
.pszText
= buffer
;
1757 item
.cchTextMax
= MAX_PATH
;
1758 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1760 /* check for a match */
1761 if (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
1764 } else if ( (charCode
!= 0) && (nItem
== -1) && (nItem
!= infoPtr
->nFocusedItem
) &&
1765 (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
1766 /* This would work but we must keep looking for a longer match */
1770 } while (idx
!= endidx
);
1773 LISTVIEW_KeySelection(infoPtr
, nItem
, FALSE
);
1778 /*************************************************************************
1779 * LISTVIEW_UpdateHeaderSize [Internal]
1781 * Function to resize the header control
1784 * [I] hwnd : handle to a window
1785 * [I] nNewScrollPos : scroll pos to set
1790 static void LISTVIEW_UpdateHeaderSize(const LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1795 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1797 if (!infoPtr
->hwndHeader
) return;
1799 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1800 point
[0].x
= winRect
.left
;
1801 point
[0].y
= winRect
.top
;
1802 point
[1].x
= winRect
.right
;
1803 point
[1].y
= winRect
.bottom
;
1805 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1806 point
[0].x
= -nNewScrollPos
;
1807 point
[1].x
+= nNewScrollPos
;
1809 SetWindowPos(infoPtr
->hwndHeader
,0,
1810 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1811 (infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
|
1812 SWP_NOZORDER
| SWP_NOACTIVATE
);
1817 * Update the scrollbars. This functions should be called whenever
1818 * the content, size or view changes.
1821 * [I] infoPtr : valid pointer to the listview structure
1826 static void LISTVIEW_UpdateScroll(const LISTVIEW_INFO
*infoPtr
)
1828 SCROLLINFO horzInfo
, vertInfo
;
1831 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
1833 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
1834 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
1835 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1837 /* for now, we'll set info.nMax to the _count_, and adjust it later */
1838 if (infoPtr
->uView
== LV_VIEW_LIST
)
1840 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
1841 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
1843 /* scroll by at least one column per page */
1844 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
1845 horzInfo
.nPage
= infoPtr
->nItemWidth
;
1847 if (infoPtr
->nItemWidth
)
1848 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
1850 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1852 horzInfo
.nMax
= infoPtr
->nItemWidth
;
1854 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
1858 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
1861 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1862 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
1863 dx
= GetScrollPos(infoPtr
->hwndSelf
, SB_HORZ
);
1864 dx
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
1865 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
1867 /* Setting the horizontal scroll can change the listview size
1868 * (and potentially everything else) so we need to recompute
1869 * everything again for the vertical scroll
1872 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
1873 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
1874 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1876 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1878 vertInfo
.nMax
= infoPtr
->nItemCount
;
1880 /* scroll by at least one page */
1881 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
1882 vertInfo
.nPage
= infoPtr
->nItemHeight
;
1884 if (infoPtr
->nItemHeight
> 0)
1885 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
1887 else if (infoPtr
->uView
!= LV_VIEW_LIST
) /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
1891 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
1894 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1895 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
1896 dy
= GetScrollPos(infoPtr
->hwndSelf
, SB_VERT
);
1897 dy
-= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
1898 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
1900 /* Change of the range may have changed the scroll pos. If so move the content */
1901 if (dx
!= 0 || dy
!= 0)
1904 listRect
= infoPtr
->rcList
;
1905 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &listRect
, &listRect
, 0, 0,
1906 SW_ERASE
| SW_INVALIDATE
);
1909 /* Update the Header Control */
1910 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
1912 horzInfo
.fMask
= SIF_POS
;
1913 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
1914 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
1921 * Shows/hides the focus rectangle.
1924 * [I] infoPtr : valid pointer to the listview structure
1925 * [I] fShow : TRUE to show the focus, FALSE to hide it.
1930 static void LISTVIEW_ShowFocusRect(const LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
1934 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
1936 if (infoPtr
->nFocusedItem
< 0) return;
1938 /* we need some gymnastics in ICON mode to handle large items */
1939 if (infoPtr
->uView
== LV_VIEW_ICON
)
1943 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
1944 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
1946 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1951 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
1953 /* for some reason, owner draw should work only in report mode */
1954 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
1959 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
1960 HFONT hOldFont
= SelectObject(hdc
, hFont
);
1962 item
.iItem
= infoPtr
->nFocusedItem
;
1964 item
.mask
= LVIF_PARAM
;
1965 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
1967 ZeroMemory(&dis
, sizeof(dis
));
1968 dis
.CtlType
= ODT_LISTVIEW
;
1969 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1970 dis
.itemID
= item
.iItem
;
1971 dis
.itemAction
= ODA_FOCUS
;
1972 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
1973 dis
.hwndItem
= infoPtr
->hwndSelf
;
1975 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
1976 dis
.itemData
= item
.lParam
;
1978 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
1980 SelectObject(hdc
, hOldFont
);
1984 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
1987 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1991 * Invalidates all visible selected items.
1993 static void LISTVIEW_InvalidateSelectedItems(const LISTVIEW_INFO
*infoPtr
)
1997 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
1998 while(iterator_next(&i
))
2000 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
2001 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
2003 iterator_destroy(&i
);
2008 * DESCRIPTION: [INTERNAL]
2009 * Computes an item's (left,top) corner, relative to rcView.
2010 * That is, the position has NOT been made relative to the Origin.
2011 * This is deliberate, to avoid computing the Origin over, and
2012 * over again, when this function is called in a loop. Instead,
2013 * one can factor the computation of the Origin before the loop,
2014 * and offset the value returned by this function, on every iteration.
2017 * [I] infoPtr : valid pointer to the listview structure
2018 * [I] nItem : item number
2019 * [O] lpptOrig : item top, left corner
2024 static void LISTVIEW_GetItemOrigin(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
2026 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
2028 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
2030 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2031 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2033 else if (infoPtr
->uView
== LV_VIEW_LIST
)
2035 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
2036 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
2037 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
2039 else /* LV_VIEW_DETAILS */
2041 lpptPosition
->x
= REPORT_MARGINX
;
2042 /* item is always at zero indexed column */
2043 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2044 lpptPosition
->x
+= LISTVIEW_GetColumnInfo(infoPtr
, 0)->rcHeader
.left
;
2045 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
2050 * DESCRIPTION: [INTERNAL]
2051 * Compute the rectangles of an item. This is to localize all
2052 * the computations in one place. If you are not interested in some
2053 * of these values, simply pass in a NULL -- the function is smart
2054 * enough to compute only what's necessary. The function computes
2055 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
2056 * one, the BOX rectangle. This rectangle is very cheap to compute,
2057 * and is guaranteed to contain all the other rectangles. Computing
2058 * the ICON rect is also cheap, but all the others are potentially
2059 * expensive. This gives an easy and effective optimization when
2060 * searching (like point inclusion, or rectangle intersection):
2061 * first test against the BOX, and if TRUE, test against the desired
2063 * If the function does not have all the necessary information
2064 * to computed the requested rectangles, will crash with a
2065 * failed assertion. This is done so we catch all programming
2066 * errors, given that the function is called only from our code.
2068 * We have the following 'special' meanings for a few fields:
2069 * * If LVIS_FOCUSED is set, we assume the item has the focus
2070 * This is important in ICON mode, where it might get a larger
2071 * then usual rectangle
2073 * Please note that subitem support works only in REPORT mode.
2076 * [I] infoPtr : valid pointer to the listview structure
2077 * [I] lpLVItem : item to compute the measures for
2078 * [O] lprcBox : ptr to Box rectangle
2079 * Same as LVM_GETITEMRECT with LVIR_BOUNDS
2080 * [0] lprcSelectBox : ptr to select box rectangle
2081 * Same as LVM_GETITEMRECT with LVIR_SELECTEDBOUNDS
2082 * [O] lprcIcon : ptr to Icon rectangle
2083 * Same as LVM_GETITEMRECT with LVIR_ICON
2084 * [O] lprcStateIcon: ptr to State Icon rectangle
2085 * [O] lprcLabel : ptr to Label rectangle
2086 * Same as LVM_GETITEMRECT with LVIR_LABEL
2091 static void LISTVIEW_GetItemMetrics(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
2092 LPRECT lprcBox
, LPRECT lprcSelectBox
,
2093 LPRECT lprcIcon
, LPRECT lprcStateIcon
, LPRECT lprcLabel
)
2095 BOOL doSelectBox
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
2096 RECT Box
, SelectBox
, Icon
, Label
;
2097 COLUMN_INFO
*lpColumnInfo
= NULL
;
2098 SIZE labelSize
= { 0, 0 };
2100 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
2102 /* Be smart and try to figure out the minimum we have to do */
2103 if (lpLVItem
->iSubItem
) assert(infoPtr
->uView
== LV_VIEW_DETAILS
);
2104 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprcBox
|| lprcLabel
))
2106 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
2107 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
2109 if (lprcSelectBox
) doSelectBox
= TRUE
;
2110 if (lprcLabel
) doLabel
= TRUE
;
2111 if (doLabel
|| lprcIcon
|| lprcStateIcon
) doIcon
= TRUE
;
2118 /************************************************************/
2119 /* compute the box rectangle (it should be cheap to do) */
2120 /************************************************************/
2121 if (lpLVItem
->iSubItem
|| infoPtr
->uView
== LV_VIEW_DETAILS
)
2122 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
2124 if (lpLVItem
->iSubItem
)
2126 Box
= lpColumnInfo
->rcHeader
;
2131 Box
.right
= infoPtr
->nItemWidth
;
2134 Box
.bottom
= infoPtr
->nItemHeight
;
2136 /******************************************************************/
2137 /* compute ICON bounding box (ala LVM_GETITEMRECT) and STATEICON */
2138 /******************************************************************/
2141 LONG state_width
= 0;
2143 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
2144 state_width
= infoPtr
->iconStateSize
.cx
;
2146 if (infoPtr
->uView
== LV_VIEW_ICON
)
2148 Icon
.left
= Box
.left
+ state_width
;
2149 if (infoPtr
->himlNormal
)
2150 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
- state_width
) / 2;
2151 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2152 Icon
.right
= Icon
.left
;
2153 Icon
.bottom
= Icon
.top
;
2154 if (infoPtr
->himlNormal
)
2156 Icon
.right
+= infoPtr
->iconSize
.cx
;
2157 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2160 else /* LV_VIEW_SMALLICON, LV_VIEW_LIST or LV_VIEW_DETAILS */
2162 Icon
.left
= Box
.left
+ state_width
;
2164 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lpLVItem
->iSubItem
== 0)
2166 /* we need the indent in report mode */
2167 assert(lpLVItem
->mask
& LVIF_INDENT
);
2168 Icon
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
+ REPORT_MARGINX
;
2172 Icon
.right
= Icon
.left
;
2173 if (infoPtr
->himlSmall
&&
2174 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 || (lpColumnInfo
->fmt
& LVCFMT_IMAGE
) ||
2175 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2176 Icon
.right
+= infoPtr
->iconSize
.cx
;
2177 Icon
.bottom
= Icon
.top
+ infoPtr
->iconSize
.cy
;
2179 if(lprcIcon
) *lprcIcon
= Icon
;
2180 TRACE(" - icon=%s\n", wine_dbgstr_rect(&Icon
));
2182 /* TODO: is this correct? */
2185 lprcStateIcon
->left
= Icon
.left
- state_width
;
2186 lprcStateIcon
->right
= Icon
.left
;
2187 lprcStateIcon
->top
= Icon
.top
;
2188 lprcStateIcon
->bottom
= lprcStateIcon
->top
+ infoPtr
->iconSize
.cy
;
2189 TRACE(" - state icon=%s\n", wine_dbgstr_rect(lprcStateIcon
));
2192 else Icon
.right
= 0;
2194 /************************************************************/
2195 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2196 /************************************************************/
2199 /* calculate how far to the right can the label stretch */
2200 Label
.right
= Box
.right
;
2201 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2203 if (lpLVItem
->iSubItem
== 0) Label
= lpColumnInfo
->rcHeader
;
2206 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && infoPtr
->uView
== LV_VIEW_DETAILS
))
2208 labelSize
.cx
= infoPtr
->nItemWidth
;
2209 labelSize
.cy
= infoPtr
->nItemHeight
;
2213 /* we need the text in non owner draw mode */
2214 assert(lpLVItem
->mask
& LVIF_TEXT
);
2215 if (is_textT(lpLVItem
->pszText
, TRUE
))
2217 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2218 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2219 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2223 /* compute rough rectangle where the label will go */
2224 SetRectEmpty(&rcText
);
2225 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2226 rcText
.bottom
= infoPtr
->nItemHeight
;
2227 if (infoPtr
->uView
== LV_VIEW_ICON
)
2228 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2230 /* now figure out the flags */
2231 if (infoPtr
->uView
== LV_VIEW_ICON
)
2232 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2234 uFormat
= LV_SL_DT_FLAGS
;
2236 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2238 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2239 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2241 SelectObject(hdc
, hOldFont
);
2242 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2246 if (infoPtr
->uView
== LV_VIEW_ICON
)
2248 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2249 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2250 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2251 Label
.right
= Label
.left
+ labelSize
.cx
;
2252 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2253 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
)
2255 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2256 labelSize
.cy
/= infoPtr
->ntmHeight
;
2257 labelSize
.cy
= max(labelSize
.cy
, 1);
2258 labelSize
.cy
*= infoPtr
->ntmHeight
;
2260 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2262 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2264 Label
.left
= Icon
.right
;
2265 Label
.top
= Box
.top
;
2266 Label
.right
= lpColumnInfo
->rcHeader
.right
;
2267 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2269 else /* LV_VIEW_SMALLICON or LV_VIEW_LIST */
2271 Label
.left
= Icon
.right
;
2272 Label
.top
= Box
.top
;
2273 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2274 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2277 if (lprcLabel
) *lprcLabel
= Label
;
2278 TRACE(" - label=%s\n", wine_dbgstr_rect(&Label
));
2281 /************************************************************/
2282 /* compute SELECT bounding box */
2283 /************************************************************/
2286 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2288 SelectBox
.left
= Icon
.left
;
2289 SelectBox
.top
= Box
.top
;
2290 SelectBox
.bottom
= Box
.bottom
;
2291 SelectBox
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2295 UnionRect(&SelectBox
, &Icon
, &Label
);
2297 if (lprcSelectBox
) *lprcSelectBox
= SelectBox
;
2298 TRACE(" - select box=%s\n", wine_dbgstr_rect(&SelectBox
));
2301 /* Fix the Box if necessary */
2304 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2305 else *lprcBox
= Box
;
2307 TRACE(" - box=%s\n", wine_dbgstr_rect(&Box
));
2311 * DESCRIPTION: [INTERNAL]
2314 * [I] infoPtr : valid pointer to the listview structure
2315 * [I] nItem : item number
2316 * [O] lprcBox : ptr to Box rectangle
2321 static void LISTVIEW_GetItemBox(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2323 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2324 POINT Position
, Origin
;
2327 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2328 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2330 /* Be smart and try to figure out the minimum we have to do */
2332 if (infoPtr
->uView
== LV_VIEW_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2333 lvItem
.mask
|= LVIF_TEXT
;
2334 lvItem
.iItem
= nItem
;
2335 lvItem
.iSubItem
= 0;
2336 lvItem
.pszText
= szDispText
;
2337 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2338 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2339 if (infoPtr
->uView
== LV_VIEW_ICON
)
2341 lvItem
.mask
|= LVIF_STATE
;
2342 lvItem
.stateMask
= LVIS_FOCUSED
;
2343 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2345 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0, 0);
2347 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
2348 SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, 0, 0))
2350 OffsetRect(lprcBox
, Origin
.x
, Position
.y
+ Origin
.y
);
2353 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2356 /* LISTVIEW_MapIdToIndex helper */
2357 static INT CALLBACK
MapIdSearchCompare(LPVOID p1
, LPVOID p2
, LPARAM lParam
)
2359 ITEM_ID
*id1
= (ITEM_ID
*)p1
;
2360 ITEM_ID
*id2
= (ITEM_ID
*)p2
;
2362 if (id1
->id
== id2
->id
) return 0;
2364 return (id1
->id
< id2
->id
) ? -1 : 1;
2369 * Returns the item index for id specified.
2372 * [I] infoPtr : valid pointer to the listview structure
2373 * [I] iID : item id to get index for
2376 * Item index, or -1 on failure.
2378 static INT
LISTVIEW_MapIdToIndex(const LISTVIEW_INFO
*infoPtr
, UINT iID
)
2383 TRACE("iID=%d\n", iID
);
2385 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2386 if (infoPtr
->nItemCount
== 0) return -1;
2389 index
= DPA_Search(infoPtr
->hdpaItemIds
, &ID
, -1, &MapIdSearchCompare
, 0, DPAS_SORTED
);
2393 ITEM_ID
*lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, index
);
2394 return DPA_GetPtrIndex(infoPtr
->hdpaItems
, lpID
->item
);
2402 * Returns the item id for index given.
2405 * [I] infoPtr : valid pointer to the listview structure
2406 * [I] iItem : item index to get id for
2411 static DWORD
LISTVIEW_MapIndexToId(const LISTVIEW_INFO
*infoPtr
, INT iItem
)
2416 TRACE("iItem=%d\n", iItem
);
2418 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return -1;
2419 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
) return -1;
2421 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, iItem
);
2422 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
2424 return lpItem
->id
->id
;
2429 * Returns the current icon position, and advances it along the top.
2430 * The returned position is not offset by Origin.
2433 * [I] infoPtr : valid pointer to the listview structure
2434 * [O] lpPos : will get the current icon position
2439 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2441 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2443 *lpPos
= infoPtr
->currIconPos
;
2445 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2446 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2448 infoPtr
->currIconPos
.x
= 0;
2449 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2455 * Returns the current icon position, and advances it down the left edge.
2456 * The returned position is not offset by Origin.
2459 * [I] infoPtr : valid pointer to the listview structure
2460 * [O] lpPos : will get the current icon position
2465 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2467 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2469 *lpPos
= infoPtr
->currIconPos
;
2471 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2472 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2474 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2475 infoPtr
->currIconPos
.y
= 0;
2481 * Moves an icon to the specified position.
2482 * It takes care of invalidating the item, etc.
2485 * [I] infoPtr : valid pointer to the listview structure
2486 * [I] nItem : the item to move
2487 * [I] lpPos : the new icon position
2488 * [I] isNew : flags the item as being new
2494 static BOOL
LISTVIEW_MoveIconTo(const LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2500 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2501 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2503 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2504 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2507 /* Allocating a POINTER for every item is too resource intensive,
2508 * so we'll keep the (x,y) in different arrays */
2509 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2510 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2512 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2519 * Arranges listview items in icon display mode.
2522 * [I] infoPtr : valid pointer to the listview structure
2523 * [I] nAlignCode : alignment code
2529 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2531 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2535 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
) return FALSE
;
2537 TRACE("nAlignCode=%d\n", nAlignCode
);
2539 if (nAlignCode
== LVA_DEFAULT
)
2541 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2542 else nAlignCode
= LVA_ALIGNTOP
;
2547 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2548 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2549 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2550 default: return FALSE
;
2553 infoPtr
->bAutoarrange
= TRUE
;
2554 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2555 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2557 next_pos(infoPtr
, &pos
);
2558 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2566 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2567 * For LVS_REPORT always returns empty rectangle.
2570 * [I] infoPtr : valid pointer to the listview structure
2571 * [O] lprcView : bounding rectangle
2577 static void LISTVIEW_GetAreaRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2581 SetRectEmpty(lprcView
);
2583 switch (infoPtr
->uView
)
2586 case LV_VIEW_SMALLICON
:
2587 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2589 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2590 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2591 lprcView
->right
= max(lprcView
->right
, x
);
2592 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2594 if (infoPtr
->nItemCount
> 0)
2596 lprcView
->right
+= infoPtr
->nItemWidth
;
2597 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2602 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2603 x
= infoPtr
->nItemCount
/ y
;
2604 if (infoPtr
->nItemCount
% y
) x
++;
2605 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2606 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2613 * Retrieves the bounding rectangle of all the items.
2616 * [I] infoPtr : valid pointer to the listview structure
2617 * [O] lprcView : bounding rectangle
2623 static BOOL
LISTVIEW_GetViewRect(const LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2627 TRACE("(lprcView=%p)\n", lprcView
);
2629 if (!lprcView
) return FALSE
;
2631 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2633 if (infoPtr
->uView
!= LV_VIEW_DETAILS
)
2635 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2636 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2639 TRACE("lprcView=%s\n", wine_dbgstr_rect(lprcView
));
2646 * Retrieves the subitem pointer associated with the subitem index.
2649 * [I] hdpaSubItems : DPA handle for a specific item
2650 * [I] nSubItem : index of subitem
2653 * SUCCESS : subitem pointer
2656 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2658 SUBITEM_INFO
*lpSubItem
;
2661 /* we should binary search here if need be */
2662 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2664 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
2665 if (lpSubItem
->iSubItem
== nSubItem
)
2675 * Calculates the desired item width.
2678 * [I] infoPtr : valid pointer to the listview structure
2681 * The desired item width.
2683 static INT
LISTVIEW_CalculateItemWidth(const LISTVIEW_INFO
*infoPtr
)
2687 TRACE("uView=%d\n", infoPtr
->uView
);
2689 if (infoPtr
->uView
== LV_VIEW_ICON
)
2690 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2691 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
2693 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2698 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
2699 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
2701 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcHeader
);
2702 nItemWidth
= rcHeader
.right
;
2705 else /* LV_VIEW_SMALLICON, or LV_VIEW_LIST */
2709 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2710 nItemWidth
= max(LISTVIEW_GetLabelWidth(infoPtr
, i
), nItemWidth
);
2712 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2713 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2715 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2723 * Calculates the desired item height.
2726 * [I] infoPtr : valid pointer to the listview structure
2729 * The desired item height.
2731 static INT
LISTVIEW_CalculateItemHeight(const LISTVIEW_INFO
*infoPtr
)
2735 TRACE("uView=%d\n", infoPtr
->uView
);
2737 if (infoPtr
->uView
== LV_VIEW_ICON
)
2738 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2741 nItemHeight
= infoPtr
->ntmHeight
;
2742 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
2744 if (infoPtr
->himlState
)
2745 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2746 if (infoPtr
->himlSmall
)
2747 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2748 if (infoPtr
->himlState
|| infoPtr
->himlSmall
)
2749 nItemHeight
+= HEIGHT_PADDING
;
2750 if (infoPtr
->nMeasureItemHeight
> 0)
2751 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2754 return max(nItemHeight
, 1);
2759 * Updates the width, and height of an item.
2762 * [I] infoPtr : valid pointer to the listview structure
2767 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2769 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2770 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2776 * Retrieves and saves important text metrics info for the current
2780 * [I] infoPtr : valid pointer to the listview structure
2783 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2785 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2786 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2787 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2791 if (GetTextMetricsW(hdc
, &tm
))
2793 infoPtr
->ntmHeight
= tm
.tmHeight
;
2794 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
2797 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
2798 infoPtr
->nEllipsisWidth
= sz
.cx
;
2800 SelectObject(hdc
, hOldFont
);
2801 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2803 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
2808 * A compare function for ranges
2811 * [I] range1 : pointer to range 1;
2812 * [I] range2 : pointer to range 2;
2816 * > 0 : if range 1 > range 2
2817 * < 0 : if range 2 > range 1
2818 * = 0 : if range intersects range 2
2820 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
2824 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
2826 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
2831 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange(range1
), debugrange(range2
), cmp
);
2837 #define ranges_check(ranges, desc) ranges_assert(ranges, desc, __FUNCTION__, __LINE__)
2839 #define ranges_check(ranges, desc) do { } while(0)
2842 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *func
, int line
)
2847 TRACE("*** Checking %s:%d:%s ***\n", func
, line
, desc
);
2849 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
2850 ranges_dump(ranges
);
2851 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
2853 prev
= DPA_GetPtr(ranges
->hdpa
, 0);
2854 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
2855 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2857 curr
= DPA_GetPtr(ranges
->hdpa
, i
);
2858 assert (prev
->upper
<= curr
->lower
);
2859 assert (curr
->lower
< curr
->upper
);
2863 TRACE("--- Done checking---\n");
2866 static RANGES
ranges_create(int count
)
2868 RANGES ranges
= Alloc(sizeof(struct tagRANGES
));
2869 if (!ranges
) return NULL
;
2870 ranges
->hdpa
= DPA_Create(count
);
2871 if (ranges
->hdpa
) return ranges
;
2876 static void ranges_clear(RANGES ranges
)
2880 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2881 Free(DPA_GetPtr(ranges
->hdpa
, i
));
2882 DPA_DeleteAllPtrs(ranges
->hdpa
);
2886 static void ranges_destroy(RANGES ranges
)
2888 if (!ranges
) return;
2889 ranges_clear(ranges
);
2890 DPA_Destroy(ranges
->hdpa
);
2894 static RANGES
ranges_clone(RANGES ranges
)
2899 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
2901 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2903 RANGE
*newrng
= Alloc(sizeof(RANGE
));
2904 if (!newrng
) goto fail
;
2905 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
2906 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
2911 TRACE ("clone failed\n");
2912 ranges_destroy(clone
);
2916 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
2920 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
2921 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
2926 static void ranges_dump(RANGES ranges
)
2930 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2931 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
2934 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
2936 RANGE srchrng
= { nItem
, nItem
+ 1 };
2938 TRACE("(nItem=%d)\n", nItem
);
2939 ranges_check(ranges
, "before contain");
2940 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
2943 static INT
ranges_itemcount(RANGES ranges
)
2947 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2949 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
2950 count
+= sel
->upper
- sel
->lower
;
2956 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
2958 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
2961 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
2962 if (index
== -1) return TRUE
;
2964 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
2966 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
2967 if (chkrng
->lower
>= nItem
)
2968 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
2969 if (chkrng
->upper
> nItem
)
2970 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
2975 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
2980 TRACE("(%s)\n", debugrange(&range
));
2981 ranges_check(ranges
, "before add");
2983 /* try find overlapping regions first */
2984 srchrgn
.lower
= range
.lower
- 1;
2985 srchrgn
.upper
= range
.upper
+ 1;
2986 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
2992 TRACE("Adding new range\n");
2994 /* create the brand new range to insert */
2995 newrgn
= Alloc(sizeof(RANGE
));
2996 if(!newrgn
) goto fail
;
2999 /* figure out where to insert it */
3000 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
3001 TRACE("index=%d\n", index
);
3002 if (index
== -1) index
= 0;
3004 /* and get it over with */
3005 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3013 RANGE
*chkrgn
, *mrgrgn
;
3014 INT fromindex
, mergeindex
;
3016 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3017 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
3019 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
3020 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
3022 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
3024 /* merge now common ranges */
3026 srchrgn
.lower
= chkrgn
->lower
- 1;
3027 srchrgn
.upper
= chkrgn
->upper
+ 1;
3031 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
3032 if (mergeindex
== -1) break;
3033 if (mergeindex
== index
)
3035 fromindex
= index
+ 1;
3039 TRACE("Merge with index %i\n", mergeindex
);
3041 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
3042 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
3043 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
3045 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
3046 if (mergeindex
< index
) index
--;
3050 ranges_check(ranges
, "after add");
3054 ranges_check(ranges
, "failed add");
3058 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
3063 TRACE("(%s)\n", debugrange(&range
));
3064 ranges_check(ranges
, "before del");
3066 /* we don't use DPAS_SORTED here, since we need *
3067 * to find the first overlapping range */
3068 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
3071 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
3073 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
3075 /* case 1: Same range */
3076 if ( (chkrgn
->upper
== range
.upper
) &&
3077 (chkrgn
->lower
== range
.lower
) )
3079 DPA_DeletePtr(ranges
->hdpa
, index
);
3082 /* case 2: engulf */
3083 else if ( (chkrgn
->upper
<= range
.upper
) &&
3084 (chkrgn
->lower
>= range
.lower
) )
3086 DPA_DeletePtr(ranges
->hdpa
, index
);
3088 /* case 3: overlap upper */
3089 else if ( (chkrgn
->upper
<= range
.upper
) &&
3090 (chkrgn
->lower
< range
.lower
) )
3092 chkrgn
->upper
= range
.lower
;
3094 /* case 4: overlap lower */
3095 else if ( (chkrgn
->upper
> range
.upper
) &&
3096 (chkrgn
->lower
>= range
.lower
) )
3098 chkrgn
->lower
= range
.upper
;
3101 /* case 5: fully internal */
3104 RANGE tmprgn
= *chkrgn
, *newrgn
;
3106 if (!(newrgn
= Alloc(sizeof(RANGE
)))) goto fail
;
3107 newrgn
->lower
= chkrgn
->lower
;
3108 newrgn
->upper
= range
.lower
;
3109 chkrgn
->lower
= range
.upper
;
3110 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
3119 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
3122 ranges_check(ranges
, "after del");
3126 ranges_check(ranges
, "failed del");
3132 * Removes all selection ranges
3135 * [I] infoPtr : valid pointer to the listview structure
3136 * [I] toSkip : item range to skip removing the selection
3142 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
3151 lvItem
.stateMask
= LVIS_SELECTED
;
3153 /* need to clone the DPA because callbacks can change it */
3154 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
3155 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
3156 while(iterator_next(&i
))
3157 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
3158 /* note that the iterator destructor will free the cloned range */
3159 iterator_destroy(&i
);
3164 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3168 if (!(toSkip
= ranges_create(1))) return FALSE
;
3169 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
3170 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
3171 ranges_destroy(toSkip
);
3175 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
3177 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
3182 * Retrieves the number of items that are marked as selected.
3185 * [I] infoPtr : valid pointer to the listview structure
3188 * Number of items selected.
3190 static INT
LISTVIEW_GetSelectedCount(const LISTVIEW_INFO
*infoPtr
)
3192 INT nSelectedCount
= 0;
3194 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3197 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
3199 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
3204 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
3206 TRACE("nSelectedCount=%d\n", nSelectedCount
);
3207 return nSelectedCount
;
3212 * Manages the item focus.
3215 * [I] infoPtr : valid pointer to the listview structure
3216 * [I] nItem : item index
3219 * TRUE : focused item changed
3220 * FALSE : focused item has NOT changed
3222 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3224 INT oldFocus
= infoPtr
->nFocusedItem
;
3227 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
3229 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
3230 lvItem
.stateMask
= LVIS_FOCUSED
;
3231 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
3233 return oldFocus
!= infoPtr
->nFocusedItem
;
3236 /* Helper function for LISTVIEW_ShiftIndices *only* */
3237 static INT
shift_item(const LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
3239 if (nShiftItem
< nItem
) return nShiftItem
;
3241 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
3243 if (direction
> 0) return nShiftItem
+ direction
;
3245 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
3250 * Updates the various indices after an item has been inserted or deleted.
3253 * [I] infoPtr : valid pointer to the listview structure
3254 * [I] nItem : item index
3255 * [I] direction : Direction of shift, +1 or -1.
3260 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
3265 /* temporarily disable change notification while shifting items */
3266 bOldChange
= infoPtr
->bDoChangeNotify
;
3267 infoPtr
->bDoChangeNotify
= FALSE
;
3269 TRACE("Shifting %iu, %i steps\n", nItem
, direction
);
3271 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3273 assert(abs(direction
) == 1);
3275 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3277 nNewFocus
= shift_item(infoPtr
, infoPtr
->nFocusedItem
, nItem
, direction
);
3278 if (nNewFocus
!= infoPtr
->nFocusedItem
)
3279 LISTVIEW_SetItemFocus(infoPtr
, nNewFocus
);
3281 /* But we are not supposed to modify nHotItem! */
3283 infoPtr
->bDoChangeNotify
= bOldChange
;
3289 * Adds a block of selections.
3292 * [I] infoPtr : valid pointer to the listview structure
3293 * [I] nItem : item index
3296 * Whether the window is still valid.
3298 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3300 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3301 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3302 HWND hwndSelf
= infoPtr
->hwndSelf
;
3303 NMLVODSTATECHANGE nmlv
;
3308 /* Temporarily disable change notification
3309 * If the control is LVS_OWNERDATA, we need to send
3310 * only one LVN_ODSTATECHANGED notification.
3311 * See MSDN documentation for LVN_ITEMCHANGED.
3313 bOldChange
= infoPtr
->bDoChangeNotify
;
3314 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3316 if (nFirst
== -1) nFirst
= nItem
;
3318 item
.state
= LVIS_SELECTED
;
3319 item
.stateMask
= LVIS_SELECTED
;
3321 for (i
= nFirst
; i
<= nLast
; i
++)
3322 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3324 ZeroMemory(&nmlv
, sizeof(nmlv
));
3325 nmlv
.iFrom
= nFirst
;
3328 nmlv
.uOldState
= item
.state
;
3330 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3331 if (!IsWindow(hwndSelf
))
3333 infoPtr
->bDoChangeNotify
= bOldChange
;
3340 * Sets a single group selection.
3343 * [I] infoPtr : valid pointer to the listview structure
3344 * [I] nItem : item index
3349 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3356 if (!(selection
= ranges_create(100))) return;
3358 item
.state
= LVIS_SELECTED
;
3359 item
.stateMask
= LVIS_SELECTED
;
3361 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
3363 if (infoPtr
->nSelectionMark
== -1)
3365 infoPtr
->nSelectionMark
= nItem
;
3366 ranges_additem(selection
, nItem
);
3372 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3373 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3374 ranges_add(selection
, sel
);
3379 RECT rcItem
, rcSel
, rcSelMark
;
3382 rcItem
.left
= LVIR_BOUNDS
;
3383 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return;
3384 rcSelMark
.left
= LVIR_BOUNDS
;
3385 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) return;
3386 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3387 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3388 while(iterator_next(&i
))
3390 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3391 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3393 iterator_destroy(&i
);
3396 /* disable per item notifications on LVS_OWNERDATA style
3397 FIXME: single LVN_ODSTATECHANGED should be used */
3398 bOldChange
= infoPtr
->bDoChangeNotify
;
3399 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3401 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3404 iterator_rangesitems(&i
, selection
);
3405 while(iterator_next(&i
))
3406 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3407 /* this will also destroy the selection */
3408 iterator_destroy(&i
);
3410 infoPtr
->bDoChangeNotify
= bOldChange
;
3412 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3417 * Sets a single selection.
3420 * [I] infoPtr : valid pointer to the listview structure
3421 * [I] nItem : item index
3426 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3430 TRACE("nItem=%d\n", nItem
);
3432 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3434 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3435 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3436 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3438 infoPtr
->nSelectionMark
= nItem
;
3443 * Set selection(s) with keyboard.
3446 * [I] infoPtr : valid pointer to the listview structure
3447 * [I] nItem : item index
3448 * [I] space : VK_SPACE code sent
3451 * SUCCESS : TRUE (needs to be repainted)
3452 * FAILURE : FALSE (nothing has changed)
3454 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL space
)
3456 /* FIXME: pass in the state */
3457 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
3458 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
3459 BOOL bResult
= FALSE
;
3461 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3462 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3466 if (infoPtr
->dwStyle
& LVS_SINGLESEL
|| (wShift
== 0 && wCtrl
== 0))
3467 LISTVIEW_SetSelection(infoPtr
, nItem
);
3471 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3475 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3476 lvItem
.stateMask
= LVIS_SELECTED
;
3479 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3480 if (lvItem
.state
& LVIS_SELECTED
)
3481 infoPtr
->nSelectionMark
= nItem
;
3483 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3486 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3489 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3493 static BOOL
LISTVIEW_GetItemAtPt(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3495 LVHITTESTINFO lvHitTestInfo
;
3497 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3498 lvHitTestInfo
.pt
.x
= pt
.x
;
3499 lvHitTestInfo
.pt
.y
= pt
.y
;
3501 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3503 lpLVItem
->mask
= LVIF_PARAM
;
3504 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3505 lpLVItem
->iSubItem
= 0;
3507 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3510 static inline BOOL
LISTVIEW_isHotTracking(const LISTVIEW_INFO
*infoPtr
)
3512 return ((infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) ||
3513 (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
) ||
3514 (infoPtr
->dwLvExStyle
& LVS_EX_TWOCLICKACTIVATE
));
3519 * Called when the mouse is being actively tracked and has hovered for a specified
3523 * [I] infoPtr : valid pointer to the listview structure
3524 * [I] fwKeys : key indicator
3525 * [I] x,y : mouse position
3528 * 0 if the message was processed, non-zero if there was an error
3531 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3532 * over the item for a certain period of time.
3535 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3537 if (LISTVIEW_isHotTracking(infoPtr
))
3545 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3546 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3554 * Called whenever WM_MOUSEMOVE is received.
3557 * [I] infoPtr : valid pointer to the listview structure
3558 * [I] fwKeys : key indicator
3559 * [I] x,y : mouse position
3562 * 0 if the message is processed, non-zero if there was an error
3564 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3566 TRACKMOUSEEVENT trackinfo
;
3568 if (!(fwKeys
& MK_LBUTTON
))
3569 infoPtr
->bLButtonDown
= FALSE
;
3571 if (infoPtr
->bLButtonDown
)
3575 LVHITTESTINFO lvHitTestInfo
;
3576 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3577 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3579 rect
.left
= infoPtr
->ptClickPos
.x
- wDragWidth
;
3580 rect
.right
= infoPtr
->ptClickPos
.x
+ wDragWidth
;
3581 rect
.top
= infoPtr
->ptClickPos
.y
- wDragHeight
;
3582 rect
.bottom
= infoPtr
->ptClickPos
.y
+ wDragHeight
;
3587 lvHitTestInfo
.pt
= tmp
;
3588 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
3590 /* reset item marker */
3591 if (infoPtr
->nLButtonDownItem
!= lvHitTestInfo
.iItem
)
3592 infoPtr
->nLButtonDownItem
= -1;
3594 if (!PtInRect(&rect
, tmp
))
3596 /* this path covers the following:
3597 1. WM_LBUTTONDOWN over selected item (sets focus on it)
3598 2. change focus with keys
3599 3. move mouse over item from step 1 selects it and moves focus on it */
3600 if (infoPtr
->nLButtonDownItem
!= -1 &&
3601 !LISTVIEW_GetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, LVIS_SELECTED
))
3605 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3606 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3608 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nLButtonDownItem
, &lvItem
);
3609 infoPtr
->nLButtonDownItem
= -1;
3612 if (!infoPtr
->bDragging
)
3616 lvHitTestInfo
.pt
= infoPtr
->ptClickPos
;
3617 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
3619 ZeroMemory(&nmlv
, sizeof(nmlv
));
3620 nmlv
.iItem
= lvHitTestInfo
.iItem
;
3621 nmlv
.ptAction
= infoPtr
->ptClickPos
;
3623 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
3624 infoPtr
->bDragging
= TRUE
;
3631 /* see if we are supposed to be tracking mouse hovering */
3632 if (LISTVIEW_isHotTracking(infoPtr
)) {
3633 /* fill in the trackinfo struct */
3634 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
3635 trackinfo
.dwFlags
= TME_QUERY
;
3636 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
3637 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
3639 /* see if we are already tracking this hwnd */
3640 _TrackMouseEvent(&trackinfo
);
3642 if(!(trackinfo
.dwFlags
& TME_HOVER
)) {
3643 trackinfo
.dwFlags
= TME_HOVER
;
3645 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
3646 _TrackMouseEvent(&trackinfo
);
3655 * Tests whether the item is assignable to a list with style lStyle
3657 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
3659 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
3660 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
3661 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
3669 * Helper for LISTVIEW_SetItemT *only*: sets item attributes.
3672 * [I] infoPtr : valid pointer to the listview structure
3673 * [I] lpLVItem : valid pointer to new item attributes
3674 * [I] isNew : the item being set is being inserted
3675 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3676 * [O] bChanged : will be set to TRUE if the item really changed
3682 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
3688 /* stateMask is ignored for LVM_INSERTITEM */
3689 UINT stateMask
= isNew
? ~0 : lpLVItem
->stateMask
;
3693 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
3695 if (lpLVItem
->mask
== 0) return TRUE
;
3697 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3699 /* a virtual listview only stores selection and focus */
3700 if (lpLVItem
->mask
& ~LVIF_STATE
)
3706 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3707 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
3711 /* we need to get the lParam and state of the item */
3712 item
.iItem
= lpLVItem
->iItem
;
3713 item
.iSubItem
= lpLVItem
->iSubItem
;
3714 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
3715 item
.stateMask
= (infoPtr
->dwStyle
& LVS_OWNERDATA
) ? LVIS_FOCUSED
| LVIS_SELECTED
: ~0;
3719 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
3721 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
3722 /* determine what fields will change */
3723 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & stateMask
& ~infoPtr
->uCallbackMask
))
3724 uChanged
|= LVIF_STATE
;
3726 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
3727 uChanged
|= LVIF_IMAGE
;
3729 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
3730 uChanged
|= LVIF_PARAM
;
3732 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
3733 uChanged
|= LVIF_INDENT
;
3735 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
3736 uChanged
|= LVIF_TEXT
;
3738 TRACE("uChanged=0x%x\n", uChanged
);
3739 if (!uChanged
) return TRUE
;
3742 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
3743 nmlv
.iItem
= lpLVItem
->iItem
;
3744 nmlv
.uNewState
= (item
.state
& ~stateMask
) | (lpLVItem
->state
& stateMask
);
3745 nmlv
.uOldState
= item
.state
;
3746 nmlv
.uChanged
= uChanged
;
3747 nmlv
.lParam
= item
.lParam
;
3749 /* send LVN_ITEMCHANGING notification, if the item is not being inserted */
3750 /* and we are _NOT_ virtual (LVS_OWNERDATA), and change notifications */
3752 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
3754 HWND hwndSelf
= infoPtr
->hwndSelf
;
3756 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
3758 if (!IsWindow(hwndSelf
))
3762 /* copy information */
3763 if (lpLVItem
->mask
& LVIF_TEXT
)
3764 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3766 if (lpLVItem
->mask
& LVIF_IMAGE
)
3767 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
3769 if (lpLVItem
->mask
& LVIF_PARAM
)
3770 lpItem
->lParam
= lpLVItem
->lParam
;
3772 if (lpLVItem
->mask
& LVIF_INDENT
)
3773 lpItem
->iIndent
= lpLVItem
->iIndent
;
3775 if (uChanged
& LVIF_STATE
)
3777 if (lpItem
&& (stateMask
& ~infoPtr
->uCallbackMask
))
3779 lpItem
->state
&= ~stateMask
;
3780 lpItem
->state
|= (lpLVItem
->state
& stateMask
);
3782 if (lpLVItem
->state
& stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3784 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
3785 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3787 else if (stateMask
& LVIS_SELECTED
)
3789 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3791 /* if we are asked to change focus, and we manage it, do it */
3792 if (stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
3794 if (lpLVItem
->state
& LVIS_FOCUSED
)
3796 if (infoPtr
->nFocusedItem
!= -1)
3798 /* remove current focus */
3799 item
.mask
= LVIF_STATE
;
3801 item
.stateMask
= LVIS_FOCUSED
;
3803 /* recurse with redrawing an item */
3804 LISTVIEW_SetItemState(infoPtr
, infoPtr
->nFocusedItem
, &item
);
3807 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
3808 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, infoPtr
->uView
== LV_VIEW_LIST
);
3810 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
3812 infoPtr
->nFocusedItem
= -1;
3817 /* if we're inserting the item, we're done */
3818 if (isNew
) return TRUE
;
3820 /* send LVN_ITEMCHANGED notification */
3821 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
3822 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
3829 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
3832 * [I] infoPtr : valid pointer to the listview structure
3833 * [I] lpLVItem : valid pointer to new subitem attributes
3834 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3835 * [O] bChanged : will be set to TRUE if the item really changed
3841 static BOOL
set_sub_item(const LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
3844 SUBITEM_INFO
*lpSubItem
;
3846 /* we do not support subitems for virtual listviews */
3847 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
3849 /* set subitem only if column is present */
3850 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
3852 /* First do some sanity checks */
3853 /* The LVIF_STATE flag is valid for subitems, but does not appear to be
3854 particularly useful. We currently do not actually do anything with
3855 the flag on subitems.
3857 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
)) return FALSE
;
3858 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
| LVIF_STATE
))) return TRUE
;
3860 /* get the subitem structure, and create it if not there */
3861 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3862 assert (hdpaSubItems
);
3864 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
3867 SUBITEM_INFO
*tmpSubItem
;
3870 lpSubItem
= Alloc(sizeof(SUBITEM_INFO
));
3871 if (!lpSubItem
) return FALSE
;
3872 /* we could binary search here, if need be...*/
3873 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
3875 tmpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
3876 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
3878 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
3883 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
3884 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
3888 if (lpLVItem
->mask
& LVIF_IMAGE
)
3889 if (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
)
3891 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
3895 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
3897 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3906 * Sets item attributes.
3909 * [I] infoPtr : valid pointer to the listview structure
3910 * [I] lpLVItem : new item attributes
3911 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3917 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, LVITEMW
*lpLVItem
, BOOL isW
)
3919 HWND hwndSelf
= infoPtr
->hwndSelf
;
3920 LPWSTR pszText
= NULL
;
3921 BOOL bResult
, bChanged
= FALSE
;
3923 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
3925 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
3928 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
3929 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_textW(lpLVItem
->pszText
))
3931 pszText
= lpLVItem
->pszText
;
3932 lpLVItem
->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
3935 /* actually set the fields */
3936 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
3938 if (lpLVItem
->iSubItem
)
3939 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
3941 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
3942 if (!IsWindow(hwndSelf
))
3945 /* redraw item, if necessary */
3946 if (bChanged
&& !infoPtr
->bIsDrawing
)
3948 /* this little optimization eliminates some nasty flicker */
3949 if ( infoPtr
->uView
== LV_VIEW_DETAILS
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
3950 !(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) &&
3951 lpLVItem
->iSubItem
> 0 && lpLVItem
->iSubItem
<= DPA_GetPtrCount(infoPtr
->hdpaColumns
) )
3952 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
3954 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
3959 textfreeT(lpLVItem
->pszText
, isW
);
3960 lpLVItem
->pszText
= pszText
;
3968 * Retrieves the index of the item at coordinate (0, 0) of the client area.
3971 * [I] infoPtr : valid pointer to the listview structure
3976 static INT
LISTVIEW_GetTopIndex(const LISTVIEW_INFO
*infoPtr
)
3979 SCROLLINFO scrollInfo
;
3981 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3982 scrollInfo
.fMask
= SIF_POS
;
3984 if (infoPtr
->uView
== LV_VIEW_LIST
)
3986 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3987 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
3989 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
3991 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3992 nItem
= scrollInfo
.nPos
;
3996 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3997 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
4000 TRACE("nItem=%d\n", nItem
);
4008 * Erases the background of the given rectangle
4011 * [I] infoPtr : valid pointer to the listview structure
4012 * [I] hdc : device context handle
4013 * [I] lprcBox : clipping rectangle
4019 static inline BOOL
LISTVIEW_FillBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
4021 if (!infoPtr
->hBkBrush
) return FALSE
;
4023 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, wine_dbgstr_rect(lprcBox
), infoPtr
->hBkBrush
);
4025 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
4033 * [I] infoPtr : valid pointer to the listview structure
4034 * [I] hdc : device context handle
4035 * [I] nItem : item index
4036 * [I] nSubItem : subitem index
4037 * [I] pos : item position in client coordinates
4038 * [I] cdmode : custom draw mode
4044 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
4047 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4048 static WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
4049 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
4051 RECT rcSelect
, rcBox
, rcIcon
, rcLabel
, rcStateIcon
;
4052 NMLVCUSTOMDRAW nmlvcd
;
4057 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, wine_dbgstr_point(&pos
));
4059 /* get information needed for drawing the item */
4060 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
| LVIF_PARAM
;
4061 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
;
4062 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
4063 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
;
4064 lvItem
.iItem
= nItem
;
4065 lvItem
.iSubItem
= nSubItem
;
4068 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4069 lvItem
.pszText
= szDispText
;
4070 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
4071 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4072 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
4073 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= szCallback
;
4074 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
4076 /* now check if we need to update the focus rectangle */
4077 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
4079 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
4080 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcSelect
, &rcIcon
, &rcStateIcon
, &rcLabel
);
4081 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
4082 OffsetRect(&rcSelect
, pos
.x
, pos
.y
);
4083 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
4084 OffsetRect(&rcStateIcon
, pos
.x
, pos
.y
);
4085 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
4086 TRACE(" rcBox=%s, rcSelect=%s, rcIcon=%s. rcLabel=%s\n",
4087 wine_dbgstr_rect(&rcBox
), wine_dbgstr_rect(&rcSelect
),
4088 wine_dbgstr_rect(&rcIcon
), wine_dbgstr_rect(&rcLabel
));
4090 /* fill in the custom draw structure */
4091 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
4093 hOldFont
= GetCurrentObject(hdc
, OBJ_FONT
);
4094 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
4095 if (cdmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4096 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4097 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4098 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
4099 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4100 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
4101 if (nSubItem
== 0 && cdsubitemmode
== CDRF_NOTIFYITEMDRAW
)
4103 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
4104 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
4106 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
4107 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4108 else if ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) == FALSE
)
4109 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, TRUE
);
4111 /* in full row select, subitems, will just use main item's colors */
4112 if (nSubItem
&& infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4113 nmlvcd
.clrTextBk
= CLR_NONE
;
4116 if (infoPtr
->himlState
&& STATEIMAGEINDEX(lvItem
.state
) && (nSubItem
== 0))
4118 UINT uStateImage
= STATEIMAGEINDEX(lvItem
.state
);
4121 TRACE("uStateImage=%d\n", uStateImage
);
4122 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
,
4123 rcStateIcon
.left
, rcStateIcon
.top
, ILD_NORMAL
);
4128 himl
= (infoPtr
->uView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
4129 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
4131 TRACE("iImage=%d\n", lvItem
.iImage
);
4132 ImageList_DrawEx(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
4133 rcIcon
.right
- rcIcon
.left
, rcIcon
.bottom
- rcIcon
.top
, infoPtr
->clrBk
, CLR_DEFAULT
,
4134 (lvItem
.state
& LVIS_SELECTED
) && (infoPtr
->bFocus
) ? ILD_SELECTED
: ILD_NORMAL
);
4137 /* Don't bother painting item being edited */
4138 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
4140 /* FIXME: temporary hack */
4141 rcSelect
.left
= rcLabel
.left
;
4143 /* draw the selection background, if we're drawing the main item */
4146 /* in icon mode, the label rect is really what we want to draw the
4148 if (infoPtr
->uView
== LV_VIEW_ICON
)
4151 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
4152 rcSelect
.right
= rcBox
.right
;
4154 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
4155 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, 0, 0, 0);
4156 /* store new focus rectangle */
4157 if (infoPtr
->nFocusedItem
== nItem
) infoPtr
->rcFocus
= rcSelect
;
4160 /* figure out the text drawing flags */
4161 uFormat
= (infoPtr
->uView
== LV_VIEW_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
4162 if (infoPtr
->uView
== LV_VIEW_ICON
)
4163 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
4166 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
4168 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
4169 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
4170 default: uFormat
|= DT_LEFT
;
4173 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
4175 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
4176 else rcLabel
.left
+= LABEL_HOR_PADDING
;
4178 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
4180 /* for GRIDLINES reduce the bottom so the text formats correctly */
4181 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4184 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
4187 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
4188 notify_postpaint(infoPtr
, &nmlvcd
);
4189 if (cdsubitemmode
& CDRF_NEWFONT
)
4190 SelectObject(hdc
, hOldFont
);
4196 * Draws listview items when in owner draw mode.
4199 * [I] infoPtr : valid pointer to the listview structure
4200 * [I] hdc : device context handle
4205 static void LISTVIEW_RefreshOwnerDraw(const LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4207 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
4208 DWORD cditemmode
= CDRF_DODEFAULT
;
4209 NMLVCUSTOMDRAW nmlvcd
;
4210 POINT Origin
, Position
;
4216 ZeroMemory(&dis
, sizeof(dis
));
4218 /* Get scroll info once before loop */
4219 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4221 /* iterate through the invalidated rows */
4222 while(iterator_next(i
))
4224 item
.iItem
= i
->nItem
;
4226 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4227 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4228 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
4230 dis
.CtlType
= ODT_LISTVIEW
;
4232 dis
.itemID
= item
.iItem
;
4233 dis
.itemAction
= ODA_DRAWENTIRE
;
4235 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
4236 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
4237 dis
.hwndItem
= infoPtr
->hwndSelf
;
4239 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
4240 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
4241 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
4242 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
4243 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
4244 dis
.itemData
= item
.lParam
;
4246 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), wine_dbgstr_rect(&dis
.rcItem
));
4249 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
4250 * structure for the rest. of the paint cycle
4252 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
4253 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
4254 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4256 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
4258 prepaint_setup (infoPtr
, hdc
, &nmlvcd
, FALSE
);
4259 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
4262 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
4263 notify_postpaint(infoPtr
, &nmlvcd
);
4269 * Draws listview items when in report display mode.
4272 * [I] infoPtr : valid pointer to the listview structure
4273 * [I] hdc : device context handle
4274 * [I] cdmode : custom draw mode
4279 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4282 RECT rcClip
, rcItem
;
4283 POINT Origin
, Position
;
4290 /* figure out what to draw */
4291 rgntype
= GetClipBox(hdc
, &rcClip
);
4292 if (rgntype
== NULLREGION
) return;
4294 /* Get scroll info once before loop */
4295 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4297 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4299 /* narrow down the columns we need to paint */
4300 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4302 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4304 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4305 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4306 ranges_additem(colRanges
, index
);
4308 iterator_rangesitems(&j
, colRanges
);
4310 /* in full row select, we _have_ to draw the main item */
4311 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
4314 /* iterate through the invalidated rows */
4315 while(iterator_next(i
))
4317 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4318 Position
.y
+= Origin
.y
;
4320 /* iterate through the invalidated columns */
4321 while(iterator_next(&j
))
4323 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4324 Position
.x
= (j
.nItem
== 0) ? rcItem
.left
+ Origin
.x
: Origin
.x
;
4326 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
4329 rcItem
.bottom
= infoPtr
->nItemHeight
;
4330 OffsetRect(&rcItem
, Position
.x
, Position
.y
);
4331 if (!RectVisible(hdc
, &rcItem
)) continue;
4334 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
4337 iterator_destroy(&j
);
4342 * Draws the gridlines if necessary when in report display mode.
4345 * [I] infoPtr : valid pointer to the listview structure
4346 * [I] hdc : device context handle
4351 static void LISTVIEW_RefreshReportGrid(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4357 RECT rcClip
, rcItem
= {0};
4365 /* figure out what to draw */
4366 rgntype
= GetClipBox(hdc
, &rcClip
);
4367 if (rgntype
== NULLREGION
) return;
4369 /* Get scroll info once before loop */
4370 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4372 colRanges
= ranges_create(DPA_GetPtrCount(infoPtr
->hdpaColumns
));
4374 /* narrow down the columns we need to paint */
4375 for(col
= 0; col
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); col
++)
4377 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, col
, 0);
4379 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4380 if ((rcItem
.right
+ Origin
.x
>= rcClip
.left
) && (rcItem
.left
+ Origin
.x
< rcClip
.right
))
4381 ranges_additem(colRanges
, index
);
4384 /* is right most vertical line visible? */
4385 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
4387 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4388 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4389 rmost
= (rcItem
.right
+ Origin
.x
< rcClip
.right
);
4392 if ((hPen
= CreatePen( PS_SOLID
, 1, comctl32_color
.clr3dFace
)))
4394 hOldPen
= SelectObject ( hdc
, hPen
);
4396 /* draw the vertical lines for the columns */
4397 iterator_rangesitems(&j
, colRanges
);
4398 while(iterator_next(&j
))
4400 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
4401 if (rcItem
.left
== 0) continue; /* skip leftmost column */
4402 rcItem
.left
+= Origin
.x
;
4403 rcItem
.right
+= Origin
.x
;
4404 rcItem
.top
= infoPtr
->rcList
.top
;
4405 rcItem
.bottom
= infoPtr
->rcList
.bottom
;
4406 TRACE("vert col=%d, rcItem=%s\n", j
.nItem
, wine_dbgstr_rect(&rcItem
));
4407 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4408 LineTo (hdc
, rcItem
.left
, rcItem
.bottom
);
4410 iterator_destroy(&j
);
4411 /* draw rightmost grid line if visible */
4414 index
= SendMessageW(infoPtr
->hwndHeader
, HDM_ORDERTOINDEX
,
4415 DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, 0);
4416 LISTVIEW_GetHeaderRect(infoPtr
, index
, &rcItem
);
4418 rcItem
.right
+= Origin
.x
;
4420 MoveToEx (hdc
, rcItem
.right
, infoPtr
->rcList
.top
, NULL
);
4421 LineTo (hdc
, rcItem
.right
, infoPtr
->rcList
.bottom
);
4424 /* draw the horizontial lines for the rows */
4425 itemheight
= LISTVIEW_CalculateItemHeight(infoPtr
);
4426 rcItem
.left
= infoPtr
->rcList
.left
;
4427 rcItem
.right
= infoPtr
->rcList
.right
;
4428 rcItem
.bottom
= rcItem
.top
= Origin
.y
- 1;
4429 MoveToEx(hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4430 LineTo(hdc
, rcItem
.right
, rcItem
.top
);
4431 for(y
=itemheight
-1+Origin
.y
; y
<=infoPtr
->rcList
.bottom
; y
+=itemheight
)
4433 rcItem
.bottom
= rcItem
.top
= y
;
4434 TRACE("horz rcItem=%s\n", wine_dbgstr_rect(&rcItem
));
4435 MoveToEx (hdc
, rcItem
.left
, rcItem
.top
, NULL
);
4436 LineTo (hdc
, rcItem
.right
, rcItem
.top
);
4439 SelectObject( hdc
, hOldPen
);
4440 DeleteObject( hPen
);
4446 * Draws listview items when in list display mode.
4449 * [I] infoPtr : valid pointer to the listview structure
4450 * [I] hdc : device context handle
4451 * [I] cdmode : custom draw mode
4456 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
4458 POINT Origin
, Position
;
4460 /* Get scroll info once before loop */
4461 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4463 while(iterator_prev(i
))
4465 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
4466 Position
.x
+= Origin
.x
;
4467 Position
.y
+= Origin
.y
;
4469 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
4476 * Draws listview items.
4479 * [I] infoPtr : valid pointer to the listview structure
4480 * [I] hdc : device context handle
4481 * [I] prcErase : rect to be erased before refresh (may be NULL)
4486 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*prcErase
)
4488 COLORREF oldTextColor
= 0, oldBkColor
= 0, oldClrTextBk
, oldClrText
;
4489 NMLVCUSTOMDRAW nmlvcd
;
4496 HBITMAP hbmp
= NULL
;
4499 LISTVIEW_DUMP(infoPtr
);
4501 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
4502 TRACE("double buffering\n");
4504 hdc
= CreateCompatibleDC(hdcOrig
);
4506 ERR("Failed to create DC for backbuffer\n");
4509 hbmp
= CreateCompatibleBitmap(hdcOrig
, infoPtr
->rcList
.right
,
4510 infoPtr
->rcList
.bottom
);
4512 ERR("Failed to create bitmap for backbuffer\n");
4517 SelectObject(hdc
, hbmp
);
4518 SelectObject(hdc
, infoPtr
->hFont
);
4520 /* Save dc values we're gonna trash while drawing
4521 * FIXME: Should be done in LISTVIEW_DrawItem() */
4522 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4523 oldBkMode
= GetBkMode(hdc
);
4524 oldBkColor
= GetBkColor(hdc
);
4525 oldTextColor
= GetTextColor(hdc
);
4528 infoPtr
->bIsDrawing
= TRUE
;
4531 LISTVIEW_FillBkgnd(infoPtr
, hdc
, prcErase
);
4532 } else if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) {
4533 /* If no erasing was done (usually because RedrawWindow was called
4534 * with RDW_INVALIDATE only) we need to copy the old contents into
4535 * the backbuffer before continuing. */
4536 BitBlt(hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
4537 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
4538 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
4539 hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
4542 /* FIXME: Shouldn't need to do this */
4543 oldClrTextBk
= infoPtr
->clrTextBk
;
4544 oldClrText
= infoPtr
->clrText
;
4546 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
4548 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
4549 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
4550 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4551 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
4552 prepaint_setup(infoPtr
, hdc
, &nmlvcd
, FALSE
);
4554 /* Use these colors to draw the items */
4555 infoPtr
->clrTextBk
= nmlvcd
.clrTextBk
;
4556 infoPtr
->clrText
= nmlvcd
.clrText
;
4558 /* nothing to draw */
4559 if(infoPtr
->nItemCount
== 0) goto enddraw
;
4561 /* figure out what we need to draw */
4562 iterator_visibleitems(&i
, infoPtr
, hdc
);
4563 range
= iterator_range(&i
);
4565 /* send cache hint notification */
4566 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4570 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
4571 nmlv
.iFrom
= range
.lower
;
4572 nmlv
.iTo
= range
.upper
- 1;
4573 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
4576 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
4577 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
4580 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4581 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
4582 else /* LV_VIEW_LIST, LV_VIEW_ICON or LV_VIEW_SMALLICON */
4583 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
4585 /* if we have a focus rect and it's visible, draw it */
4586 if (infoPtr
->bFocus
&& range
.lower
<= infoPtr
->nFocusedItem
&&
4587 (range
.upper
- 1) >= infoPtr
->nFocusedItem
)
4588 LISTVIEW_DrawFocusRect(infoPtr
, hdc
);
4590 iterator_destroy(&i
);
4593 /* For LVS_EX_GRIDLINES go and draw lines */
4594 /* This includes the case where there were *no* items */
4595 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
)
4596 LISTVIEW_RefreshReportGrid(infoPtr
, hdc
);
4598 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
4599 notify_postpaint(infoPtr
, &nmlvcd
);
4601 infoPtr
->clrTextBk
= oldClrTextBk
;
4602 infoPtr
->clrText
= oldClrText
;
4605 BitBlt(hdcOrig
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
,
4606 infoPtr
->rcList
.right
- infoPtr
->rcList
.left
,
4607 infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
,
4608 hdc
, infoPtr
->rcList
.left
, infoPtr
->rcList
.top
, SRCCOPY
);
4613 SelectObject(hdc
, hOldFont
);
4614 SetBkMode(hdc
, oldBkMode
);
4615 SetBkColor(hdc
, oldBkColor
);
4616 SetTextColor(hdc
, oldTextColor
);
4619 infoPtr
->bIsDrawing
= FALSE
;
4625 * Calculates the approximate width and height of a given number of items.
4628 * [I] infoPtr : valid pointer to the listview structure
4629 * [I] nItemCount : number of items
4630 * [I] wWidth : width
4631 * [I] wHeight : height
4634 * Returns a DWORD. The width in the low word and the height in high word.
4636 static DWORD
LISTVIEW_ApproximateViewRect(const LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
4637 WORD wWidth
, WORD wHeight
)
4639 INT nItemCountPerColumn
= 1;
4640 INT nColumnCount
= 0;
4641 DWORD dwViewRect
= 0;
4643 if (nItemCount
== -1)
4644 nItemCount
= infoPtr
->nItemCount
;
4646 if (infoPtr
->uView
== LV_VIEW_LIST
)
4648 if (wHeight
== 0xFFFF)
4650 /* use current height */
4651 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
4654 if (wHeight
< infoPtr
->nItemHeight
)
4655 wHeight
= infoPtr
->nItemHeight
;
4659 if (infoPtr
->nItemHeight
> 0)
4661 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
4662 if (nItemCountPerColumn
== 0)
4663 nItemCountPerColumn
= 1;
4665 if (nItemCount
% nItemCountPerColumn
!= 0)
4666 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
4668 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
4672 /* Microsoft padding magic */
4673 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
4674 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
4676 dwViewRect
= MAKELONG(wWidth
, wHeight
);
4678 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
4682 if (infoPtr
->nItemCount
> 0)
4684 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
4685 wWidth
= rcBox
.right
- rcBox
.left
;
4686 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
4690 /* use current height and width */
4691 if (wHeight
== 0xffff)
4692 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
4693 if (wWidth
== 0xffff)
4694 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
4697 dwViewRect
= MAKELONG(wWidth
, wHeight
);
4699 else if (infoPtr
->uView
== LV_VIEW_SMALLICON
)
4700 FIXME("uView == LV_VIEW_SMALLICON: not implemented\n");
4701 else if (infoPtr
->uView
== LV_VIEW_ICON
)
4702 FIXME("uView == LV_VIEW_ICON: not implemented\n");
4709 * Cancel edit label with saving item text.
4712 * [I] infoPtr : valid pointer to the listview structure
4715 * Always returns TRUE.
4717 static LRESULT
LISTVIEW_CancelEditLabel(LISTVIEW_INFO
*infoPtr
)
4719 /* handle value will be lost after LISTVIEW_EndEditLabelT */
4720 HWND edit
= infoPtr
->hwndEdit
;
4722 LISTVIEW_EndEditLabelT(infoPtr
, TRUE
, IsWindowUnicode(infoPtr
->hwndEdit
));
4723 SendMessageW(edit
, WM_CLOSE
, 0, 0);
4730 * Create a drag image list for the specified item.
4733 * [I] infoPtr : valid pointer to the listview structure
4734 * [I] iItem : index of item
4735 * [O] lppt : Upper-left corner of the image
4738 * Returns a handle to the image list if successful, NULL otherwise.
4740 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
4746 HBITMAP hbmp
, hOldbmp
;
4747 HIMAGELIST dragList
= 0;
4748 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
4750 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
)
4753 rcItem
.left
= LVIR_BOUNDS
;
4754 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
4757 lppt
->x
= rcItem
.left
;
4758 lppt
->y
= rcItem
.top
;
4760 size
.cx
= rcItem
.right
- rcItem
.left
;
4761 size
.cy
= rcItem
.bottom
- rcItem
.top
;
4763 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
4764 hdc
= CreateCompatibleDC(hdcOrig
);
4765 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
4766 hOldbmp
= SelectObject(hdc
, hbmp
);
4768 rcItem
.left
= rcItem
.top
= 0;
4769 rcItem
.right
= size
.cx
;
4770 rcItem
.bottom
= size
.cy
;
4771 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
4774 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
4776 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4777 SelectObject(hdc
, hOldbmp
);
4778 ImageList_Add(dragList
, hbmp
, 0);
4781 SelectObject(hdc
, hOldbmp
);
4785 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
4787 TRACE("ret=%p\n", dragList
);
4795 * Removes all listview items and subitems.
4798 * [I] infoPtr : valid pointer to the listview structure
4804 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
, BOOL destroy
)
4807 HDPA hdpaSubItems
= NULL
;
4814 /* we do it directly, to avoid notifications */
4815 ranges_clear(infoPtr
->selectionRanges
);
4816 infoPtr
->nSelectionMark
= -1;
4817 infoPtr
->nFocusedItem
= -1;
4818 SetRectEmpty(&infoPtr
->rcFocus
);
4819 /* But we are supposed to leave nHotItem as is! */
4822 /* send LVN_DELETEALLITEMS notification */
4823 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
4825 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
4827 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
4829 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
4831 /* send LVN_DELETEITEM notification, if not suppressed
4832 and if it is not a virtual listview */
4833 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
4834 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
4835 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
4837 hdrItem
= DPA_GetPtr(hdpaSubItems
, j
);
4838 if (is_textW(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
4841 DPA_Destroy(hdpaSubItems
);
4842 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
4844 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
4845 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
4846 infoPtr
->nItemCount
--;
4851 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
4852 LISTVIEW_UpdateScroll(infoPtr
);
4854 LISTVIEW_InvalidateList(infoPtr
);
4861 * Scrolls, and updates the columns, when a column is changing width.
4864 * [I] infoPtr : valid pointer to the listview structure
4865 * [I] nColumn : column to scroll
4866 * [I] dx : amount of scroll, in pixels
4871 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
4873 COLUMN_INFO
*lpColumnInfo
;
4878 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
4879 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
4880 rcCol
= lpColumnInfo
->rcHeader
;
4881 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
4882 rcCol
.left
= rcCol
.right
;
4884 /* adjust the other columns */
4885 for (nCol
= nColumn
; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
4887 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
4888 lpColumnInfo
->rcHeader
.left
+= dx
;
4889 lpColumnInfo
->rcHeader
.right
+= dx
;
4892 /* do not update screen if not in report mode */
4893 if (!is_redrawing(infoPtr
) || infoPtr
->uView
!= LV_VIEW_DETAILS
) return;
4895 /* Need to reset the item width when inserting a new column */
4896 infoPtr
->nItemWidth
+= dx
;
4898 LISTVIEW_UpdateScroll(infoPtr
);
4899 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
4901 /* scroll to cover the deleted column, and invalidate for redraw */
4902 rcOld
= infoPtr
->rcList
;
4903 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
4904 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4909 * Removes a column from the listview control.
4912 * [I] infoPtr : valid pointer to the listview structure
4913 * [I] nColumn : column index
4919 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
4923 TRACE("nColumn=%d\n", nColumn
);
4925 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
4926 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4928 /* While the MSDN specifically says that column zero should not be deleted,
4929 what actually happens is that the column itself is deleted but no items or subitems
4933 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
4935 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nColumn
, 0))
4938 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
4939 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
4941 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
4943 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
4945 INT nItem
, nSubItem
, i
;
4947 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
4949 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
4952 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4954 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
4955 if (lpSubItem
->iSubItem
== nColumn
)
4958 lpDelItem
= lpSubItem
;
4960 else if (lpSubItem
->iSubItem
> nColumn
)
4962 lpSubItem
->iSubItem
--;
4966 /* if we found our subitem, zapp it */
4970 if (is_textW(lpDelItem
->hdr
.pszText
))
4971 Free(lpDelItem
->hdr
.pszText
);
4976 /* free dpa memory */
4977 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
4982 /* update the other column info */
4983 LISTVIEW_UpdateItemSize(infoPtr
);
4984 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
4985 LISTVIEW_InvalidateList(infoPtr
);
4987 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
4994 * Invalidates the listview after an item's insertion or deletion.
4997 * [I] infoPtr : valid pointer to the listview structure
4998 * [I] nItem : item index
4999 * [I] dir : -1 if deleting, 1 if inserting
5004 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
5006 INT nPerCol
, nItemCol
, nItemRow
;
5010 /* if we don't refresh, what's the point of scrolling? */
5011 if (!is_redrawing(infoPtr
)) return;
5013 assert (abs(dir
) == 1);
5015 /* arrange icons if autoarrange is on */
5016 if (is_autoarrange(infoPtr
))
5018 BOOL arrange
= TRUE
;
5019 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
5020 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
5021 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
5024 /* scrollbars need updating */
5025 LISTVIEW_UpdateScroll(infoPtr
);
5027 /* figure out the item's position */
5028 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5029 nPerCol
= infoPtr
->nItemCount
+ 1;
5030 else if (infoPtr
->uView
== LV_VIEW_LIST
)
5031 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
5032 else /* LV_VIEW_ICON, or LV_VIEW_SMALLICON */
5035 nItemCol
= nItem
/ nPerCol
;
5036 nItemRow
= nItem
% nPerCol
;
5037 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5039 /* move the items below up a slot */
5040 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
5041 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
5042 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
5043 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5044 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5045 TRACE("rcScroll=%s, dx=%d\n", wine_dbgstr_rect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
5046 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5048 TRACE("Scrolling rcScroll=%s, rcList=%s\n", wine_dbgstr_rect(&rcScroll
), wine_dbgstr_rect(&infoPtr
->rcList
));
5049 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
5050 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5053 /* report has only that column, so we're done */
5054 if (infoPtr
->uView
== LV_VIEW_DETAILS
) return;
5056 /* now for LISTs, we have to deal with the columns to the right */
5057 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
5059 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
5060 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
5061 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
5062 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
5063 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
5064 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
5069 * Removes an item from the listview control.
5072 * [I] infoPtr : valid pointer to the listview structure
5073 * [I] nItem : item index
5079 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5082 const BOOL is_icon
= (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
);
5084 TRACE("(nItem=%d)\n", nItem
);
5086 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5088 /* remove selection, and focus */
5090 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
5091 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
5093 /* send LVN_DELETEITEM notification. */
5094 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
5096 /* we need to do this here, because we'll be deleting stuff */
5098 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5100 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5108 hdpaSubItems
= DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
5109 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5111 /* free id struct */
5112 i
= DPA_GetPtrIndex(infoPtr
->hdpaItemIds
, lpItem
->id
);
5113 lpID
= DPA_GetPtr(infoPtr
->hdpaItemIds
, i
);
5114 DPA_DeletePtr(infoPtr
->hdpaItemIds
, i
);
5116 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
5118 hdrItem
= DPA_GetPtr(hdpaSubItems
, i
);
5119 if (is_textW(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
5122 DPA_Destroy(hdpaSubItems
);
5127 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
5128 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
5131 infoPtr
->nItemCount
--;
5132 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
5134 /* now is the invalidation fun */
5136 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
5143 * Callback implementation for editlabel control
5146 * [I] infoPtr : valid pointer to the listview structure
5147 * [I] storeText : store edit box text as item text
5148 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
5154 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, BOOL storeText
, BOOL isW
)
5156 HWND hwndSelf
= infoPtr
->hwndSelf
;
5157 NMLVDISPINFOW dispInfo
;
5158 INT editedItem
= infoPtr
->nEditLabelItem
;
5160 WCHAR
*pszText
= NULL
;
5165 DWORD len
= isW
? GetWindowTextLengthW(infoPtr
->hwndEdit
) : GetWindowTextLengthA(infoPtr
->hwndEdit
);
5169 if ((pszText
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))))
5171 if (isW
) GetWindowTextW(infoPtr
->hwndEdit
, pszText
, len
+1);
5172 else GetWindowTextA(infoPtr
->hwndEdit
, (CHAR
*)pszText
, len
+1);
5177 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
5179 infoPtr
->nEditLabelItem
= -1;
5180 infoPtr
->hwndEdit
= 0;
5182 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5183 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5184 dispInfo
.item
.iItem
= editedItem
;
5185 dispInfo
.item
.iSubItem
= 0;
5186 dispInfo
.item
.stateMask
= ~0;
5187 if (!LISTVIEW_GetItemW(infoPtr
, &dispInfo
.item
))
5194 bSame
= (lstrcmpW(dispInfo
.item
.pszText
, pszText
) == 0);
5197 LPWSTR tmp
= textdupTtoW(pszText
, FALSE
);
5198 bSame
= (lstrcmpW(dispInfo
.item
.pszText
, tmp
) == 0);
5199 textfreeT(tmp
, FALSE
);
5207 /* add the text from the edit in */
5208 dispInfo
.item
.mask
|= LVIF_TEXT
;
5209 dispInfo
.item
.pszText
= pszText
;
5210 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5212 /* Do we need to update the Item Text */
5213 if (!notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
))
5218 if (!IsWindow(hwndSelf
))
5223 if (!pszText
) return TRUE
;
5225 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
5227 HDPA hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, editedItem
);
5228 ITEM_INFO
* lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5229 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
5231 LISTVIEW_InvalidateItem(infoPtr
, editedItem
);
5237 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5238 dispInfo
.item
.mask
= LVIF_TEXT
;
5239 dispInfo
.item
.iItem
= editedItem
;
5240 dispInfo
.item
.iSubItem
= 0;
5241 dispInfo
.item
.pszText
= pszText
;
5242 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
5243 res
= LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
5253 * Begin in place editing of specified list view item
5256 * [I] infoPtr : valid pointer to the listview structure
5257 * [I] nItem : item index
5258 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
5264 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
5266 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
5267 NMLVDISPINFOW dispInfo
;
5270 HWND hwndSelf
= infoPtr
->hwndSelf
;
5272 HFONT hOldFont
= NULL
;
5273 TEXTMETRICW textMetric
;
5275 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
5277 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
5279 /* Is the EditBox still there, if so remove it */
5280 if(infoPtr
->hwndEdit
!= 0)
5282 SetFocus(infoPtr
->hwndSelf
);
5283 infoPtr
->hwndEdit
= 0;
5286 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5288 infoPtr
->nEditLabelItem
= nItem
;
5290 LISTVIEW_SetSelection(infoPtr
, nItem
);
5291 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
5292 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
5294 rect
.left
= LVIR_LABEL
;
5295 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
5297 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5298 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
5299 dispInfo
.item
.iItem
= nItem
;
5300 dispInfo
.item
.iSubItem
= 0;
5301 dispInfo
.item
.stateMask
= ~0;
5302 dispInfo
.item
.pszText
= szDispText
;
5303 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
5304 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
5306 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, WS_VISIBLE
, isW
);
5307 if (!infoPtr
->hwndEdit
) return 0;
5309 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
5311 if (!IsWindow(hwndSelf
))
5313 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
5314 infoPtr
->hwndEdit
= 0;
5318 /* Now position and display edit box */
5319 hdc
= GetDC(infoPtr
->hwndSelf
);
5321 /* Select the font to get appropriate metric dimensions */
5322 if(infoPtr
->hFont
!= 0)
5323 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
5325 /* Get String Length in pixels */
5326 GetTextExtentPoint32W(hdc
, dispInfo
.item
.pszText
, lstrlenW(dispInfo
.item
.pszText
), &sz
);
5328 /* Add Extra spacing for the next character */
5329 GetTextMetricsW(hdc
, &textMetric
);
5330 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
5332 if(infoPtr
->hFont
!= 0)
5333 SelectObject(hdc
, hOldFont
);
5335 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
5337 MoveWindow(infoPtr
->hwndEdit
, rect
.left
- 2, rect
.top
- 1, sz
.cx
,
5338 rect
.bottom
- rect
.top
+ 2, FALSE
);
5339 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
5340 SetFocus(infoPtr
->hwndEdit
);
5341 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
5342 return infoPtr
->hwndEdit
;
5348 * Ensures the specified item is visible, scrolling into view if necessary.
5351 * [I] infoPtr : valid pointer to the listview structure
5352 * [I] nItem : item index
5353 * [I] bPartial : partially or entirely visible
5359 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
5361 INT nScrollPosHeight
= 0;
5362 INT nScrollPosWidth
= 0;
5363 INT nHorzAdjust
= 0;
5364 INT nVertAdjust
= 0;
5367 RECT rcItem
, rcTemp
;
5369 rcItem
.left
= LVIR_BOUNDS
;
5370 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
5372 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
5374 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
5376 /* scroll left/right, but in LV_VIEW_DETAILS mode */
5377 if (infoPtr
->uView
== LV_VIEW_LIST
)
5378 nScrollPosWidth
= infoPtr
->nItemWidth
;
5379 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
5380 nScrollPosWidth
= 1;
5382 if (rcItem
.left
< infoPtr
->rcList
.left
)
5385 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
5390 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
5394 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
5396 /* scroll up/down, but not in LVS_LIST mode */
5397 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
5398 nScrollPosHeight
= infoPtr
->nItemHeight
;
5399 else if ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
))
5400 nScrollPosHeight
= 1;
5402 if (rcItem
.top
< infoPtr
->rcList
.top
)
5405 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
5410 if (infoPtr
->uView
!= LV_VIEW_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
5414 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
5416 if (nScrollPosWidth
)
5418 INT diff
= nHorzDiff
/ nScrollPosWidth
;
5419 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
5420 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
5423 if (nScrollPosHeight
)
5425 INT diff
= nVertDiff
/ nScrollPosHeight
;
5426 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
5427 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
5435 * Searches for an item with specific characteristics.
5438 * [I] hwnd : window handle
5439 * [I] nStart : base item index
5440 * [I] lpFindInfo : item information to look for
5443 * SUCCESS : index of item
5446 static INT
LISTVIEW_FindItemW(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
5447 const LVFINDINFOW
*lpFindInfo
)
5449 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5450 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
5451 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
5452 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
5453 POINT Position
, Destination
;
5456 /* Search in virtual listviews should be done by application, not by
5457 listview control, so we just send LVN_ODFINDITEMW and return the result */
5458 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5462 nmlv
.iStart
= nStart
;
5463 nmlv
.lvfi
= *lpFindInfo
;
5464 return notify_hdr(infoPtr
, LVN_ODFINDITEMW
, (LPNMHDR
)&nmlv
.hdr
);
5467 if (!lpFindInfo
|| nItem
< 0) return -1;
5470 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
))
5472 lvItem
.mask
|= LVIF_TEXT
;
5473 lvItem
.pszText
= szDispText
;
5474 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5477 if (lpFindInfo
->flags
& LVFI_WRAP
)
5480 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
5481 (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
))
5486 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5487 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
5488 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
5489 switch(lpFindInfo
->vkDirection
)
5491 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
5492 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
5493 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
5494 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
5495 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
5496 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
5497 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
5499 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
5500 Destination
.x
= rcArea
.right
;
5501 Destination
.y
= rcArea
.bottom
;
5503 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
5507 else Destination
.x
= Destination
.y
= 0;
5509 /* if LVFI_PARAM is specified, all other flags are ignored */
5510 if (lpFindInfo
->flags
& LVFI_PARAM
)
5512 lvItem
.mask
|= LVIF_PARAM
;
5514 lvItem
.mask
&= ~LVIF_TEXT
;
5518 for (; nItem
< nLast
; nItem
++)
5520 lvItem
.iItem
= nItem
;
5521 lvItem
.iSubItem
= 0;
5522 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
5524 if (lvItem
.mask
& LVIF_PARAM
)
5526 if (lpFindInfo
->lParam
== lvItem
.lParam
)
5532 if (lvItem
.mask
& LVIF_TEXT
)
5534 if (lpFindInfo
->flags
& LVFI_PARTIAL
)
5536 if (strstrW(lvItem
.pszText
, lpFindInfo
->psz
) == NULL
) continue;
5540 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
5544 if (!bNearest
) return nItem
;
5546 /* This is very inefficient. To do a good job here,
5547 * we need a sorted array of (x,y) item positions */
5548 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
5550 /* compute the distance^2 to the destination */
5551 xdist
= Destination
.x
- Position
.x
;
5552 ydist
= Destination
.y
- Position
.y
;
5553 dist
= xdist
* xdist
+ ydist
* ydist
;
5555 /* remember the distance, and item if it's closer */
5559 nNearestItem
= nItem
;
5566 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
5571 return nNearestItem
;
5576 * Searches for an item with specific characteristics.
5579 * [I] hwnd : window handle
5580 * [I] nStart : base item index
5581 * [I] lpFindInfo : item information to look for
5584 * SUCCESS : index of item
5587 static INT
LISTVIEW_FindItemA(const LISTVIEW_INFO
*infoPtr
, INT nStart
,
5588 const LVFINDINFOA
*lpFindInfo
)
5590 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
);
5595 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
5596 if (hasText
) fiw
.psz
= strW
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
5597 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
5598 textfreeT(strW
, FALSE
);
5604 * Retrieves the background image of the listview control.
5607 * [I] infoPtr : valid pointer to the listview structure
5608 * [O] lpBkImage : background image attributes
5614 /* static BOOL LISTVIEW_GetBkImage(const LISTVIEW_INFO *infoPtr, LPLVBKIMAGE lpBkImage) */
5616 /* FIXME (listview, "empty stub!\n"); */
5622 * Retrieves column attributes.
5625 * [I] infoPtr : valid pointer to the listview structure
5626 * [I] nColumn : column index
5627 * [IO] lpColumn : column information
5628 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
5629 * otherwise it is in fact a LPLVCOLUMNA
5635 static BOOL
LISTVIEW_GetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
5637 COLUMN_INFO
*lpColumnInfo
;
5640 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5641 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
5643 /* initialize memory */
5644 ZeroMemory(&hdi
, sizeof(hdi
));
5646 if (lpColumn
->mask
& LVCF_TEXT
)
5648 hdi
.mask
|= HDI_TEXT
;
5649 hdi
.pszText
= lpColumn
->pszText
;
5650 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
5653 if (lpColumn
->mask
& LVCF_IMAGE
)
5654 hdi
.mask
|= HDI_IMAGE
;
5656 if (lpColumn
->mask
& LVCF_ORDER
)
5657 hdi
.mask
|= HDI_ORDER
;
5659 if (lpColumn
->mask
& LVCF_SUBITEM
)
5660 hdi
.mask
|= HDI_LPARAM
;
5662 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
5664 if (lpColumn
->mask
& LVCF_FMT
)
5665 lpColumn
->fmt
= lpColumnInfo
->fmt
;
5667 if (lpColumn
->mask
& LVCF_WIDTH
)
5668 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
5670 if (lpColumn
->mask
& LVCF_IMAGE
)
5671 lpColumn
->iImage
= hdi
.iImage
;
5673 if (lpColumn
->mask
& LVCF_ORDER
)
5674 lpColumn
->iOrder
= hdi
.iOrder
;
5676 if (lpColumn
->mask
& LVCF_SUBITEM
)
5677 lpColumn
->iSubItem
= hdi
.lParam
;
5683 static BOOL
LISTVIEW_GetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
5685 TRACE("iCount=%d, lpiArray=%p\n", iCount
, lpiArray
);
5690 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETORDERARRAY
, iCount
, (LPARAM
)lpiArray
);
5695 * Retrieves the column width.
5698 * [I] infoPtr : valid pointer to the listview structure
5699 * [I] int : column index
5702 * SUCCESS : column width
5705 static INT
LISTVIEW_GetColumnWidth(const LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5707 INT nColumnWidth
= 0;
5710 TRACE("nColumn=%d\n", nColumn
);
5712 /* we have a 'column' in LIST and REPORT mode only */
5713 switch(infoPtr
->uView
)
5716 nColumnWidth
= infoPtr
->nItemWidth
;
5718 case LV_VIEW_DETAILS
:
5719 /* We are not using LISTVIEW_GetHeaderRect as this data is updated only after a HDM_ITEMCHANGED.
5720 * There is an application that subclasses the listview, calls LVM_GETCOLUMNWIDTH in the
5721 * HDM_ITEMCHANGED handler and goes into infinite recursion if it receives old data.
5723 * TODO: should we do the same in LVM_GETCOLUMN?
5725 hdItem
.mask
= HDI_WIDTH
;
5726 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdItem
))
5728 WARN("(%p): HDM_GETITEMW failed for item %d\n", infoPtr
->hwndSelf
, nColumn
);
5731 nColumnWidth
= hdItem
.cxy
;
5735 TRACE("nColumnWidth=%d\n", nColumnWidth
);
5736 return nColumnWidth
;
5741 * In list or report display mode, retrieves the number of items that can fit
5742 * vertically in the visible area. In icon or small icon display mode,
5743 * retrieves the total number of visible items.
5746 * [I] infoPtr : valid pointer to the listview structure
5749 * Number of fully visible items.
5751 static INT
LISTVIEW_GetCountPerPage(const LISTVIEW_INFO
*infoPtr
)
5753 switch (infoPtr
->uView
)
5756 case LV_VIEW_SMALLICON
:
5757 return infoPtr
->nItemCount
;
5758 case LV_VIEW_DETAILS
:
5759 return LISTVIEW_GetCountPerColumn(infoPtr
);
5761 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
5769 * Retrieves an image list handle.
5772 * [I] infoPtr : valid pointer to the listview structure
5773 * [I] nImageList : image list identifier
5776 * SUCCESS : image list handle
5779 static HIMAGELIST
LISTVIEW_GetImageList(const LISTVIEW_INFO
*infoPtr
, INT nImageList
)
5783 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
5784 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
5785 case LVSIL_STATE
: return infoPtr
->himlState
;
5790 /* LISTVIEW_GetISearchString */
5794 * Retrieves item attributes.
5797 * [I] hwnd : window handle
5798 * [IO] lpLVItem : item info
5799 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
5800 * if FALSE, then lpLVItem is a LPLVITEMA.
5803 * This is the internal 'GetItem' interface -- it tries to
5804 * be smart and avoid text copies, if possible, by modifying
5805 * lpLVItem->pszText to point to the text string. Please note
5806 * that this is not always possible (e.g. OWNERDATA), so on
5807 * entry you *must* supply valid values for pszText, and cchTextMax.
5808 * The only difference to the documented interface is that upon
5809 * return, you should use *only* the lpLVItem->pszText, rather than
5810 * the buffer pointer you provided on input. Most code already does
5811 * that, so it's not a problem.
5812 * For the two cases when the text must be copied (that is,
5813 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
5819 static BOOL
LISTVIEW_GetItemT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
5821 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
5822 NMLVDISPINFOW dispInfo
;
5828 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
5830 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
5833 if (lpLVItem
->mask
== 0) return TRUE
;
5835 /* make a local copy */
5836 isubitem
= lpLVItem
->iSubItem
;
5838 /* a quick optimization if all we're asked is the focus state
5839 * these queries are worth optimising since they are common,
5840 * and can be answered in constant time, without the heavy accesses */
5841 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
5842 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
5844 lpLVItem
->state
= 0;
5845 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
5846 lpLVItem
->state
|= LVIS_FOCUSED
;
5850 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5852 /* if the app stores all the data, handle it separately */
5853 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5855 dispInfo
.item
.state
= 0;
5857 /* apparently, we should not callback for lParam in LVS_OWNERDATA */
5858 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) ||
5859 ((lpLVItem
->mask
& LVIF_STATE
) && (infoPtr
->uCallbackMask
& lpLVItem
->stateMask
)))
5861 UINT mask
= lpLVItem
->mask
;
5863 /* NOTE: copy only fields which we _know_ are initialized, some apps
5864 * depend on the uninitialized fields being 0 */
5865 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
5866 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
5867 dispInfo
.item
.iSubItem
= isubitem
;
5868 if (lpLVItem
->mask
& LVIF_TEXT
)
5870 if (lpLVItem
->mask
& LVIF_NORECOMPUTE
)
5872 dispInfo
.item
.mask
&= ~(LVIF_TEXT
| LVIF_NORECOMPUTE
);
5875 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
5876 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
5879 if (lpLVItem
->mask
& LVIF_STATE
)
5880 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
5881 /* could be zeroed on LVIF_NORECOMPUTE case */
5882 if (dispInfo
.item
.mask
!= 0)
5884 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
5885 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
5886 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
5888 /* full size structure expected - _WIN32IE >= 0x560 */
5889 *lpLVItem
= dispInfo
.item
;
5891 else if (lpLVItem
->mask
& LVIF_INDENT
)
5893 /* indent member expected - _WIN32IE >= 0x300 */
5894 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
5898 /* minimal structure expected */
5899 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
5901 lpLVItem
->mask
= mask
;
5902 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
5906 /* make sure lParam is zeroed out */
5907 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
5909 /* callback marked pointer required here */
5910 if ((lpLVItem
->mask
& LVIF_TEXT
) && (lpLVItem
->mask
& LVIF_NORECOMPUTE
))
5911 lpLVItem
->pszText
= LPSTR_TEXTCALLBACKW
;
5913 /* we store only a little state, so if we're not asked, we're done */
5914 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
5916 /* if focus is handled by us, report it */
5917 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
5919 lpLVItem
->state
&= ~LVIS_FOCUSED
;
5920 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
5921 lpLVItem
->state
|= LVIS_FOCUSED
;
5924 /* and do the same for selection, if we handle it */
5925 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
5927 lpLVItem
->state
&= ~LVIS_SELECTED
;
5928 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
5929 lpLVItem
->state
|= LVIS_SELECTED
;
5935 /* find the item and subitem structures before we proceed */
5936 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
5937 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
5942 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
5943 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
5946 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
5951 pItemHdr
= &lpItem
->hdr
;
5953 /* Do we need to query the state from the app? */
5954 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
5956 dispInfo
.item
.mask
|= LVIF_STATE
;
5957 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
5960 /* Do we need to enquire about the image? */
5961 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
5962 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
5964 dispInfo
.item
.mask
|= LVIF_IMAGE
;
5965 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
5968 /* Only items support indentation */
5969 if ((lpLVItem
->mask
& LVIF_INDENT
) && lpItem
->iIndent
== I_INDENTCALLBACK
&&
5972 dispInfo
.item
.mask
|= LVIF_INDENT
;
5973 dispInfo
.item
.iIndent
= I_INDENTCALLBACK
;
5976 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
5977 if ((lpLVItem
->mask
& LVIF_TEXT
) && !(lpLVItem
->mask
& LVIF_NORECOMPUTE
) &&
5978 !is_textW(pItemHdr
->pszText
))
5980 dispInfo
.item
.mask
|= LVIF_TEXT
;
5981 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
5982 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
5983 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
5984 *dispInfo
.item
.pszText
= '\0';
5987 /* If we don't have all the requested info, query the application */
5988 if (dispInfo
.item
.mask
!= 0)
5990 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
5991 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
5992 dispInfo
.item
.lParam
= lpItem
->lParam
;
5993 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
5994 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
5997 /* we should not store values for subitems */
5998 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
6000 /* Now, handle the iImage field */
6001 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
6003 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
6004 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
6005 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
6007 else if (lpLVItem
->mask
& LVIF_IMAGE
)
6009 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
6010 lpLVItem
->iImage
= pItemHdr
->iImage
;
6012 lpLVItem
->iImage
= 0;
6015 /* The pszText field */
6016 if (dispInfo
.item
.mask
& LVIF_TEXT
)
6018 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
6019 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
6021 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
6023 else if (lpLVItem
->mask
& LVIF_TEXT
)
6025 /* if LVN_GETDISPINFO's disabled with LVIF_NORECOMPUTE return callback placeholder */
6026 if (isW
|| !is_textW(pItemHdr
->pszText
)) lpLVItem
->pszText
= pItemHdr
->pszText
;
6027 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
6030 /* Next is the lParam field */
6031 if (dispInfo
.item
.mask
& LVIF_PARAM
)
6033 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
6034 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
6035 lpItem
->lParam
= dispInfo
.item
.lParam
;
6037 else if (lpLVItem
->mask
& LVIF_PARAM
)
6038 lpLVItem
->lParam
= lpItem
->lParam
;
6040 /* if this is a subitem, we're done */
6041 if (isubitem
) return TRUE
;
6043 /* ... the state field (this one is different due to uCallbackmask) */
6044 if (lpLVItem
->mask
& LVIF_STATE
)
6046 lpLVItem
->state
= lpItem
->state
& lpLVItem
->stateMask
;
6047 if (dispInfo
.item
.mask
& LVIF_STATE
)
6049 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
6050 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
6052 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
6054 lpLVItem
->state
&= ~LVIS_FOCUSED
;
6055 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
6056 lpLVItem
->state
|= LVIS_FOCUSED
;
6058 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
6060 lpLVItem
->state
&= ~LVIS_SELECTED
;
6061 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
6062 lpLVItem
->state
|= LVIS_SELECTED
;
6066 /* and last, but not least, the indent field */
6067 if (dispInfo
.item
.mask
& LVIF_INDENT
)
6069 lpLVItem
->iIndent
= dispInfo
.item
.iIndent
;
6070 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && lpItem
->iIndent
== I_INDENTCALLBACK
)
6071 lpItem
->iIndent
= dispInfo
.item
.iIndent
;
6073 else if (lpLVItem
->mask
& LVIF_INDENT
)
6075 lpLVItem
->iIndent
= lpItem
->iIndent
;
6083 * Retrieves item attributes.
6086 * [I] hwnd : window handle
6087 * [IO] lpLVItem : item info
6088 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
6089 * if FALSE, then lpLVItem is a LPLVITEMA.
6092 * This is the external 'GetItem' interface -- it properly copies
6093 * the text in the provided buffer.
6099 static BOOL
LISTVIEW_GetItemExtT(const LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
6104 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
6107 pszText
= lpLVItem
->pszText
;
6108 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
6109 if (bResult
&& lpLVItem
->pszText
!= pszText
)
6111 if (lpLVItem
->pszText
!= LPSTR_TEXTCALLBACKW
)
6112 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
6114 pszText
= LPSTR_TEXTCALLBACKW
;
6116 lpLVItem
->pszText
= pszText
;
6124 * Retrieves the position (upper-left) of the listview control item.
6125 * Note that for LVS_ICON style, the upper-left is that of the icon
6126 * and not the bounding box.
6129 * [I] infoPtr : valid pointer to the listview structure
6130 * [I] nItem : item index
6131 * [O] lpptPosition : coordinate information
6137 static BOOL
LISTVIEW_GetItemPosition(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
6141 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
6143 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6145 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6146 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
6148 if (infoPtr
->uView
== LV_VIEW_ICON
)
6150 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
6151 lpptPosition
->y
+= ICON_TOP_PADDING
;
6153 lpptPosition
->x
+= Origin
.x
;
6154 lpptPosition
->y
+= Origin
.y
;
6156 TRACE (" lpptPosition=%s\n", wine_dbgstr_point(lpptPosition
));
6163 * Retrieves the bounding rectangle for a listview control item.
6166 * [I] infoPtr : valid pointer to the listview structure
6167 * [I] nItem : item index
6168 * [IO] lprc : bounding rectangle coordinates
6169 * lprc->left specifies the portion of the item for which the bounding
6170 * rectangle will be retrieved.
6172 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
6173 * including the icon and label.
6176 * * Experiment shows that native control returns:
6177 * * width = min (48, length of text line)
6178 * * .left = position.x - (width - iconsize.cx)/2
6179 * * .right = .left + width
6180 * * height = #lines of text * ntmHeight + icon height + 8
6181 * * .top = position.y - 2
6182 * * .bottom = .top + height
6183 * * separation between items .y = itemSpacing.cy - height
6184 * * .x = itemSpacing.cx - width
6185 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
6188 * * Experiment shows that native control returns:
6189 * * width = iconSize.cx + 16
6190 * * .left = position.x - (width - iconsize.cx)/2
6191 * * .right = .left + width
6192 * * height = iconSize.cy + 4
6193 * * .top = position.y - 2
6194 * * .bottom = .top + height
6195 * * separation between items .y = itemSpacing.cy - height
6196 * * .x = itemSpacing.cx - width
6197 * LVIR_LABEL Returns the bounding rectangle of the item text.
6200 * * Experiment shows that native control returns:
6201 * * width = text length
6202 * * .left = position.x - width/2
6203 * * .right = .left + width
6204 * * height = ntmH * linecount + 2
6205 * * .top = position.y + iconSize.cy + 6
6206 * * .bottom = .top + height
6207 * * separation between items .y = itemSpacing.cy - height
6208 * * .x = itemSpacing.cx - width
6209 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
6210 * rectangles, but excludes columns in report view.
6217 * Note that the bounding rectangle of the label in the LVS_ICON view depends
6218 * upon whether the window has the focus currently and on whether the item
6219 * is the one with the focus. Ensure that the control's record of which
6220 * item has the focus agrees with the items' records.
6222 static BOOL
LISTVIEW_GetItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6224 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6225 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
6226 POINT Position
, Origin
;
6229 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
6231 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
6233 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6234 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
6236 /* Be smart and try to figure out the minimum we have to do */
6237 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
6238 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
6239 if (infoPtr
->uView
== LV_VIEW_ICON
&& lprc
->left
!= LVIR_ICON
&&
6240 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
6241 oversizedBox
= TRUE
;
6243 /* get what we need from the item before hand, so we make
6244 * only one request. This can speed up things, if data
6245 * is stored on the app side */
6247 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6248 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
6249 lvItem
.iItem
= nItem
;
6250 lvItem
.iSubItem
= 0;
6251 lvItem
.pszText
= szDispText
;
6252 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6253 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6254 /* we got the state already up, simulate it here, to avoid a reget */
6255 if (infoPtr
->uView
== LV_VIEW_ICON
&& (lprc
->left
!= LVIR_ICON
))
6257 lvItem
.mask
|= LVIF_STATE
;
6258 lvItem
.stateMask
= LVIS_FOCUSED
;
6259 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
6262 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
6263 lprc
->left
= LVIR_BOUNDS
;
6267 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
6271 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, NULL
, lprc
);
6275 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
6278 case LVIR_SELECTBOUNDS
:
6279 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, lprc
, NULL
, NULL
, NULL
);
6283 WARN("Unknown value: %d\n", lprc
->left
);
6287 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6288 OffsetRect(lprc
, Origin
.x
, Position
.y
+ Origin
.y
);
6290 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
6292 TRACE(" rect=%s\n", wine_dbgstr_rect(lprc
));
6299 * Retrieves the spacing between listview control items.
6302 * [I] infoPtr : valid pointer to the listview structure
6303 * [IO] lprc : rectangle to receive the output
6304 * on input, lprc->top = nSubItem
6305 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
6307 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
6308 * not only those of the first column.
6309 * Fortunately, LISTVIEW_GetItemMetrics does the right thing.
6315 static BOOL
LISTVIEW_GetSubItemRect(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
6321 if (!lprc
) return FALSE
;
6323 nColumn
= lprc
->top
;
6325 TRACE("(nItem=%d, nSubItem=%d)\n", nItem
, lprc
->top
);
6326 /* On WinNT, a subitem of '0' calls LISTVIEW_GetItemRect */
6328 return LISTVIEW_GetItemRect(infoPtr
, nItem
, lprc
);
6330 if (infoPtr
->uView
!= LV_VIEW_DETAILS
) return FALSE
;
6332 /* special case for header items */
6335 if (lprc
->left
!= LVIR_BOUNDS
)
6337 FIXME("Only LVIR_BOUNDS is implemented for header, got %d\n", lprc
->left
);
6341 if (infoPtr
->hwndHeader
)
6342 return SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, lprc
->top
, (LPARAM
)lprc
);
6345 memset(lprc
, 0, sizeof(RECT
));
6350 if (!LISTVIEW_GetItemPosition(infoPtr
, nItem
, &Position
)) return FALSE
;
6352 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6355 lvItem
.iItem
= nItem
;
6356 lvItem
.iSubItem
= nColumn
;
6358 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
6362 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
, NULL
);
6367 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
, NULL
);
6371 ERR("Unknown bounds=%d\n", lprc
->left
);
6375 OffsetRect(lprc
, 0, Position
.y
);
6382 * Retrieves the width of a label.
6385 * [I] infoPtr : valid pointer to the listview structure
6388 * SUCCESS : string width (in pixels)
6391 static INT
LISTVIEW_GetLabelWidth(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
6393 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6396 TRACE("(nItem=%d)\n", nItem
);
6398 lvItem
.mask
= LVIF_TEXT
;
6399 lvItem
.iItem
= nItem
;
6400 lvItem
.iSubItem
= 0;
6401 lvItem
.pszText
= szDispText
;
6402 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6403 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
6405 return LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
6410 * Retrieves the spacing between listview control items.
6413 * [I] infoPtr : valid pointer to the listview structure
6414 * [I] bSmall : flag for small or large icon
6417 * Horizontal + vertical spacing
6419 static LONG
LISTVIEW_GetItemSpacing(const LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
6425 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
6429 if (infoPtr
->uView
== LV_VIEW_ICON
)
6430 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
6432 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
6439 * Retrieves the state of a listview control item.
6442 * [I] infoPtr : valid pointer to the listview structure
6443 * [I] nItem : item index
6444 * [I] uMask : state mask
6447 * State specified by the mask.
6449 static UINT
LISTVIEW_GetItemState(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
6453 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6455 lvItem
.iItem
= nItem
;
6456 lvItem
.iSubItem
= 0;
6457 lvItem
.mask
= LVIF_STATE
;
6458 lvItem
.stateMask
= uMask
;
6459 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
6461 return lvItem
.state
& uMask
;
6466 * Retrieves the text of a listview control item or subitem.
6469 * [I] hwnd : window handle
6470 * [I] nItem : item index
6471 * [IO] lpLVItem : item information
6472 * [I] isW : TRUE if lpLVItem is Unicode
6475 * SUCCESS : string length
6478 static INT
LISTVIEW_GetItemTextT(const LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
6480 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
6482 lpLVItem
->mask
= LVIF_TEXT
;
6483 lpLVItem
->iItem
= nItem
;
6484 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
6486 return textlenT(lpLVItem
->pszText
, isW
);
6491 * Searches for an item based on properties + relationships.
6494 * [I] infoPtr : valid pointer to the listview structure
6495 * [I] nItem : item index
6496 * [I] uFlags : relationship flag
6499 * SUCCESS : item index
6502 static INT
LISTVIEW_GetNextItem(const LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
6505 LVFINDINFOW lvFindInfo
;
6506 INT nCountPerColumn
;
6510 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
6511 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
6513 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
6515 if (uFlags
& LVNI_CUT
)
6518 if (uFlags
& LVNI_DROPHILITED
)
6519 uMask
|= LVIS_DROPHILITED
;
6521 if (uFlags
& LVNI_FOCUSED
)
6522 uMask
|= LVIS_FOCUSED
;
6524 if (uFlags
& LVNI_SELECTED
)
6525 uMask
|= LVIS_SELECTED
;
6527 /* if we're asked for the focused item, that's only one,
6528 * so it's worth optimizing */
6529 if (uFlags
& LVNI_FOCUSED
)
6531 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
6532 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
6535 if (uFlags
& LVNI_ABOVE
)
6537 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
6542 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6548 /* Special case for autoarrange - move 'til the top of a list */
6549 if (is_autoarrange(infoPtr
))
6551 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
6552 while (nItem
- nCountPerRow
>= 0)
6554 nItem
-= nCountPerRow
;
6555 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6560 lvFindInfo
.flags
= LVFI_NEARESTXY
;
6561 lvFindInfo
.vkDirection
= VK_UP
;
6562 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
6563 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
6565 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6570 else if (uFlags
& LVNI_BELOW
)
6572 if ((infoPtr
->uView
== LV_VIEW_LIST
) || (infoPtr
->uView
== LV_VIEW_DETAILS
))
6574 while (nItem
< infoPtr
->nItemCount
)
6577 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6583 /* Special case for autoarrange - move 'til the bottom of a list */
6584 if (is_autoarrange(infoPtr
))
6586 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
6587 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
6589 nItem
+= nCountPerRow
;
6590 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6595 lvFindInfo
.flags
= LVFI_NEARESTXY
;
6596 lvFindInfo
.vkDirection
= VK_DOWN
;
6597 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
6598 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
6600 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6605 else if (uFlags
& LVNI_TOLEFT
)
6607 if (infoPtr
->uView
== LV_VIEW_LIST
)
6609 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
6610 while (nItem
- nCountPerColumn
>= 0)
6612 nItem
-= nCountPerColumn
;
6613 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6617 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6619 /* Special case for autoarrange - move 'til the beginning of a row */
6620 if (is_autoarrange(infoPtr
))
6622 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
6623 while (nItem
% nCountPerRow
> 0)
6626 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6631 lvFindInfo
.flags
= LVFI_NEARESTXY
;
6632 lvFindInfo
.vkDirection
= VK_LEFT
;
6633 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
6634 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
6636 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6641 else if (uFlags
& LVNI_TORIGHT
)
6643 if (infoPtr
->uView
== LV_VIEW_LIST
)
6645 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
6646 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
6648 nItem
+= nCountPerColumn
;
6649 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6653 else if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
6655 /* Special case for autoarrange - move 'til the end of a row */
6656 if (is_autoarrange(infoPtr
))
6658 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
6659 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
6662 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6667 lvFindInfo
.flags
= LVFI_NEARESTXY
;
6668 lvFindInfo
.vkDirection
= VK_RIGHT
;
6669 LISTVIEW_GetItemPosition(infoPtr
, nItem
, &lvFindInfo
.pt
);
6670 while ((nItem
= LISTVIEW_FindItemW(infoPtr
, nItem
, &lvFindInfo
)) != -1)
6672 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
6681 /* search by index */
6682 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
6684 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
6692 /* LISTVIEW_GetNumberOfWorkAreas */
6696 * Retrieves the origin coordinates when in icon or small icon display mode.
6699 * [I] infoPtr : valid pointer to the listview structure
6700 * [O] lpptOrigin : coordinate information
6705 static void LISTVIEW_GetOrigin(const LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
6707 INT nHorzPos
= 0, nVertPos
= 0;
6708 SCROLLINFO scrollInfo
;
6710 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
6711 scrollInfo
.fMask
= SIF_POS
;
6713 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
6714 nHorzPos
= scrollInfo
.nPos
;
6715 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
6716 nVertPos
= scrollInfo
.nPos
;
6718 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
6720 lpptOrigin
->x
= infoPtr
->rcList
.left
;
6721 lpptOrigin
->y
= infoPtr
->rcList
.top
;
6722 if (infoPtr
->uView
== LV_VIEW_LIST
)
6723 nHorzPos
*= infoPtr
->nItemWidth
;
6724 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6725 nVertPos
*= infoPtr
->nItemHeight
;
6727 lpptOrigin
->x
-= nHorzPos
;
6728 lpptOrigin
->y
-= nVertPos
;
6730 TRACE(" origin=%s\n", wine_dbgstr_point(lpptOrigin
));
6735 * Retrieves the width of a string.
6738 * [I] hwnd : window handle
6739 * [I] lpszText : text string to process
6740 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
6743 * SUCCESS : string width (in pixels)
6746 static INT
LISTVIEW_GetStringWidthT(const LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
6751 if (is_textT(lpszText
, isW
))
6753 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
6754 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
6755 HFONT hOldFont
= SelectObject(hdc
, hFont
);
6758 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
6760 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
6761 SelectObject(hdc
, hOldFont
);
6762 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6764 return stringSize
.cx
;
6769 * Determines which listview item is located at the specified position.
6772 * [I] infoPtr : valid pointer to the listview structure
6773 * [IO] lpht : hit test information
6774 * [I] subitem : fill out iSubItem.
6775 * [I] select : return the index only if the hit selects the item
6778 * (mm 20001022): We must not allow iSubItem to be touched, for
6779 * an app might pass only a structure with space up to iItem!
6780 * (MS Office 97 does that for instance in the file open dialog)
6783 * SUCCESS : item index
6786 static INT
LISTVIEW_HitTest(const LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
6788 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6789 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
6790 POINT Origin
, Position
, opt
;
6795 TRACE("(pt=%s, subitem=%d, select=%d)\n", wine_dbgstr_point(&lpht
->pt
), subitem
, select
);
6799 if (subitem
) lpht
->iSubItem
= 0;
6801 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
6802 lpht
->flags
|= LVHT_TOLEFT
;
6803 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
6804 lpht
->flags
|= LVHT_TORIGHT
;
6806 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
6807 lpht
->flags
|= LVHT_ABOVE
;
6808 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
6809 lpht
->flags
|= LVHT_BELOW
;
6811 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
6812 if (lpht
->flags
) return -1;
6814 lpht
->flags
|= LVHT_NOWHERE
;
6816 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6818 /* first deal with the large items */
6819 rcSearch
.left
= lpht
->pt
.x
;
6820 rcSearch
.top
= lpht
->pt
.y
;
6821 rcSearch
.right
= rcSearch
.left
+ 1;
6822 rcSearch
.bottom
= rcSearch
.top
+ 1;
6824 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
6825 iterator_next(&i
); /* go to first item in the sequence */
6827 iterator_destroy(&i
);
6829 TRACE("lpht->iItem=%d\n", iItem
);
6830 if (iItem
== -1) return -1;
6832 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& subitem
)
6834 RECT bounds
, *pRect
;
6837 /* for top/bottom only */
6838 bounds
.left
= LVIR_BOUNDS
;
6839 LISTVIEW_GetItemRect(infoPtr
, iItem
, &bounds
);
6840 opt
.x
= lpht
->pt
.x
- Origin
.x
;
6843 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
6845 pRect
= &LISTVIEW_GetColumnInfo(infoPtr
, j
)->rcHeader
;
6846 bounds
.left
= pRect
->left
;
6847 bounds
.right
= pRect
->right
;
6849 if (PtInRect(&bounds
, opt
))
6855 TRACE("lpht->iSubItem=%d\n", lpht
->iSubItem
);
6858 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
6859 if (infoPtr
->uView
== LV_VIEW_DETAILS
) lvItem
.mask
|= LVIF_INDENT
;
6860 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
6861 if (infoPtr
->uView
== LV_VIEW_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
6862 lvItem
.iItem
= iItem
;
6863 lvItem
.iSubItem
= subitem
? lpht
->iSubItem
: 0;
6864 lvItem
.pszText
= szDispText
;
6865 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6866 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
6867 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
6869 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
6870 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
6871 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
6872 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
6874 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6877 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
6878 opt
.x
= lpht
->pt
.x
- Origin
.x
;
6882 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
6883 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
6885 TRACE("rcBounds=%s\n", wine_dbgstr_rect(&rcBounds
));
6886 if (!PtInRect(&rcBounds
, opt
)) return -1;
6888 if (PtInRect(&rcIcon
, opt
))
6889 lpht
->flags
|= LVHT_ONITEMICON
;
6890 else if (PtInRect(&rcLabel
, opt
))
6891 lpht
->flags
|= LVHT_ONITEMLABEL
;
6892 else if (infoPtr
->himlState
&& PtInRect(&rcState
, opt
))
6893 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
6894 /* special case for LVS_EX_FULLROWSELECT */
6895 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
&&
6896 !(lpht
->flags
& LVHT_ONITEM
))
6898 lpht
->flags
= LVHT_ONITEM
| LVHT_ABOVE
;
6900 if (lpht
->flags
& LVHT_ONITEM
)
6901 lpht
->flags
&= ~LVHT_NOWHERE
;
6902 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
6904 if (select
&& !(infoPtr
->uView
== LV_VIEW_DETAILS
&&
6905 ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) ||
6906 (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
))))
6908 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
6910 /* get main item bounds */
6911 lvItem
.iSubItem
= 0;
6912 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, NULL
, &rcIcon
, &rcState
, &rcLabel
);
6913 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
6914 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
6916 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
6918 return lpht
->iItem
= iItem
;
6923 * Inserts a new item in the listview control.
6926 * [I] infoPtr : valid pointer to the listview structure
6927 * [I] lpLVItem : item information
6928 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
6931 * SUCCESS : new item index
6934 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
6941 BOOL is_sorted
, has_changed
;
6943 HWND hwndSelf
= infoPtr
->hwndSelf
;
6945 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6947 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
6949 /* make sure it's an item, and not a subitem; cannot insert a subitem */
6950 if (!lpLVItem
|| lpLVItem
->iSubItem
) return -1;
6952 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
6954 if (!(lpItem
= Alloc(sizeof(ITEM_INFO
)))) return -1;
6956 /* insert item in listview control data structure */
6957 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
6958 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
6960 /* link with id struct */
6961 if (!(lpID
= Alloc(sizeof(ITEM_ID
)))) goto fail
;
6963 lpID
->item
= hdpaSubItems
;
6964 lpID
->id
= get_next_itemid(infoPtr
);
6965 if ( DPA_InsertPtr(infoPtr
->hdpaItemIds
, infoPtr
->nItemCount
, lpID
) == -1) goto fail
;
6967 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
6968 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
6970 if (lpLVItem
->iItem
< 0 && !is_sorted
) return -1;
6972 /* calculate new item index */
6979 while (i
< infoPtr
->nItemCount
)
6981 hItem
= DPA_GetPtr( infoPtr
->hdpaItems
, i
);
6982 item_s
= (ITEM_INFO
*)DPA_GetPtr(hItem
, 0);
6984 cmpv
= textcmpWT(item_s
->hdr
.pszText
, lpLVItem
->pszText
, TRUE
);
6985 if (infoPtr
->dwStyle
& LVS_SORTDESCENDING
) cmpv
*= -1;
6987 if (cmpv
>= 0) break;
6993 nItem
= min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
6995 TRACE(" inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
6996 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
6997 if (nItem
== -1) goto fail
;
6998 infoPtr
->nItemCount
++;
7000 /* shift indices first so they don't get tangled */
7001 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
7003 /* set the item attributes */
7004 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
7006 /* full size structure expected - _WIN32IE >= 0x560 */
7009 else if (lpLVItem
->mask
& LVIF_INDENT
)
7011 /* indent member expected - _WIN32IE >= 0x300 */
7012 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
7016 /* minimal structure expected */
7017 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
7020 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7022 item
.mask
|= LVIF_STATE
;
7023 item
.stateMask
|= LVIS_STATEIMAGEMASK
;
7024 item
.state
&= ~LVIS_STATEIMAGEMASK
;
7025 item
.state
|= INDEXTOSTATEIMAGEMASK(1);
7027 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
7029 /* make room for the position, if we are in the right mode */
7030 if ((infoPtr
->uView
== LV_VIEW_SMALLICON
) || (infoPtr
->uView
== LV_VIEW_ICON
))
7032 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
7034 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
7036 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
7041 /* send LVN_INSERTITEM notification */
7042 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
7044 nmlv
.lParam
= lpItem
->lParam
;
7045 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
7046 if (!IsWindow(hwndSelf
))
7049 /* align items (set position of each item) */
7050 if (infoPtr
->uView
== LV_VIEW_SMALLICON
|| infoPtr
->uView
== LV_VIEW_ICON
)
7054 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
7055 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
7057 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
7059 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
7062 /* now is the invalidation fun */
7063 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
7067 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
7068 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
7069 infoPtr
->nItemCount
--;
7071 DPA_DeletePtr(hdpaSubItems
, 0);
7072 DPA_Destroy (hdpaSubItems
);
7079 * Checks item visibility.
7082 * [I] infoPtr : valid pointer to the listview structure
7083 * [I] nFirst : item index to check for
7086 * Item visible : TRUE
7087 * Item invisible or failure : FALSE
7089 static BOOL
LISTVIEW_IsItemVisible(const LISTVIEW_INFO
*infoPtr
, INT nItem
)
7091 POINT Origin
, Position
;
7096 TRACE("nItem=%d\n", nItem
);
7098 if (nItem
< 0 || nItem
>= DPA_GetPtrCount(infoPtr
->hdpaItems
)) return FALSE
;
7100 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7101 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
7102 rcItem
.left
= Position
.x
+ Origin
.x
;
7103 rcItem
.top
= Position
.y
+ Origin
.y
;
7104 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
7105 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
7107 hdc
= GetDC(infoPtr
->hwndSelf
);
7108 if (!hdc
) return FALSE
;
7109 ret
= RectVisible(hdc
, &rcItem
);
7110 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7117 * Redraws a range of items.
7120 * [I] infoPtr : valid pointer to the listview structure
7121 * [I] nFirst : first item
7122 * [I] nLast : last item
7128 static BOOL
LISTVIEW_RedrawItems(const LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
7132 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
7133 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
7136 for (i
= nFirst
; i
<= nLast
; i
++)
7137 LISTVIEW_InvalidateItem(infoPtr
, i
);
7144 * Scroll the content of a listview.
7147 * [I] infoPtr : valid pointer to the listview structure
7148 * [I] dx : horizontal scroll amount in pixels
7149 * [I] dy : vertical scroll amount in pixels
7156 * If the control is in report view (LV_VIEW_DETAILS) the control can
7157 * be scrolled only in line increments. "dy" will be rounded to the
7158 * nearest number of pixels that are a whole line. Ex: if line height
7159 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
7160 * is passed, then the scroll will be 0. (per MSDN 7/2002)
7162 * For: (per experimentation with native control and CSpy ListView)
7163 * LV_VIEW_ICON dy=1 = 1 pixel (vertical only)
7165 * LV_VIEW_SMALLICON dy=1 = 1 pixel (vertical only)
7167 * LV_VIEW_LIST dx=1 = 1 column (horizontal only)
7168 * but will only scroll 1 column per message
7169 * no matter what the value.
7170 * dy must be 0 or FALSE returned.
7171 * LV_VIEW_DETAILS dx=1 = 1 pixel
7175 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7177 switch(infoPtr
->uView
) {
7178 case LV_VIEW_DETAILS
:
7179 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
7180 dy
/= infoPtr
->nItemHeight
;
7183 if (dy
!= 0) return FALSE
;
7190 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
, 0);
7191 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
, 0);
7198 * Sets the background color.
7201 * [I] infoPtr : valid pointer to the listview structure
7202 * [I] clrBk : background color
7208 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrBk
)
7210 TRACE("(clrBk=%x)\n", clrBk
);
7212 if(infoPtr
->clrBk
!= clrBk
) {
7213 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
7214 infoPtr
->clrBk
= clrBk
;
7215 if (clrBk
== CLR_NONE
)
7216 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
7218 infoPtr
->hBkBrush
= CreateSolidBrush(clrBk
);
7219 LISTVIEW_InvalidateList(infoPtr
);
7225 /* LISTVIEW_SetBkImage */
7227 /*** Helper for {Insert,Set}ColumnT *only* */
7228 static void column_fill_hditem(const LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
,
7229 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7231 if (lpColumn
->mask
& LVCF_FMT
)
7233 /* format member is valid */
7234 lphdi
->mask
|= HDI_FORMAT
;
7236 /* set text alignment (leftmost column must be left-aligned) */
7237 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
7238 lphdi
->fmt
|= HDF_LEFT
;
7239 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
7240 lphdi
->fmt
|= HDF_RIGHT
;
7241 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
7242 lphdi
->fmt
|= HDF_CENTER
;
7244 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
7245 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
7247 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
7249 lphdi
->fmt
|= HDF_IMAGE
;
7250 lphdi
->iImage
= I_IMAGECALLBACK
;
7254 if (lpColumn
->mask
& LVCF_WIDTH
)
7256 lphdi
->mask
|= HDI_WIDTH
;
7257 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
7259 /* make it fill the remainder of the controls width */
7263 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
7265 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
7266 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
7269 /* retrieve the layout of the header */
7270 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
7271 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, wine_dbgstr_rect(&rcHeader
));
7273 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
7276 lphdi
->cxy
= lpColumn
->cx
;
7279 if (lpColumn
->mask
& LVCF_TEXT
)
7281 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
7282 lphdi
->fmt
|= HDF_STRING
;
7283 lphdi
->pszText
= lpColumn
->pszText
;
7284 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
7287 if (lpColumn
->mask
& LVCF_IMAGE
)
7289 lphdi
->mask
|= HDI_IMAGE
;
7290 lphdi
->iImage
= lpColumn
->iImage
;
7293 if (lpColumn
->mask
& LVCF_ORDER
)
7295 lphdi
->mask
|= HDI_ORDER
;
7296 lphdi
->iOrder
= lpColumn
->iOrder
;
7303 * Inserts a new column.
7306 * [I] infoPtr : valid pointer to the listview structure
7307 * [I] nColumn : column index
7308 * [I] lpColumn : column information
7309 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
7312 * SUCCESS : new column index
7315 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
7316 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7318 COLUMN_INFO
*lpColumnInfo
;
7322 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
7324 if (!lpColumn
|| nColumn
< 0) return -1;
7325 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
7327 ZeroMemory(&hdi
, sizeof(HDITEMW
));
7328 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
7331 * A mask not including LVCF_WIDTH turns into a mask of width, width 10
7332 * (can be seen in SPY) otherwise column never gets added.
7334 if (!(lpColumn
->mask
& LVCF_WIDTH
)) {
7335 hdi
.mask
|= HDI_WIDTH
;
7340 * when the iSubItem is available Windows copies it to the header lParam. It seems
7341 * to happen only in LVM_INSERTCOLUMN - not in LVM_SETCOLUMN
7343 if (lpColumn
->mask
& LVCF_SUBITEM
)
7345 hdi
.mask
|= HDI_LPARAM
;
7346 hdi
.lParam
= lpColumn
->iSubItem
;
7349 /* create header if not present */
7350 LISTVIEW_CreateHeader(infoPtr
);
7351 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
) &&
7352 (infoPtr
->uView
== LV_VIEW_DETAILS
) && (WS_VISIBLE
& infoPtr
->dwStyle
))
7354 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
7357 /* insert item in header control */
7358 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
7359 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
7360 (WPARAM
)nColumn
, (LPARAM
)&hdi
);
7361 if (nNewColumn
== -1) return -1;
7362 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
7364 /* create our own column info */
7365 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
7366 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
7368 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
7369 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMRECT
, nNewColumn
, (LPARAM
)&lpColumnInfo
->rcHeader
))
7372 /* now we have to actually adjust the data */
7373 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
7375 SUBITEM_INFO
*lpSubItem
;
7379 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
7381 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
7382 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
7384 lpSubItem
= DPA_GetPtr(hdpaSubItems
, i
);
7385 if (lpSubItem
->iSubItem
>= nNewColumn
)
7386 lpSubItem
->iSubItem
++;
7391 /* make space for the new column */
7392 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
7393 LISTVIEW_UpdateItemSize(infoPtr
);
7398 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
7401 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
7409 * Sets the attributes of a header item.
7412 * [I] infoPtr : valid pointer to the listview structure
7413 * [I] nColumn : column index
7414 * [I] lpColumn : column attributes
7415 * [I] isW: if TRUE, then lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
7421 static BOOL
LISTVIEW_SetColumnT(const LISTVIEW_INFO
*infoPtr
, INT nColumn
,
7422 const LVCOLUMNW
*lpColumn
, BOOL isW
)
7424 HDITEMW hdi
, hdiget
;
7427 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
7429 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
7431 ZeroMemory(&hdi
, sizeof(HDITEMW
));
7432 if (lpColumn
->mask
& LVCF_FMT
)
7434 hdi
.mask
|= HDI_FORMAT
;
7435 hdiget
.mask
= HDI_FORMAT
;
7436 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdiget
))
7437 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
7439 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
7441 /* set header item attributes */
7442 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, (WPARAM
)nColumn
, (LPARAM
)&hdi
);
7443 if (!bResult
) return FALSE
;
7445 if (lpColumn
->mask
& LVCF_FMT
)
7447 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
7448 int oldFmt
= lpColumnInfo
->fmt
;
7450 lpColumnInfo
->fmt
= lpColumn
->fmt
;
7451 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
7453 if (infoPtr
->uView
== LV_VIEW_DETAILS
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
7462 * Sets the column order array
7465 * [I] infoPtr : valid pointer to the listview structure
7466 * [I] iCount : number of elements in column order array
7467 * [I] lpiArray : pointer to column order array
7473 static BOOL
LISTVIEW_SetColumnOrderArray(const LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
7475 FIXME("iCount %d lpiArray %p\n", iCount
, lpiArray
);
7486 * Sets the width of a column
7489 * [I] infoPtr : valid pointer to the listview structure
7490 * [I] nColumn : column index
7491 * [I] cx : column width
7497 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
7499 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
7503 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
7505 /* set column width only if in report or list mode */
7506 if (infoPtr
->uView
!= LV_VIEW_DETAILS
&& infoPtr
->uView
!= LV_VIEW_LIST
) return FALSE
;
7508 /* take care of invalid cx values */
7509 if(infoPtr
->uView
== LV_VIEW_DETAILS
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
7510 else if (infoPtr
->uView
== LV_VIEW_LIST
&& cx
< 1) return FALSE
;
7512 /* resize all columns if in LV_VIEW_LIST mode */
7513 if(infoPtr
->uView
== LV_VIEW_LIST
)
7515 infoPtr
->nItemWidth
= cx
;
7516 LISTVIEW_InvalidateList(infoPtr
);
7520 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
7522 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
7527 lvItem
.mask
= LVIF_TEXT
;
7529 lvItem
.iSubItem
= nColumn
;
7530 lvItem
.pszText
= szDispText
;
7531 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
7532 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
7534 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
7535 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
7536 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
7538 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
7539 max_cx
+= infoPtr
->iconSize
.cx
;
7540 max_cx
+= TRAILING_LABEL_PADDING
;
7543 /* autosize based on listview items width */
7544 if(cx
== LVSCW_AUTOSIZE
)
7546 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
7548 /* if iCol is the last column make it fill the remainder of the controls width */
7549 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
7554 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7555 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
7557 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
7561 /* Despite what the MS docs say, if this is not the last
7562 column, then MS resizes the column to the width of the
7563 largest text string in the column, including headers
7564 and items. This is different from LVSCW_AUTOSIZE in that
7565 LVSCW_AUTOSIZE ignores the header string length. */
7568 /* retrieve header text */
7569 hdi
.mask
= HDI_TEXT
;
7570 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
7571 hdi
.pszText
= szDispText
;
7572 if (SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, nColumn
, (LPARAM
)&hdi
))
7574 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
7575 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
7578 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
7579 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
7580 /* FIXME: Take into account the header image, if one is present */
7581 SelectObject(hdc
, old_font
);
7582 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
7584 cx
= max (cx
, max_cx
);
7588 if (cx
< 0) return FALSE
;
7590 /* call header to update the column change */
7591 hdi
.mask
= HDI_WIDTH
;
7593 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
7594 return SendMessageW(infoPtr
->hwndHeader
, HDM_SETITEMW
, nColumn
, (LPARAM
)&hdi
);
7598 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
7601 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(const LISTVIEW_INFO
*infoPtr
)
7604 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
7606 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
7607 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
7610 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
7611 ILC_COLOR
| ILC_MASK
, 2, 2);
7612 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
7613 hdc
= CreateCompatibleDC(hdc_wnd
);
7614 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
7615 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
7616 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
7618 rc
.left
= rc
.top
= 0;
7619 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
7620 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
7622 hbm_orig
= SelectObject(hdc
, hbm_mask
);
7623 FillRect(hdc
, &rc
, hbr_white
);
7624 InflateRect(&rc
, -2, -2);
7625 FillRect(hdc
, &rc
, hbr_black
);
7627 SelectObject(hdc
, hbm_im
);
7628 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
7629 SelectObject(hdc
, hbm_orig
);
7630 ImageList_Add(himl
, hbm_im
, hbm_mask
);
7632 SelectObject(hdc
, hbm_im
);
7633 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
7634 SelectObject(hdc
, hbm_orig
);
7635 ImageList_Add(himl
, hbm_im
, hbm_mask
);
7637 DeleteObject(hbm_mask
);
7638 DeleteObject(hbm_im
);
7646 * Sets the extended listview style.
7649 * [I] infoPtr : valid pointer to the listview structure
7651 * [I] dwStyle : style
7654 * SUCCESS : previous style
7657 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD dwMask
, DWORD dwExStyle
)
7659 DWORD dwOldExStyle
= infoPtr
->dwLvExStyle
;
7663 infoPtr
->dwLvExStyle
= (dwOldExStyle
& ~dwMask
) | (dwExStyle
& dwMask
);
7665 infoPtr
->dwLvExStyle
= dwExStyle
;
7667 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_CHECKBOXES
)
7669 HIMAGELIST himl
= 0;
7670 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
7673 item
.mask
= LVIF_STATE
;
7674 item
.stateMask
= LVIS_STATEIMAGEMASK
;
7675 item
.state
= INDEXTOSTATEIMAGEMASK(1);
7676 LISTVIEW_SetItemState(infoPtr
, -1, &item
);
7678 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
7680 LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
7683 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_HEADERDRAGDROP
)
7687 /* if not already created */
7688 LISTVIEW_CreateHeader(infoPtr
);
7690 dwStyle
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
7691 if (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
)
7692 dwStyle
|= HDS_DRAGDROP
;
7694 dwStyle
&= ~HDS_DRAGDROP
;
7695 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, dwStyle
);
7698 /* GRIDLINES adds decoration at top so changes sizes */
7699 if((infoPtr
->dwLvExStyle
^ dwOldExStyle
) & LVS_EX_GRIDLINES
)
7701 LISTVIEW_UpdateSize(infoPtr
);
7705 LISTVIEW_InvalidateList(infoPtr
);
7706 return dwOldExStyle
;
7711 * Sets the new hot cursor used during hot tracking and hover selection.
7714 * [I] infoPtr : valid pointer to the listview structure
7715 * [I] hCursor : the new hot cursor handle
7718 * Returns the previous hot cursor
7720 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
7722 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
7724 infoPtr
->hHotCursor
= hCursor
;
7732 * Sets the hot item index.
7735 * [I] infoPtr : valid pointer to the listview structure
7736 * [I] iIndex : index
7739 * SUCCESS : previous hot item index
7740 * FAILURE : -1 (no hot item)
7742 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
7744 INT iOldIndex
= infoPtr
->nHotItem
;
7746 infoPtr
->nHotItem
= iIndex
;
7754 * Sets the amount of time the cursor must hover over an item before it is selected.
7757 * [I] infoPtr : valid pointer to the listview structure
7758 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
7761 * Returns the previous hover time
7763 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
7765 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
7767 infoPtr
->dwHoverTime
= dwHoverTime
;
7769 return oldHoverTime
;
7774 * Sets spacing for icons of LVS_ICON style.
7777 * [I] infoPtr : valid pointer to the listview structure
7778 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
7779 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
7782 * MAKELONG(oldcx, oldcy)
7784 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
7786 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
7788 TRACE("requested=(%d,%d)\n", cx
, cy
);
7790 /* this is supported only for LVS_ICON style */
7791 if (infoPtr
->uView
!= LV_VIEW_ICON
) return oldspacing
;
7793 /* set to defaults, if instructed to */
7794 if (cx
== -1) cx
= GetSystemMetrics(SM_CXICONSPACING
);
7795 if (cy
== -1) cy
= GetSystemMetrics(SM_CYICONSPACING
);
7797 /* if 0 then compute width
7798 * FIXME: Should scan each item and determine max width of
7799 * icon or label, then make that the width */
7801 cx
= infoPtr
->iconSpacing
.cx
;
7803 /* if 0 then compute height */
7805 cy
= infoPtr
->iconSize
.cy
+ 2 * infoPtr
->ntmHeight
+
7806 ICON_BOTTOM_PADDING
+ ICON_TOP_PADDING
+ LABEL_VERT_PADDING
;
7809 infoPtr
->iconSpacing
.cx
= cx
;
7810 infoPtr
->iconSpacing
.cy
= cy
;
7812 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%d,%d), ntmH=%d\n",
7813 LOWORD(oldspacing
), HIWORD(oldspacing
), cx
, cy
,
7814 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
7815 infoPtr
->ntmHeight
);
7817 /* these depend on the iconSpacing */
7818 LISTVIEW_UpdateItemSize(infoPtr
);
7823 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL small
)
7827 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
7834 size
->cx
= GetSystemMetrics(small
? SM_CXSMICON
: SM_CXICON
);
7835 size
->cy
= GetSystemMetrics(small
? SM_CYSMICON
: SM_CYICON
);
7844 * [I] infoPtr : valid pointer to the listview structure
7845 * [I] nType : image list type
7846 * [I] himl : image list handle
7849 * SUCCESS : old image list
7852 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
7854 INT oldHeight
= infoPtr
->nItemHeight
;
7855 HIMAGELIST himlOld
= 0;
7857 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
7862 himlOld
= infoPtr
->himlNormal
;
7863 infoPtr
->himlNormal
= himl
;
7864 if (infoPtr
->uView
== LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
7865 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
7869 himlOld
= infoPtr
->himlSmall
;
7870 infoPtr
->himlSmall
= himl
;
7871 if (infoPtr
->uView
!= LV_VIEW_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
7875 himlOld
= infoPtr
->himlState
;
7876 infoPtr
->himlState
= himl
;
7877 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
7878 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
7882 ERR("Unknown icon type=%d\n", nType
);
7886 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
7887 if (infoPtr
->nItemHeight
!= oldHeight
)
7888 LISTVIEW_UpdateScroll(infoPtr
);
7895 * Preallocates memory (does *not* set the actual count of items !)
7898 * [I] infoPtr : valid pointer to the listview structure
7899 * [I] nItems : item count (projected number of items to allocate)
7900 * [I] dwFlags : update flags
7906 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
7908 TRACE("(nItems=%d, dwFlags=%x)\n", nItems
, dwFlags
);
7910 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
7912 INT nOldCount
= infoPtr
->nItemCount
;
7914 if (nItems
< nOldCount
)
7916 RANGE range
= { nItems
, nOldCount
};
7917 ranges_del(infoPtr
->selectionRanges
, range
);
7918 if (infoPtr
->nFocusedItem
>= nItems
)
7920 LISTVIEW_SetItemFocus(infoPtr
, -1);
7921 SetRectEmpty(&infoPtr
->rcFocus
);
7925 infoPtr
->nItemCount
= nItems
;
7926 LISTVIEW_UpdateScroll(infoPtr
);
7928 /* the flags are valid only in ownerdata report and list modes */
7929 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
) dwFlags
= 0;
7931 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
7932 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
7934 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
7935 LISTVIEW_InvalidateList(infoPtr
);
7942 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7943 nFrom
= min(nOldCount
, nItems
);
7944 nTo
= max(nOldCount
, nItems
);
7946 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
7949 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
7950 rcErase
.right
= infoPtr
->nItemWidth
;
7951 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
7952 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
7953 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
7954 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
7956 else /* LV_VIEW_LIST */
7958 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
7960 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
7961 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
7962 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
7963 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
7964 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
7965 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
7966 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
7968 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
7970 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
7971 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
7972 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
7973 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
7974 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
7980 /* According to MSDN for non-LVS_OWNERDATA this is just
7981 * a performance issue. The control allocates its internal
7982 * data structures for the number of items specified. It
7983 * cuts down on the number of memory allocations. Therefore
7984 * we will just issue a WARN here
7986 WARN("for non-ownerdata performance option not implemented.\n");
7994 * Sets the position of an item.
7997 * [I] infoPtr : valid pointer to the listview structure
7998 * [I] nItem : item index
7999 * [I] pt : coordinate
8005 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, POINT pt
)
8009 TRACE("(nItem=%d, &pt=%s\n", nItem
, wine_dbgstr_point(&pt
));
8011 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
8012 !(infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)) return FALSE
;
8014 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
8016 /* This point value seems to be an undocumented feature.
8017 * The best guess is that it means either at the origin,
8018 * or at true beginning of the list. I will assume the origin. */
8019 if ((pt
.x
== -1) && (pt
.y
== -1))
8022 if (infoPtr
->uView
== LV_VIEW_ICON
)
8024 pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
8025 pt
.y
-= ICON_TOP_PADDING
;
8030 infoPtr
->bAutoarrange
= FALSE
;
8032 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, FALSE
);
8037 * Sets the state of one or many items.
8040 * [I] infoPtr : valid pointer to the listview structure
8041 * [I] nItem : item index
8042 * [I] lpLVItem : item or subitem info
8048 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
)
8050 BOOL bResult
= TRUE
;
8053 lvItem
.iItem
= nItem
;
8054 lvItem
.iSubItem
= 0;
8055 lvItem
.mask
= LVIF_STATE
;
8056 lvItem
.state
= lpLVItem
->state
;
8057 lvItem
.stateMask
= lpLVItem
->stateMask
;
8058 TRACE("lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
8062 /* select all isn't allowed in LVS_SINGLESEL */
8063 if ((lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) && (infoPtr
->dwStyle
& LVS_SINGLESEL
))
8066 /* apply to all items */
8067 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
8068 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) bResult
= FALSE
;
8071 bResult
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
8074 * Update selection mark
8076 * Investigation on windows 2k showed that selection mark was updated
8077 * whenever a new selection was made, but if the selected item was
8078 * unselected it was not updated.
8080 * we are probably still not 100% accurate, but this at least sets the
8081 * proper selection mark when it is needed
8084 if (bResult
&& (lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) &&
8085 (infoPtr
->nSelectionMark
== -1))
8088 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
8090 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
8092 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
8094 infoPtr
->nSelectionMark
= i
;
8098 else if (ranges_contain(infoPtr
->selectionRanges
, i
))
8100 infoPtr
->nSelectionMark
= i
;
8111 * Sets the text of an item or subitem.
8114 * [I] hwnd : window handle
8115 * [I] nItem : item index
8116 * [I] lpLVItem : item or subitem info
8117 * [I] isW : TRUE if input is Unicode
8123 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
8127 if (nItem
< 0 && nItem
>= infoPtr
->nItemCount
) return FALSE
;
8129 lvItem
.iItem
= nItem
;
8130 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
8131 lvItem
.mask
= LVIF_TEXT
;
8132 lvItem
.pszText
= lpLVItem
->pszText
;
8133 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
8135 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
8137 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
8142 * Set item index that marks the start of a multiple selection.
8145 * [I] infoPtr : valid pointer to the listview structure
8146 * [I] nIndex : index
8149 * Index number or -1 if there is no selection mark.
8151 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
8153 INT nOldIndex
= infoPtr
->nSelectionMark
;
8155 TRACE("(nIndex=%d)\n", nIndex
);
8157 infoPtr
->nSelectionMark
= nIndex
;
8164 * Sets the text background color.
8167 * [I] infoPtr : valid pointer to the listview structure
8168 * [I] clrTextBk : text background color
8174 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrTextBk
)
8176 TRACE("(clrTextBk=%x)\n", clrTextBk
);
8178 if (infoPtr
->clrTextBk
!= clrTextBk
)
8180 infoPtr
->clrTextBk
= clrTextBk
;
8181 LISTVIEW_InvalidateList(infoPtr
);
8189 * Sets the text foreground color.
8192 * [I] infoPtr : valid pointer to the listview structure
8193 * [I] clrText : text color
8199 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF clrText
)
8201 TRACE("(clrText=%x)\n", clrText
);
8203 if (infoPtr
->clrText
!= clrText
)
8205 infoPtr
->clrText
= clrText
;
8206 LISTVIEW_InvalidateList(infoPtr
);
8214 * Sets new ToolTip window to ListView control.
8217 * [I] infoPtr : valid pointer to the listview structure
8218 * [I] hwndNewToolTip : handle to new ToolTip
8223 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
8225 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
8226 infoPtr
->hwndToolTip
= hwndNewToolTip
;
8227 return hwndOldToolTip
;
8232 * sets the Unicode character format flag for the control
8234 * [I] infoPtr :valid pointer to the listview structure
8235 * [I] fUnicode :true to switch to UNICODE false to switch to ANSI
8238 * Old Unicode Format
8240 static BOOL
LISTVIEW_SetUnicodeFormat( LISTVIEW_INFO
*infoPtr
, BOOL fUnicode
)
8242 SHORT rc
= infoPtr
->notifyFormat
;
8243 infoPtr
->notifyFormat
= (fUnicode
) ? NFR_UNICODE
: NFR_ANSI
;
8244 return rc
== NFR_UNICODE
;
8249 * sets the control view mode
8251 * [I] infoPtr :valid pointer to the listview structure
8252 * [I] nView :new view mode value
8258 static INT
LISTVIEW_SetView(LISTVIEW_INFO
*infoPtr
, DWORD nView
)
8260 SIZE oldIconSize
= infoPtr
->iconSize
;
8263 if (infoPtr
->uView
== nView
) return 1;
8265 if ((INT
)nView
< 0 || nView
> LV_VIEW_MAX
) return -1;
8266 if (nView
== LV_VIEW_TILE
)
8268 FIXME("View LV_VIEW_TILE unimplemented\n");
8272 infoPtr
->uView
= nView
;
8274 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8275 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8277 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
8278 SetRectEmpty(&infoPtr
->rcFocus
);
8280 himl
= (nView
== LV_VIEW_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
8281 set_icon_size(&infoPtr
->iconSize
, himl
, nView
!= LV_VIEW_ICON
);
8286 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
8288 TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
8289 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
8290 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
8292 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8294 case LV_VIEW_SMALLICON
:
8295 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8297 case LV_VIEW_DETAILS
:
8302 LISTVIEW_CreateHeader( infoPtr
);
8304 hl
.prc
= &infoPtr
->rcList
;
8306 SendMessageW(infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
8307 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
8308 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
) ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
8315 LISTVIEW_UpdateItemSize(infoPtr
);
8316 LISTVIEW_UpdateSize(infoPtr
);
8317 LISTVIEW_UpdateScroll(infoPtr
);
8318 LISTVIEW_InvalidateList(infoPtr
);
8320 TRACE("nView=%d\n", nView
);
8325 /* LISTVIEW_SetWorkAreas */
8329 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMS
8332 * [I] first : pointer to first ITEM_INFO to compare
8333 * [I] second : pointer to second ITEM_INFO to compare
8334 * [I] lParam : HWND of control
8337 * if first comes before second : negative
8338 * if first comes after second : positive
8339 * if first and second are equivalent : zero
8341 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
8343 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
8344 ITEM_INFO
* lv_first
= DPA_GetPtr( first
, 0 );
8345 ITEM_INFO
* lv_second
= DPA_GetPtr( second
, 0 );
8347 /* Forward the call to the client defined callback */
8348 return (infoPtr
->pfnCompare
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
8353 * Callback internally used by LISTVIEW_SortItems() in response of LVM_SORTITEMSEX
8356 * [I] first : pointer to first ITEM_INFO to compare
8357 * [I] second : pointer to second ITEM_INFO to compare
8358 * [I] lParam : HWND of control
8361 * if first comes before second : negative
8362 * if first comes after second : positive
8363 * if first and second are equivalent : zero
8365 static INT WINAPI
LISTVIEW_CallBackCompareEx(LPVOID first
, LPVOID second
, LPARAM lParam
)
8367 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
8368 INT first_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, first
);
8369 INT second_idx
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, second
);
8371 /* Forward the call to the client defined callback */
8372 return (infoPtr
->pfnCompare
)( first_idx
, second_idx
, infoPtr
->lParamSort
);
8377 * Sorts the listview items.
8380 * [I] infoPtr : valid pointer to the listview structure
8381 * [I] pfnCompare : application-defined value
8382 * [I] lParamSort : pointer to comparison callback
8383 * [I] IsEx : TRUE when LVM_SORTITEMSEX used
8389 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
,
8390 LPARAM lParamSort
, BOOL IsEx
)
8394 LPVOID selectionMarkItem
= NULL
;
8395 LPVOID focusedItem
= NULL
;
8398 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
8400 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
8402 if (!pfnCompare
) return FALSE
;
8403 if (!infoPtr
->hdpaItems
) return FALSE
;
8405 /* if there are 0 or 1 items, there is no need to sort */
8406 if (infoPtr
->nItemCount
< 2) return TRUE
;
8408 /* clear selection */
8409 ranges_clear(infoPtr
->selectionRanges
);
8411 /* save selection mark and focused item */
8412 if (infoPtr
->nSelectionMark
>= 0)
8413 selectionMarkItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
);
8414 if (infoPtr
->nFocusedItem
>= 0)
8415 focusedItem
= DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
8417 infoPtr
->pfnCompare
= pfnCompare
;
8418 infoPtr
->lParamSort
= lParamSort
;
8420 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompareEx
, (LPARAM
)infoPtr
);
8422 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
8424 /* restore selection ranges */
8425 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
8427 hdpaSubItems
= DPA_GetPtr(infoPtr
->hdpaItems
, i
);
8428 lpItem
= DPA_GetPtr(hdpaSubItems
, 0);
8430 if (lpItem
->state
& LVIS_SELECTED
)
8431 ranges_additem(infoPtr
->selectionRanges
, i
);
8433 /* restore selection mark and focused item */
8434 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
8435 infoPtr
->nFocusedItem
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, focusedItem
);
8437 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
8439 /* refresh the display */
8440 if (infoPtr
->uView
!= LV_VIEW_ICON
&& infoPtr
->uView
!= LV_VIEW_SMALLICON
)
8441 LISTVIEW_InvalidateList(infoPtr
);
8448 * Update theme handle after a theme change.
8451 * [I] infoPtr : valid pointer to the listview structure
8455 * FAILURE : something else
8457 static LRESULT
LISTVIEW_ThemeChanged(const LISTVIEW_INFO
*infoPtr
)
8459 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
8460 CloseThemeData(theme
);
8461 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
8467 * Updates an items or rearranges the listview control.
8470 * [I] infoPtr : valid pointer to the listview structure
8471 * [I] nItem : item index
8477 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
8479 TRACE("(nItem=%d)\n", nItem
);
8481 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
8483 /* rearrange with default alignment style */
8484 if (is_autoarrange(infoPtr
))
8485 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8487 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
8494 * Draw the track line at the place defined in the infoPtr structure.
8495 * The line is drawn with a XOR pen so drawing the line for the second time
8496 * in the same place erases the line.
8499 * [I] infoPtr : valid pointer to the listview structure
8505 static BOOL
LISTVIEW_DrawTrackLine(const LISTVIEW_INFO
*infoPtr
)
8511 if (infoPtr
->xTrackLine
== -1)
8514 if (!(hdc
= GetDC(infoPtr
->hwndSelf
)))
8516 hOldPen
= SelectObject(hdc
, GetStockObject(BLACK_PEN
));
8517 oldROP
= SetROP2(hdc
, R2_XORPEN
);
8518 MoveToEx(hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.top
, NULL
);
8519 LineTo(hdc
, infoPtr
->xTrackLine
, infoPtr
->rcList
.bottom
);
8520 SetROP2(hdc
, oldROP
);
8521 SelectObject(hdc
, hOldPen
);
8522 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
8528 * Called when an edit control should be displayed. This function is called after
8529 * we are sure that there was a single click - not a double click (this is a TIMERPROC).
8532 * [I] hwnd : Handle to the listview
8533 * [I] uMsg : WM_TIMER (ignored)
8534 * [I] idEvent : The timer ID interpreted as a pointer to a DELAYED_EDIT_ITEM struct
8535 * [I] dwTimer : The elapsed time (ignored)
8540 static VOID CALLBACK
LISTVIEW_DelayedEditItem(HWND hwnd
, UINT uMsg
, UINT_PTR idEvent
, DWORD dwTime
)
8542 DELAYED_ITEM_EDIT
*editItem
= (DELAYED_ITEM_EDIT
*)idEvent
;
8543 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
8545 KillTimer(hwnd
, idEvent
);
8546 editItem
->fEnabled
= FALSE
;
8547 /* check if the item is still selected */
8548 if (infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, editItem
->iItem
, LVIS_SELECTED
))
8549 LISTVIEW_EditLabelT(infoPtr
, editItem
->iItem
, TRUE
);
8554 * Creates the listview control - the WM_NCCREATE phase.
8557 * [I] hwnd : window handle
8558 * [I] lpcs : the create parameters
8564 static LRESULT
LISTVIEW_NCCreate(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
8566 LISTVIEW_INFO
*infoPtr
;
8569 TRACE("(lpcs=%p)\n", lpcs
);
8571 /* initialize info pointer */
8572 infoPtr
= Alloc(sizeof(LISTVIEW_INFO
));
8573 if (!infoPtr
) return FALSE
;
8575 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
8577 infoPtr
->hwndSelf
= hwnd
;
8578 infoPtr
->dwStyle
= lpcs
->style
; /* Note: may be changed in WM_CREATE */
8579 map_style_view(infoPtr
);
8580 /* determine the type of structures to use */
8581 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
8582 /* infoPtr->notifyFormat will be filled in WM_CREATE */
8584 /* initialize color information */
8585 infoPtr
->clrBk
= CLR_NONE
;
8586 infoPtr
->clrText
= CLR_DEFAULT
;
8587 infoPtr
->clrTextBk
= CLR_DEFAULT
;
8588 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
8590 /* set default values */
8591 infoPtr
->nFocusedItem
= -1;
8592 infoPtr
->nSelectionMark
= -1;
8593 infoPtr
->nHotItem
= -1;
8594 infoPtr
->bRedraw
= TRUE
;
8595 infoPtr
->bNoItemMetrics
= TRUE
;
8596 infoPtr
->bDoChangeNotify
= TRUE
;
8597 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
);
8598 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
);
8599 infoPtr
->nEditLabelItem
= -1;
8600 infoPtr
->nLButtonDownItem
= -1;
8601 infoPtr
->dwHoverTime
= -1; /* default system hover time */
8602 infoPtr
->nMeasureItemHeight
= 0;
8603 infoPtr
->xTrackLine
= -1; /* no track line */
8604 infoPtr
->itemEdit
.fEnabled
= FALSE
;
8605 infoPtr
->iVersion
= COMCTL32_VERSION
;
8607 /* get default font (icon title) */
8608 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
8609 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
8610 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
8611 LISTVIEW_SaveTextMetrics(infoPtr
);
8613 /* allocate memory for the data structure */
8614 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
8615 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
8616 if (!(infoPtr
->hdpaItemIds
= DPA_Create(10))) goto fail
;
8617 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
8618 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
8619 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
8623 DestroyWindow(infoPtr
->hwndHeader
);
8624 ranges_destroy(infoPtr
->selectionRanges
);
8625 DPA_Destroy(infoPtr
->hdpaItems
);
8626 DPA_Destroy(infoPtr
->hdpaItemIds
);
8627 DPA_Destroy(infoPtr
->hdpaPosX
);
8628 DPA_Destroy(infoPtr
->hdpaPosY
);
8629 DPA_Destroy(infoPtr
->hdpaColumns
);
8636 * Creates the listview control - the WM_CREATE phase. Most of the data is
8637 * already set up in LISTVIEW_NCCreate
8640 * [I] hwnd : window handle
8641 * [I] lpcs : the create parameters
8647 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
8649 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
8651 TRACE("(lpcs=%p)\n", lpcs
);
8653 infoPtr
->dwStyle
= lpcs
->style
;
8654 map_style_view(infoPtr
);
8656 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
8657 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)NF_QUERY
);
8658 /* on error defaulting to ANSI notifications */
8659 if (infoPtr
->notifyFormat
== 0) infoPtr
->notifyFormat
= NFR_ANSI
;
8661 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && (lpcs
->style
& WS_VISIBLE
))
8663 if (LISTVIEW_CreateHeader(infoPtr
) < 0) return -1;
8666 infoPtr
->hwndHeader
= 0;
8668 /* init item size to avoid division by 0 */
8669 LISTVIEW_UpdateItemSize (infoPtr
);
8671 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8673 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
) && (WS_VISIBLE
& lpcs
->style
))
8675 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
8677 LISTVIEW_UpdateScroll(infoPtr
);
8678 /* send WM_MEASUREITEM notification */
8679 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) notify_measureitem(infoPtr
);
8682 OpenThemeData(hwnd
, themeClass
);
8684 /* initialize the icon sizes */
8685 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, infoPtr
->uView
!= LV_VIEW_ICON
);
8686 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
8692 * Destroys the listview control.
8695 * [I] infoPtr : valid pointer to the listview structure
8701 static LRESULT
LISTVIEW_Destroy(const LISTVIEW_INFO
*infoPtr
)
8703 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
8704 CloseThemeData(theme
);
8710 * Enables the listview control.
8713 * [I] infoPtr : valid pointer to the listview structure
8714 * [I] bEnable : specifies whether to enable or disable the window
8720 static BOOL
LISTVIEW_Enable(const LISTVIEW_INFO
*infoPtr
, BOOL bEnable
)
8722 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
8723 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
8729 * Erases the background of the listview control.
8732 * [I] infoPtr : valid pointer to the listview structure
8733 * [I] hdc : device context handle
8739 static inline BOOL
LISTVIEW_EraseBkgnd(const LISTVIEW_INFO
*infoPtr
, HDC hdc
)
8743 TRACE("(hdc=%p)\n", hdc
);
8745 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
8747 if (infoPtr
->clrBk
== CLR_NONE
)
8748 return SendMessageW(infoPtr
->hwndNotify
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
8750 /* for double buffered controls we need to do this during refresh */
8751 if (infoPtr
->dwLvExStyle
& LVS_EX_DOUBLEBUFFER
) return FALSE
;
8753 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
8759 * Helper function for LISTVIEW_[HV]Scroll *only*.
8760 * Performs vertical/horizontal scrolling by a give amount.
8763 * [I] infoPtr : valid pointer to the listview structure
8764 * [I] dx : amount of horizontal scroll
8765 * [I] dy : amount of vertical scroll
8767 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
8769 /* now we can scroll the list */
8770 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
8771 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
8772 /* if we have focus, adjust rect */
8773 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
8774 UpdateWindow(infoPtr
->hwndSelf
);
8779 * Performs vertical scrolling.
8782 * [I] infoPtr : valid pointer to the listview structure
8783 * [I] nScrollCode : scroll code
8784 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
8785 * [I] hScrollWnd : scrollbar control window handle
8791 * SB_LINEUP/SB_LINEDOWN:
8792 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
8793 * for LVS_REPORT is 1 line
8794 * for LVS_LIST cannot occur
8797 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
8798 INT nScrollDiff
, HWND hScrollWnd
)
8800 INT nOldScrollPos
, nNewScrollPos
;
8801 SCROLLINFO scrollInfo
;
8804 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
8805 debugscrollcode(nScrollCode
), nScrollDiff
);
8807 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8809 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
8810 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
8812 is_an_icon
= ((infoPtr
->uView
== LV_VIEW_ICON
) || (infoPtr
->uView
== LV_VIEW_SMALLICON
));
8814 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
8816 nOldScrollPos
= scrollInfo
.nPos
;
8817 switch (nScrollCode
)
8823 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
8827 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
8831 nScrollDiff
= -scrollInfo
.nPage
;
8835 nScrollDiff
= scrollInfo
.nPage
;
8838 case SB_THUMBPOSITION
:
8840 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
8847 /* quit right away if pos isn't changing */
8848 if (nScrollDiff
== 0) return 0;
8850 /* calculate new position, and handle overflows */
8851 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
8852 if (nScrollDiff
> 0) {
8853 if (nNewScrollPos
< nOldScrollPos
||
8854 nNewScrollPos
> scrollInfo
.nMax
)
8855 nNewScrollPos
= scrollInfo
.nMax
;
8857 if (nNewScrollPos
> nOldScrollPos
||
8858 nNewScrollPos
< scrollInfo
.nMin
)
8859 nNewScrollPos
= scrollInfo
.nMin
;
8862 /* set the new position, and reread in case it changed */
8863 scrollInfo
.fMask
= SIF_POS
;
8864 scrollInfo
.nPos
= nNewScrollPos
;
8865 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
8867 /* carry on only if it really changed */
8868 if (nNewScrollPos
== nOldScrollPos
) return 0;
8870 /* now adjust to client coordinates */
8871 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
8872 if (infoPtr
->uView
== LV_VIEW_DETAILS
) nScrollDiff
*= infoPtr
->nItemHeight
;
8874 /* and scroll the window */
8875 scroll_list(infoPtr
, 0, nScrollDiff
);
8882 * Performs horizontal scrolling.
8885 * [I] infoPtr : valid pointer to the listview structure
8886 * [I] nScrollCode : scroll code
8887 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
8888 * [I] hScrollWnd : scrollbar control window handle
8894 * SB_LINELEFT/SB_LINERIGHT:
8895 * for LVS_ICON, LVS_SMALLICON 1 pixel
8896 * for LVS_REPORT is 1 pixel
8897 * for LVS_LIST is 1 column --> which is a 1 because the
8898 * scroll is based on columns not pixels
8901 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
8902 INT nScrollDiff
, HWND hScrollWnd
)
8904 INT nOldScrollPos
, nNewScrollPos
;
8905 SCROLLINFO scrollInfo
;
8907 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
8908 debugscrollcode(nScrollCode
), nScrollDiff
);
8910 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8912 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
8913 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
8915 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
8917 nOldScrollPos
= scrollInfo
.nPos
;
8919 switch (nScrollCode
)
8933 nScrollDiff
= -scrollInfo
.nPage
;
8937 nScrollDiff
= scrollInfo
.nPage
;
8940 case SB_THUMBPOSITION
:
8942 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
8949 /* quit right away if pos isn't changing */
8950 if (nScrollDiff
== 0) return 0;
8952 /* calculate new position, and handle overflows */
8953 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
8954 if (nScrollDiff
> 0) {
8955 if (nNewScrollPos
< nOldScrollPos
||
8956 nNewScrollPos
> scrollInfo
.nMax
)
8957 nNewScrollPos
= scrollInfo
.nMax
;
8959 if (nNewScrollPos
> nOldScrollPos
||
8960 nNewScrollPos
< scrollInfo
.nMin
)
8961 nNewScrollPos
= scrollInfo
.nMin
;
8964 /* set the new position, and reread in case it changed */
8965 scrollInfo
.fMask
= SIF_POS
;
8966 scrollInfo
.nPos
= nNewScrollPos
;
8967 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
8969 /* carry on only if it really changed */
8970 if (nNewScrollPos
== nOldScrollPos
) return 0;
8972 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
8973 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
8975 /* now adjust to client coordinates */
8976 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
8977 if (infoPtr
->uView
== LV_VIEW_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
8979 /* and scroll the window */
8980 scroll_list(infoPtr
, nScrollDiff
, 0);
8985 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
8987 INT gcWheelDelta
= 0;
8988 INT pulScrollLines
= 3;
8989 SCROLLINFO scrollInfo
;
8991 TRACE("(wheelDelta=%d)\n", wheelDelta
);
8993 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
8994 gcWheelDelta
-= wheelDelta
;
8996 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
8997 scrollInfo
.fMask
= SIF_POS
;
8999 switch(infoPtr
->uView
)
9002 case LV_VIEW_SMALLICON
:
9004 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
9005 * should be fixed in the future.
9007 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (gcWheelDelta
< 0) ?
9008 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
, 0);
9011 case LV_VIEW_DETAILS
:
9012 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
9014 int cLineScroll
= min(LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
9015 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
9016 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, cLineScroll
, 0);
9021 LISTVIEW_HScroll(infoPtr
, (gcWheelDelta
< 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0, 0);
9032 * [I] infoPtr : valid pointer to the listview structure
9033 * [I] nVirtualKey : virtual key
9034 * [I] lKeyData : key data
9039 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
9041 HWND hwndSelf
= infoPtr
->hwndSelf
;
9043 NMLVKEYDOWN nmKeyDown
;
9045 TRACE("(nVirtualKey=%d, lKeyData=%d)\n", nVirtualKey
, lKeyData
);
9047 /* send LVN_KEYDOWN notification */
9048 nmKeyDown
.wVKey
= nVirtualKey
;
9049 nmKeyDown
.flags
= 0;
9050 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
9051 if (!IsWindow(hwndSelf
))
9054 switch (nVirtualKey
)
9057 nItem
= infoPtr
->nFocusedItem
;
9058 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
9059 toggle_checkbox_state(infoPtr
, infoPtr
->nFocusedItem
);
9063 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
9065 if (!notify(infoPtr
, NM_RETURN
)) return 0;
9066 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
9071 if (infoPtr
->nItemCount
> 0)
9076 if (infoPtr
->nItemCount
> 0)
9077 nItem
= infoPtr
->nItemCount
- 1;
9081 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
9085 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
9089 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
9093 nItem
= LISTVIEW_GetNextItem(infoPtr
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
9097 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9099 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9100 if (infoPtr
->nFocusedItem
== topidx
)
9101 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
9106 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
9107 * LISTVIEW_GetCountPerRow(infoPtr
);
9108 if(nItem
< 0) nItem
= 0;
9112 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9114 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
9115 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
9116 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
9117 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
9119 nItem
= topidx
+ cnt
- 1;
9122 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
9123 * LISTVIEW_GetCountPerRow(infoPtr
);
9124 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
9128 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
9129 LISTVIEW_KeySelection(infoPtr
, nItem
, nVirtualKey
== VK_SPACE
);
9139 * [I] infoPtr : valid pointer to the listview structure
9144 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
9148 /* if we did not have the focus, there's nothing to do */
9149 if (!infoPtr
->bFocus
) return 0;
9151 /* send NM_KILLFOCUS notification */
9152 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
9154 /* if we have a focus rectangle, get rid of it */
9155 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
9157 /* set window focus flag */
9158 infoPtr
->bFocus
= FALSE
;
9160 /* invalidate the selected items before resetting focus flag */
9161 LISTVIEW_InvalidateSelectedItems(infoPtr
);
9168 * Processes double click messages (left mouse button).
9171 * [I] infoPtr : valid pointer to the listview structure
9172 * [I] wKey : key flag
9173 * [I] x,y : mouse coordinate
9178 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9180 LVHITTESTINFO htInfo
;
9182 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
9184 /* Cancel the item edition if any */
9185 if (infoPtr
->itemEdit
.fEnabled
)
9187 KillTimer(infoPtr
->hwndSelf
, (UINT_PTR
)&infoPtr
->itemEdit
);
9188 infoPtr
->itemEdit
.fEnabled
= FALSE
;
9191 /* send NM_RELEASEDCAPTURE notification */
9192 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9197 /* send NM_DBLCLK notification */
9198 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
9199 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
9201 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
9202 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
9209 * Processes mouse down messages (left mouse button).
9212 * infoPtr [I ] valid pointer to the listview structure
9213 * wKey [I ] key flag
9214 * x,y [I ] mouse coordinate
9219 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9221 LVHITTESTINFO lvHitTestInfo
;
9222 static BOOL bGroupSelect
= TRUE
;
9223 POINT pt
= { x
, y
};
9226 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
9228 /* send NM_RELEASEDCAPTURE notification */
9229 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9231 /* set left button down flag and record the click position */
9232 infoPtr
->bLButtonDown
= TRUE
;
9233 infoPtr
->ptClickPos
= pt
;
9234 infoPtr
->bDragging
= FALSE
;
9236 lvHitTestInfo
.pt
.x
= x
;
9237 lvHitTestInfo
.pt
.y
= y
;
9239 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
9240 TRACE("at %s, nItem=%d\n", wine_dbgstr_point(&pt
), nItem
);
9241 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
9243 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
9245 toggle_checkbox_state(infoPtr
, nItem
);
9249 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
9251 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9252 infoPtr
->nEditLabelItem
= nItem
;
9254 LISTVIEW_SetSelection(infoPtr
, nItem
);
9258 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
9262 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
9263 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
9264 infoPtr
->nSelectionMark
= nItem
;
9270 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
9271 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
9273 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
9274 infoPtr
->nSelectionMark
= nItem
;
9277 else if (wKey
& MK_CONTROL
)
9281 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
9283 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
9284 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
9285 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
9286 infoPtr
->nSelectionMark
= nItem
;
9288 else if (wKey
& MK_SHIFT
)
9290 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
9294 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9296 infoPtr
->nEditLabelItem
= nItem
;
9297 infoPtr
->nLButtonDownItem
= nItem
;
9299 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
9302 /* set selection (clears other pre-existing selections) */
9303 LISTVIEW_SetSelection(infoPtr
, nItem
);
9307 if (infoPtr
->dwLvExStyle
& LVS_EX_ONECLICKACTIVATE
)
9308 if(lvHitTestInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&lvHitTestInfo
);
9312 /* remove all selections */
9313 if (!(wKey
& MK_CONTROL
) && !(wKey
& MK_SHIFT
))
9314 LISTVIEW_DeselectAll(infoPtr
);
9323 * Processes mouse up messages (left mouse button).
9326 * infoPtr [I ] valid pointer to the listview structure
9327 * wKey [I ] key flag
9328 * x,y [I ] mouse coordinate
9333 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9335 LVHITTESTINFO lvHitTestInfo
;
9337 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
9339 if (!infoPtr
->bLButtonDown
) return 0;
9341 lvHitTestInfo
.pt
.x
= x
;
9342 lvHitTestInfo
.pt
.y
= y
;
9344 /* send NM_CLICK notification */
9345 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
9346 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
9348 /* set left button flag */
9349 infoPtr
->bLButtonDown
= FALSE
;
9351 /* set a single selection, reset others */
9352 if(lvHitTestInfo
.iItem
== infoPtr
->nLButtonDownItem
&& lvHitTestInfo
.iItem
!= -1)
9353 LISTVIEW_SetSelection(infoPtr
, infoPtr
->nLButtonDownItem
);
9354 infoPtr
->nLButtonDownItem
= -1;
9356 if (infoPtr
->bDragging
)
9358 infoPtr
->bDragging
= FALSE
;
9362 /* if we clicked on a selected item, edit the label */
9363 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
9365 /* we want to make sure the user doesn't want to do a double click. So we will
9366 * delay the edit. WM_LBUTTONDBLCLICK will cancel the timer
9368 infoPtr
->itemEdit
.fEnabled
= TRUE
;
9369 infoPtr
->itemEdit
.iItem
= lvHitTestInfo
.iItem
;
9370 SetTimer(infoPtr
->hwndSelf
,
9371 (UINT_PTR
)&infoPtr
->itemEdit
,
9372 GetDoubleClickTime(),
9373 LISTVIEW_DelayedEditItem
);
9376 if (!infoPtr
->bFocus
)
9377 SetFocus(infoPtr
->hwndSelf
);
9384 * Destroys the listview control (called after WM_DESTROY).
9387 * [I] infoPtr : valid pointer to the listview structure
9392 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
9396 /* delete all items */
9397 LISTVIEW_DeleteAllItems(infoPtr
, TRUE
);
9399 /* destroy data structure */
9400 DPA_Destroy(infoPtr
->hdpaItems
);
9401 DPA_Destroy(infoPtr
->hdpaItemIds
);
9402 DPA_Destroy(infoPtr
->hdpaPosX
);
9403 DPA_Destroy(infoPtr
->hdpaPosY
);
9404 DPA_Destroy(infoPtr
->hdpaColumns
);
9405 ranges_destroy(infoPtr
->selectionRanges
);
9407 /* destroy image lists */
9408 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
9410 if (infoPtr
->himlNormal
)
9411 ImageList_Destroy(infoPtr
->himlNormal
);
9412 if (infoPtr
->himlSmall
)
9413 ImageList_Destroy(infoPtr
->himlSmall
);
9414 if (infoPtr
->himlState
)
9415 ImageList_Destroy(infoPtr
->himlState
);
9418 /* destroy font, bkgnd brush */
9420 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
9421 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
9423 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
9425 /* free listview info pointer*/
9433 * Handles notifications from header.
9436 * [I] infoPtr : valid pointer to the listview structure
9437 * [I] nCtrlId : control identifier
9438 * [I] lpnmh : notification information
9443 static LRESULT
LISTVIEW_HeaderNotification(LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
9445 HWND hwndSelf
= infoPtr
->hwndSelf
;
9447 TRACE("(lpnmh=%p)\n", lpnmh
);
9449 if (!lpnmh
|| lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
9451 switch (lpnmh
->hdr
.code
)
9456 COLUMN_INFO
*lpColumnInfo
;
9460 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
9463 /* remove the old line (if any) */
9464 LISTVIEW_DrawTrackLine(infoPtr
);
9466 /* compute & draw the new line */
9467 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
9468 x
= lpColumnInfo
->rcHeader
.left
+ lpnmh
->pitem
->cxy
;
9469 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
9470 infoPtr
->xTrackLine
= x
+ ptOrigin
.x
;
9471 LISTVIEW_DrawTrackLine(infoPtr
);
9477 /* remove the track line (if any) */
9478 LISTVIEW_DrawTrackLine(infoPtr
);
9479 infoPtr
->xTrackLine
= -1;
9483 notify_forward_header(infoPtr
, lpnmh
);
9484 return (infoPtr
->dwLvExStyle
& LVS_EX_HEADERDRAGDROP
) == 0;
9487 FIXME("Changing column order not implemented\n");
9488 notify_forward_header(infoPtr
, lpnmh
);
9491 case HDN_ITEMCHANGINGW
:
9492 case HDN_ITEMCHANGINGA
:
9493 return notify_forward_header(infoPtr
, lpnmh
);
9495 case HDN_ITEMCHANGEDW
:
9496 case HDN_ITEMCHANGEDA
:
9498 COLUMN_INFO
*lpColumnInfo
;
9501 notify_forward_header(infoPtr
, lpnmh
);
9502 if (!IsWindow(hwndSelf
))
9505 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
9509 hdi
.mask
= HDI_WIDTH
;
9510 if (!SendMessageW(infoPtr
->hwndHeader
, HDM_GETITEMW
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
9514 cxy
= lpnmh
->pitem
->cxy
;
9516 /* determine how much we change since the last know position */
9517 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
9518 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
9521 lpColumnInfo
->rcHeader
.right
+= dx
;
9522 if (lpnmh
->iItem
+ 1 < DPA_GetPtrCount(infoPtr
->hdpaColumns
))
9523 LISTVIEW_ScrollColumns(infoPtr
, lpnmh
->iItem
+ 1, dx
);
9526 /* only needs to update the scrolls */
9527 infoPtr
->nItemWidth
+= dx
;
9528 LISTVIEW_UpdateScroll(infoPtr
);
9530 LISTVIEW_UpdateItemSize(infoPtr
);
9531 if (infoPtr
->uView
== LV_VIEW_DETAILS
&& is_redrawing(infoPtr
))
9534 RECT rcCol
= lpColumnInfo
->rcHeader
;
9536 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
9537 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
9539 rcCol
.top
= infoPtr
->rcList
.top
;
9540 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
9542 /* resizing left-aligned columns leaves most of the left side untouched */
9543 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
9545 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
;
9548 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
9551 /* when shrinking the last column clear the now unused field */
9552 if (lpnmh
->iItem
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
9558 /* deal with right from rightmost column area */
9559 right
.left
= rcCol
.right
;
9560 right
.top
= rcCol
.top
;
9561 right
.bottom
= rcCol
.bottom
;
9562 right
.right
= infoPtr
->rcList
.right
;
9564 LISTVIEW_InvalidateRect(infoPtr
, &right
);
9567 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
9573 case HDN_ITEMCLICKW
:
9574 case HDN_ITEMCLICKA
:
9576 /* Handle sorting by Header Column */
9579 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
9581 nmlv
.iSubItem
= lpnmh
->iItem
;
9582 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
9583 notify_forward_header(infoPtr
, lpnmh
);
9587 case HDN_DIVIDERDBLCLICKW
:
9588 case HDN_DIVIDERDBLCLICKA
:
9589 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
9590 notify_forward_header(infoPtr
, lpnmh
);
9599 * Paint non-client area of control.
9602 * [I] infoPtr : valid pointer to the listview structureof the sender
9603 * [I] region : update region
9606 * TRUE - frame was painted
9607 * FALSE - call default window proc
9609 static BOOL
LISTVIEW_NCPaint(const LISTVIEW_INFO
*infoPtr
, HRGN region
)
9611 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
9615 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
9616 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
9618 if (!theme
) return FALSE
;
9620 GetWindowRect(infoPtr
->hwndSelf
, &r
);
9622 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
9623 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
9624 if (region
!= (HRGN
)1)
9625 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
9626 OffsetRect(&r
, -r
.left
, -r
.top
);
9628 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
9629 OffsetRect(&r
, -r
.left
, -r
.top
);
9631 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
9632 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
9633 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
9634 ReleaseDC(infoPtr
->hwndSelf
, dc
);
9636 /* Call default proc to get the scrollbars etc. painted */
9637 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
9644 * Determines the type of structure to use.
9647 * [I] infoPtr : valid pointer to the listview structureof the sender
9648 * [I] hwndFrom : listview window handle
9649 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
9654 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
9656 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
9658 if (nCommand
== NF_REQUERY
)
9659 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
9661 return infoPtr
->notifyFormat
;
9666 * Paints/Repaints the listview control.
9669 * [I] infoPtr : valid pointer to the listview structure
9670 * [I] hdc : device context handle
9675 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
9677 TRACE("(hdc=%p)\n", hdc
);
9679 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
9681 infoPtr
->bNoItemMetrics
= FALSE
;
9682 LISTVIEW_UpdateItemSize(infoPtr
);
9683 if (infoPtr
->uView
== LV_VIEW_ICON
|| infoPtr
->uView
== LV_VIEW_SMALLICON
)
9684 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9685 LISTVIEW_UpdateScroll(infoPtr
);
9688 if (infoPtr
->hwndHeader
) UpdateWindow(infoPtr
->hwndHeader
);
9691 LISTVIEW_Refresh(infoPtr
, hdc
, NULL
);
9696 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
9698 LISTVIEW_Refresh(infoPtr
, hdc
, ps
.fErase
? &ps
.rcPaint
: NULL
);
9699 EndPaint(infoPtr
->hwndSelf
, &ps
);
9708 * Paints/Repaints the listview control.
9711 * [I] infoPtr : valid pointer to the listview structure
9712 * [I] hdc : device context handle
9713 * [I] options : drawing options
9718 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
9720 FIXME("Partial Stub: (hdc=%p options=0x%08x)\n", hdc
, options
);
9722 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
9725 if (options
& PRF_ERASEBKGND
)
9726 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
9728 if (options
& PRF_CLIENT
)
9729 LISTVIEW_Paint(infoPtr
, hdc
);
9737 * Processes double click messages (right mouse button).
9740 * [I] infoPtr : valid pointer to the listview structure
9741 * [I] wKey : key flag
9742 * [I] x,y : mouse coordinate
9747 static LRESULT
LISTVIEW_RButtonDblClk(const LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9749 LVHITTESTINFO lvHitTestInfo
;
9751 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
9753 /* send NM_RELEASEDCAPTURE notification */
9754 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9756 /* send NM_RDBLCLK notification */
9757 lvHitTestInfo
.pt
.x
= x
;
9758 lvHitTestInfo
.pt
.y
= y
;
9759 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
9760 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
9767 * Processes mouse down messages (right mouse button).
9770 * [I] infoPtr : valid pointer to the listview structure
9771 * [I] wKey : key flag
9772 * [I] x,y : mouse coordinate
9777 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9779 LVHITTESTINFO lvHitTestInfo
;
9782 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
9784 /* send NM_RELEASEDCAPTURE notification */
9785 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
9787 /* make sure the listview control window has the focus */
9788 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
9790 /* set right button down flag */
9791 infoPtr
->bRButtonDown
= TRUE
;
9793 /* determine the index of the selected item */
9794 lvHitTestInfo
.pt
.x
= x
;
9795 lvHitTestInfo
.pt
.y
= y
;
9796 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
9798 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
9800 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
9801 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
9802 !LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
9803 LISTVIEW_SetSelection(infoPtr
, nItem
);
9807 LISTVIEW_DeselectAll(infoPtr
);
9815 * Processes mouse up messages (right mouse button).
9818 * [I] infoPtr : valid pointer to the listview structure
9819 * [I] wKey : key flag
9820 * [I] x,y : mouse coordinate
9825 static LRESULT
LISTVIEW_RButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
9827 LVHITTESTINFO lvHitTestInfo
;
9830 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
9832 if (!infoPtr
->bRButtonDown
) return 0;
9834 /* set button flag */
9835 infoPtr
->bRButtonDown
= FALSE
;
9837 /* Send NM_RCLICK notification */
9838 lvHitTestInfo
.pt
.x
= x
;
9839 lvHitTestInfo
.pt
.y
= y
;
9840 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
9841 if (!notify_click(infoPtr
, NM_RCLICK
, &lvHitTestInfo
)) return 0;
9843 /* Change to screen coordinate for WM_CONTEXTMENU */
9844 pt
= lvHitTestInfo
.pt
;
9845 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
9847 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
9848 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
9849 (WPARAM
)infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
9860 * [I] infoPtr : valid pointer to the listview structure
9861 * [I] hwnd : window handle of window containing the cursor
9862 * [I] nHittest : hit-test code
9863 * [I] wMouseMsg : ideintifier of the mouse message
9866 * TRUE if cursor is set
9869 static BOOL
LISTVIEW_SetCursor(const LISTVIEW_INFO
*infoPtr
, HWND hwnd
, UINT nHittest
, UINT wMouseMsg
)
9871 LVHITTESTINFO lvHitTestInfo
;
9873 if(!(LISTVIEW_isHotTracking(infoPtr
))) return FALSE
;
9875 if(!infoPtr
->hHotCursor
) return FALSE
;
9877 GetCursorPos(&lvHitTestInfo
.pt
);
9878 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) return FALSE
;
9880 SetCursor(infoPtr
->hHotCursor
);
9890 * [I] infoPtr : valid pointer to the listview structure
9891 * [I] hwndLoseFocus : handle of previously focused window
9896 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
9898 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
9900 /* if we have the focus already, there's nothing to do */
9901 if (infoPtr
->bFocus
) return 0;
9903 /* send NM_SETFOCUS notification */
9904 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
9906 /* set window focus flag */
9907 infoPtr
->bFocus
= TRUE
;
9909 /* put the focus rect back on */
9910 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
9912 /* redraw all visible selected items */
9913 LISTVIEW_InvalidateSelectedItems(infoPtr
);
9923 * [I] infoPtr : valid pointer to the listview structure
9924 * [I] fRedraw : font handle
9925 * [I] fRedraw : redraw flag
9930 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
9932 HFONT oldFont
= infoPtr
->hFont
;
9934 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
9936 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
9937 if (infoPtr
->hFont
== oldFont
) return 0;
9939 LISTVIEW_SaveTextMetrics(infoPtr
);
9941 if (infoPtr
->uView
== LV_VIEW_DETAILS
)
9943 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
9944 LISTVIEW_UpdateSize(infoPtr
);
9945 LISTVIEW_UpdateScroll(infoPtr
);
9948 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
9955 * Message handling for WM_SETREDRAW.
9956 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
9959 * [I] infoPtr : valid pointer to the listview structure
9960 * [I] bRedraw: state of redraw flag
9963 * DefWinProc return value
9965 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
9967 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
9969 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
9970 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
9972 infoPtr
->bRedraw
= bRedraw
;
9974 if(!bRedraw
) return 0;
9976 if (is_autoarrange(infoPtr
))
9977 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9978 LISTVIEW_UpdateScroll(infoPtr
);
9980 /* despite what the WM_SETREDRAW docs says, apps expect us
9981 * to invalidate the listview here... stupid! */
9982 LISTVIEW_InvalidateList(infoPtr
);
9989 * Resizes the listview control. This function processes WM_SIZE
9990 * messages. At this time, the width and height are not used.
9993 * [I] infoPtr : valid pointer to the listview structure
9994 * [I] Width : new width
9995 * [I] Height : new height
10000 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
10002 RECT rcOld
= infoPtr
->rcList
;
10004 TRACE("(width=%d, height=%d)\n", Width
, Height
);
10006 LISTVIEW_UpdateSize(infoPtr
);
10007 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
10009 /* do not bother with display related stuff if we're not redrawing */
10010 if (!is_redrawing(infoPtr
)) return 0;
10012 if (is_autoarrange(infoPtr
))
10013 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10015 LISTVIEW_UpdateScroll(infoPtr
);
10017 /* refresh all only for lists whose height changed significantly */
10018 if ((infoPtr
->uView
== LV_VIEW_LIST
) &&
10019 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
10020 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
10021 LISTVIEW_InvalidateList(infoPtr
);
10028 * Sets the size information.
10031 * [I] infoPtr : valid pointer to the listview structure
10036 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
10038 TRACE("uView=%d, rcList(old)=%s\n", infoPtr
->uView
, wine_dbgstr_rect(&infoPtr
->rcList
));
10040 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
10042 if (infoPtr
->uView
== LV_VIEW_LIST
)
10044 /* Apparently the "LIST" style is supposed to have the same
10045 * number of items in a column even if there is no scroll bar.
10046 * Since if a scroll bar already exists then the bottom is already
10047 * reduced, only reduce if the scroll bar does not currently exist.
10048 * The "2" is there to mimic the native control. I think it may be
10049 * related to either padding or edges. (GLA 7/2002)
10051 if (!(infoPtr
->dwStyle
& WS_HSCROLL
))
10052 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
10053 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
10055 else if (infoPtr
->uView
== LV_VIEW_DETAILS
)
10060 hl
.prc
= &infoPtr
->rcList
;
10062 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10063 TRACE(" wp.flags=0x%08x, wp=%d,%d (%dx%d)\n", wp
.flags
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10064 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
10065 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
10066 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
10067 TRACE(" after SWP wp=%d,%d (%dx%d)\n", wp
.x
, wp
.y
, wp
.cx
, wp
.cy
);
10069 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
10070 infoPtr
->rcList
.top
+= (infoPtr
->dwLvExStyle
& LVS_EX_GRIDLINES
) ? 2 : 0;
10073 TRACE(" rcList=%s\n", wine_dbgstr_rect(&infoPtr
->rcList
));
10078 * Processes WM_STYLECHANGED messages.
10081 * [I] infoPtr : valid pointer to the listview structure
10082 * [I] wStyleType : window style type (normal or extended)
10083 * [I] lpss : window style information
10088 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10089 const STYLESTRUCT
*lpss
)
10091 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
10092 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
10095 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10096 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10098 if (wStyleType
!= GWL_STYLE
) return 0;
10100 infoPtr
->dwStyle
= lpss
->styleNew
;
10101 map_style_view(infoPtr
);
10103 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
10104 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
10105 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
10107 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
10108 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
10109 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
10111 if (uNewView
!= uOldView
)
10113 SIZE oldIconSize
= infoPtr
->iconSize
;
10116 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
10117 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
10119 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
10120 SetRectEmpty(&infoPtr
->rcFocus
);
10122 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
10123 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
10125 if (uNewView
== LVS_ICON
)
10127 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
10129 TRACE("icon old size=(%d,%d), new size=(%d,%d)\n",
10130 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
10131 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
10134 else if (uNewView
== LVS_REPORT
)
10139 LISTVIEW_CreateHeader( infoPtr
);
10141 hl
.prc
= &infoPtr
->rcList
;
10143 SendMessageW( infoPtr
->hwndHeader
, HDM_LAYOUT
, 0, (LPARAM
)&hl
);
10144 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
,
10145 wp
.flags
| ((infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
)
10146 ? SWP_HIDEWINDOW
: SWP_SHOWWINDOW
));
10149 LISTVIEW_UpdateItemSize(infoPtr
);
10152 if (uNewView
== LVS_REPORT
)
10154 if ((lpss
->styleOld
^ lpss
->styleNew
) & LVS_NOCOLUMNHEADER
)
10156 if (lpss
->styleNew
& LVS_NOCOLUMNHEADER
)
10158 /* Turn off the header control */
10159 style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
);
10160 TRACE("Hide header control, was 0x%08x\n", style
);
10161 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, style
| HDS_HIDDEN
);
10163 /* Turn on the header control */
10164 if ((style
= GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
)) & HDS_HIDDEN
)
10166 TRACE("Show header control, was 0x%08x\n", style
);
10167 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
, (style
& ~HDS_HIDDEN
) | WS_VISIBLE
);
10173 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
10174 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
10175 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
10177 /* update the size of the client area */
10178 LISTVIEW_UpdateSize(infoPtr
);
10180 /* add scrollbars if needed */
10181 LISTVIEW_UpdateScroll(infoPtr
);
10183 /* invalidate client area + erase background */
10184 LISTVIEW_InvalidateList(infoPtr
);
10191 * Processes WM_STYLECHANGING messages.
10194 * [I] infoPtr : valid pointer to the listview structure
10195 * [I] wStyleType : window style type (normal or extended)
10196 * [I0] lpss : window style information
10201 static INT
LISTVIEW_StyleChanging(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
10204 TRACE("(styletype=%lx, styleOld=0x%08x, styleNew=0x%08x)\n",
10205 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
10207 /* don't forward LVS_OWNERDATA only if not already set to */
10208 if ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_OWNERDATA
)
10210 if (lpss
->styleOld
& LVS_OWNERDATA
)
10211 lpss
->styleNew
|= LVS_OWNERDATA
;
10213 lpss
->styleNew
&= ~LVS_OWNERDATA
;
10221 * Processes WM_SHOWWINDOW messages.
10224 * [I] infoPtr : valid pointer to the listview structure
10225 * [I] bShown : window is being shown (FALSE when hidden)
10226 * [I] iStatus : window show status
10231 static LRESULT
LISTVIEW_ShowWindow(LISTVIEW_INFO
*infoPtr
, BOOL bShown
, INT iStatus
)
10233 /* header delayed creation */
10234 if ((infoPtr
->uView
== LV_VIEW_DETAILS
) && bShown
)
10236 LISTVIEW_CreateHeader(infoPtr
);
10238 if (!(LVS_NOCOLUMNHEADER
& infoPtr
->dwStyle
))
10239 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
10247 * Processes CCM_GETVERSION messages.
10250 * [I] infoPtr : valid pointer to the listview structure
10255 static inline LRESULT
LISTVIEW_GetVersion(const LISTVIEW_INFO
*infoPtr
)
10257 return infoPtr
->iVersion
;
10262 * Processes CCM_SETVERSION messages.
10265 * [I] infoPtr : valid pointer to the listview structure
10266 * [I] iVersion : version to be set
10269 * -1 when requested version is greater than DLL version;
10270 * previous version otherwise
10272 static LRESULT
LISTVIEW_SetVersion(LISTVIEW_INFO
*infoPtr
, DWORD iVersion
)
10274 INT iOldVersion
= infoPtr
->iVersion
;
10276 if (iVersion
> COMCTL32_VERSION
)
10279 infoPtr
->iVersion
= iVersion
;
10281 TRACE("new version %d\n", iVersion
);
10283 return iOldVersion
;
10288 * Window procedure of the listview control.
10291 static LRESULT WINAPI
10292 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
10294 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
10296 TRACE("(uMsg=%x wParam=%lx lParam=%lx)\n", uMsg
, wParam
, lParam
);
10298 if (!infoPtr
&& (uMsg
!= WM_NCCREATE
))
10299 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
10303 case LVM_APPROXIMATEVIEWRECT
:
10304 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
10305 LOWORD(lParam
), HIWORD(lParam
));
10307 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
10309 case LVM_CANCELEDITLABEL
:
10310 return LISTVIEW_CancelEditLabel(infoPtr
);
10312 case LVM_CREATEDRAGIMAGE
:
10313 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
10315 case LVM_DELETEALLITEMS
:
10316 return LISTVIEW_DeleteAllItems(infoPtr
, FALSE
);
10318 case LVM_DELETECOLUMN
:
10319 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
10321 case LVM_DELETEITEM
:
10322 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
10324 case LVM_EDITLABELW
:
10325 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, TRUE
);
10327 case LVM_EDITLABELA
:
10328 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, FALSE
);
10330 /* case LVM_ENABLEGROUPVIEW: */
10332 case LVM_ENSUREVISIBLE
:
10333 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
10335 case LVM_FINDITEMW
:
10336 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
10338 case LVM_FINDITEMA
:
10339 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
10341 case LVM_GETBKCOLOR
:
10342 return infoPtr
->clrBk
;
10344 /* case LVM_GETBKIMAGE: */
10346 case LVM_GETCALLBACKMASK
:
10347 return infoPtr
->uCallbackMask
;
10349 case LVM_GETCOLUMNA
:
10350 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
10352 case LVM_GETCOLUMNW
:
10353 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
10355 case LVM_GETCOLUMNORDERARRAY
:
10356 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
10358 case LVM_GETCOLUMNWIDTH
:
10359 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
10361 case LVM_GETCOUNTPERPAGE
:
10362 return LISTVIEW_GetCountPerPage(infoPtr
);
10364 case LVM_GETEDITCONTROL
:
10365 return (LRESULT
)infoPtr
->hwndEdit
;
10367 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
10368 return infoPtr
->dwLvExStyle
;
10370 /* case LVM_GETGROUPINFO: */
10372 /* case LVM_GETGROUPMETRICS: */
10374 case LVM_GETHEADER
:
10375 return (LRESULT
)infoPtr
->hwndHeader
;
10377 case LVM_GETHOTCURSOR
:
10378 return (LRESULT
)infoPtr
->hHotCursor
;
10380 case LVM_GETHOTITEM
:
10381 return infoPtr
->nHotItem
;
10383 case LVM_GETHOVERTIME
:
10384 return infoPtr
->dwHoverTime
;
10386 case LVM_GETIMAGELIST
:
10387 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
10389 /* case LVM_GETINSERTMARK: */
10391 /* case LVM_GETINSERTMARKCOLOR: */
10393 /* case LVM_GETINSERTMARKRECT: */
10395 case LVM_GETISEARCHSTRINGA
:
10396 case LVM_GETISEARCHSTRINGW
:
10397 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
10401 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
10404 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
10406 case LVM_GETITEMCOUNT
:
10407 return infoPtr
->nItemCount
;
10409 case LVM_GETITEMPOSITION
:
10410 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
10412 case LVM_GETITEMRECT
:
10413 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
10415 case LVM_GETITEMSPACING
:
10416 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
10418 case LVM_GETITEMSTATE
:
10419 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
10421 case LVM_GETITEMTEXTA
:
10422 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
10424 case LVM_GETITEMTEXTW
:
10425 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
10427 case LVM_GETNEXTITEM
:
10428 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
10430 case LVM_GETNUMBEROFWORKAREAS
:
10431 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
10434 case LVM_GETORIGIN
:
10435 if (!lParam
) return FALSE
;
10436 if (infoPtr
->uView
== LV_VIEW_DETAILS
||
10437 infoPtr
->uView
== LV_VIEW_LIST
) return FALSE
;
10438 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
10441 /* case LVM_GETOUTLINECOLOR: */
10443 /* case LVM_GETSELECTEDCOLUMN: */
10445 case LVM_GETSELECTEDCOUNT
:
10446 return LISTVIEW_GetSelectedCount(infoPtr
);
10448 case LVM_GETSELECTIONMARK
:
10449 return infoPtr
->nSelectionMark
;
10451 case LVM_GETSTRINGWIDTHA
:
10452 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, FALSE
);
10454 case LVM_GETSTRINGWIDTHW
:
10455 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, TRUE
);
10457 case LVM_GETSUBITEMRECT
:
10458 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
10460 case LVM_GETTEXTBKCOLOR
:
10461 return infoPtr
->clrTextBk
;
10463 case LVM_GETTEXTCOLOR
:
10464 return infoPtr
->clrText
;
10466 /* case LVM_GETTILEINFO: */
10468 /* case LVM_GETTILEVIEWINFO: */
10470 case LVM_GETTOOLTIPS
:
10471 if( !infoPtr
->hwndToolTip
)
10472 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
10473 return (LRESULT
)infoPtr
->hwndToolTip
;
10475 case LVM_GETTOPINDEX
:
10476 return LISTVIEW_GetTopIndex(infoPtr
);
10478 case LVM_GETUNICODEFORMAT
:
10479 return (infoPtr
->notifyFormat
== NFR_UNICODE
);
10482 return infoPtr
->uView
;
10484 case LVM_GETVIEWRECT
:
10485 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
10487 case LVM_GETWORKAREAS
:
10488 FIXME("LVM_GETWORKAREAS: unimplemented\n");
10491 /* case LVM_HASGROUP: */
10494 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, TRUE
);
10496 case LVM_INSERTCOLUMNA
:
10497 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
10499 case LVM_INSERTCOLUMNW
:
10500 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
10502 /* case LVM_INSERTGROUP: */
10504 /* case LVM_INSERTGROUPSORTED: */
10506 case LVM_INSERTITEMA
:
10507 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
10509 case LVM_INSERTITEMW
:
10510 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
10512 /* case LVM_INSERTMARKHITTEST: */
10514 /* case LVM_ISGROUPVIEWENABLED: */
10516 case LVM_ISITEMVISIBLE
:
10517 return LISTVIEW_IsItemVisible(infoPtr
, (INT
)wParam
);
10519 case LVM_MAPIDTOINDEX
:
10520 return LISTVIEW_MapIdToIndex(infoPtr
, (UINT
)wParam
);
10522 case LVM_MAPINDEXTOID
:
10523 return LISTVIEW_MapIndexToId(infoPtr
, (INT
)wParam
);
10525 /* case LVM_MOVEGROUP: */
10527 /* case LVM_MOVEITEMTOGROUP: */
10529 case LVM_REDRAWITEMS
:
10530 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
10532 /* case LVM_REMOVEALLGROUPS: */
10534 /* case LVM_REMOVEGROUP: */
10537 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
10539 case LVM_SETBKCOLOR
:
10540 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
10542 /* case LVM_SETBKIMAGE: */
10544 case LVM_SETCALLBACKMASK
:
10545 infoPtr
->uCallbackMask
= (UINT
)wParam
;
10548 case LVM_SETCOLUMNA
:
10549 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
10551 case LVM_SETCOLUMNW
:
10552 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
10554 case LVM_SETCOLUMNORDERARRAY
:
10555 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
10557 case LVM_SETCOLUMNWIDTH
:
10558 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
10560 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
10561 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
10563 /* case LVM_SETGROUPINFO: */
10565 /* case LVM_SETGROUPMETRICS: */
10567 case LVM_SETHOTCURSOR
:
10568 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
10570 case LVM_SETHOTITEM
:
10571 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
10573 case LVM_SETHOVERTIME
:
10574 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)wParam
);
10576 case LVM_SETICONSPACING
:
10577 return LISTVIEW_SetIconSpacing(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
10579 case LVM_SETIMAGELIST
:
10580 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
10582 /* case LVM_SETINFOTIP: */
10584 /* case LVM_SETINSERTMARK: */
10586 /* case LVM_SETINSERTMARKCOLOR: */
10591 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
10592 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, (uMsg
== LVM_SETITEMW
));
10595 case LVM_SETITEMCOUNT
:
10596 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
10598 case LVM_SETITEMPOSITION
:
10601 pt
.x
= (short)LOWORD(lParam
);
10602 pt
.y
= (short)HIWORD(lParam
);
10603 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, pt
);
10606 case LVM_SETITEMPOSITION32
:
10607 if (lParam
== 0) return FALSE
;
10608 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, *((POINT
*)lParam
));
10610 case LVM_SETITEMSTATE
:
10611 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
10613 case LVM_SETITEMTEXTA
:
10614 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
10616 case LVM_SETITEMTEXTW
:
10617 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
10619 /* case LVM_SETOUTLINECOLOR: */
10621 /* case LVM_SETSELECTEDCOLUMN: */
10623 case LVM_SETSELECTIONMARK
:
10624 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
10626 case LVM_SETTEXTBKCOLOR
:
10627 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
10629 case LVM_SETTEXTCOLOR
:
10630 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
10632 /* case LVM_SETTILEINFO: */
10634 /* case LVM_SETTILEVIEWINFO: */
10636 /* case LVM_SETTILEWIDTH: */
10638 case LVM_SETTOOLTIPS
:
10639 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
10641 case LVM_SETUNICODEFORMAT
:
10642 return LISTVIEW_SetUnicodeFormat(infoPtr
, wParam
);
10645 return LISTVIEW_SetView(infoPtr
, wParam
);
10647 /* case LVM_SETWORKAREAS: */
10649 /* case LVM_SORTGROUPS: */
10651 case LVM_SORTITEMS
:
10652 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, (LPARAM
)wParam
, FALSE
);
10654 case LVM_SORTITEMSEX
:
10655 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, (LPARAM
)wParam
, TRUE
);
10657 case LVM_SUBITEMHITTEST
:
10658 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
10661 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
10663 case CCM_GETVERSION
:
10664 return LISTVIEW_GetVersion(infoPtr
);
10666 case CCM_SETVERSION
:
10667 return LISTVIEW_SetVersion(infoPtr
, wParam
);
10670 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
10673 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
10676 return LISTVIEW_NCCreate(hwnd
, (LPCREATESTRUCTW
)lParam
);
10679 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
10682 return LISTVIEW_Destroy(infoPtr
);
10685 return LISTVIEW_Enable(infoPtr
, (BOOL
)wParam
);
10687 case WM_ERASEBKGND
:
10688 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
10690 case WM_GETDLGCODE
:
10691 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
10694 return (LRESULT
)infoPtr
->hFont
;
10697 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
10700 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
10703 return LISTVIEW_KillFocus(infoPtr
);
10705 case WM_LBUTTONDBLCLK
:
10706 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10708 case WM_LBUTTONDOWN
:
10709 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10712 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10715 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10717 case WM_MOUSEHOVER
:
10718 return LISTVIEW_MouseHover(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10721 return LISTVIEW_NCDestroy(infoPtr
);
10724 if (LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
))
10729 if (lParam
&& ((LPNMHDR
)lParam
)->hwndFrom
== infoPtr
->hwndHeader
)
10730 return LISTVIEW_HeaderNotification(infoPtr
, (LPNMHEADERW
)lParam
);
10733 case WM_NOTIFYFORMAT
:
10734 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
10736 case WM_PRINTCLIENT
:
10737 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
10740 return LISTVIEW_Paint(infoPtr
, (HDC
)wParam
);
10742 case WM_RBUTTONDBLCLK
:
10743 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10745 case WM_RBUTTONDOWN
:
10746 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10749 return LISTVIEW_RButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
10752 if(LISTVIEW_SetCursor(infoPtr
, (HWND
)wParam
, LOWORD(lParam
), HIWORD(lParam
)))
10757 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
10760 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
10763 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
10765 case WM_SHOWWINDOW
:
10766 LISTVIEW_ShowWindow(infoPtr
, (BOOL
)wParam
, (INT
)lParam
);
10767 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
10770 return LISTVIEW_Size(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
10772 case WM_STYLECHANGED
:
10773 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
10775 case WM_STYLECHANGING
:
10776 return LISTVIEW_StyleChanging(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
10778 case WM_SYSCOLORCHANGE
:
10779 COMCTL32_RefreshSysColors();
10782 /* case WM_TIMER: */
10783 case WM_THEMECHANGED
:
10784 return LISTVIEW_ThemeChanged(infoPtr
);
10787 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
10789 case WM_MOUSEWHEEL
:
10790 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
10791 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
10792 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
10794 case WM_WINDOWPOSCHANGED
:
10795 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
10797 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
10798 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
10800 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (infoPtr
->uView
== LV_VIEW_DETAILS
))
10802 if (notify_measureitem(infoPtr
)) LISTVIEW_InvalidateList(infoPtr
);
10805 LISTVIEW_UpdateSize(infoPtr
);
10806 LISTVIEW_UpdateScroll(infoPtr
);
10808 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
10810 /* case WM_WININICHANGE: */
10813 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
) && !COMCTL32_IsReflectedMessage(uMsg
))
10814 ERR("unknown msg %04x wp=%08lx lp=%08lx\n", uMsg
, wParam
, lParam
);
10817 /* call default window procedure */
10818 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
10825 * Registers the window class.
10833 void LISTVIEW_Register(void)
10835 WNDCLASSW wndClass
;
10837 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
10838 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
10839 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
10840 wndClass
.cbClsExtra
= 0;
10841 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
10842 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
10843 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
10844 wndClass
.lpszClassName
= WC_LISTVIEWW
;
10845 RegisterClassW(&wndClass
);
10850 * Unregisters the window class.
10858 void LISTVIEW_Unregister(void)
10860 UnregisterClassW(WC_LISTVIEWW
, NULL
);
10865 * Handle any WM_COMMAND messages
10868 * [I] infoPtr : valid pointer to the listview structure
10869 * [I] wParam : the first message parameter
10870 * [I] lParam : the second message parameter
10875 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
10877 switch (HIWORD(wParam
))
10882 * Adjust the edit window size
10884 WCHAR buffer
[1024];
10885 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
10886 HFONT hFont
, hOldFont
= 0;
10890 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
10891 GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
10892 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
10894 /* Select font to get the right dimension of the string */
10895 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
10898 hOldFont
= SelectObject(hdc
, hFont
);
10901 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
10903 TEXTMETRICW textMetric
;
10905 /* Add Extra spacing for the next character */
10906 GetTextMetricsW(hdc
, &textMetric
);
10907 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
10915 rect
.bottom
- rect
.top
,
10916 SWP_DRAWFRAME
|SWP_NOMOVE
);
10919 SelectObject(hdc
, hOldFont
);
10921 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
10927 LISTVIEW_CancelEditLabel(infoPtr
);
10931 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
10940 * Subclassed edit control windproc function
10943 * [I] hwnd : the edit window handle
10944 * [I] uMsg : the message that is to be processed
10945 * [I] wParam : first message parameter
10946 * [I] lParam : second message parameter
10947 * [I] isW : TRUE if input is Unicode
10952 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
10954 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
10957 TRACE("(hwnd=%p, uMsg=%x, wParam=%lx, lParam=%lx, isW=%d)\n",
10958 hwnd
, uMsg
, wParam
, lParam
, isW
);
10962 case WM_GETDLGCODE
:
10963 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
10967 WNDPROC editProc
= infoPtr
->EditWndProc
;
10968 infoPtr
->EditWndProc
= 0;
10969 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
10970 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
10974 if (VK_ESCAPE
== (INT
)wParam
)
10979 else if (VK_RETURN
== (INT
)wParam
)
10983 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
10986 /* kill the edit */
10987 if (infoPtr
->hwndEdit
)
10988 LISTVIEW_EndEditLabelT(infoPtr
, save
, isW
);
10990 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
10996 * Subclassed edit control Unicode windproc function
10999 * [I] hwnd : the edit window handle
11000 * [I] uMsg : the message that is to be processed
11001 * [I] wParam : first message parameter
11002 * [I] lParam : second message parameter
11006 static LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11008 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
11013 * Subclassed edit control ANSI windproc function
11016 * [I] hwnd : the edit window handle
11017 * [I] uMsg : the message that is to be processed
11018 * [I] wParam : first message parameter
11019 * [I] lParam : second message parameter
11023 static LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
11025 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
11030 * Creates a subclassed edit control
11033 * [I] infoPtr : valid pointer to the listview structure
11034 * [I] text : initial text for the edit
11035 * [I] style : the window style
11036 * [I] isW : TRUE if input is Unicode
11040 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, DWORD style
, BOOL isW
)
11042 WCHAR editName
[5] = { 'E', 'd', 'i', 't', '\0' };
11044 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
11046 TRACE("(text=%s, ..., isW=%d)\n", debugtext_t(text
, isW
), isW
);
11048 style
|= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
;
11050 /* Window will be resized and positioned after LVN_BEGINLABELEDIT */
11052 hedit
= CreateWindowW(editName
, text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
11054 hedit
= CreateWindowA("Edit", (LPCSTR
)text
, style
, 0, 0, 0, 0, infoPtr
->hwndSelf
, 0, hinst
, 0);
11056 if (!hedit
) return 0;
11058 infoPtr
->EditWndProc
= (WNDPROC
)
11059 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
11060 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
11062 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);