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
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * This code was audited for completeness against the documented features
27 * of Comctl32.dll version 6.0 on May. 20, 2005, by James Hawkins.
29 * Unless otherwise noted, we believe this code to be complete, as per
30 * the specification mentioned above.
31 * If you discover missing features, or bugs, please note them below.
35 * Default Message Processing
36 * -- EN_KILLFOCUS should be handled in WM_COMMAND
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_ERASEBKGND: forward this message to the parent window if the bkgnd
41 * -- WM_WINDOWPOSCHANGED: arrange the list items if the current view is icon
42 * or small icon and the LVS_AUTOARRANGE style is specified.
47 * -- Hot item handling, mouse hovering
48 * -- Workareas support
53 * -- Expand large item in ICON mode when the cursor is flying over the icon or text.
54 * -- Support CustomDraw options for _WIN32_IE >= 0x560 (see NMLVCUSTOMDRAW docs).
55 * -- LVA_SNAPTOGRID not implemented
56 * -- LISTVIEW_ApproximateViewRect partially implemented
57 * -- LISTVIEW_[GS]etColumnOrderArray stubs
58 * -- LISTVIEW_SetColumnWidth ignores header images & bitmap
59 * -- LISTVIEW_SetIconSpacing is incomplete
60 * -- LISTVIEW_SortItems is broken
61 * -- LISTVIEW_StyleChanged doesn't handle some changes too well
64 * -- LISTVIEW_GetNextItem needs to be rewritten. It is currently
65 * linear in the number of items in the list, and this is
66 * unacceptable for large lists.
67 * -- in sorted mode, LISTVIEW_InsertItemT sorts the array,
68 * instead of inserting in the right spot
69 * -- we should keep an ordered array of coordinates in iconic mode
70 * this would allow to frame items (iterator_frameditems),
71 * and find nearest item (LVFI_NEARESTXY) a lot more efficiently
79 * -- LVIS_ACTIVATING (not currently supported by comctl32.dll version 6.0)
86 * -- LVS_NOSCROLL (see Q137520)
87 * -- LVS_SORTASCENDING, LVS_SORTDESCENDING
89 * -- LVS_TYPESTYLEMASK
92 * -- LVS_EX_BORDERSELECT
95 * -- LVS_EX_HEADERDRAGDROP
98 * -- LVS_EX_MULTIWORKAREAS
99 * -- LVS_EX_ONECLICKACTIVATE
101 * -- LVS_EX_SIMPLESELECT
102 * -- LVS_EX_TRACKSELECT
103 * -- LVS_EX_TWOCLICKACTIVATE
104 * -- LVS_EX_UNDERLINECOLD
105 * -- LVS_EX_UNDERLINEHOT
108 * -- LVN_BEGINSCROLL, LVN_ENDSCROLL
111 * -- LVN_MARQUEEBEGIN
118 * -- LVM_CANCELEDITLABEL
119 * -- LVM_ENABLEGROUPVIEW
120 * -- LVM_GETBKIMAGE, LVM_SETBKIMAGE
121 * -- LVM_GETGROUPINFO, LVM_SETGROUPINFO
122 * -- LVM_GETGROUPMETRICS, LVM_SETGROUPMETRICS
123 * -- LVM_GETINSERTMARK, LVM_SETINSERTMARK
124 * -- LVM_GETINSERTMARKCOLOR, LVM_SETINSERTMARKCOLOR
125 * -- LVM_GETINSERTMARKRECT
126 * -- LVM_GETNUMBEROFWORKAREAS
127 * -- LVM_GETOUTLINECOLOR, LVM_SETOUTLINECOLOR
128 * -- LVM_GETSELECTEDCOLUMN, LVM_SETSELECTEDCOLUMN
129 * -- LVM_GETISEARCHSTRINGW, LVM_GETISEARCHSTRINGA
130 * -- LVM_GETTILEINFO, LVM_SETTILEINFO
131 * -- LVM_GETTILEVIEWINFO, LVM_SETTILEVIEWINFO
132 * -- LVM_GETUNICODEFORMAT, LVM_SETUNICODEFORMAT
133 * -- LVM_GETVIEW, LVM_SETVIEW
134 * -- LVM_GETWORKAREAS, LVM_SETWORKAREAS
135 * -- LVM_HASGROUP, LVM_INSERTGROUP, LVM_REMOVEGROUP, LVM_REMOVEALLGROUPS
136 * -- LVM_INSERTGROUPSORTED
137 * -- LVM_INSERTMARKHITTEST
138 * -- LVM_ISGROUPVIEWENABLED
139 * -- LVM_MAPIDTOINDEX, LVM_MAPINDEXTOID
141 * -- LVM_MOVEITEMTOGROUP
143 * -- LVM_SETTILEWIDTH
148 * -- ListView_GetCheckSate, ListView_SetCheckState
149 * -- ListView_GetHoverTime, ListView_SetHoverTime
150 * -- ListView_GetISearchString
151 * -- ListView_GetNumberOfWorkAreas
152 * -- ListView_GetOrigin
153 * -- ListView_GetTextBkColor
154 * -- ListView_GetUnicodeFormat, ListView_SetUnicodeFormat
155 * -- ListView_GetWorkAreas, ListView_SetWorkAreas
156 * -- ListView_SortItemsEx
161 * Known differences in message stream from native control (not known if
162 * these differences cause problems):
163 * LVM_INSERTITEM issues LVM_SETITEMSTATE and LVM_SETITEM in certain cases.
164 * LVM_SETITEM does not always issue LVN_ITEMCHANGING/LVN_ITEMCHANGED.
165 * WM_CREATE does not issue WM_QUERYUISTATE and associated registry
166 * processing for "USEDOUBLECLICKTIME".
170 #include "wine/port.h"
186 #include "commctrl.h"
187 #include "comctl32.h"
190 #include "wine/debug.h"
191 #include "wine/unicode.h"
193 WINE_DEFAULT_DEBUG_CHANNEL(listview
);
195 /* make sure you set this to 0 for production use! */
196 #define DEBUG_RANGES 1
198 typedef struct tagCOLUMN_INFO
200 RECT rcHeader
; /* tracks the header's rectangle */
201 int fmt
; /* same as LVCOLUMN.fmt */
204 typedef struct tagITEMHDR
208 } ITEMHDR
, *LPITEMHDR
;
210 typedef struct tagSUBITEM_INFO
216 typedef struct tagITEM_INFO
224 typedef struct tagRANGE
230 typedef struct tagRANGES
235 typedef struct tagITERATOR
244 typedef struct tagLISTVIEW_INFO
251 COLORREF clrTextBkDefault
;
252 HIMAGELIST himlNormal
;
253 HIMAGELIST himlSmall
;
254 HIMAGELIST himlState
;
257 POINT ptClickPos
; /* point where the user clicked */
258 BOOL bNoItemMetrics
; /* flags if item metrics are not yet computed */
261 RANGES selectionRanges
;
266 RECT rcList
; /* This rectangle is really the window
267 * client rectangle possibly reduced by the
268 * horizontal scroll bar and/or header - see
269 * LISTVIEW_UpdateSize. This rectangle offset
270 * by the LISTVIEW_GetOrigin value is in
271 * client coordinates */
280 INT ntmHeight
; /* Some cached metrics of the font used */
281 INT ntmMaxCharWidth
; /* by the listview to draw items */
283 BOOL bRedraw
; /* Turns on/off repaints & invalidations */
284 BOOL bAutoarrange
; /* Autoarrange flag when NOT in LVS_AUTOARRANGE */
286 BOOL bDoChangeNotify
; /* send change notification messages? */
289 DWORD dwStyle
; /* the cached window GWL_STYLE */
290 DWORD dwLvExStyle
; /* extended listview style */
291 INT nItemCount
; /* the number of items in the list */
292 HDPA hdpaItems
; /* array ITEM_INFO pointers */
293 HDPA hdpaPosX
; /* maintains the (X, Y) coordinates of the */
294 HDPA hdpaPosY
; /* items in LVS_ICON, and LVS_SMALLICON modes */
295 HDPA hdpaColumns
; /* array of COLUMN_INFO pointers */
296 POINT currIconPos
; /* this is the position next icon will be placed */
297 PFNLVCOMPARE pfnCompare
;
305 DWORD cditemmode
; /* Keep the custom draw flags for an item/row */
307 DWORD lastKeyPressTimestamp
;
309 INT nSearchParamLength
;
310 WCHAR szSearchParam
[ MAX_PATH
];
312 INT nMeasureItemHeight
;
318 /* How many we debug buffer to allocate */
319 #define DEBUG_BUFFERS 20
320 /* The size of a single debug bbuffer */
321 #define DEBUG_BUFFER_SIZE 256
323 /* Internal interface to LISTVIEW_HScroll and LISTVIEW_VScroll */
324 #define SB_INTERNAL -1
326 /* maximum size of a label */
327 #define DISP_TEXT_SIZE 512
329 /* padding for items in list and small icon display modes */
330 #define WIDTH_PADDING 12
332 /* padding for items in list, report and small icon display modes */
333 #define HEIGHT_PADDING 1
335 /* offset of items in report display mode */
336 #define REPORT_MARGINX 2
338 /* padding for icon in large icon display mode
339 * ICON_TOP_PADDING_NOTHITABLE - space between top of box and area
340 * that HITTEST will see.
341 * ICON_TOP_PADDING_HITABLE - spacing between above and icon.
342 * ICON_TOP_PADDING - sum of the two above.
343 * ICON_BOTTOM_PADDING - between bottom of icon and top of text
344 * LABEL_HOR_PADDING - between text and sides of box
345 * LABEL_VERT_PADDING - between bottom of text and end of box
347 * ICON_LR_PADDING - additional width above icon size.
348 * ICON_LR_HALF - half of the above value
350 #define ICON_TOP_PADDING_NOTHITABLE 2
351 #define ICON_TOP_PADDING_HITABLE 2
352 #define ICON_TOP_PADDING (ICON_TOP_PADDING_NOTHITABLE + ICON_TOP_PADDING_HITABLE)
353 #define ICON_BOTTOM_PADDING 4
354 #define LABEL_HOR_PADDING 5
355 #define LABEL_VERT_PADDING 7
356 #define ICON_LR_PADDING 16
357 #define ICON_LR_HALF (ICON_LR_PADDING/2)
359 /* default label width for items in list and small icon display modes */
360 #define DEFAULT_LABEL_WIDTH 40
362 /* default column width for items in list display mode */
363 #define DEFAULT_COLUMN_WIDTH 128
365 /* Size of "line" scroll for V & H scrolls */
366 #define LISTVIEW_SCROLL_ICON_LINE_SIZE 37
368 /* Padding betwen image and label */
369 #define IMAGE_PADDING 2
371 /* Padding behind the label */
372 #define TRAILING_LABEL_PADDING 12
373 #define TRAILING_HEADER_PADDING 11
375 /* Border for the icon caption */
376 #define CAPTION_BORDER 2
378 /* Standard DrawText flags */
379 #define LV_ML_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
380 #define LV_FL_DT_FLAGS (DT_TOP | DT_NOPREFIX | DT_EDITCONTROL | DT_CENTER | DT_WORDBREAK | DT_NOCLIP)
381 #define LV_SL_DT_FLAGS (DT_VCENTER | DT_NOPREFIX | DT_EDITCONTROL | DT_SINGLELINE | DT_WORD_ELLIPSIS | DT_END_ELLIPSIS)
383 /* Image index from state */
384 #define STATEIMAGEINDEX(x) (((x) & LVIS_STATEIMAGEMASK) >> 12)
386 /* The time in milliseconds to reset the search in the list */
387 #define KEY_DELAY 450
389 /* Dump the LISTVIEW_INFO structure to the debug channel */
390 #define LISTVIEW_DUMP(iP) do { \
391 TRACE("hwndSelf=%p, clrBk=0x%06lx, clrText=0x%06lx, clrTextBk=0x%06lx, ItemHeight=%d, ItemWidth=%d, Style=0x%08lx\n", \
392 iP->hwndSelf, iP->clrBk, iP->clrText, iP->clrTextBk, \
393 iP->nItemHeight, iP->nItemWidth, iP->dwStyle); \
394 TRACE("hwndSelf=%p, himlNor=%p, himlSml=%p, himlState=%p, Focused=%d, Hot=%d, exStyle=0x%08lx, Focus=%d\n", \
395 iP->hwndSelf, iP->himlNormal, iP->himlSmall, iP->himlState, \
396 iP->nFocusedItem, iP->nHotItem, iP->dwLvExStyle, iP->bFocus ); \
397 TRACE("hwndSelf=%p, ntmH=%d, icSz.cx=%ld, icSz.cy=%ld, icSp.cx=%ld, icSp.cy=%ld, notifyFmt=%d\n", \
398 iP->hwndSelf, iP->ntmHeight, iP->iconSize.cx, iP->iconSize.cy, \
399 iP->iconSpacing.cx, iP->iconSpacing.cy, iP->notifyFormat); \
400 TRACE("hwndSelf=%p, rcList=%s\n", iP->hwndSelf, debugrect(&iP->rcList)); \
403 static const WCHAR themeClass
[] = {'L','i','s','t','V','i','e','w',0};
406 * forward declarations
408 static BOOL
LISTVIEW_GetItemT(LISTVIEW_INFO
*, LPLVITEMW
, BOOL
);
409 static void LISTVIEW_GetItemBox(LISTVIEW_INFO
*, INT
, LPRECT
);
410 static void LISTVIEW_GetItemOrigin(LISTVIEW_INFO
*, INT
, LPPOINT
);
411 static BOOL
LISTVIEW_GetItemPosition(LISTVIEW_INFO
*, INT
, LPPOINT
);
412 static BOOL
LISTVIEW_GetItemRect(LISTVIEW_INFO
*, INT
, LPRECT
);
413 static INT
LISTVIEW_GetLabelWidth(LISTVIEW_INFO
*, INT
);
414 static void LISTVIEW_GetOrigin(LISTVIEW_INFO
*, LPPOINT
);
415 static BOOL
LISTVIEW_GetViewRect(LISTVIEW_INFO
*, LPRECT
);
416 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*, INT
);
417 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*, const LVITEMW
*, BOOL
);
418 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*);
419 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*, INT
);
420 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*);
421 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*, INT
, BOOL
);
422 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*, WPARAM
, LPARAM
);
423 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*, PFNLVCOMPARE
, LPARAM
);
424 static INT
LISTVIEW_GetStringWidthT(LISTVIEW_INFO
*, LPCWSTR
, BOOL
);
425 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*, INT
);
426 static UINT
LISTVIEW_GetItemState(LISTVIEW_INFO
*, INT
, UINT
);
427 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*, INT
, const LVITEMW
*);
428 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
429 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*, INT
, INT
, HWND
);
430 static INT
LISTVIEW_GetTopIndex(LISTVIEW_INFO
*);
431 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*, INT
, BOOL
);
432 static HWND
CreateEditLabelT(LISTVIEW_INFO
*, LPCWSTR
, DWORD
, INT
, INT
, INT
, INT
, BOOL
);
433 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*, INT
, HIMAGELIST
);
434 static INT
LISTVIEW_HitTest(LISTVIEW_INFO
*, LPLVHITTESTINFO
, BOOL
, BOOL
);
436 /******** Text handling functions *************************************/
438 /* A text pointer is either NULL, LPSTR_TEXTCALLBACK, or points to a
439 * text string. The string may be ANSI or Unicode, in which case
440 * the boolean isW tells us the type of the string.
442 * The name of the function tell what type of strings it expects:
443 * W: Unicode, T: ANSI/Unicode - function of isW
446 static inline BOOL
is_textW(LPCWSTR text
)
448 return text
!= NULL
&& text
!= LPSTR_TEXTCALLBACKW
;
451 static inline BOOL
is_textT(LPCWSTR text
, BOOL isW
)
453 /* we can ignore isW since LPSTR_TEXTCALLBACKW == LPSTR_TEXTCALLBACKA */
454 return is_textW(text
);
457 static inline int textlenT(LPCWSTR text
, BOOL isW
)
459 return !is_textT(text
, isW
) ? 0 :
460 isW
? lstrlenW(text
) : lstrlenA((LPCSTR
)text
);
463 static inline void textcpynT(LPWSTR dest
, BOOL isDestW
, LPCWSTR src
, BOOL isSrcW
, INT max
)
466 if (isSrcW
) lstrcpynW(dest
, src
, max
);
467 else MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)src
, -1, dest
, max
);
469 if (isSrcW
) WideCharToMultiByte(CP_ACP
, 0, src
, -1, (LPSTR
)dest
, max
, NULL
, NULL
);
470 else lstrcpynA((LPSTR
)dest
, (LPCSTR
)src
, max
);
473 static inline LPWSTR
textdupTtoW(LPCWSTR text
, BOOL isW
)
475 LPWSTR wstr
= (LPWSTR
)text
;
477 if (!isW
&& is_textT(text
, isW
))
479 INT len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, NULL
, 0);
480 wstr
= Alloc(len
* sizeof(WCHAR
));
481 if (wstr
) MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)text
, -1, wstr
, len
);
483 TRACE(" wstr=%s\n", text
== LPSTR_TEXTCALLBACKW
? "(callback)" : debugstr_w(wstr
));
487 static inline void textfreeT(LPWSTR wstr
, BOOL isW
)
489 if (!isW
&& is_textT(wstr
, isW
)) Free (wstr
);
493 * dest is a pointer to a Unicode string
494 * src is a pointer to a string (Unicode if isW, ANSI if !isW)
496 static BOOL
textsetptrT(LPWSTR
*dest
, LPWSTR src
, BOOL isW
)
500 if (src
== LPSTR_TEXTCALLBACKW
)
502 if (is_textW(*dest
)) Free(*dest
);
503 *dest
= LPSTR_TEXTCALLBACKW
;
507 LPWSTR pszText
= textdupTtoW(src
, isW
);
508 if (*dest
== LPSTR_TEXTCALLBACKW
) *dest
= NULL
;
509 bResult
= Str_SetPtrW(dest
, pszText
);
510 textfreeT(pszText
, isW
);
516 * compares a Unicode to a Unicode/ANSI text string
518 static inline int textcmpWT(LPCWSTR aw
, LPCWSTR bt
, BOOL isW
)
520 if (!aw
) return bt
? -1 : 0;
521 if (!bt
) return aw
? 1 : 0;
522 if (aw
== LPSTR_TEXTCALLBACKW
)
523 return bt
== LPSTR_TEXTCALLBACKW
? 0 : -1;
524 if (bt
!= LPSTR_TEXTCALLBACKW
)
526 LPWSTR bw
= textdupTtoW(bt
, isW
);
527 int r
= bw
? lstrcmpW(aw
, bw
) : 1;
535 static inline int lstrncmpiW(LPCWSTR s1
, LPCWSTR s2
, int n
)
539 n
= min(min(n
, strlenW(s1
)), strlenW(s2
));
540 res
= CompareStringW(LOCALE_USER_DEFAULT
, NORM_IGNORECASE
, s1
, n
, s2
, n
);
541 return res
? res
- sizeof(WCHAR
) : res
;
544 /******** Debugging functions *****************************************/
546 static inline LPCSTR
debugtext_t(LPCWSTR text
, BOOL isW
)
548 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
549 return isW
? debugstr_w(text
) : debugstr_a((LPCSTR
)text
);
552 static inline LPCSTR
debugtext_tn(LPCWSTR text
, BOOL isW
, INT n
)
554 if (text
== LPSTR_TEXTCALLBACKW
) return "(callback)";
555 n
= min(textlenT(text
, isW
), n
);
556 return isW
? debugstr_wn(text
, n
) : debugstr_an((LPCSTR
)text
, n
);
559 static char* debug_getbuf(void)
561 static int index
= 0;
562 static char buffers
[DEBUG_BUFFERS
][DEBUG_BUFFER_SIZE
];
563 return buffers
[index
++ % DEBUG_BUFFERS
];
566 static inline const char* debugrange(const RANGE
*lprng
)
570 char* buf
= debug_getbuf();
571 snprintf(buf
, DEBUG_BUFFER_SIZE
, "[%d, %d)", lprng
->lower
, lprng
->upper
);
573 } else return "(null)";
576 static inline const char* debugpoint(const POINT
*lppt
)
580 char* buf
= debug_getbuf();
581 snprintf(buf
, DEBUG_BUFFER_SIZE
, "(%ld, %ld)", lppt
->x
, lppt
->y
);
583 } else return "(null)";
586 static inline const char* debugrect(const RECT
*rect
)
590 char* buf
= debug_getbuf();
591 snprintf(buf
, DEBUG_BUFFER_SIZE
, "[(%ld, %ld);(%ld, %ld)]",
592 rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
594 } else return "(null)";
597 static const char* debugscrollinfo(const SCROLLINFO
*pScrollInfo
)
599 char* buf
= debug_getbuf(), *text
= buf
;
600 int len
, size
= DEBUG_BUFFER_SIZE
;
602 if (pScrollInfo
== NULL
) return "(null)";
603 len
= snprintf(buf
, size
, "{cbSize=%d, ", pScrollInfo
->cbSize
);
604 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
605 if (pScrollInfo
->fMask
& SIF_RANGE
)
606 len
= snprintf(buf
, size
, "nMin=%d, nMax=%d, ", pScrollInfo
->nMin
, pScrollInfo
->nMax
);
608 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
609 if (pScrollInfo
->fMask
& SIF_PAGE
)
610 len
= snprintf(buf
, size
, "nPage=%u, ", pScrollInfo
->nPage
);
612 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
613 if (pScrollInfo
->fMask
& SIF_POS
)
614 len
= snprintf(buf
, size
, "nPos=%d, ", pScrollInfo
->nPos
);
616 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
617 if (pScrollInfo
->fMask
& SIF_TRACKPOS
)
618 len
= snprintf(buf
, size
, "nTrackPos=%d, ", pScrollInfo
->nTrackPos
);
620 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
623 buf
= text
+ strlen(text
);
625 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
629 static const char* debugnmlistview(const NMLISTVIEW
*plvnm
)
633 char* buf
= debug_getbuf();
634 snprintf(buf
, DEBUG_BUFFER_SIZE
, "iItem=%d, iSubItem=%d, uNewState=0x%x,"
635 " uOldState=0x%x, uChanged=0x%x, ptAction=%s, lParam=%ld\n",
636 plvnm
->iItem
, plvnm
->iSubItem
, plvnm
->uNewState
, plvnm
->uOldState
,
637 plvnm
->uChanged
, debugpoint(&plvnm
->ptAction
), plvnm
->lParam
);
639 } else return "(null)";
642 static const char* debuglvitem_t(const LVITEMW
*lpLVItem
, BOOL isW
)
644 char* buf
= debug_getbuf(), *text
= buf
;
645 int len
, size
= DEBUG_BUFFER_SIZE
;
647 if (lpLVItem
== NULL
) return "(null)";
648 len
= snprintf(buf
, size
, "{iItem=%d, iSubItem=%d, ", lpLVItem
->iItem
, lpLVItem
->iSubItem
);
649 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
650 if (lpLVItem
->mask
& LVIF_STATE
)
651 len
= snprintf(buf
, size
, "state=%x, stateMask=%x, ", lpLVItem
->state
, lpLVItem
->stateMask
);
653 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
654 if (lpLVItem
->mask
& LVIF_TEXT
)
655 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpLVItem
->pszText
, isW
, 80), lpLVItem
->cchTextMax
);
657 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
658 if (lpLVItem
->mask
& LVIF_IMAGE
)
659 len
= snprintf(buf
, size
, "iImage=%d, ", lpLVItem
->iImage
);
661 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
662 if (lpLVItem
->mask
& LVIF_PARAM
)
663 len
= snprintf(buf
, size
, "lParam=%lx, ", lpLVItem
->lParam
);
665 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
666 if (lpLVItem
->mask
& LVIF_INDENT
)
667 len
= snprintf(buf
, size
, "iIndent=%d, ", lpLVItem
->iIndent
);
669 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
672 buf
= text
+ strlen(text
);
674 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
678 static const char* debuglvcolumn_t(const LVCOLUMNW
*lpColumn
, BOOL isW
)
680 char* buf
= debug_getbuf(), *text
= buf
;
681 int len
, size
= DEBUG_BUFFER_SIZE
;
683 if (lpColumn
== NULL
) return "(null)";
684 len
= snprintf(buf
, size
, "{");
685 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
686 if (lpColumn
->mask
& LVCF_SUBITEM
)
687 len
= snprintf(buf
, size
, "iSubItem=%d, ", lpColumn
->iSubItem
);
689 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
690 if (lpColumn
->mask
& LVCF_FMT
)
691 len
= snprintf(buf
, size
, "fmt=%x, ", lpColumn
->fmt
);
693 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
694 if (lpColumn
->mask
& LVCF_WIDTH
)
695 len
= snprintf(buf
, size
, "cx=%d, ", lpColumn
->cx
);
697 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
698 if (lpColumn
->mask
& LVCF_TEXT
)
699 len
= snprintf(buf
, size
, "pszText=%s, cchTextMax=%d, ", debugtext_tn(lpColumn
->pszText
, isW
, 80), lpColumn
->cchTextMax
);
701 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
702 if (lpColumn
->mask
& LVCF_IMAGE
)
703 len
= snprintf(buf
, size
, "iImage=%d, ", lpColumn
->iImage
);
705 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
706 if (lpColumn
->mask
& LVCF_ORDER
)
707 len
= snprintf(buf
, size
, "iOrder=%d, ", lpColumn
->iOrder
);
709 if (len
== -1) goto end
; buf
+= len
; size
-= len
;
712 buf
= text
+ strlen(text
);
714 if (buf
- text
> 2) { buf
[-2] = '}'; buf
[-1] = 0; }
718 static const char* debuglvhittestinfo(const LVHITTESTINFO
*lpht
)
722 char* buf
= debug_getbuf();
723 snprintf(buf
, DEBUG_BUFFER_SIZE
, "{pt=%s, flags=0x%x, iItem=%d, iSubItem=%d}",
724 debugpoint(&lpht
->pt
), lpht
->flags
, lpht
->iItem
, lpht
->iSubItem
);
726 } else return "(null)";
729 /* Return the corresponding text for a given scroll value */
730 static inline LPCSTR
debugscrollcode(int nScrollCode
)
734 case SB_LINELEFT
: return "SB_LINELEFT";
735 case SB_LINERIGHT
: return "SB_LINERIGHT";
736 case SB_PAGELEFT
: return "SB_PAGELEFT";
737 case SB_PAGERIGHT
: return "SB_PAGERIGHT";
738 case SB_THUMBPOSITION
: return "SB_THUMBPOSITION";
739 case SB_THUMBTRACK
: return "SB_THUMBTRACK";
740 case SB_ENDSCROLL
: return "SB_ENDSCROLL";
741 case SB_INTERNAL
: return "SB_INTERNAL";
742 default: return "unknown";
747 /******** Notification functions i************************************/
749 static LRESULT
notify_forward_header(LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
751 return SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
752 (WPARAM
)lpnmh
->hdr
.idFrom
, (LPARAM
)lpnmh
);
755 static LRESULT
notify_hdr(LISTVIEW_INFO
*infoPtr
, INT code
, LPNMHDR pnmh
)
759 TRACE("(code=%d)\n", code
);
761 pnmh
->hwndFrom
= infoPtr
->hwndSelf
;
762 pnmh
->idFrom
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
764 result
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFY
,
765 (WPARAM
)pnmh
->idFrom
, (LPARAM
)pnmh
);
767 TRACE(" <= %ld\n", result
);
772 static inline BOOL
notify(LISTVIEW_INFO
*infoPtr
, INT code
)
775 HWND hwnd
= infoPtr
->hwndSelf
;
776 notify_hdr(infoPtr
, code
, &nmh
);
777 return IsWindow(hwnd
);
780 static inline void notify_itemactivate(LISTVIEW_INFO
*infoPtr
, LVHITTESTINFO
*htInfo
)
791 item
.mask
= LVIF_PARAM
|LVIF_STATE
;
792 item
.iItem
= htInfo
->iItem
;
794 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) {
795 nmia
.lParam
= item
.lParam
;
796 nmia
.uOldState
= item
.state
;
797 nmia
.uNewState
= item
.state
| LVIS_ACTIVATING
;
798 nmia
.uChanged
= LVIF_STATE
;
801 nmia
.iItem
= htInfo
->iItem
;
802 nmia
.iSubItem
= htInfo
->iSubItem
;
803 nmia
.ptAction
= htInfo
->pt
;
805 if (GetKeyState(VK_SHIFT
) & 0x8000) nmia
.uKeyFlags
|= LVKF_SHIFT
;
806 if (GetKeyState(VK_CONTROL
) & 0x8000) nmia
.uKeyFlags
|= LVKF_CONTROL
;
807 if (GetKeyState(VK_MENU
) & 0x8000) nmia
.uKeyFlags
|= LVKF_ALT
;
809 notify_hdr(infoPtr
, LVN_ITEMACTIVATE
, (LPNMHDR
)&nmia
);
812 static inline LRESULT
notify_listview(LISTVIEW_INFO
*infoPtr
, INT code
, LPNMLISTVIEW plvnm
)
814 TRACE("(code=%d, plvnm=%s)\n", code
, debugnmlistview(plvnm
));
815 return notify_hdr(infoPtr
, code
, (LPNMHDR
)plvnm
);
818 static BOOL
notify_click(LISTVIEW_INFO
*infoPtr
, INT code
, LVHITTESTINFO
*lvht
)
822 HWND hwnd
= infoPtr
->hwndSelf
;
824 TRACE("code=%d, lvht=%s\n", code
, debuglvhittestinfo(lvht
));
825 ZeroMemory(&nmlv
, sizeof(nmlv
));
826 nmlv
.iItem
= lvht
->iItem
;
827 nmlv
.iSubItem
= lvht
->iSubItem
;
828 nmlv
.ptAction
= lvht
->pt
;
829 item
.mask
= LVIF_PARAM
;
830 item
.iItem
= lvht
->iItem
;
832 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
833 notify_listview(infoPtr
, code
, &nmlv
);
834 return IsWindow(hwnd
);
837 static BOOL
notify_deleteitem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
841 HWND hwnd
= infoPtr
->hwndSelf
;
843 ZeroMemory(&nmlv
, sizeof (NMLISTVIEW
));
845 item
.mask
= LVIF_PARAM
;
848 if (LISTVIEW_GetItemT(infoPtr
, &item
, TRUE
)) nmlv
.lParam
= item
.lParam
;
849 notify_listview(infoPtr
, LVN_DELETEITEM
, &nmlv
);
850 return IsWindow(hwnd
);
853 static int get_ansi_notification(INT unicodeNotificationCode
)
855 switch (unicodeNotificationCode
)
857 case LVN_BEGINLABELEDITW
: return LVN_BEGINLABELEDITA
;
858 case LVN_ENDLABELEDITW
: return LVN_ENDLABELEDITA
;
859 case LVN_GETDISPINFOW
: return LVN_GETDISPINFOA
;
860 case LVN_SETDISPINFOW
: return LVN_SETDISPINFOA
;
861 case LVN_ODFINDITEMW
: return LVN_ODFINDITEMA
;
862 case LVN_GETINFOTIPW
: return LVN_GETINFOTIPA
;
864 ERR("unknown notification %x\n", unicodeNotificationCode
);
870 Send notification. depends on dispinfoW having same
871 structure as dispinfoA.
872 infoPtr : listview struct
873 notificationCode : *Unicode* notification code
874 pdi : dispinfo structure (can be unicode or ansi)
875 isW : TRUE if dispinfo is Unicode
877 static BOOL
notify_dispinfoT(LISTVIEW_INFO
*infoPtr
, INT notificationCode
, LPNMLVDISPINFOW pdi
, BOOL isW
)
879 BOOL bResult
= FALSE
;
880 BOOL convertToAnsi
= FALSE
, convertToUnicode
= FALSE
;
881 INT cchTempBufMax
= 0, savCchTextMax
= 0, realNotifCode
;
882 LPWSTR pszTempBuf
= NULL
, savPszText
= NULL
;
884 if ((pdi
->item
.mask
& LVIF_TEXT
) && is_textT(pdi
->item
.pszText
, isW
))
886 convertToAnsi
= (isW
&& infoPtr
->notifyFormat
== NFR_ANSI
);
887 convertToUnicode
= (!isW
&& infoPtr
->notifyFormat
== NFR_UNICODE
);
890 if (convertToAnsi
|| convertToUnicode
)
892 if (notificationCode
!= LVN_GETDISPINFOW
)
894 cchTempBufMax
= convertToUnicode
?
895 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1, NULL
, 0):
896 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, NULL
, 0, NULL
, NULL
);
900 cchTempBufMax
= pdi
->item
.cchTextMax
;
901 *pdi
->item
.pszText
= 0; /* make sure we don't process garbage */
904 pszTempBuf
= Alloc( (convertToUnicode
? sizeof(WCHAR
) : sizeof(CHAR
)) * cchTempBufMax
);
905 if (!pszTempBuf
) return FALSE
;
907 if (convertToUnicode
)
908 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)pdi
->item
.pszText
, -1,
909 pszTempBuf
, cchTempBufMax
);
911 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) pszTempBuf
,
912 cchTempBufMax
, NULL
, NULL
);
914 savCchTextMax
= pdi
->item
.cchTextMax
;
915 savPszText
= pdi
->item
.pszText
;
916 pdi
->item
.pszText
= pszTempBuf
;
917 pdi
->item
.cchTextMax
= cchTempBufMax
;
920 if (infoPtr
->notifyFormat
== NFR_ANSI
)
921 realNotifCode
= get_ansi_notification(notificationCode
);
923 realNotifCode
= notificationCode
;
924 TRACE(" pdi->item=%s\n", debuglvitem_t(&pdi
->item
, infoPtr
->notifyFormat
!= NFR_ANSI
));
925 bResult
= notify_hdr(infoPtr
, realNotifCode
, &pdi
->hdr
);
927 if (convertToUnicode
|| convertToAnsi
)
929 if (convertToUnicode
) /* note : pointer can be changed by app ! */
930 WideCharToMultiByte(CP_ACP
, 0, pdi
->item
.pszText
, -1, (LPSTR
) savPszText
,
931 savCchTextMax
, NULL
, NULL
);
933 MultiByteToWideChar(CP_ACP
, 0, (LPSTR
) pdi
->item
.pszText
, -1,
934 savPszText
, savCchTextMax
);
935 pdi
->item
.pszText
= savPszText
; /* restores our buffer */
936 pdi
->item
.cchTextMax
= savCchTextMax
;
942 static void customdraw_fill(NMLVCUSTOMDRAW
*lpnmlvcd
, LISTVIEW_INFO
*infoPtr
, HDC hdc
,
943 const RECT
*rcBounds
, const LVITEMW
*lplvItem
)
945 ZeroMemory(lpnmlvcd
, sizeof(NMLVCUSTOMDRAW
));
946 lpnmlvcd
->nmcd
.hdc
= hdc
;
947 lpnmlvcd
->nmcd
.rc
= *rcBounds
;
948 lpnmlvcd
->clrTextBk
= infoPtr
->clrTextBk
;
949 lpnmlvcd
->clrText
= infoPtr
->clrText
;
950 if (!lplvItem
) return;
951 lpnmlvcd
->nmcd
.dwItemSpec
= lplvItem
->iItem
+ 1;
952 lpnmlvcd
->iSubItem
= lplvItem
->iSubItem
;
953 if (lplvItem
->state
& LVIS_SELECTED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_SELECTED
;
954 if (lplvItem
->state
& LVIS_FOCUSED
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_FOCUS
;
955 if (lplvItem
->iItem
== infoPtr
->nHotItem
) lpnmlvcd
->nmcd
.uItemState
|= CDIS_HOT
;
956 lpnmlvcd
->nmcd
.lItemlParam
= lplvItem
->lParam
;
959 static inline DWORD
notify_customdraw (LISTVIEW_INFO
*infoPtr
, DWORD dwDrawStage
, NMLVCUSTOMDRAW
*lpnmlvcd
)
961 BOOL isForItem
= (lpnmlvcd
->nmcd
.dwItemSpec
!= 0);
964 lpnmlvcd
->nmcd
.dwDrawStage
= dwDrawStage
;
965 if (isForItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_ITEM
;
966 if (lpnmlvcd
->iSubItem
) lpnmlvcd
->nmcd
.dwDrawStage
|= CDDS_SUBITEM
;
967 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
--;
968 result
= notify_hdr(infoPtr
, NM_CUSTOMDRAW
, &lpnmlvcd
->nmcd
.hdr
);
969 if (isForItem
) lpnmlvcd
->nmcd
.dwItemSpec
++;
973 static void prepaint_setup (LISTVIEW_INFO
*infoPtr
, HDC hdc
, NMLVCUSTOMDRAW
*lpnmlvcd
)
975 /* apprently, for selected items, we have to override the returned values */
976 if (lpnmlvcd
->nmcd
.uItemState
& CDIS_SELECTED
)
980 lpnmlvcd
->clrTextBk
= comctl32_color
.clrHighlight
;
981 lpnmlvcd
->clrText
= comctl32_color
.clrHighlightText
;
983 else if (infoPtr
->dwStyle
& LVS_SHOWSELALWAYS
)
985 lpnmlvcd
->clrTextBk
= comctl32_color
.clr3dFace
;
986 lpnmlvcd
->clrText
= comctl32_color
.clrBtnText
;
990 /* Set the text attributes */
991 if (lpnmlvcd
->clrTextBk
!= CLR_NONE
)
993 SetBkMode(hdc
, OPAQUE
);
994 if (lpnmlvcd
->clrTextBk
== CLR_DEFAULT
)
995 SetBkColor(hdc
, infoPtr
->clrTextBkDefault
);
997 SetBkColor(hdc
,lpnmlvcd
->clrTextBk
);
1000 SetBkMode(hdc
, TRANSPARENT
);
1001 SetTextColor(hdc
, lpnmlvcd
->clrText
);
1004 static inline DWORD
notify_postpaint (LISTVIEW_INFO
*infoPtr
, NMLVCUSTOMDRAW
*lpnmlvcd
)
1006 return notify_customdraw(infoPtr
, CDDS_POSTPAINT
, lpnmlvcd
);
1009 /******** Item iterator functions **********************************/
1011 static RANGES
ranges_create(int count
);
1012 static void ranges_destroy(RANGES ranges
);
1013 static BOOL
ranges_add(RANGES ranges
, RANGE range
);
1014 static BOOL
ranges_del(RANGES ranges
, RANGE range
);
1015 static void ranges_dump(RANGES ranges
);
1017 static inline BOOL
ranges_additem(RANGES ranges
, INT nItem
)
1019 RANGE range
= { nItem
, nItem
+ 1 };
1021 return ranges_add(ranges
, range
);
1024 static inline BOOL
ranges_delitem(RANGES ranges
, INT nItem
)
1026 RANGE range
= { nItem
, nItem
+ 1 };
1028 return ranges_del(ranges
, range
);
1032 * ITERATOR DOCUMENTATION
1034 * The iterator functions allow for easy, and convenient iteration
1035 * over items of iterest in the list. Typically, you create a
1036 * iterator, use it, and destroy it, as such:
1039 * iterator_xxxitems(&i, ...);
1040 * while (iterator_{prev,next}(&i)
1042 * //code which uses i.nItem
1044 * iterator_destroy(&i);
1046 * where xxx is either: framed, or visible.
1047 * Note that it is important that the code destroys the iterator
1048 * after it's done with it, as the creation of the iterator may
1049 * allocate memory, which thus needs to be freed.
1051 * You can iterate both forwards, and backwards through the list,
1052 * by using iterator_next or iterator_prev respectively.
1054 * Lower numbered items are draw on top of higher number items in
1055 * LVS_ICON, and LVS_SMALLICON (which are the only modes where
1056 * items may overlap). So, to test items, you should use
1058 * which lists the items top to bottom (in Z-order).
1059 * For drawing items, you should use
1061 * which lists the items bottom to top (in Z-order).
1062 * If you keep iterating over the items after the end-of-items
1063 * marker (-1) is returned, the iterator will start from the
1064 * beginning. Typically, you don't need to test for -1,
1065 * because iterator_{next,prev} will return TRUE if more items
1066 * are to be iterated over, or FALSE otherwise.
1068 * Note: the iterator is defined to be bidirectional. That is,
1069 * any number of prev followed by any number of next, or
1070 * five versa, should leave the iterator at the same item:
1071 * prev * n, next * n = next * n, prev * n
1073 * The iterator has a notion of an out-of-order, special item,
1074 * which sits at the start of the list. This is used in
1075 * LVS_ICON, and LVS_SMALLICON mode to handle the focused item,
1076 * which needs to be first, as it may overlap other items.
1078 * The code is a bit messy because we have:
1079 * - a special item to deal with
1080 * - simple range, or composite range
1082 * If you find bugs, or want to add features, please make sure you
1083 * always check/modify *both* iterator_prev, and iterator_next.
1087 * This function iterates through the items in increasing order,
1088 * but prefixed by the special item, then -1. That is:
1089 * special, 1, 2, 3, ..., n, -1.
1090 * Each item is listed only once.
1092 static inline BOOL
iterator_next(ITERATOR
* i
)
1096 i
->nItem
= i
->nSpecial
;
1097 if (i
->nItem
!= -1) return TRUE
;
1099 if (i
->nItem
== i
->nSpecial
)
1101 if (i
->ranges
) i
->index
= 0;
1107 if (i
->nItem
== i
->nSpecial
) i
->nItem
++;
1108 if (i
->nItem
< i
->range
.upper
) return TRUE
;
1113 if (i
->index
< DPA_GetPtrCount(i
->ranges
->hdpa
))
1114 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, i
->index
++);
1117 else if (i
->nItem
>= i
->range
.upper
) goto end
;
1119 i
->nItem
= i
->range
.lower
;
1120 if (i
->nItem
>= 0) goto testitem
;
1127 * This function iterates through the items in decreasing order,
1128 * followed by the special item, then -1. That is:
1129 * n, n-1, ..., 3, 2, 1, special, -1.
1130 * Each item is listed only once.
1132 static inline BOOL
iterator_prev(ITERATOR
* i
)
1139 if (i
->ranges
) i
->index
= DPA_GetPtrCount(i
->ranges
->hdpa
);
1142 if (i
->nItem
== i
->nSpecial
)
1150 if (i
->nItem
== i
->nSpecial
) i
->nItem
--;
1151 if (i
->nItem
>= i
->range
.lower
) return TRUE
;
1157 i
->range
= *(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, --i
->index
);
1160 else if (!start
&& i
->nItem
< i
->range
.lower
) goto end
;
1162 i
->nItem
= i
->range
.upper
;
1163 if (i
->nItem
> 0) goto testitem
;
1165 return (i
->nItem
= i
->nSpecial
) != -1;
1168 static RANGE
iterator_range(ITERATOR
* i
)
1172 if (!i
->ranges
) return i
->range
;
1174 if (DPA_GetPtrCount(i
->ranges
->hdpa
) > 0)
1176 range
.lower
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, 0)).lower
;
1177 range
.upper
= (*(RANGE
*)DPA_GetPtr(i
->ranges
->hdpa
, DPA_GetPtrCount(i
->ranges
->hdpa
) - 1)).upper
;
1179 else range
.lower
= range
.upper
= 0;
1185 * Releases resources associated with this ierator.
1187 static inline void iterator_destroy(ITERATOR
* i
)
1189 ranges_destroy(i
->ranges
);
1193 * Create an empty iterator.
1195 static inline BOOL
iterator_empty(ITERATOR
* i
)
1197 ZeroMemory(i
, sizeof(*i
));
1198 i
->nItem
= i
->nSpecial
= i
->range
.lower
= i
->range
.upper
= -1;
1203 * Create an iterator over a range.
1205 static inline BOOL
iterator_rangeitems(ITERATOR
* i
, RANGE range
)
1213 * Create an iterator over a bunch of ranges.
1214 * Please note that the iterator will take ownership of the ranges,
1215 * and will free them upon destruction.
1217 static inline BOOL
iterator_rangesitems(ITERATOR
* i
, RANGES ranges
)
1225 * Creates an iterator over the items which intersect lprc.
1227 static BOOL
iterator_frameditems(ITERATOR
* i
, LISTVIEW_INFO
* infoPtr
, const RECT
*lprc
)
1229 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1230 RECT frame
= *lprc
, rcItem
, rcTemp
;
1233 /* in case we fail, we want to return an empty iterator */
1234 if (!iterator_empty(i
)) return FALSE
;
1236 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1238 TRACE("(lprc=%s)\n", debugrect(lprc
));
1239 OffsetRect(&frame
, -Origin
.x
, -Origin
.y
);
1241 if (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)
1245 if (uView
== LVS_ICON
&& infoPtr
->nFocusedItem
!= -1)
1247 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcItem
);
1248 if (IntersectRect(&rcTemp
, &rcItem
, lprc
))
1249 i
->nSpecial
= infoPtr
->nFocusedItem
;
1251 if (!(iterator_rangesitems(i
, ranges_create(50)))) return FALSE
;
1252 /* to do better here, we need to have PosX, and PosY sorted */
1253 TRACE("building icon ranges:\n");
1254 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
1256 rcItem
.left
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1257 rcItem
.top
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1258 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1259 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1260 if (IntersectRect(&rcTemp
, &rcItem
, &frame
))
1261 ranges_additem(i
->ranges
, nItem
);
1265 else if (uView
== LVS_REPORT
)
1269 if (frame
.left
>= infoPtr
->nItemWidth
) return TRUE
;
1270 if (frame
.top
>= infoPtr
->nItemHeight
* infoPtr
->nItemCount
) return TRUE
;
1272 range
.lower
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1273 range
.upper
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, infoPtr
->nItemCount
- 1) + 1;
1274 if (range
.upper
<= range
.lower
) return TRUE
;
1275 if (!iterator_rangeitems(i
, range
)) return FALSE
;
1276 TRACE(" report=%s\n", debugrange(&i
->range
));
1280 INT nPerCol
= max((infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
, 1);
1281 INT nFirstRow
= max(frame
.top
/ infoPtr
->nItemHeight
, 0);
1282 INT nLastRow
= min((frame
.bottom
- 1) / infoPtr
->nItemHeight
, nPerCol
- 1);
1283 INT nFirstCol
= max(frame
.left
/ infoPtr
->nItemWidth
, 0);
1284 INT nLastCol
= min((frame
.right
- 1) / infoPtr
->nItemWidth
, (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
);
1285 INT lower
= nFirstCol
* nPerCol
+ nFirstRow
;
1289 TRACE("nPerCol=%d, nFirstRow=%d, nLastRow=%d, nFirstCol=%d, nLastCol=%d, lower=%d\n",
1290 nPerCol
, nFirstRow
, nLastRow
, nFirstCol
, nLastCol
, lower
);
1292 if (nLastCol
< nFirstCol
|| nLastRow
< nFirstRow
) return TRUE
;
1294 if (!(iterator_rangesitems(i
, ranges_create(nLastCol
- nFirstCol
+ 1)))) return FALSE
;
1295 TRACE("building list ranges:\n");
1296 for (nCol
= nFirstCol
; nCol
<= nLastCol
; nCol
++)
1298 item_range
.lower
= nCol
* nPerCol
+ nFirstRow
;
1299 if(item_range
.lower
>= infoPtr
->nItemCount
) break;
1300 item_range
.upper
= min(nCol
* nPerCol
+ nLastRow
+ 1, infoPtr
->nItemCount
);
1301 TRACE(" list=%s\n", debugrange(&item_range
));
1302 ranges_add(i
->ranges
, item_range
);
1310 * Creates an iterator over the items which intersect the visible region of hdc.
1312 static BOOL
iterator_visibleitems(ITERATOR
*i
, LISTVIEW_INFO
*infoPtr
, HDC hdc
)
1314 POINT Origin
, Position
;
1315 RECT rcItem
, rcClip
;
1318 rgntype
= GetClipBox(hdc
, &rcClip
);
1319 if (rgntype
== NULLREGION
) return iterator_empty(i
);
1320 if (!iterator_frameditems(i
, infoPtr
, &rcClip
)) return FALSE
;
1321 if (rgntype
== SIMPLEREGION
) return TRUE
;
1323 /* first deal with the special item */
1324 if (i
->nSpecial
!= -1)
1326 LISTVIEW_GetItemBox(infoPtr
, i
->nSpecial
, &rcItem
);
1327 if (!RectVisible(hdc
, &rcItem
)) i
->nSpecial
= -1;
1330 /* if we can't deal with the region, we'll just go with the simple range */
1331 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1332 TRACE("building visible range:\n");
1333 if (!i
->ranges
&& i
->range
.lower
< i
->range
.upper
)
1335 if (!(i
->ranges
= ranges_create(50))) return TRUE
;
1336 if (!ranges_add(i
->ranges
, i
->range
))
1338 ranges_destroy(i
->ranges
);
1344 /* now delete the invisible items from the list */
1345 while(iterator_next(i
))
1347 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
1348 rcItem
.left
= Position
.x
+ Origin
.x
;
1349 rcItem
.top
= Position
.y
+ Origin
.y
;
1350 rcItem
.right
= rcItem
.left
+ infoPtr
->nItemWidth
;
1351 rcItem
.bottom
= rcItem
.top
+ infoPtr
->nItemHeight
;
1352 if (!RectVisible(hdc
, &rcItem
))
1353 ranges_delitem(i
->ranges
, i
->nItem
);
1355 /* the iterator should restart on the next iterator_next */
1361 /******** Misc helper functions ************************************/
1363 static inline LRESULT
CallWindowProcT(WNDPROC proc
, HWND hwnd
, UINT uMsg
,
1364 WPARAM wParam
, LPARAM lParam
, BOOL isW
)
1366 if (isW
) return CallWindowProcW(proc
, hwnd
, uMsg
, wParam
, lParam
);
1367 else return CallWindowProcA(proc
, hwnd
, uMsg
, wParam
, lParam
);
1370 static inline BOOL
is_autoarrange(LISTVIEW_INFO
*infoPtr
)
1372 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1374 return ((infoPtr
->dwStyle
& LVS_AUTOARRANGE
) || infoPtr
->bAutoarrange
) &&
1375 (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
);
1378 /******** Internal API functions ************************************/
1380 static inline COLUMN_INFO
* LISTVIEW_GetColumnInfo(LISTVIEW_INFO
*infoPtr
, INT nSubItem
)
1382 static COLUMN_INFO mainItem
;
1384 if (nSubItem
== 0 && DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0) return &mainItem
;
1385 assert (nSubItem
>= 0 && nSubItem
< DPA_GetPtrCount(infoPtr
->hdpaColumns
));
1386 return (COLUMN_INFO
*)DPA_GetPtr(infoPtr
->hdpaColumns
, nSubItem
);
1389 static inline void LISTVIEW_GetHeaderRect(LISTVIEW_INFO
*infoPtr
, INT nSubItem
, RECT
*lprc
)
1391 *lprc
= LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->rcHeader
;
1394 static inline BOOL
LISTVIEW_GetItemW(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
)
1396 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
1399 /* Listview invalidation functions: use _only_ these functions to invalidate */
1401 static inline BOOL
is_redrawing(LISTVIEW_INFO
*infoPtr
)
1403 return infoPtr
->bRedraw
;
1406 static inline void LISTVIEW_InvalidateRect(LISTVIEW_INFO
*infoPtr
, const RECT
* rect
)
1408 if(!is_redrawing(infoPtr
)) return;
1409 TRACE(" invalidating rect=%s\n", debugrect(rect
));
1410 InvalidateRect(infoPtr
->hwndSelf
, rect
, TRUE
);
1413 static inline void LISTVIEW_InvalidateItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
1417 if(!is_redrawing(infoPtr
)) return;
1418 LISTVIEW_GetItemBox(infoPtr
, nItem
, &rcBox
);
1419 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1422 static inline void LISTVIEW_InvalidateSubItem(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT nSubItem
)
1424 POINT Origin
, Position
;
1427 if(!is_redrawing(infoPtr
)) return;
1428 assert ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_REPORT
);
1429 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
1430 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
1431 LISTVIEW_GetHeaderRect(infoPtr
, nSubItem
, &rcBox
);
1433 rcBox
.bottom
= infoPtr
->nItemHeight
;
1434 OffsetRect(&rcBox
, Origin
.x
+ Position
.x
, Origin
.y
+ Position
.y
);
1435 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1438 static inline void LISTVIEW_InvalidateList(LISTVIEW_INFO
*infoPtr
)
1440 LISTVIEW_InvalidateRect(infoPtr
, NULL
);
1443 static inline void LISTVIEW_InvalidateColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
1447 if(!is_redrawing(infoPtr
)) return;
1448 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
1449 rcCol
.top
= infoPtr
->rcList
.top
;
1450 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
1451 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
1456 * Retrieves the number of items that can fit vertically in the client area.
1459 * [I] infoPtr : valid pointer to the listview structure
1462 * Number of items per row.
1464 static inline INT
LISTVIEW_GetCountPerRow(LISTVIEW_INFO
*infoPtr
)
1466 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1468 return max(nListWidth
/infoPtr
->nItemWidth
, 1);
1473 * Retrieves the number of items that can fit horizontally in the client
1477 * [I] infoPtr : valid pointer to the listview structure
1480 * Number of items per column.
1482 static inline INT
LISTVIEW_GetCountPerColumn(LISTVIEW_INFO
*infoPtr
)
1484 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1486 return max(nListHeight
/ infoPtr
->nItemHeight
, 1);
1490 /*************************************************************************
1491 * LISTVIEW_ProcessLetterKeys
1493 * Processes keyboard messages generated by pressing the letter keys
1495 * What this does is perform a case insensitive search from the
1496 * current position with the following quirks:
1497 * - If two chars or more are pressed in quick succession we search
1498 * for the corresponding string (e.g. 'abc').
1499 * - If there is a delay we wipe away the current search string and
1500 * restart with just that char.
1501 * - If the user keeps pressing the same character, whether slowly or
1502 * fast, so that the search string is entirely composed of this
1503 * character ('aaaaa' for instance), then we search for first item
1504 * that starting with that character.
1505 * - If the user types the above character in quick succession, then
1506 * we must also search for the corresponding string ('aaaaa'), and
1507 * go to that string if there is a match.
1510 * [I] hwnd : handle to the window
1511 * [I] charCode : the character code, the actual character
1512 * [I] keyData : key data
1520 * - The current implementation has a list of characters it will
1521 * accept and it ignores averything else. In particular it will
1522 * ignore accentuated characters which seems to match what
1523 * Windows does. But I'm not sure it makes sense to follow
1525 * - We don't sound a beep when the search fails.
1529 * TREEVIEW_ProcessLetterKeys
1531 static INT
LISTVIEW_ProcessLetterKeys(LISTVIEW_INFO
*infoPtr
, WPARAM charCode
, LPARAM keyData
)
1536 WCHAR buffer
[MAX_PATH
];
1537 DWORD lastKeyPressTimestamp
= infoPtr
->lastKeyPressTimestamp
;
1539 /* simple parameter checking */
1540 if (!charCode
|| !keyData
) return 0;
1542 /* only allow the valid WM_CHARs through */
1543 if (!isalnum(charCode
) &&
1544 charCode
!= '.' && charCode
!= '`' && charCode
!= '!' &&
1545 charCode
!= '@' && charCode
!= '#' && charCode
!= '$' &&
1546 charCode
!= '%' && charCode
!= '^' && charCode
!= '&' &&
1547 charCode
!= '*' && charCode
!= '(' && charCode
!= ')' &&
1548 charCode
!= '-' && charCode
!= '_' && charCode
!= '+' &&
1549 charCode
!= '=' && charCode
!= '\\'&& charCode
!= ']' &&
1550 charCode
!= '}' && charCode
!= '[' && charCode
!= '{' &&
1551 charCode
!= '/' && charCode
!= '?' && charCode
!= '>' &&
1552 charCode
!= '<' && charCode
!= ',' && charCode
!= '~')
1555 /* if there's one item or less, there is no where to go */
1556 if (infoPtr
->nItemCount
<= 1) return 0;
1558 /* update the search parameters */
1559 infoPtr
->lastKeyPressTimestamp
= GetTickCount();
1560 if (infoPtr
->lastKeyPressTimestamp
- lastKeyPressTimestamp
< KEY_DELAY
) {
1561 if (infoPtr
->nSearchParamLength
< MAX_PATH
)
1562 infoPtr
->szSearchParam
[infoPtr
->nSearchParamLength
++]=charCode
;
1563 if (infoPtr
->charCode
!= charCode
)
1564 infoPtr
->charCode
= charCode
= 0;
1566 infoPtr
->charCode
=charCode
;
1567 infoPtr
->szSearchParam
[0]=charCode
;
1568 infoPtr
->nSearchParamLength
=1;
1569 /* Redundant with the 1 char string */
1573 /* and search from the current position */
1575 if (infoPtr
->nFocusedItem
>= 0) {
1576 endidx
=infoPtr
->nFocusedItem
;
1578 /* if looking for single character match,
1579 * then we must always move forward
1581 if (infoPtr
->nSearchParamLength
== 1)
1584 endidx
=infoPtr
->nItemCount
;
1588 if (idx
== infoPtr
->nItemCount
) {
1589 if (endidx
== infoPtr
->nItemCount
|| endidx
== 0)
1595 item
.mask
= LVIF_TEXT
;
1598 item
.pszText
= buffer
;
1599 item
.cchTextMax
= MAX_PATH
;
1600 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) return 0;
1602 /* check for a match */
1603 if (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,infoPtr
->nSearchParamLength
) == 0) {
1606 } else if ( (charCode
!= 0) && (nItem
== -1) && (nItem
!= infoPtr
->nFocusedItem
) &&
1607 (lstrncmpiW(item
.pszText
,infoPtr
->szSearchParam
,1) == 0) ) {
1608 /* This would work but we must keep looking for a longer match */
1612 } while (idx
!= endidx
);
1615 LISTVIEW_KeySelection(infoPtr
, nItem
);
1620 /*************************************************************************
1621 * LISTVIEW_UpdateHeaderSize [Internal]
1623 * Function to resize the header control
1626 * [I] hwnd : handle to a window
1627 * [I] nNewScrollPos : scroll pos to set
1632 static void LISTVIEW_UpdateHeaderSize(LISTVIEW_INFO
*infoPtr
, INT nNewScrollPos
)
1637 TRACE("nNewScrollPos=%d\n", nNewScrollPos
);
1639 GetWindowRect(infoPtr
->hwndHeader
, &winRect
);
1640 point
[0].x
= winRect
.left
;
1641 point
[0].y
= winRect
.top
;
1642 point
[1].x
= winRect
.right
;
1643 point
[1].y
= winRect
.bottom
;
1645 MapWindowPoints(HWND_DESKTOP
, infoPtr
->hwndSelf
, point
, 2);
1646 point
[0].x
= -nNewScrollPos
;
1647 point
[1].x
+= nNewScrollPos
;
1649 SetWindowPos(infoPtr
->hwndHeader
,0,
1650 point
[0].x
,point
[0].y
,point
[1].x
,point
[1].y
,
1651 SWP_NOZORDER
| SWP_NOACTIVATE
);
1656 * Update the scrollbars. This functions should be called whenever
1657 * the content, size or view changes.
1660 * [I] infoPtr : valid pointer to the listview structure
1665 static void LISTVIEW_UpdateScroll(LISTVIEW_INFO
*infoPtr
)
1667 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1668 SCROLLINFO horzInfo
, vertInfo
;
1670 if ((infoPtr
->dwStyle
& LVS_NOSCROLL
) || !is_redrawing(infoPtr
)) return;
1672 ZeroMemory(&horzInfo
, sizeof(SCROLLINFO
));
1673 horzInfo
.cbSize
= sizeof(SCROLLINFO
);
1674 horzInfo
.nPage
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
1676 /* for now, we'll set info.nMax to the _count_, and adjust it later */
1677 if (uView
== LVS_LIST
)
1679 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
1680 horzInfo
.nMax
= (infoPtr
->nItemCount
+ nPerCol
- 1) / nPerCol
;
1682 /* scroll by at least one column per page */
1683 if(horzInfo
.nPage
< infoPtr
->nItemWidth
)
1684 horzInfo
.nPage
= infoPtr
->nItemWidth
;
1686 horzInfo
.nPage
/= infoPtr
->nItemWidth
;
1688 else if (uView
== LVS_REPORT
)
1690 horzInfo
.nMax
= infoPtr
->nItemWidth
;
1692 else /* LVS_ICON, or LVS_SMALLICON */
1696 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) horzInfo
.nMax
= rcView
.right
- rcView
.left
;
1699 horzInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1700 horzInfo
.nMax
= max(horzInfo
.nMax
- 1, 0);
1701 SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
, TRUE
);
1702 TRACE("horzInfo=%s\n", debugscrollinfo(&horzInfo
));
1704 /* Setting the horizontal scroll can change the listview size
1705 * (and potentially everything else) so we need to recompute
1706 * everything again for the vertical scroll
1709 ZeroMemory(&vertInfo
, sizeof(SCROLLINFO
));
1710 vertInfo
.cbSize
= sizeof(SCROLLINFO
);
1711 vertInfo
.nPage
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
1713 if (uView
== LVS_REPORT
)
1715 vertInfo
.nMax
= infoPtr
->nItemCount
;
1717 /* scroll by at least one page */
1718 if(vertInfo
.nPage
< infoPtr
->nItemHeight
)
1719 vertInfo
.nPage
= infoPtr
->nItemHeight
;
1721 vertInfo
.nPage
/= infoPtr
->nItemHeight
;
1723 else if (uView
!= LVS_LIST
) /* LVS_ICON, or LVS_SMALLICON */
1727 if (LISTVIEW_GetViewRect(infoPtr
, &rcView
)) vertInfo
.nMax
= rcView
.bottom
- rcView
.top
;
1730 vertInfo
.fMask
= SIF_RANGE
| SIF_PAGE
;
1731 vertInfo
.nMax
= max(vertInfo
.nMax
- 1, 0);
1732 SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &vertInfo
, TRUE
);
1733 TRACE("vertInfo=%s\n", debugscrollinfo(&vertInfo
));
1735 /* Update the Header Control */
1736 if (uView
== LVS_REPORT
)
1738 horzInfo
.fMask
= SIF_POS
;
1739 GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &horzInfo
);
1740 LISTVIEW_UpdateHeaderSize(infoPtr
, horzInfo
.nPos
);
1747 * Shows/hides the focus rectangle.
1750 * [I] infoPtr : valid pointer to the listview structure
1751 * [I] fShow : TRUE to show the focus, FALSE to hide it.
1756 static void LISTVIEW_ShowFocusRect(LISTVIEW_INFO
*infoPtr
, BOOL fShow
)
1758 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1761 TRACE("fShow=%d, nItem=%d\n", fShow
, infoPtr
->nFocusedItem
);
1763 if (infoPtr
->nFocusedItem
< 0) return;
1765 /* we need some gymnastics in ICON mode to handle large items */
1766 if ( (infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_ICON
)
1770 LISTVIEW_GetItemBox(infoPtr
, infoPtr
->nFocusedItem
, &rcBox
);
1771 if ((rcBox
.bottom
- rcBox
.top
) > infoPtr
->nItemHeight
)
1773 LISTVIEW_InvalidateRect(infoPtr
, &rcBox
);
1778 if (!(hdc
= GetDC(infoPtr
->hwndSelf
))) return;
1780 /* for some reason, owner draw should work only in report mode */
1781 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (uView
== LVS_REPORT
))
1786 item
.iItem
= infoPtr
->nFocusedItem
;
1788 item
.mask
= LVIF_PARAM
;
1789 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) goto done
;
1791 ZeroMemory(&dis
, sizeof(dis
));
1792 dis
.CtlType
= ODT_LISTVIEW
;
1793 dis
.CtlID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
1794 dis
.itemID
= item
.iItem
;
1795 dis
.itemAction
= ODA_FOCUS
;
1796 if (fShow
) dis
.itemState
|= ODS_FOCUS
;
1797 dis
.hwndItem
= infoPtr
->hwndSelf
;
1799 LISTVIEW_GetItemBox(infoPtr
, dis
.itemID
, &dis
.rcItem
);
1800 dis
.itemData
= item
.lParam
;
1802 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
1806 DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
1809 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
1813 * Invalidates all visible selected items.
1815 static void LISTVIEW_InvalidateSelectedItems(LISTVIEW_INFO
*infoPtr
)
1819 iterator_frameditems(&i
, infoPtr
, &infoPtr
->rcList
);
1820 while(iterator_next(&i
))
1822 if (LISTVIEW_GetItemState(infoPtr
, i
.nItem
, LVIS_SELECTED
))
1823 LISTVIEW_InvalidateItem(infoPtr
, i
.nItem
);
1825 iterator_destroy(&i
);
1830 * DESCRIPTION: [INTERNAL]
1831 * Computes an item's (left,top) corner, relative to rcView.
1832 * That is, the position has NOT been made relative to the Origin.
1833 * This is deliberate, to avoid computing the Origin over, and
1834 * over again, when this function is call in a loop. Instead,
1835 * one ca factor the computation of the Origin before the loop,
1836 * and offset the value retured by this function, on every iteration.
1839 * [I] infoPtr : valid pointer to the listview structure
1840 * [I] nItem : item number
1841 * [O] lpptOrig : item top, left corner
1846 static void LISTVIEW_GetItemOrigin(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
1848 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1850 assert(nItem
>= 0 && nItem
< infoPtr
->nItemCount
);
1852 if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
1854 lpptPosition
->x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
1855 lpptPosition
->y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
1857 else if (uView
== LVS_LIST
)
1859 INT nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
1860 lpptPosition
->x
= nItem
/ nCountPerColumn
* infoPtr
->nItemWidth
;
1861 lpptPosition
->y
= nItem
% nCountPerColumn
* infoPtr
->nItemHeight
;
1863 else /* LVS_REPORT */
1865 lpptPosition
->x
= 0;
1866 lpptPosition
->y
= nItem
* infoPtr
->nItemHeight
;
1871 * DESCRIPTION: [INTERNAL]
1872 * Compute the rectangles of an item. This is to localize all
1873 * the computations in one place. If you are not interested in some
1874 * of these values, simply pass in a NULL -- the fucntion is smart
1875 * enough to compute only what's necessary. The function computes
1876 * the standard rectangles (BOUNDS, ICON, LABEL) plus a non-standard
1877 * one, the BOX rectangle. This rectangle is very cheap to compute,
1878 * and is guaranteed to contain all the other rectangles. Computing
1879 * the ICON rect is also cheap, but all the others are potentaily
1880 * expensive. This gives an easy and effective optimization when
1881 * searching (like point inclusion, or rectangle intersection):
1882 * first test against the BOX, and if TRUE, test agains the desired
1884 * If the function does not have all the necessary information
1885 * to computed the requested rectangles, will crash with a
1886 * failed assertion. This is done so we catch all programming
1887 * errors, given that the function is called only from our code.
1889 * We have the following 'special' meanings for a few fields:
1890 * * If LVIS_FOCUSED is set, we assume the item has the focus
1891 * This is important in ICON mode, where it might get a larger
1892 * then usual rectange
1894 * Please note that subitem support works only in REPORT mode.
1897 * [I] infoPtr : valid pointer to the listview structure
1898 * [I] lpLVItem : item to compute the measures for
1899 * [O] lprcBox : ptr to Box rectangle
1900 * The internal LVIR_BOX rectangle
1901 * [0] lprcState : ptr to State icon rectangle
1902 * The internal LVIR_STATE rectangle
1903 * [O] lprcIcon : ptr to Icon rectangle
1904 * Same as LVM_GETITEMRECT with LVIR_ICON
1905 * [O] lprcLabel : ptr to Label rectangle
1906 * Same as LVM_GETITEMRECT with LVIR_LABEL
1911 static void LISTVIEW_GetItemMetrics(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
,
1912 LPRECT lprcBox
, LPRECT lprcState
,
1913 LPRECT lprcIcon
, LPRECT lprcLabel
)
1915 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
1916 BOOL doState
= FALSE
, doIcon
= FALSE
, doLabel
= FALSE
, oversizedBox
= FALSE
;
1917 RECT Box
, State
, Icon
, Label
;
1918 COLUMN_INFO
*lpColumnInfo
= NULL
;
1920 TRACE("(lpLVItem=%s)\n", debuglvitem_t(lpLVItem
, TRUE
));
1922 /* Be smart and try to figure out the minimum we have to do */
1923 if (lpLVItem
->iSubItem
) assert(uView
== LVS_REPORT
);
1924 if (uView
== LVS_ICON
&& (lprcBox
|| lprcLabel
))
1926 assert((lpLVItem
->mask
& LVIF_STATE
) && (lpLVItem
->stateMask
& LVIS_FOCUSED
));
1927 if (lpLVItem
->state
& LVIS_FOCUSED
) oversizedBox
= doLabel
= TRUE
;
1929 if (lprcLabel
) doLabel
= TRUE
;
1930 if (doLabel
|| lprcIcon
) doIcon
= TRUE
;
1931 if (doIcon
|| lprcState
) doState
= TRUE
;
1933 /************************************************************/
1934 /* compute the box rectangle (it should be cheap to do) */
1935 /************************************************************/
1936 if (lpLVItem
->iSubItem
|| uView
== LVS_REPORT
)
1937 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpLVItem
->iSubItem
);
1939 if (lpLVItem
->iSubItem
)
1941 Box
= lpColumnInfo
->rcHeader
;
1946 Box
.right
= infoPtr
->nItemWidth
;
1949 Box
.bottom
= infoPtr
->nItemHeight
;
1951 /************************************************************/
1952 /* compute STATEICON bounding box */
1953 /************************************************************/
1956 if (uView
== LVS_ICON
)
1958 State
.left
= Box
.left
- infoPtr
->iconStateSize
.cx
- 2;
1959 if (infoPtr
->himlNormal
)
1960 State
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
1961 State
.top
= Box
.top
+ infoPtr
->iconSize
.cy
- infoPtr
->iconStateSize
.cy
+ 4;
1965 /* we need the ident in report mode, if we don't have it, we fail */
1966 State
.left
= Box
.left
;
1967 if (uView
== LVS_REPORT
)
1969 if (lpLVItem
->iSubItem
== 0)
1971 State
.left
+= REPORT_MARGINX
;
1972 assert(lpLVItem
->mask
& LVIF_INDENT
);
1973 State
.left
+= infoPtr
->iconSize
.cx
* lpLVItem
->iIndent
;
1976 State
.top
= Box
.top
;
1978 State
.right
= State
.left
;
1979 State
.bottom
= State
.top
;
1980 if (infoPtr
->himlState
&& lpLVItem
->iSubItem
== 0)
1982 State
.right
+= infoPtr
->iconStateSize
.cx
;
1983 State
.bottom
+= infoPtr
->iconStateSize
.cy
;
1985 if (lprcState
) *lprcState
= State
;
1986 TRACE(" - state=%s\n", debugrect(&State
));
1988 else State
.right
= 0;
1990 /************************************************************/
1991 /* compute ICON bounding box (ala LVM_GETITEMRECT) */
1992 /************************************************************/
1995 if (uView
== LVS_ICON
)
1997 Icon
.left
= Box
.left
;
1998 if (infoPtr
->himlNormal
)
1999 Icon
.left
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
2000 Icon
.top
= Box
.top
+ ICON_TOP_PADDING
;
2001 Icon
.right
= Icon
.left
;
2002 Icon
.bottom
= Icon
.top
;
2003 if (infoPtr
->himlNormal
)
2005 Icon
.right
+= infoPtr
->iconSize
.cx
;
2006 Icon
.bottom
+= infoPtr
->iconSize
.cy
;
2009 else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
2011 Icon
.left
= State
.right
;
2013 Icon
.right
= Icon
.left
;
2014 if (infoPtr
->himlSmall
&&
2015 (!lpColumnInfo
|| lpLVItem
->iSubItem
== 0 || (lpColumnInfo
->fmt
& LVCFMT_IMAGE
) ||
2016 ((infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
) && lpLVItem
->iImage
!= I_IMAGECALLBACK
)))
2017 Icon
.right
+= infoPtr
->iconSize
.cx
;
2018 Icon
.bottom
= Icon
.top
+ infoPtr
->nItemHeight
;
2020 if(lprcIcon
) *lprcIcon
= Icon
;
2021 TRACE(" - icon=%s\n", debugrect(&Icon
));
2023 else Icon
.right
= 0;
2025 /************************************************************/
2026 /* compute LABEL bounding box (ala LVM_GETITEMRECT) */
2027 /************************************************************/
2030 SIZE labelSize
= { 0, 0 };
2032 /* calculate how far to the right can the label strech */
2033 Label
.right
= Box
.right
;
2034 if (uView
== LVS_REPORT
)
2036 if (lpLVItem
->iSubItem
== 0) Label
= lpColumnInfo
->rcHeader
;
2039 if (lpLVItem
->iSubItem
|| ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && uView
== LVS_REPORT
))
2041 labelSize
.cx
= infoPtr
->nItemWidth
;
2042 labelSize
.cy
= infoPtr
->nItemHeight
;
2046 /* we need the text in non owner draw mode */
2047 assert(lpLVItem
->mask
& LVIF_TEXT
);
2048 if (is_textT(lpLVItem
->pszText
, TRUE
))
2050 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2051 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2052 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2056 /* compute rough rectangle where the label will go */
2057 SetRectEmpty(&rcText
);
2058 rcText
.right
= infoPtr
->nItemWidth
- TRAILING_LABEL_PADDING
;
2059 rcText
.bottom
= infoPtr
->nItemHeight
;
2060 if (uView
== LVS_ICON
)
2061 rcText
.bottom
-= ICON_TOP_PADDING
+ infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2063 /* now figure out the flags */
2064 if (uView
== LVS_ICON
)
2065 uFormat
= oversizedBox
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
;
2067 uFormat
= LV_SL_DT_FLAGS
;
2069 DrawTextW (hdc
, lpLVItem
->pszText
, -1, &rcText
, uFormat
| DT_CALCRECT
);
2071 labelSize
.cx
= min(rcText
.right
- rcText
.left
+ TRAILING_LABEL_PADDING
, infoPtr
->nItemWidth
);
2072 labelSize
.cy
= rcText
.bottom
- rcText
.top
;
2074 SelectObject(hdc
, hOldFont
);
2075 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2079 if (uView
== LVS_ICON
)
2081 Label
.left
= Box
.left
+ (infoPtr
->nItemWidth
- labelSize
.cx
) / 2;
2082 Label
.top
= Box
.top
+ ICON_TOP_PADDING_HITABLE
+
2083 infoPtr
->iconSize
.cy
+ ICON_BOTTOM_PADDING
;
2084 Label
.right
= Label
.left
+ labelSize
.cx
;
2085 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2086 if (!oversizedBox
&& labelSize
.cy
> infoPtr
->ntmHeight
&&
2089 labelSize
.cy
= min(Box
.bottom
- Label
.top
, labelSize
.cy
);
2090 labelSize
.cy
/= infoPtr
->ntmHeight
;
2091 labelSize
.cy
= max(labelSize
.cy
, 1);
2092 labelSize
.cy
*= infoPtr
->ntmHeight
;
2094 Label
.bottom
= Label
.top
+ labelSize
.cy
+ HEIGHT_PADDING
;
2096 else /* LVS_SMALLICON, LVS_LIST or LVS_REPORT */
2098 Label
.left
= Icon
.right
;
2099 Label
.top
= Box
.top
;
2100 Label
.right
= min(Label
.left
+ labelSize
.cx
, Label
.right
);
2101 Label
.bottom
= Label
.top
+ infoPtr
->nItemHeight
;
2104 if (lprcLabel
) *lprcLabel
= Label
;
2105 TRACE(" - label=%s\n", debugrect(&Label
));
2108 /* Fix the Box if necessary */
2111 if (oversizedBox
) UnionRect(lprcBox
, &Box
, &Label
);
2112 else *lprcBox
= Box
;
2114 TRACE(" - box=%s\n", debugrect(&Box
));
2118 * DESCRIPTION: [INTERNAL]
2121 * [I] infoPtr : valid pointer to the listview structure
2122 * [I] nItem : item number
2123 * [O] lprcBox : ptr to Box rectangle
2128 static void LISTVIEW_GetItemBox(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprcBox
)
2130 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2131 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
2132 POINT Position
, Origin
;
2135 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
2136 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
2138 /* Be smart and try to figure out the minimum we have to do */
2140 if (uView
== LVS_ICON
&& infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
2141 lvItem
.mask
|= LVIF_TEXT
;
2142 lvItem
.iItem
= nItem
;
2143 lvItem
.iSubItem
= 0;
2144 lvItem
.pszText
= szDispText
;
2145 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
2146 if (lvItem
.mask
) LISTVIEW_GetItemW(infoPtr
, &lvItem
);
2147 if (uView
== LVS_ICON
)
2149 lvItem
.mask
|= LVIF_STATE
;
2150 lvItem
.stateMask
= LVIS_FOCUSED
;
2151 lvItem
.state
= (lvItem
.mask
& LVIF_TEXT
? LVIS_FOCUSED
: 0);
2153 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprcBox
, 0, 0, 0);
2155 OffsetRect(lprcBox
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
2161 * Returns the current icon position, and advances it along the top.
2162 * The returned position is not offset by Origin.
2165 * [I] infoPtr : valid pointer to the listview structure
2166 * [O] lpPos : will get the current icon position
2171 static void LISTVIEW_NextIconPosTop(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2173 INT nListWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
2175 *lpPos
= infoPtr
->currIconPos
;
2177 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2178 if (infoPtr
->currIconPos
.x
+ infoPtr
->nItemWidth
<= nListWidth
) return;
2180 infoPtr
->currIconPos
.x
= 0;
2181 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2187 * Returns the current icon position, and advances it down the left edge.
2188 * The returned position is not offset by Origin.
2191 * [I] infoPtr : valid pointer to the listview structure
2192 * [O] lpPos : will get the current icon position
2197 static void LISTVIEW_NextIconPosLeft(LISTVIEW_INFO
*infoPtr
, LPPOINT lpPos
)
2199 INT nListHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
2201 *lpPos
= infoPtr
->currIconPos
;
2203 infoPtr
->currIconPos
.y
+= infoPtr
->nItemHeight
;
2204 if (infoPtr
->currIconPos
.y
+ infoPtr
->nItemHeight
<= nListHeight
) return;
2206 infoPtr
->currIconPos
.x
+= infoPtr
->nItemWidth
;
2207 infoPtr
->currIconPos
.y
= 0;
2213 * Moves an icon to the specified position.
2214 * It takes care of invalidating the item, etc.
2217 * [I] infoPtr : valid pointer to the listview structure
2218 * [I] nItem : the item to move
2219 * [I] lpPos : the new icon position
2220 * [I] isNew : flags the item as being new
2226 static BOOL
LISTVIEW_MoveIconTo(LISTVIEW_INFO
*infoPtr
, INT nItem
, const POINT
*lppt
, BOOL isNew
)
2232 old
.x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, nItem
);
2233 old
.y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, nItem
);
2235 if (lppt
->x
== old
.x
&& lppt
->y
== old
.y
) return TRUE
;
2236 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2239 /* Allocating a POINTER for every item is too resource intensive,
2240 * so we'll keep the (x,y) in different arrays */
2241 if (!DPA_SetPtr(infoPtr
->hdpaPosX
, nItem
, (void *)(LONG_PTR
)lppt
->x
)) return FALSE
;
2242 if (!DPA_SetPtr(infoPtr
->hdpaPosY
, nItem
, (void *)(LONG_PTR
)lppt
->y
)) return FALSE
;
2244 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
2251 * Arranges listview items in icon display mode.
2254 * [I] infoPtr : valid pointer to the listview structure
2255 * [I] nAlignCode : alignment code
2261 static BOOL
LISTVIEW_Arrange(LISTVIEW_INFO
*infoPtr
, INT nAlignCode
)
2263 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2264 void (*next_pos
)(LISTVIEW_INFO
*, LPPOINT
);
2268 if (uView
!= LVS_ICON
&& uView
!= LVS_SMALLICON
) return FALSE
;
2270 TRACE("nAlignCode=%d\n", nAlignCode
);
2272 if (nAlignCode
== LVA_DEFAULT
)
2274 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
) nAlignCode
= LVA_ALIGNLEFT
;
2275 else nAlignCode
= LVA_ALIGNTOP
;
2280 case LVA_ALIGNLEFT
: next_pos
= LISTVIEW_NextIconPosLeft
; break;
2281 case LVA_ALIGNTOP
: next_pos
= LISTVIEW_NextIconPosTop
; break;
2282 case LVA_SNAPTOGRID
: next_pos
= LISTVIEW_NextIconPosTop
; break; /* FIXME */
2283 default: return FALSE
;
2286 infoPtr
->bAutoarrange
= TRUE
;
2287 infoPtr
->currIconPos
.x
= infoPtr
->currIconPos
.y
= 0;
2288 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2290 next_pos(infoPtr
, &pos
);
2291 LISTVIEW_MoveIconTo(infoPtr
, i
, &pos
, FALSE
);
2299 * Retrieves the bounding rectangle of all the items, not offset by Origin.
2302 * [I] infoPtr : valid pointer to the listview structure
2303 * [O] lprcView : bounding rectangle
2309 static void LISTVIEW_GetAreaRect(LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2313 SetRectEmpty(lprcView
);
2315 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
2319 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2321 x
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosX
, i
);
2322 y
= (LONG_PTR
)DPA_GetPtr(infoPtr
->hdpaPosY
, i
);
2323 lprcView
->right
= max(lprcView
->right
, x
);
2324 lprcView
->bottom
= max(lprcView
->bottom
, y
);
2326 if (infoPtr
->nItemCount
> 0)
2328 lprcView
->right
+= infoPtr
->nItemWidth
;
2329 lprcView
->bottom
+= infoPtr
->nItemHeight
;
2334 y
= LISTVIEW_GetCountPerColumn(infoPtr
);
2335 x
= infoPtr
->nItemCount
/ y
;
2336 if (infoPtr
->nItemCount
% y
) x
++;
2337 lprcView
->right
= x
* infoPtr
->nItemWidth
;
2338 lprcView
->bottom
= y
* infoPtr
->nItemHeight
;
2342 lprcView
->right
= infoPtr
->nItemWidth
;
2343 lprcView
->bottom
= infoPtr
->nItemCount
* infoPtr
->nItemHeight
;
2350 * Retrieves the bounding rectangle of all the items.
2353 * [I] infoPtr : valid pointer to the listview structure
2354 * [O] lprcView : bounding rectangle
2360 static BOOL
LISTVIEW_GetViewRect(LISTVIEW_INFO
*infoPtr
, LPRECT lprcView
)
2364 TRACE("(lprcView=%p)\n", lprcView
);
2366 if (!lprcView
) return FALSE
;
2368 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
2369 LISTVIEW_GetAreaRect(infoPtr
, lprcView
);
2370 OffsetRect(lprcView
, ptOrigin
.x
, ptOrigin
.y
);
2372 TRACE("lprcView=%s\n", debugrect(lprcView
));
2379 * Retrieves the subitem pointer associated with the subitem index.
2382 * [I] hdpaSubItems : DPA handle for a specific item
2383 * [I] nSubItem : index of subitem
2386 * SUCCESS : subitem pointer
2389 static SUBITEM_INFO
* LISTVIEW_GetSubItemPtr(HDPA hdpaSubItems
, INT nSubItem
)
2391 SUBITEM_INFO
*lpSubItem
;
2394 /* we should binary search here if need be */
2395 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
2397 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
2398 if (lpSubItem
->iSubItem
== nSubItem
)
2408 * Caclulates the desired item width.
2411 * [I] infoPtr : valid pointer to the listview structure
2414 * The desired item width.
2416 static INT
LISTVIEW_CalculateItemWidth(LISTVIEW_INFO
*infoPtr
)
2418 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2421 TRACE("uView=%d\n", uView
);
2423 if (uView
== LVS_ICON
)
2424 nItemWidth
= infoPtr
->iconSpacing
.cx
;
2425 else if (uView
== LVS_REPORT
)
2429 if (DPA_GetPtrCount(infoPtr
->hdpaColumns
) > 0)
2431 LISTVIEW_GetHeaderRect(infoPtr
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1, &rcHeader
);
2432 nItemWidth
= rcHeader
.right
;
2435 else /* LVS_SMALLICON, or LVS_LIST */
2439 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2440 nItemWidth
= max(LISTVIEW_GetLabelWidth(infoPtr
, i
), nItemWidth
);
2442 if (infoPtr
->himlSmall
) nItemWidth
+= infoPtr
->iconSize
.cx
;
2443 if (infoPtr
->himlState
) nItemWidth
+= infoPtr
->iconStateSize
.cx
;
2445 nItemWidth
= max(DEFAULT_COLUMN_WIDTH
, nItemWidth
+ WIDTH_PADDING
);
2448 return max(nItemWidth
, 1);
2453 * Caclulates the desired item height.
2456 * [I] infoPtr : valid pointer to the listview structure
2459 * The desired item height.
2461 static INT
LISTVIEW_CalculateItemHeight(LISTVIEW_INFO
*infoPtr
)
2463 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
2466 TRACE("uView=%d\n", uView
);
2468 if (uView
== LVS_ICON
)
2469 nItemHeight
= infoPtr
->iconSpacing
.cy
;
2472 nItemHeight
= infoPtr
->ntmHeight
;
2473 if (infoPtr
->himlState
)
2474 nItemHeight
= max(nItemHeight
, infoPtr
->iconStateSize
.cy
);
2475 if (infoPtr
->himlSmall
)
2476 nItemHeight
= max(nItemHeight
, infoPtr
->iconSize
.cy
);
2477 if (infoPtr
->himlState
|| infoPtr
->himlSmall
)
2478 nItemHeight
+= HEIGHT_PADDING
;
2479 if (infoPtr
->nMeasureItemHeight
> 0)
2480 nItemHeight
= infoPtr
->nMeasureItemHeight
;
2483 return max(nItemHeight
, 1);
2488 * Updates the width, and height of an item.
2491 * [I] infoPtr : valid pointer to the listview structure
2496 static inline void LISTVIEW_UpdateItemSize(LISTVIEW_INFO
*infoPtr
)
2498 infoPtr
->nItemWidth
= LISTVIEW_CalculateItemWidth(infoPtr
);
2499 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
2505 * Retrieves and saves important text metrics info for the current
2509 * [I] infoPtr : valid pointer to the listview structure
2512 static void LISTVIEW_SaveTextMetrics(LISTVIEW_INFO
*infoPtr
)
2514 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
2515 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
2516 HFONT hOldFont
= SelectObject(hdc
, hFont
);
2520 if (GetTextMetricsW(hdc
, &tm
))
2522 infoPtr
->ntmHeight
= tm
.tmHeight
;
2523 infoPtr
->ntmMaxCharWidth
= tm
.tmMaxCharWidth
;
2526 if (GetTextExtentPoint32A(hdc
, "...", 3, &sz
))
2527 infoPtr
->nEllipsisWidth
= sz
.cx
;
2529 SelectObject(hdc
, hOldFont
);
2530 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
2532 TRACE("tmHeight=%d\n", infoPtr
->ntmHeight
);
2537 * A compare function for ranges
2540 * [I] range1 : pointer to range 1;
2541 * [I] range2 : pointer to range 2;
2545 * > 0 : if range 1 > range 2
2546 * < 0 : if range 2 > range 1
2547 * = 0 : if range intersects range 2
2549 static INT CALLBACK
ranges_cmp(LPVOID range1
, LPVOID range2
, LPARAM flags
)
2553 if (((RANGE
*)range1
)->upper
<= ((RANGE
*)range2
)->lower
)
2555 else if (((RANGE
*)range2
)->upper
<= ((RANGE
*)range1
)->lower
)
2560 TRACE("range1=%s, range2=%s, cmp=%d\n", debugrange((RANGE
*)range1
), debugrange((RANGE
*)range2
), cmp
);
2566 #define ranges_check(ranges, desc) ranges_assert(ranges, desc, __FUNCTION__, __LINE__)
2568 #define ranges_check(ranges, desc) do { } while(0)
2571 static void ranges_assert(RANGES ranges
, LPCSTR desc
, const char *func
, int line
)
2576 TRACE("*** Checking %s:%d:%s ***\n", func
, line
, desc
);
2578 assert (DPA_GetPtrCount(ranges
->hdpa
) >= 0);
2579 ranges_dump(ranges
);
2580 prev
= (RANGE
*)DPA_GetPtr(ranges
->hdpa
, 0);
2581 if (DPA_GetPtrCount(ranges
->hdpa
) > 0)
2582 assert (prev
->lower
>= 0 && prev
->lower
< prev
->upper
);
2583 for (i
= 1; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2585 curr
= (RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
);
2586 assert (prev
->upper
<= curr
->lower
);
2587 assert (curr
->lower
< curr
->upper
);
2590 TRACE("--- Done checking---\n");
2593 static RANGES
ranges_create(int count
)
2595 RANGES ranges
= (RANGES
)Alloc(sizeof(struct tagRANGES
));
2596 if (!ranges
) return NULL
;
2597 ranges
->hdpa
= DPA_Create(count
);
2598 if (ranges
->hdpa
) return ranges
;
2603 static void ranges_clear(RANGES ranges
)
2607 for(i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2608 Free(DPA_GetPtr(ranges
->hdpa
, i
));
2609 DPA_DeleteAllPtrs(ranges
->hdpa
);
2613 static void ranges_destroy(RANGES ranges
)
2615 if (!ranges
) return;
2616 ranges_clear(ranges
);
2617 DPA_Destroy(ranges
->hdpa
);
2621 static RANGES
ranges_clone(RANGES ranges
)
2626 if (!(clone
= ranges_create(DPA_GetPtrCount(ranges
->hdpa
)))) goto fail
;
2628 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2630 RANGE
*newrng
= (RANGE
*)Alloc(sizeof(RANGE
));
2631 if (!newrng
) goto fail
;
2632 *newrng
= *((RANGE
*)DPA_GetPtr(ranges
->hdpa
, i
));
2633 DPA_SetPtr(clone
->hdpa
, i
, newrng
);
2638 TRACE ("clone failed\n");
2639 ranges_destroy(clone
);
2643 static RANGES
ranges_diff(RANGES ranges
, RANGES sub
)
2647 for (i
= 0; i
< DPA_GetPtrCount(sub
->hdpa
); i
++)
2648 ranges_del(ranges
, *((RANGE
*)DPA_GetPtr(sub
->hdpa
, i
)));
2653 static void ranges_dump(RANGES ranges
)
2657 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2658 TRACE(" %s\n", debugrange(DPA_GetPtr(ranges
->hdpa
, i
)));
2661 static inline BOOL
ranges_contain(RANGES ranges
, INT nItem
)
2663 RANGE srchrng
= { nItem
, nItem
+ 1 };
2665 TRACE("(nItem=%d)\n", nItem
);
2666 ranges_check(ranges
, "before contain");
2667 return DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
) != -1;
2670 static INT
ranges_itemcount(RANGES ranges
)
2674 for (i
= 0; i
< DPA_GetPtrCount(ranges
->hdpa
); i
++)
2676 RANGE
*sel
= DPA_GetPtr(ranges
->hdpa
, i
);
2677 count
+= sel
->upper
- sel
->lower
;
2683 static BOOL
ranges_shift(RANGES ranges
, INT nItem
, INT delta
, INT nUpper
)
2685 RANGE srchrng
= { nItem
, nItem
+ 1 }, *chkrng
;
2688 index
= DPA_Search(ranges
->hdpa
, &srchrng
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
2689 if (index
== -1) return TRUE
;
2691 for (; index
< DPA_GetPtrCount(ranges
->hdpa
); index
++)
2693 chkrng
= DPA_GetPtr(ranges
->hdpa
, index
);
2694 if (chkrng
->lower
>= nItem
)
2695 chkrng
->lower
= max(min(chkrng
->lower
+ delta
, nUpper
- 1), 0);
2696 if (chkrng
->upper
> nItem
)
2697 chkrng
->upper
= max(min(chkrng
->upper
+ delta
, nUpper
), 0);
2702 static BOOL
ranges_add(RANGES ranges
, RANGE range
)
2707 TRACE("(%s)\n", debugrange(&range
));
2708 ranges_check(ranges
, "before add");
2710 /* try find overlapping regions first */
2711 srchrgn
.lower
= range
.lower
- 1;
2712 srchrgn
.upper
= range
.upper
+ 1;
2713 index
= DPA_Search(ranges
->hdpa
, &srchrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
);
2719 TRACE("Adding new range\n");
2721 /* create the brand new range to insert */
2722 newrgn
= (RANGE
*)Alloc(sizeof(RANGE
));
2723 if(!newrgn
) goto fail
;
2726 /* figure out where to insert it */
2727 index
= DPA_Search(ranges
->hdpa
, newrgn
, 0, ranges_cmp
, 0, DPAS_SORTED
| DPAS_INSERTAFTER
);
2728 TRACE("index=%d\n", index
);
2729 if (index
== -1) index
= 0;
2731 /* and get it over with */
2732 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
2740 RANGE
*chkrgn
, *mrgrgn
;
2741 INT fromindex
, mergeindex
;
2743 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
2744 TRACE("Merge with %s @%d\n", debugrange(chkrgn
), index
);
2746 chkrgn
->lower
= min(range
.lower
, chkrgn
->lower
);
2747 chkrgn
->upper
= max(range
.upper
, chkrgn
->upper
);
2749 TRACE("New range %s @%d\n", debugrange(chkrgn
), index
);
2751 /* merge now common anges */
2753 srchrgn
.lower
= chkrgn
->lower
- 1;
2754 srchrgn
.upper
= chkrgn
->upper
+ 1;
2758 mergeindex
= DPA_Search(ranges
->hdpa
, &srchrgn
, fromindex
, ranges_cmp
, 0, 0);
2759 if (mergeindex
== -1) break;
2760 if (mergeindex
== index
)
2762 fromindex
= index
+ 1;
2766 TRACE("Merge with index %i\n", mergeindex
);
2768 mrgrgn
= DPA_GetPtr(ranges
->hdpa
, mergeindex
);
2769 chkrgn
->lower
= min(chkrgn
->lower
, mrgrgn
->lower
);
2770 chkrgn
->upper
= max(chkrgn
->upper
, mrgrgn
->upper
);
2772 DPA_DeletePtr(ranges
->hdpa
, mergeindex
);
2773 if (mergeindex
< index
) index
--;
2777 ranges_check(ranges
, "after add");
2781 ranges_check(ranges
, "failed add");
2785 static BOOL
ranges_del(RANGES ranges
, RANGE range
)
2790 TRACE("(%s)\n", debugrange(&range
));
2791 ranges_check(ranges
, "before del");
2793 /* we don't use DPAS_SORTED here, since we need *
2794 * to find the first overlapping range */
2795 index
= DPA_Search(ranges
->hdpa
, &range
, 0, ranges_cmp
, 0, 0);
2798 chkrgn
= DPA_GetPtr(ranges
->hdpa
, index
);
2800 TRACE("Matches range %s @%d\n", debugrange(chkrgn
), index
);
2802 /* case 1: Same range */
2803 if ( (chkrgn
->upper
== range
.upper
) &&
2804 (chkrgn
->lower
== range
.lower
) )
2806 DPA_DeletePtr(ranges
->hdpa
, index
);
2809 /* case 2: engulf */
2810 else if ( (chkrgn
->upper
<= range
.upper
) &&
2811 (chkrgn
->lower
>= range
.lower
) )
2813 DPA_DeletePtr(ranges
->hdpa
, index
);
2815 /* case 3: overlap upper */
2816 else if ( (chkrgn
->upper
<= range
.upper
) &&
2817 (chkrgn
->lower
< range
.lower
) )
2819 chkrgn
->upper
= range
.lower
;
2821 /* case 4: overlap lower */
2822 else if ( (chkrgn
->upper
> range
.upper
) &&
2823 (chkrgn
->lower
>= range
.lower
) )
2825 chkrgn
->lower
= range
.upper
;
2828 /* case 5: fully internal */
2831 RANGE tmprgn
= *chkrgn
, *newrgn
;
2833 if (!(newrgn
= (RANGE
*)Alloc(sizeof(RANGE
)))) goto fail
;
2834 newrgn
->lower
= chkrgn
->lower
;
2835 newrgn
->upper
= range
.lower
;
2836 chkrgn
->lower
= range
.upper
;
2837 if (DPA_InsertPtr(ranges
->hdpa
, index
, newrgn
) == -1)
2846 index
= DPA_Search(ranges
->hdpa
, &range
, index
, ranges_cmp
, 0, 0);
2849 ranges_check(ranges
, "after del");
2853 ranges_check(ranges
, "failed del");
2859 * Removes all selection ranges
2862 * [I] infoPtr : valid pointer to the listview structure
2863 * [I] toSkip : item range to skip removing the selection
2869 static BOOL
LISTVIEW_DeselectAllSkipItems(LISTVIEW_INFO
*infoPtr
, RANGES toSkip
)
2878 lvItem
.stateMask
= LVIS_SELECTED
;
2880 /* need to clone the DPA because callbacks can change it */
2881 if (!(clone
= ranges_clone(infoPtr
->selectionRanges
))) return FALSE
;
2882 iterator_rangesitems(&i
, ranges_diff(clone
, toSkip
));
2883 while(iterator_next(&i
))
2884 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &lvItem
);
2885 /* note that the iterator destructor will free the cloned range */
2886 iterator_destroy(&i
);
2891 static inline BOOL
LISTVIEW_DeselectAllSkipItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2895 if (!(toSkip
= ranges_create(1))) return FALSE
;
2896 if (nItem
!= -1) ranges_additem(toSkip
, nItem
);
2897 LISTVIEW_DeselectAllSkipItems(infoPtr
, toSkip
);
2898 ranges_destroy(toSkip
);
2902 static inline BOOL
LISTVIEW_DeselectAll(LISTVIEW_INFO
*infoPtr
)
2904 return LISTVIEW_DeselectAllSkipItem(infoPtr
, -1);
2909 * Retrieves the number of items that are marked as selected.
2912 * [I] infoPtr : valid pointer to the listview structure
2915 * Number of items selected.
2917 static INT
LISTVIEW_GetSelectedCount(LISTVIEW_INFO
*infoPtr
)
2919 INT nSelectedCount
= 0;
2921 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
2924 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
2926 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
2931 nSelectedCount
= ranges_itemcount(infoPtr
->selectionRanges
);
2933 TRACE("nSelectedCount=%d\n", nSelectedCount
);
2934 return nSelectedCount
;
2939 * Manages the item focus.
2942 * [I] infoPtr : valid pointer to the listview structure
2943 * [I] nItem : item index
2946 * TRUE : focused item changed
2947 * FALSE : focused item has NOT changed
2949 static inline BOOL
LISTVIEW_SetItemFocus(LISTVIEW_INFO
*infoPtr
, INT nItem
)
2951 INT oldFocus
= infoPtr
->nFocusedItem
;
2954 if (nItem
== infoPtr
->nFocusedItem
) return FALSE
;
2956 lvItem
.state
= nItem
== -1 ? 0 : LVIS_FOCUSED
;
2957 lvItem
.stateMask
= LVIS_FOCUSED
;
2958 LISTVIEW_SetItemState(infoPtr
, nItem
== -1 ? infoPtr
->nFocusedItem
: nItem
, &lvItem
);
2960 return oldFocus
!= infoPtr
->nFocusedItem
;
2963 /* Helper function for LISTVIEW_ShiftIndices *only* */
2964 static INT
shift_item(LISTVIEW_INFO
*infoPtr
, INT nShiftItem
, INT nItem
, INT direction
)
2966 if (nShiftItem
< nItem
) return nShiftItem
;
2968 if (nShiftItem
> nItem
) return nShiftItem
+ direction
;
2970 if (direction
> 0) return nShiftItem
+ direction
;
2972 return min(nShiftItem
, infoPtr
->nItemCount
- 1);
2977 * Updates the various indices after an item has been inserted or deleted.
2980 * [I] infoPtr : valid pointer to the listview structure
2981 * [I] nItem : item index
2982 * [I] direction : Direction of shift, +1 or -1.
2987 static void LISTVIEW_ShiftIndices(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT direction
)
2992 /* temporarily disable change notification while shifting items */
2993 bOldChange
= infoPtr
->bDoChangeNotify
;
2994 infoPtr
->bDoChangeNotify
= FALSE
;
2996 TRACE("Shifting %iu, %i steps\n", nItem
, direction
);
2998 ranges_shift(infoPtr
->selectionRanges
, nItem
, direction
, infoPtr
->nItemCount
);
3000 assert(abs(direction
) == 1);
3002 infoPtr
->nSelectionMark
= shift_item(infoPtr
, infoPtr
->nSelectionMark
, nItem
, direction
);
3004 nNewFocus
= shift_item(infoPtr
, infoPtr
->nFocusedItem
, nItem
, direction
);
3005 if (nNewFocus
!= infoPtr
->nFocusedItem
)
3006 LISTVIEW_SetItemFocus(infoPtr
, nNewFocus
);
3008 /* But we are not supposed to modify nHotItem! */
3010 infoPtr
->bDoChangeNotify
= bOldChange
;
3016 * Adds a block of selections.
3019 * [I] infoPtr : valid pointer to the listview structure
3020 * [I] nItem : item index
3023 * Whether the window is still valid.
3025 static BOOL
LISTVIEW_AddGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3027 INT nFirst
= min(infoPtr
->nSelectionMark
, nItem
);
3028 INT nLast
= max(infoPtr
->nSelectionMark
, nItem
);
3029 HWND hwndSelf
= infoPtr
->hwndSelf
;
3030 NMLVODSTATECHANGE nmlv
;
3035 /* Temporarily disable change notification
3036 * If the control is LVS_OWNERDATA, we need to send
3037 * only one LVN_ODSTATECHANGED notification.
3038 * See MSDN documentation for LVN_ITEMCHANGED.
3040 bOldChange
= infoPtr
->bDoChangeNotify
;
3041 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) infoPtr
->bDoChangeNotify
= FALSE
;
3043 if (nFirst
== -1) nFirst
= nItem
;
3045 item
.state
= LVIS_SELECTED
;
3046 item
.stateMask
= LVIS_SELECTED
;
3048 for (i
= nFirst
; i
<= nLast
; i
++)
3049 LISTVIEW_SetItemState(infoPtr
,i
,&item
);
3051 ZeroMemory(&nmlv
, sizeof(nmlv
));
3052 nmlv
.iFrom
= nFirst
;
3055 nmlv
.uOldState
= item
.state
;
3057 notify_hdr(infoPtr
, LVN_ODSTATECHANGED
, (LPNMHDR
)&nmlv
);
3058 if (!IsWindow(hwndSelf
))
3060 infoPtr
->bDoChangeNotify
= bOldChange
;
3067 * Sets a single group selection.
3070 * [I] infoPtr : valid pointer to the listview structure
3071 * [I] nItem : item index
3076 static void LISTVIEW_SetGroupSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3078 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3083 if (!(selection
= ranges_create(100))) return;
3085 item
.state
= LVIS_SELECTED
;
3086 item
.stateMask
= LVIS_SELECTED
;
3088 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
3090 if (infoPtr
->nSelectionMark
== -1)
3092 infoPtr
->nSelectionMark
= nItem
;
3093 ranges_additem(selection
, nItem
);
3099 sel
.lower
= min(infoPtr
->nSelectionMark
, nItem
);
3100 sel
.upper
= max(infoPtr
->nSelectionMark
, nItem
) + 1;
3101 ranges_add(selection
, sel
);
3106 RECT rcItem
, rcSel
, rcSelMark
;
3109 rcItem
.left
= LVIR_BOUNDS
;
3110 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return;
3111 rcSelMark
.left
= LVIR_BOUNDS
;
3112 if (!LISTVIEW_GetItemRect(infoPtr
, infoPtr
->nSelectionMark
, &rcSelMark
)) return;
3113 UnionRect(&rcSel
, &rcItem
, &rcSelMark
);
3114 iterator_frameditems(&i
, infoPtr
, &rcSel
);
3115 while(iterator_next(&i
))
3117 LISTVIEW_GetItemPosition(infoPtr
, i
.nItem
, &ptItem
);
3118 if (PtInRect(&rcSel
, ptItem
)) ranges_additem(selection
, i
.nItem
);
3120 iterator_destroy(&i
);
3123 LISTVIEW_DeselectAllSkipItems(infoPtr
, selection
);
3124 iterator_rangesitems(&i
, selection
);
3125 while(iterator_next(&i
))
3126 LISTVIEW_SetItemState(infoPtr
, i
.nItem
, &item
);
3127 /* this will also destroy the selection */
3128 iterator_destroy(&i
);
3130 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3135 * Sets a single selection.
3138 * [I] infoPtr : valid pointer to the listview structure
3139 * [I] nItem : item index
3144 static void LISTVIEW_SetSelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3148 TRACE("nItem=%d\n", nItem
);
3150 LISTVIEW_DeselectAllSkipItem(infoPtr
, nItem
);
3152 lvItem
.state
= LVIS_FOCUSED
| LVIS_SELECTED
;
3153 lvItem
.stateMask
= LVIS_FOCUSED
| LVIS_SELECTED
;
3154 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3156 infoPtr
->nSelectionMark
= nItem
;
3161 * Set selection(s) with keyboard.
3164 * [I] infoPtr : valid pointer to the listview structure
3165 * [I] nItem : item index
3168 * SUCCESS : TRUE (needs to be repainted)
3169 * FAILURE : FALSE (nothing has changed)
3171 static BOOL
LISTVIEW_KeySelection(LISTVIEW_INFO
*infoPtr
, INT nItem
)
3173 /* FIXME: pass in the state */
3174 WORD wShift
= HIWORD(GetKeyState(VK_SHIFT
));
3175 WORD wCtrl
= HIWORD(GetKeyState(VK_CONTROL
));
3176 BOOL bResult
= FALSE
;
3178 TRACE("nItem=%d, wShift=%d, wCtrl=%d\n", nItem
, wShift
, wCtrl
);
3179 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
3181 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
3184 LISTVIEW_SetSelection(infoPtr
, nItem
);
3191 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
3196 lvItem
.state
= ~LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3197 lvItem
.stateMask
= LVIS_SELECTED
;
3198 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvItem
);
3200 if (lvItem
.state
& LVIS_SELECTED
)
3201 infoPtr
->nSelectionMark
= nItem
;
3203 bResult
= LISTVIEW_SetItemFocus(infoPtr
, nItem
);
3208 LISTVIEW_SetSelection(infoPtr
, nItem
);
3211 LISTVIEW_EnsureVisible(infoPtr
, nItem
, FALSE
);
3214 UpdateWindow(infoPtr
->hwndSelf
); /* update client area */
3218 static BOOL
LISTVIEW_GetItemAtPt(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, POINT pt
)
3220 LVHITTESTINFO lvHitTestInfo
;
3222 ZeroMemory(&lvHitTestInfo
, sizeof(lvHitTestInfo
));
3223 lvHitTestInfo
.pt
.x
= pt
.x
;
3224 lvHitTestInfo
.pt
.y
= pt
.y
;
3226 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
3228 lpLVItem
->mask
= LVIF_PARAM
;
3229 lpLVItem
->iItem
= lvHitTestInfo
.iItem
;
3230 lpLVItem
->iSubItem
= 0;
3232 return LISTVIEW_GetItemT(infoPtr
, lpLVItem
, TRUE
);
3237 * Called when the mouse is being actively tracked and has hovered for a specified
3241 * [I] infoPtr : valid pointer to the listview structure
3242 * [I] fwKeys : key indicator
3243 * [I] x,y : mouse position
3246 * 0 if the message was processed, non-zero if there was an error
3249 * LVS_EX_TRACKSELECT: An item is automatically selected when the cursor remains
3250 * over the item for a certain period of time.
3253 static LRESULT
LISTVIEW_MouseHover(LISTVIEW_INFO
*infoPtr
, WORD fwKyes
, INT x
, INT y
)
3255 if (infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)
3263 if (LISTVIEW_GetItemAtPt(infoPtr
, &item
, pt
))
3264 LISTVIEW_SetSelection(infoPtr
, item
.iItem
);
3272 * Called whenever WM_MOUSEMOVE is received.
3275 * [I] infoPtr : valid pointer to the listview structure
3276 * [I] fwKeys : key indicator
3277 * [I] x,y : mouse position
3280 * 0 if the message is processed, non-zero if there was an error
3282 static LRESULT
LISTVIEW_MouseMove(LISTVIEW_INFO
*infoPtr
, WORD fwKeys
, INT x
, INT y
)
3284 TRACKMOUSEEVENT trackinfo
;
3286 if (!(fwKeys
& MK_LBUTTON
))
3287 infoPtr
->bLButtonDown
= FALSE
;
3289 if (infoPtr
->bLButtonDown
&& DragDetect(infoPtr
->hwndSelf
, infoPtr
->ptClickPos
))
3291 LVHITTESTINFO lvHitTestInfo
;
3294 lvHitTestInfo
.pt
= infoPtr
->ptClickPos
;
3295 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
3297 ZeroMemory(&nmlv
, sizeof(nmlv
));
3298 nmlv
.iItem
= lvHitTestInfo
.iItem
;
3299 nmlv
.ptAction
= infoPtr
->ptClickPos
;
3301 notify_listview(infoPtr
, LVN_BEGINDRAG
, &nmlv
);
3306 infoPtr
->bLButtonDown
= FALSE
;
3308 /* see if we are supposed to be tracking mouse hovering */
3309 if(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
) {
3310 /* fill in the trackinfo struct */
3311 trackinfo
.cbSize
= sizeof(TRACKMOUSEEVENT
);
3312 trackinfo
.dwFlags
= TME_QUERY
;
3313 trackinfo
.hwndTrack
= infoPtr
->hwndSelf
;
3314 trackinfo
.dwHoverTime
= infoPtr
->dwHoverTime
;
3316 /* see if we are already tracking this hwnd */
3317 _TrackMouseEvent(&trackinfo
);
3319 if(!(trackinfo
.dwFlags
& TME_HOVER
)) {
3320 trackinfo
.dwFlags
= TME_HOVER
;
3322 /* call TRACKMOUSEEVENT so we receive WM_MOUSEHOVER messages */
3323 _TrackMouseEvent(&trackinfo
);
3332 * Tests wheather the item is assignable to a list with style lStyle
3334 static inline BOOL
is_assignable_item(const LVITEMW
*lpLVItem
, LONG lStyle
)
3336 if ( (lpLVItem
->mask
& LVIF_TEXT
) &&
3337 (lpLVItem
->pszText
== LPSTR_TEXTCALLBACKW
) &&
3338 (lStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) ) return FALSE
;
3346 * Helper for LISTVIEW_SetItemT *only*: sets item attributes.
3349 * [I] infoPtr : valid pointer to the listview structure
3350 * [I] lpLVItem : valid pointer to new item atttributes
3351 * [I] isNew : the item being set is being inserted
3352 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3353 * [O] bChanged : will be set to TRUE if the item really changed
3359 static BOOL
set_main_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isNew
, BOOL isW
, BOOL
*bChanged
)
3361 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3369 assert(lpLVItem
->iItem
>= 0 && lpLVItem
->iItem
< infoPtr
->nItemCount
);
3371 if (lpLVItem
->mask
== 0) return TRUE
;
3373 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
3375 /* a virtual listview we stores only selection and focus */
3376 if (lpLVItem
->mask
& ~LVIF_STATE
)
3382 HDPA hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3383 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
3387 /* we need to get the lParam and state of the item */
3388 item
.iItem
= lpLVItem
->iItem
;
3389 item
.iSubItem
= lpLVItem
->iSubItem
;
3390 item
.mask
= LVIF_STATE
| LVIF_PARAM
;
3391 item
.stateMask
= ~0;
3394 if (!isNew
&& !LISTVIEW_GetItemW(infoPtr
, &item
)) return FALSE
;
3396 TRACE("oldState=%x, newState=%x\n", item
.state
, lpLVItem
->state
);
3397 /* determine what fields will change */
3398 if ((lpLVItem
->mask
& LVIF_STATE
) && ((item
.state
^ lpLVItem
->state
) & lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
))
3399 uChanged
|= LVIF_STATE
;
3401 if ((lpLVItem
->mask
& LVIF_IMAGE
) && (lpItem
->hdr
.iImage
!= lpLVItem
->iImage
))
3402 uChanged
|= LVIF_IMAGE
;
3404 if ((lpLVItem
->mask
& LVIF_PARAM
) && (lpItem
->lParam
!= lpLVItem
->lParam
))
3405 uChanged
|= LVIF_PARAM
;
3407 if ((lpLVItem
->mask
& LVIF_INDENT
) && (lpItem
->iIndent
!= lpLVItem
->iIndent
))
3408 uChanged
|= LVIF_INDENT
;
3410 if ((lpLVItem
->mask
& LVIF_TEXT
) && textcmpWT(lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
))
3411 uChanged
|= LVIF_TEXT
;
3413 TRACE("uChanged=0x%x\n", uChanged
);
3414 if (!uChanged
) return TRUE
;
3417 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
3418 nmlv
.iItem
= lpLVItem
->iItem
;
3419 nmlv
.uNewState
= (item
.state
& ~lpLVItem
->stateMask
) | (lpLVItem
->state
& lpLVItem
->stateMask
);
3420 nmlv
.uOldState
= item
.state
;
3421 nmlv
.uChanged
= uChanged
;
3422 nmlv
.lParam
= item
.lParam
;
3424 /* send LVN_ITEMCHANGING notification, if the item is not being inserted */
3425 /* and we are _NOT_ virtual (LVS_OWERNDATA), and change notifications */
3427 if(lpItem
&& !isNew
&& infoPtr
->bDoChangeNotify
)
3429 HWND hwndSelf
= infoPtr
->hwndSelf
;
3431 if (notify_listview(infoPtr
, LVN_ITEMCHANGING
, &nmlv
))
3433 if (!IsWindow(hwndSelf
))
3437 /* copy information */
3438 if (lpLVItem
->mask
& LVIF_TEXT
)
3439 textsetptrT(&lpItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3441 if (lpLVItem
->mask
& LVIF_IMAGE
)
3442 lpItem
->hdr
.iImage
= lpLVItem
->iImage
;
3444 if (lpLVItem
->mask
& LVIF_PARAM
)
3445 lpItem
->lParam
= lpLVItem
->lParam
;
3447 if (lpLVItem
->mask
& LVIF_INDENT
)
3448 lpItem
->iIndent
= lpLVItem
->iIndent
;
3450 if (uChanged
& LVIF_STATE
)
3452 if (lpItem
&& (lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& ~(LVIS_FOCUSED
| LVIS_SELECTED
)))
3454 lpItem
->state
&= ~lpLVItem
->stateMask
;
3455 lpItem
->state
|= (lpLVItem
->state
& lpLVItem
->stateMask
);
3457 if (lpLVItem
->state
& lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
3459 if (infoPtr
->dwStyle
& LVS_SINGLESEL
) LISTVIEW_DeselectAllSkipItem(infoPtr
, lpLVItem
->iItem
);
3460 ranges_additem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3462 else if (lpLVItem
->stateMask
& LVIS_SELECTED
)
3463 ranges_delitem(infoPtr
->selectionRanges
, lpLVItem
->iItem
);
3465 /* if we are asked to change focus, and we manage it, do it */
3466 if (lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
3468 if (lpLVItem
->state
& LVIS_FOCUSED
)
3470 LISTVIEW_SetItemFocus(infoPtr
, -1);
3471 infoPtr
->nFocusedItem
= lpLVItem
->iItem
;
3472 LISTVIEW_EnsureVisible(infoPtr
, lpLVItem
->iItem
, uView
== LVS_LIST
);
3474 else if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
3475 infoPtr
->nFocusedItem
= -1;
3479 /* if we're inserting the item, we're done */
3480 if (isNew
) return TRUE
;
3482 /* send LVN_ITEMCHANGED notification */
3483 if (lpLVItem
->mask
& LVIF_PARAM
) nmlv
.lParam
= lpLVItem
->lParam
;
3484 if (infoPtr
->bDoChangeNotify
) notify_listview(infoPtr
, LVN_ITEMCHANGED
, &nmlv
);
3491 * Helper for LISTVIEW_{Set,Insert}ItemT *only*: sets subitem attributes.
3494 * [I] infoPtr : valid pointer to the listview structure
3495 * [I] lpLVItem : valid pointer to new subitem atttributes
3496 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3497 * [O] bChanged : will be set to TRUE if the item really changed
3503 static BOOL
set_sub_item(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
, BOOL
*bChanged
)
3506 SUBITEM_INFO
*lpSubItem
;
3508 /* we do not support subitems for virtual listviews */
3509 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
3511 /* set subitem only if column is present */
3512 if (lpLVItem
->iSubItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
3514 /* First do some sanity checks */
3515 if (lpLVItem
->mask
& ~(LVIF_TEXT
| LVIF_IMAGE
)) return FALSE
;
3516 if (!(lpLVItem
->mask
& (LVIF_TEXT
| LVIF_IMAGE
))) return TRUE
;
3518 /* get the subitem structure, and create it if not there */
3519 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
3520 assert (hdpaSubItems
);
3522 lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, lpLVItem
->iSubItem
);
3525 SUBITEM_INFO
*tmpSubItem
;
3528 lpSubItem
= (SUBITEM_INFO
*)Alloc(sizeof(SUBITEM_INFO
));
3529 if (!lpSubItem
) return FALSE
;
3530 /* we could binary search here, if need be...*/
3531 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
3533 tmpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
3534 if (tmpSubItem
->iSubItem
> lpLVItem
->iSubItem
) break;
3536 if (DPA_InsertPtr(hdpaSubItems
, i
, lpSubItem
) == -1)
3541 lpSubItem
->iSubItem
= lpLVItem
->iSubItem
;
3542 lpSubItem
->hdr
.iImage
= I_IMAGECALLBACK
;
3546 if (lpLVItem
->mask
& LVIF_IMAGE
)
3547 if (lpSubItem
->hdr
.iImage
!= lpLVItem
->iImage
)
3549 lpSubItem
->hdr
.iImage
= lpLVItem
->iImage
;
3553 if (lpLVItem
->mask
& LVIF_TEXT
)
3554 if (lpSubItem
->hdr
.pszText
!= lpLVItem
->pszText
)
3556 textsetptrT(&lpSubItem
->hdr
.pszText
, lpLVItem
->pszText
, isW
);
3565 * Sets item attributes.
3568 * [I] infoPtr : valid pointer to the listview structure
3569 * [I] lpLVItem : new item atttributes
3570 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
3576 static BOOL
LISTVIEW_SetItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
3578 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3579 HWND hwndSelf
= infoPtr
->hwndSelf
;
3580 LPWSTR pszText
= NULL
;
3581 BOOL bResult
, bChanged
= FALSE
;
3583 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
3585 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
3588 /* For efficiency, we transform the lpLVItem->pszText to Unicode here */
3589 if ((lpLVItem
->mask
& LVIF_TEXT
) && is_textW(lpLVItem
->pszText
))
3591 pszText
= lpLVItem
->pszText
;
3592 ((LVITEMW
*)lpLVItem
)->pszText
= textdupTtoW(lpLVItem
->pszText
, isW
);
3595 /* actually set the fields */
3596 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return FALSE
;
3598 if (lpLVItem
->iSubItem
)
3599 bResult
= set_sub_item(infoPtr
, lpLVItem
, TRUE
, &bChanged
);
3601 bResult
= set_main_item(infoPtr
, lpLVItem
, FALSE
, TRUE
, &bChanged
);
3602 if (!IsWindow(hwndSelf
))
3605 /* redraw item, if necessary */
3606 if (bChanged
&& !infoPtr
->bIsDrawing
)
3608 /* this little optimization eliminates some nasty flicker */
3609 if ( uView
== LVS_REPORT
&& !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) &&
3610 (!(infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) || lpLVItem
->iSubItem
) )
3611 LISTVIEW_InvalidateSubItem(infoPtr
, lpLVItem
->iItem
, lpLVItem
->iSubItem
);
3613 LISTVIEW_InvalidateItem(infoPtr
, lpLVItem
->iItem
);
3618 textfreeT(lpLVItem
->pszText
, isW
);
3619 ((LVITEMW
*)lpLVItem
)->pszText
= pszText
;
3627 * Retrieves the index of the item at coordinate (0, 0) of the client area.
3630 * [I] infoPtr : valid pointer to the listview structure
3635 static INT
LISTVIEW_GetTopIndex(LISTVIEW_INFO
*infoPtr
)
3637 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3639 SCROLLINFO scrollInfo
;
3641 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
3642 scrollInfo
.fMask
= SIF_POS
;
3644 if (uView
== LVS_LIST
)
3646 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
3647 nItem
= scrollInfo
.nPos
* LISTVIEW_GetCountPerColumn(infoPtr
);
3649 else if (uView
== LVS_REPORT
)
3651 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3652 nItem
= scrollInfo
.nPos
;
3656 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
3657 nItem
= LISTVIEW_GetCountPerRow(infoPtr
) * (scrollInfo
.nPos
/ infoPtr
->nItemHeight
);
3660 TRACE("nItem=%d\n", nItem
);
3668 * Erases the background of the given rectangle
3671 * [I] infoPtr : valid pointer to the listview structure
3672 * [I] hdc : device context handle
3673 * [I] lprcBox : clipping rectangle
3679 static inline BOOL
LISTVIEW_FillBkgnd(LISTVIEW_INFO
*infoPtr
, HDC hdc
, const RECT
*lprcBox
)
3681 if (!infoPtr
->hBkBrush
) return FALSE
;
3683 TRACE("(hdc=%p, lprcBox=%s, hBkBrush=%p)\n", hdc
, debugrect(lprcBox
), infoPtr
->hBkBrush
);
3685 return FillRect(hdc
, lprcBox
, infoPtr
->hBkBrush
);
3693 * [I] infoPtr : valid pointer to the listview structure
3694 * [I] hdc : device context handle
3695 * [I] nItem : item index
3696 * [I] nSubItem : subitem index
3697 * [I] pos : item position in client coordinates
3698 * [I] cdmode : custom draw mode
3704 static BOOL
LISTVIEW_DrawItem(LISTVIEW_INFO
*infoPtr
, HDC hdc
, INT nItem
, INT nSubItem
, POINT pos
, DWORD cdmode
)
3706 UINT uFormat
, uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
3707 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
3708 static const WCHAR szCallback
[] = { '(', 'c', 'a', 'l', 'l', 'b', 'a', 'c', 'k', ')', 0 };
3709 DWORD cdsubitemmode
= CDRF_DODEFAULT
;
3710 RECT
* lprcFocus
, rcSelect
, rcBox
, rcState
, rcIcon
, rcLabel
;
3711 NMLVCUSTOMDRAW nmlvcd
;
3715 TRACE("(hdc=%p, nItem=%d, nSubItem=%d, pos=%s)\n", hdc
, nItem
, nSubItem
, debugpoint(&pos
));
3717 /* get information needed for drawing the item */
3718 lvItem
.mask
= LVIF_TEXT
| LVIF_IMAGE
;
3719 if (nSubItem
== 0) lvItem
.mask
|= LVIF_STATE
| LVIF_PARAM
;
3720 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
3721 lvItem
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
| LVIS_STATEIMAGEMASK
;
3722 lvItem
.iItem
= nItem
;
3723 lvItem
.iSubItem
= nSubItem
;
3726 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
3727 lvItem
.pszText
= szDispText
;
3728 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
3729 if (nSubItem
> 0 && (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3730 lvItem
.state
= LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
);
3731 if (lvItem
.pszText
== LPSTR_TEXTCALLBACKW
) lvItem
.pszText
= (LPWSTR
)szCallback
;
3732 TRACE(" lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
3734 /* now check if we need to update the focus rectangle */
3735 lprcFocus
= infoPtr
->bFocus
&& (lvItem
.state
& LVIS_FOCUSED
) ? &infoPtr
->rcFocus
: 0;
3737 if (!lprcFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
3738 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcState
, &rcIcon
, &rcLabel
);
3739 OffsetRect(&rcBox
, pos
.x
, pos
.y
);
3740 OffsetRect(&rcState
, pos
.x
, pos
.y
);
3741 OffsetRect(&rcIcon
, pos
.x
, pos
.y
);
3742 OffsetRect(&rcLabel
, pos
.x
, pos
.y
);
3743 TRACE(" rcBox=%s, rcState=%s, rcIcon=%s. rcLabel=%s\n",
3744 debugrect(&rcBox
), debugrect(&rcState
), debugrect(&rcIcon
), debugrect(&rcLabel
));
3746 /* fill in the custom draw structure */
3747 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcBox
, &lvItem
);
3749 if (nSubItem
> 0) cdmode
= infoPtr
->cditemmode
;
3750 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
3751 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
3752 if (nSubItem
== 0) infoPtr
->cditemmode
= cdsubitemmode
;
3753 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
3754 /* we have to send a CDDS_SUBITEM customdraw explicitly for subitem 0 */
3755 if (nSubItem
== 0 && cdsubitemmode
== CDRF_NOTIFYITEMDRAW
)
3757 cdsubitemmode
= notify_customdraw(infoPtr
, CDDS_SUBITEM
| CDDS_ITEMPREPAINT
, &nmlvcd
);
3758 if (cdsubitemmode
& CDRF_SKIPDEFAULT
) goto postpaint
;
3760 if (nSubItem
== 0 || (cdmode
& CDRF_NOTIFYITEMDRAW
))
3761 prepaint_setup(infoPtr
, hdc
, &nmlvcd
);
3763 /* in full row select, subitems, will just use main item's colors */
3764 if (nSubItem
&& uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3765 nmlvcd
.clrTextBk
= CLR_NONE
;
3768 if (infoPtr
->himlState
&& !IsRectEmpty(&rcState
))
3770 UINT uStateImage
= STATEIMAGEINDEX(lvItem
.state
);
3773 TRACE("uStateImage=%d\n", uStateImage
);
3774 ImageList_Draw(infoPtr
->himlState
, uStateImage
- 1, hdc
, rcState
.left
, rcState
.top
, ILD_NORMAL
);
3779 himl
= (uView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
3780 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
))
3782 TRACE("iImage=%d\n", lvItem
.iImage
);
3783 ImageList_Draw(himl
, lvItem
.iImage
, hdc
, rcIcon
.left
, rcIcon
.top
,
3784 (lvItem
.state
& LVIS_SELECTED
) && (infoPtr
->bFocus
) ? ILD_SELECTED
: ILD_NORMAL
);
3787 /* Don't bother painting item being edited */
3788 if (infoPtr
->hwndEdit
&& nItem
== infoPtr
->nEditLabelItem
&& nSubItem
== 0) goto postpaint
;
3790 /* draw the selection background, if we're drawing the main item */
3794 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
))
3795 rcSelect
.right
= rcBox
.right
;
3797 if (nmlvcd
.clrTextBk
!= CLR_NONE
)
3798 ExtTextOutW(hdc
, rcSelect
.left
, rcSelect
.top
, ETO_OPAQUE
, &rcSelect
, 0, 0, 0);
3799 if(lprcFocus
) *lprcFocus
= rcSelect
;
3802 /* figure out the text drawing flags */
3803 uFormat
= (uView
== LVS_ICON
? (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
) : LV_SL_DT_FLAGS
);
3804 if (uView
== LVS_ICON
)
3805 uFormat
= (lprcFocus
? LV_FL_DT_FLAGS
: LV_ML_DT_FLAGS
);
3808 switch (LISTVIEW_GetColumnInfo(infoPtr
, nSubItem
)->fmt
& LVCFMT_JUSTIFYMASK
)
3810 case LVCFMT_RIGHT
: uFormat
|= DT_RIGHT
; break;
3811 case LVCFMT_CENTER
: uFormat
|= DT_CENTER
; break;
3812 default: uFormat
|= DT_LEFT
;
3815 if (!(uFormat
& (DT_RIGHT
| DT_CENTER
)))
3817 if (himl
&& lvItem
.iImage
>= 0 && !IsRectEmpty(&rcIcon
)) rcLabel
.left
+= IMAGE_PADDING
;
3818 else rcLabel
.left
+= LABEL_HOR_PADDING
;
3820 else if (uFormat
& DT_RIGHT
) rcLabel
.right
-= LABEL_HOR_PADDING
;
3821 DrawTextW(hdc
, lvItem
.pszText
, -1, &rcLabel
, uFormat
);
3824 if (cdsubitemmode
& CDRF_NOTIFYPOSTPAINT
)
3825 notify_postpaint(infoPtr
, &nmlvcd
);
3831 * Draws listview items when in owner draw mode.
3834 * [I] infoPtr : valid pointer to the listview structure
3835 * [I] hdc : device context handle
3840 static void LISTVIEW_RefreshOwnerDraw(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
3842 UINT uID
= (UINT
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
3843 DWORD cditemmode
= CDRF_DODEFAULT
;
3844 NMLVCUSTOMDRAW nmlvcd
;
3845 POINT Origin
, Position
;
3851 ZeroMemory(&dis
, sizeof(dis
));
3853 /* Get scroll info once before loop */
3854 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3856 /* iterate through the invalidated rows */
3857 while(iterator_next(i
))
3859 item
.iItem
= i
->nItem
;
3861 item
.mask
= LVIF_PARAM
| LVIF_STATE
;
3862 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
3863 if (!LISTVIEW_GetItemW(infoPtr
, &item
)) continue;
3865 dis
.CtlType
= ODT_LISTVIEW
;
3867 dis
.itemID
= item
.iItem
;
3868 dis
.itemAction
= ODA_DRAWENTIRE
;
3870 if (item
.state
& LVIS_SELECTED
) dis
.itemState
|= ODS_SELECTED
;
3871 if (infoPtr
->bFocus
&& (item
.state
& LVIS_FOCUSED
)) dis
.itemState
|= ODS_FOCUS
;
3872 dis
.hwndItem
= infoPtr
->hwndSelf
;
3874 LISTVIEW_GetItemOrigin(infoPtr
, dis
.itemID
, &Position
);
3875 dis
.rcItem
.left
= Position
.x
+ Origin
.x
;
3876 dis
.rcItem
.right
= dis
.rcItem
.left
+ infoPtr
->nItemWidth
;
3877 dis
.rcItem
.top
= Position
.y
+ Origin
.y
;
3878 dis
.rcItem
.bottom
= dis
.rcItem
.top
+ infoPtr
->nItemHeight
;
3879 dis
.itemData
= item
.lParam
;
3881 TRACE("item=%s, rcItem=%s\n", debuglvitem_t(&item
, TRUE
), debugrect(&dis
.rcItem
));
3884 * Even if we do not send the CDRF_NOTIFYITEMDRAW we need to fill the nmlvcd
3885 * structure for the rest. of the paint cycle
3887 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &dis
.rcItem
, &item
);
3888 if (cdmode
& CDRF_NOTIFYITEMDRAW
)
3889 cditemmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
3891 if (!(cditemmode
& CDRF_SKIPDEFAULT
))
3893 prepaint_setup (infoPtr
, hdc
, &nmlvcd
);
3894 SendMessageW(infoPtr
->hwndNotify
, WM_DRAWITEM
, dis
.CtlID
, (LPARAM
)&dis
);
3897 if (cditemmode
& CDRF_NOTIFYPOSTPAINT
)
3898 notify_postpaint(infoPtr
, &nmlvcd
);
3904 * Draws listview items when in report display mode.
3907 * [I] infoPtr : valid pointer to the listview structure
3908 * [I] hdc : device context handle
3909 * [I] cdmode : custom draw mode
3914 static void LISTVIEW_RefreshReport(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
3917 RECT rcClip
, rcItem
;
3918 POINT Origin
, Position
;
3924 /* figure out what to draw */
3925 rgntype
= GetClipBox(hdc
, &rcClip
);
3926 if (rgntype
== NULLREGION
) return;
3928 /* Get scroll info once before loop */
3929 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3931 /* narrow down the columns we need to paint */
3932 for(colRange
.lower
= 0; colRange
.lower
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); colRange
.lower
++)
3934 LISTVIEW_GetHeaderRect(infoPtr
, colRange
.lower
, &rcItem
);
3935 if (rcItem
.right
+ Origin
.x
>= rcClip
.left
) break;
3937 for(colRange
.upper
= DPA_GetPtrCount(infoPtr
->hdpaColumns
); colRange
.upper
> 0; colRange
.upper
--)
3939 LISTVIEW_GetHeaderRect(infoPtr
, colRange
.upper
- 1, &rcItem
);
3940 if (rcItem
.left
+ Origin
.x
< rcClip
.right
) break;
3942 iterator_rangeitems(&j
, colRange
);
3944 /* in full row select, we _have_ to draw the main item */
3945 if (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
)
3948 /* iterate through the invalidated rows */
3949 while(iterator_next(i
))
3951 /* iterate through the invalidated columns */
3952 while(iterator_next(&j
))
3954 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
3955 Position
.x
+= Origin
.x
;
3956 Position
.y
+= Origin
.y
;
3958 if (rgntype
== COMPLEXREGION
&& !((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && j
.nItem
== 0))
3960 LISTVIEW_GetHeaderRect(infoPtr
, j
.nItem
, &rcItem
);
3962 rcItem
.bottom
= infoPtr
->nItemHeight
;
3963 OffsetRect(&rcItem
, Position
.x
, Position
.y
);
3964 if (!RectVisible(hdc
, &rcItem
)) continue;
3967 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, j
.nItem
, Position
, cdmode
);
3970 iterator_destroy(&j
);
3975 * Draws listview items when in list display mode.
3978 * [I] infoPtr : valid pointer to the listview structure
3979 * [I] hdc : device context handle
3980 * [I] cdmode : custom draw mode
3985 static void LISTVIEW_RefreshList(LISTVIEW_INFO
*infoPtr
, ITERATOR
*i
, HDC hdc
, DWORD cdmode
)
3987 POINT Origin
, Position
;
3989 /* Get scroll info once before loop */
3990 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
3992 while(iterator_prev(i
))
3994 LISTVIEW_GetItemOrigin(infoPtr
, i
->nItem
, &Position
);
3995 Position
.x
+= Origin
.x
;
3996 Position
.y
+= Origin
.y
;
3998 LISTVIEW_DrawItem(infoPtr
, hdc
, i
->nItem
, 0, Position
, cdmode
);
4005 * Draws listview items.
4008 * [I] infoPtr : valid pointer to the listview structure
4009 * [I] hdc : device context handle
4014 static void LISTVIEW_Refresh(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
4016 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4017 COLORREF oldTextColor
, oldClrTextBk
, oldClrText
;
4018 NMLVCUSTOMDRAW nmlvcd
;
4025 LISTVIEW_DUMP(infoPtr
);
4027 infoPtr
->bIsDrawing
= TRUE
;
4029 /* save dc values we're gonna trash while drawing */
4030 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
4031 oldBkMode
= GetBkMode(hdc
);
4032 infoPtr
->clrTextBkDefault
= GetBkColor(hdc
);
4033 oldTextColor
= GetTextColor(hdc
);
4035 oldClrTextBk
= infoPtr
->clrTextBk
;
4036 oldClrText
= infoPtr
->clrText
;
4038 infoPtr
->cditemmode
= CDRF_DODEFAULT
;
4040 GetClientRect(infoPtr
->hwndSelf
, &rcClient
);
4041 customdraw_fill(&nmlvcd
, infoPtr
, hdc
, &rcClient
, 0);
4042 cdmode
= notify_customdraw(infoPtr
, CDDS_PREPAINT
, &nmlvcd
);
4043 if (cdmode
& CDRF_SKIPDEFAULT
) goto enddraw
;
4044 prepaint_setup(infoPtr
, hdc
, &nmlvcd
);
4046 /* Use these colors to draw the items */
4047 infoPtr
->clrTextBk
= nmlvcd
.clrTextBk
;
4048 infoPtr
->clrText
= nmlvcd
.clrText
;
4050 /* nothing to draw */
4051 if(infoPtr
->nItemCount
== 0) goto enddraw
;
4053 /* figure out what we need to draw */
4054 iterator_visibleitems(&i
, infoPtr
, hdc
);
4056 /* send cache hint notification */
4057 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
4059 RANGE range
= iterator_range(&i
);
4062 ZeroMemory(&nmlv
, sizeof(NMLVCACHEHINT
));
4063 nmlv
.iFrom
= range
.lower
;
4064 nmlv
.iTo
= range
.upper
- 1;
4065 notify_hdr(infoPtr
, LVN_ODCACHEHINT
, &nmlv
.hdr
);
4068 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (uView
== LVS_REPORT
))
4069 LISTVIEW_RefreshOwnerDraw(infoPtr
, &i
, hdc
, cdmode
);
4072 if (uView
== LVS_REPORT
)
4073 LISTVIEW_RefreshReport(infoPtr
, &i
, hdc
, cdmode
);
4074 else /* LVS_LIST, LVS_ICON or LVS_SMALLICON */
4075 LISTVIEW_RefreshList(infoPtr
, &i
, hdc
, cdmode
);
4077 /* if we have a focus rect, draw it */
4078 if (infoPtr
->bFocus
)
4079 DrawFocusRect(hdc
, &infoPtr
->rcFocus
);
4081 iterator_destroy(&i
);
4084 if (cdmode
& CDRF_NOTIFYPOSTPAINT
)
4085 notify_postpaint(infoPtr
, &nmlvcd
);
4087 infoPtr
->clrTextBk
= oldClrTextBk
;
4088 infoPtr
->clrText
= oldClrText
;
4090 SelectObject(hdc
, hOldFont
);
4091 SetBkMode(hdc
, oldBkMode
);
4092 SetBkColor(hdc
, infoPtr
->clrTextBkDefault
);
4093 SetTextColor(hdc
, oldTextColor
);
4094 infoPtr
->bIsDrawing
= FALSE
;
4100 * Calculates the approximate width and height of a given number of items.
4103 * [I] infoPtr : valid pointer to the listview structure
4104 * [I] nItemCount : number of items
4105 * [I] wWidth : width
4106 * [I] wHeight : height
4109 * Returns a DWORD. The width in the low word and the height in high word.
4111 static DWORD
LISTVIEW_ApproximateViewRect(LISTVIEW_INFO
*infoPtr
, INT nItemCount
,
4112 WORD wWidth
, WORD wHeight
)
4114 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4115 INT nItemCountPerColumn
= 1;
4116 INT nColumnCount
= 0;
4117 DWORD dwViewRect
= 0;
4119 if (nItemCount
== -1)
4120 nItemCount
= infoPtr
->nItemCount
;
4122 if (uView
== LVS_LIST
)
4124 if (wHeight
== 0xFFFF)
4126 /* use current height */
4127 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
4130 if (wHeight
< infoPtr
->nItemHeight
)
4131 wHeight
= infoPtr
->nItemHeight
;
4135 if (infoPtr
->nItemHeight
> 0)
4137 nItemCountPerColumn
= wHeight
/ infoPtr
->nItemHeight
;
4138 if (nItemCountPerColumn
== 0)
4139 nItemCountPerColumn
= 1;
4141 if (nItemCount
% nItemCountPerColumn
!= 0)
4142 nColumnCount
= nItemCount
/ nItemCountPerColumn
;
4144 nColumnCount
= nItemCount
/ nItemCountPerColumn
+ 1;
4148 /* Microsoft padding magic */
4149 wHeight
= nItemCountPerColumn
* infoPtr
->nItemHeight
+ 2;
4150 wWidth
= nColumnCount
* infoPtr
->nItemWidth
+ 2;
4152 dwViewRect
= MAKELONG(wWidth
, wHeight
);
4154 else if (uView
== LVS_REPORT
)
4158 if (infoPtr
->nItemCount
> 0)
4160 LISTVIEW_GetItemBox(infoPtr
, 0, &rcBox
);
4161 wWidth
= rcBox
.right
- rcBox
.left
;
4162 wHeight
= (rcBox
.bottom
- rcBox
.top
) * nItemCount
;
4166 /* use current height and width */
4167 if (wHeight
== 0xffff)
4168 wHeight
= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
;
4169 if (wWidth
== 0xffff)
4170 wWidth
= infoPtr
->rcList
.right
- infoPtr
->rcList
.left
;
4173 dwViewRect
= MAKELONG(wWidth
, wHeight
);
4175 else if (uView
== LVS_SMALLICON
)
4176 FIXME("uView == LVS_SMALLICON: not implemented\n");
4177 else if (uView
== LVS_ICON
)
4178 FIXME("uView == LVS_ICON: not implemented\n");
4186 * Create a drag image list for the specified item.
4189 * [I] infoPtr : valid pointer to the listview structure
4190 * [I] iItem : index of item
4191 * [O] lppt : Upperr-left corner of the image
4194 * Returns a handle to the image list if successful, NULL otherwise.
4196 static HIMAGELIST
LISTVIEW_CreateDragImage(LISTVIEW_INFO
*infoPtr
, INT iItem
, LPPOINT lppt
)
4202 HBITMAP hbmp
, hOldbmp
;
4203 HIMAGELIST dragList
= 0;
4204 TRACE("iItem=%d Count=%d\n", iItem
, infoPtr
->nItemCount
);
4206 if (iItem
< 0 || iItem
>= infoPtr
->nItemCount
)
4209 rcItem
.left
= LVIR_BOUNDS
;
4210 if (!LISTVIEW_GetItemRect(infoPtr
, iItem
, &rcItem
))
4213 lppt
->x
= rcItem
.left
;
4214 lppt
->y
= rcItem
.top
;
4216 size
.cx
= rcItem
.right
- rcItem
.left
;
4217 size
.cy
= rcItem
.bottom
- rcItem
.top
;
4219 hdcOrig
= GetDC(infoPtr
->hwndSelf
);
4220 hdc
= CreateCompatibleDC(hdcOrig
);
4221 hbmp
= CreateCompatibleBitmap(hdcOrig
, size
.cx
, size
.cy
);
4222 hOldbmp
= SelectObject(hdc
, hbmp
);
4224 rcItem
.left
= rcItem
.top
= 0;
4225 rcItem
.right
= size
.cx
;
4226 rcItem
.bottom
= size
.cy
;
4227 FillRect(hdc
, &rcItem
, infoPtr
->hBkBrush
);
4230 if (LISTVIEW_DrawItem(infoPtr
, hdc
, iItem
, 0, pos
, infoPtr
->cditemmode
))
4232 dragList
= ImageList_Create(size
.cx
, size
.cy
, ILC_COLOR
, 10, 10);
4233 SelectObject(hdc
, hOldbmp
);
4234 ImageList_Add(dragList
, hbmp
, 0);
4237 SelectObject(hdc
, hOldbmp
);
4241 ReleaseDC(infoPtr
->hwndSelf
, hdcOrig
);
4243 TRACE("ret=%p\n", dragList
);
4251 * Removes all listview items and subitems.
4254 * [I] infoPtr : valid pointer to the listview structure
4260 static BOOL
LISTVIEW_DeleteAllItems(LISTVIEW_INFO
*infoPtr
)
4263 HDPA hdpaSubItems
= NULL
;
4270 /* we do it directly, to avoid notifications */
4271 ranges_clear(infoPtr
->selectionRanges
);
4272 infoPtr
->nSelectionMark
= -1;
4273 infoPtr
->nFocusedItem
= -1;
4274 SetRectEmpty(&infoPtr
->rcFocus
);
4275 /* But we are supposed to leave nHotItem as is! */
4278 /* send LVN_DELETEALLITEMS notification */
4279 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
4281 bSuppress
= notify_listview(infoPtr
, LVN_DELETEALLITEMS
, &nmlv
);
4283 for (i
= infoPtr
->nItemCount
- 1; i
>= 0; i
--)
4285 /* send LVN_DELETEITEM notification, if not suppressed */
4286 if (!bSuppress
) notify_deleteitem(infoPtr
, i
);
4287 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
4289 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, i
);
4290 for (j
= 0; j
< DPA_GetPtrCount(hdpaSubItems
); j
++)
4292 hdrItem
= (ITEMHDR
*)DPA_GetPtr(hdpaSubItems
, j
);
4293 if (is_textW(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
4296 DPA_Destroy(hdpaSubItems
);
4297 DPA_DeletePtr(infoPtr
->hdpaItems
, i
);
4299 DPA_DeletePtr(infoPtr
->hdpaPosX
, i
);
4300 DPA_DeletePtr(infoPtr
->hdpaPosY
, i
);
4301 infoPtr
->nItemCount
--;
4304 LISTVIEW_UpdateScroll(infoPtr
);
4306 LISTVIEW_InvalidateList(infoPtr
);
4313 * Scrolls, and updates the columns, when a column is changing width.
4316 * [I] infoPtr : valid pointer to the listview structure
4317 * [I] nColumn : column to scroll
4318 * [I] dx : amount of scroll, in pixels
4323 static void LISTVIEW_ScrollColumns(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT dx
)
4325 COLUMN_INFO
*lpColumnInfo
;
4330 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) < 1) return;
4331 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1));
4332 rcCol
= lpColumnInfo
->rcHeader
;
4333 if (nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
))
4334 rcCol
.left
= rcCol
.right
;
4336 /* ajust the other columns */
4337 for (nCol
= nColumn
; nCol
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); nCol
++)
4339 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nCol
);
4340 lpColumnInfo
->rcHeader
.left
+= dx
;
4341 lpColumnInfo
->rcHeader
.right
+= dx
;
4344 /* do not update screen if not in report mode */
4345 if (!is_redrawing(infoPtr
) || (infoPtr
->dwStyle
& LVS_TYPEMASK
) != LVS_REPORT
) return;
4347 /* if we have a focus, must first erase the focus rect */
4348 if (infoPtr
->bFocus
) LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
4350 /* Need to reset the item width when inserting a new column */
4351 infoPtr
->nItemWidth
+= dx
;
4353 LISTVIEW_UpdateScroll(infoPtr
);
4354 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
4356 /* scroll to cover the deleted column, and invalidate for redraw */
4357 rcOld
= infoPtr
->rcList
;
4358 rcOld
.left
= ptOrigin
.x
+ rcCol
.left
+ dx
;
4359 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, 0, &rcOld
, &rcOld
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4361 /* we can restore focus now */
4362 if (infoPtr
->bFocus
) LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
4367 * Removes a column from the listview control.
4370 * [I] infoPtr : valid pointer to the listview structure
4371 * [I] nColumn : column index
4377 static BOOL
LISTVIEW_DeleteColumn(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
4381 TRACE("nColumn=%d\n", nColumn
);
4383 if (nColumn
< 0 || DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0
4384 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
4386 /* While the MSDN specifically says that column zero should not be deleted,
4387 what actually happens is that the column itself is deleted but no items or subitems
4391 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcCol
);
4393 if (!Header_DeleteItem(infoPtr
->hwndHeader
, nColumn
))
4396 Free(DPA_GetPtr(infoPtr
->hdpaColumns
, nColumn
));
4397 DPA_DeletePtr(infoPtr
->hdpaColumns
, nColumn
);
4399 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && nColumn
)
4401 SUBITEM_INFO
*lpSubItem
, *lpDelItem
;
4403 INT nItem
, nSubItem
, i
;
4405 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
4407 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
4410 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4412 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
4413 if (lpSubItem
->iSubItem
== nColumn
)
4416 lpDelItem
= lpSubItem
;
4418 else if (lpSubItem
->iSubItem
> nColumn
)
4420 lpSubItem
->iSubItem
--;
4424 /* if we found our subitem, zapp it */
4428 if (is_textW(lpDelItem
->hdr
.pszText
))
4429 Free(lpDelItem
->hdr
.pszText
);
4434 /* free dpa memory */
4435 DPA_DeletePtr(hdpaSubItems
, nSubItem
);
4440 /* update the other column info */
4441 if(DPA_GetPtrCount(infoPtr
->hdpaColumns
) == 0)
4442 LISTVIEW_InvalidateList(infoPtr
);
4444 LISTVIEW_ScrollColumns(infoPtr
, nColumn
, -(rcCol
.right
- rcCol
.left
));
4451 * Invalidates the listview after an item's insertion or deletion.
4454 * [I] infoPtr : valid pointer to the listview structure
4455 * [I] nItem : item index
4456 * [I] dir : -1 if deleting, 1 if inserting
4461 static void LISTVIEW_ScrollOnInsert(LISTVIEW_INFO
*infoPtr
, INT nItem
, INT dir
)
4463 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4464 INT nPerCol
, nItemCol
, nItemRow
;
4468 /* if we don't refresh, what's the point of scrolling? */
4469 if (!is_redrawing(infoPtr
)) return;
4471 assert (abs(dir
) == 1);
4473 /* arrange icons if autoarrange is on */
4474 if (is_autoarrange(infoPtr
))
4476 BOOL arrange
= TRUE
;
4477 if (dir
< 0 && nItem
>= infoPtr
->nItemCount
) arrange
= FALSE
;
4478 if (dir
> 0 && nItem
== infoPtr
->nItemCount
- 1) arrange
= FALSE
;
4479 if (arrange
) LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
4482 /* scrollbars need updating */
4483 LISTVIEW_UpdateScroll(infoPtr
);
4485 /* figure out the item's position */
4486 if (uView
== LVS_REPORT
)
4487 nPerCol
= infoPtr
->nItemCount
+ 1;
4488 else if (uView
== LVS_LIST
)
4489 nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
4490 else /* LVS_ICON, or LVS_SMALLICON */
4493 nItemCol
= nItem
/ nPerCol
;
4494 nItemRow
= nItem
% nPerCol
;
4495 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4497 /* move the items below up a slot */
4498 rcScroll
.left
= nItemCol
* infoPtr
->nItemWidth
;
4499 rcScroll
.top
= nItemRow
* infoPtr
->nItemHeight
;
4500 rcScroll
.right
= rcScroll
.left
+ infoPtr
->nItemWidth
;
4501 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
4502 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
4503 TRACE("rcScroll=%s, dx=%d\n", debugrect(&rcScroll
), dir
* infoPtr
->nItemHeight
);
4504 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
4506 TRACE("Scrolling rcScroll=%s, rcList=%s\n", debugrect(&rcScroll
), debugrect(&infoPtr
->rcList
));
4507 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
4508 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4511 /* report has only that column, so we're done */
4512 if (uView
== LVS_REPORT
) return;
4514 /* now for LISTs, we have to deal with the columns to the right */
4515 rcScroll
.left
= (nItemCol
+ 1) * infoPtr
->nItemWidth
;
4517 rcScroll
.right
= (infoPtr
->nItemCount
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
4518 rcScroll
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
4519 OffsetRect(&rcScroll
, Origin
.x
, Origin
.y
);
4520 if (IntersectRect(&rcScroll
, &rcScroll
, &infoPtr
->rcList
))
4521 ScrollWindowEx(infoPtr
->hwndSelf
, 0, dir
* infoPtr
->nItemHeight
,
4522 &rcScroll
, &rcScroll
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
4527 * Removes an item from the listview control.
4530 * [I] infoPtr : valid pointer to the listview structure
4531 * [I] nItem : item index
4537 static BOOL
LISTVIEW_DeleteItem(LISTVIEW_INFO
*infoPtr
, INT nItem
)
4539 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4542 TRACE("(nItem=%d)\n", nItem
);
4544 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
4546 /* remove selection, and focus */
4548 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
4549 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
4551 /* send LVN_DELETEITEM notification. */
4552 if (!notify_deleteitem(infoPtr
, nItem
)) return FALSE
;
4554 /* we need to do this here, because we'll be deleting stuff */
4555 if (uView
== LVS_SMALLICON
|| uView
== LVS_ICON
)
4556 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
4558 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
4564 hdpaSubItems
= (HDPA
)DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
4565 for (i
= 0; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
4567 hdrItem
= (ITEMHDR
*)DPA_GetPtr(hdpaSubItems
, i
);
4568 if (is_textW(hdrItem
->pszText
)) Free(hdrItem
->pszText
);
4571 DPA_Destroy(hdpaSubItems
);
4574 if (uView
== LVS_SMALLICON
|| uView
== LVS_ICON
)
4576 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
4577 DPA_DeletePtr(infoPtr
->hdpaPosY
, nItem
);
4580 infoPtr
->nItemCount
--;
4581 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
4583 /* now is the invalidation fun */
4584 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, -1);
4591 * Callback implementation for editlabel control
4594 * [I] infoPtr : valid pointer to the listview structure
4595 * [I] pszText : modified text
4596 * [I] isW : TRUE if psxText is Unicode, FALSE if it's ANSI
4602 static BOOL
LISTVIEW_EndEditLabelT(LISTVIEW_INFO
*infoPtr
, LPWSTR pszText
, BOOL isW
)
4604 HWND hwndSelf
= infoPtr
->hwndSelf
;
4605 NMLVDISPINFOW dispInfo
;
4607 TRACE("(pszText=%s, isW=%d)\n", debugtext_t(pszText
, isW
), isW
);
4609 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4610 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
;
4611 dispInfo
.item
.iItem
= infoPtr
->nEditLabelItem
;
4612 dispInfo
.item
.iSubItem
= 0;
4613 dispInfo
.item
.stateMask
= ~0;
4614 if (!LISTVIEW_GetItemW(infoPtr
, &dispInfo
.item
)) return FALSE
;
4615 /* add the text from the edit in */
4616 dispInfo
.item
.mask
|= LVIF_TEXT
;
4617 dispInfo
.item
.pszText
= pszText
;
4618 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
4620 /* Do we need to update the Item Text */
4621 if (!notify_dispinfoT(infoPtr
, LVN_ENDLABELEDITW
, &dispInfo
, isW
)) return FALSE
;
4622 if (!IsWindow(hwndSelf
))
4624 if (!pszText
) return TRUE
;
4626 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
))
4628 HDPA hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nEditLabelItem
);
4629 ITEM_INFO
* lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
4630 if (lpItem
&& lpItem
->hdr
.pszText
== LPSTR_TEXTCALLBACKW
)
4632 LISTVIEW_InvalidateItem(infoPtr
, infoPtr
->nEditLabelItem
);
4637 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4638 dispInfo
.item
.mask
= LVIF_TEXT
;
4639 dispInfo
.item
.iItem
= infoPtr
->nEditLabelItem
;
4640 dispInfo
.item
.iSubItem
= 0;
4641 dispInfo
.item
.pszText
= pszText
;
4642 dispInfo
.item
.cchTextMax
= textlenT(pszText
, isW
);
4643 return LISTVIEW_SetItemT(infoPtr
, &dispInfo
.item
, isW
);
4648 * Begin in place editing of specified list view item
4651 * [I] infoPtr : valid pointer to the listview structure
4652 * [I] nItem : item index
4653 * [I] isW : TRUE if it's a Unicode req, FALSE if ASCII
4659 static HWND
LISTVIEW_EditLabelT(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL isW
)
4661 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
4662 NMLVDISPINFOW dispInfo
;
4664 HWND hwndSelf
= infoPtr
->hwndSelf
;
4666 TRACE("(nItem=%d, isW=%d)\n", nItem
, isW
);
4668 if (~infoPtr
->dwStyle
& LVS_EDITLABELS
) return 0;
4669 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
4671 infoPtr
->nEditLabelItem
= nItem
;
4673 /* Is the EditBox still there, if so remove it */
4674 if(infoPtr
->hwndEdit
!= 0)
4676 SetFocus(infoPtr
->hwndSelf
);
4677 infoPtr
->hwndEdit
= 0;
4680 LISTVIEW_SetSelection(infoPtr
, nItem
);
4681 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
4682 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
4684 rect
.left
= LVIR_LABEL
;
4685 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rect
)) return 0;
4687 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
4688 dispInfo
.item
.mask
= LVIF_PARAM
| LVIF_STATE
| LVIF_TEXT
;
4689 dispInfo
.item
.iItem
= nItem
;
4690 dispInfo
.item
.iSubItem
= 0;
4691 dispInfo
.item
.stateMask
= ~0;
4692 dispInfo
.item
.pszText
= szDispText
;
4693 dispInfo
.item
.cchTextMax
= DISP_TEXT_SIZE
;
4694 if (!LISTVIEW_GetItemT(infoPtr
, &dispInfo
.item
, isW
)) return 0;
4696 infoPtr
->hwndEdit
= CreateEditLabelT(infoPtr
, dispInfo
.item
.pszText
, WS_VISIBLE
,
4697 rect
.left
-2, rect
.top
-1, 0, rect
.bottom
- rect
.top
+2, isW
);
4698 if (!infoPtr
->hwndEdit
) return 0;
4700 if (notify_dispinfoT(infoPtr
, LVN_BEGINLABELEDITW
, &dispInfo
, isW
))
4702 if (!IsWindow(hwndSelf
))
4704 SendMessageW(infoPtr
->hwndEdit
, WM_CLOSE
, 0, 0);
4705 infoPtr
->hwndEdit
= 0;
4709 ShowWindow(infoPtr
->hwndEdit
, SW_NORMAL
);
4710 SetFocus(infoPtr
->hwndEdit
);
4711 SendMessageW(infoPtr
->hwndEdit
, EM_SETSEL
, 0, -1);
4712 return infoPtr
->hwndEdit
;
4718 * Ensures the specified item is visible, scrolling into view if necessary.
4721 * [I] infoPtr : valid pointer to the listview structure
4722 * [I] nItem : item index
4723 * [I] bPartial : partially or entirely visible
4729 static BOOL
LISTVIEW_EnsureVisible(LISTVIEW_INFO
*infoPtr
, INT nItem
, BOOL bPartial
)
4731 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4732 INT nScrollPosHeight
= 0;
4733 INT nScrollPosWidth
= 0;
4734 INT nHorzAdjust
= 0;
4735 INT nVertAdjust
= 0;
4738 RECT rcItem
, rcTemp
;
4740 rcItem
.left
= LVIR_BOUNDS
;
4741 if (!LISTVIEW_GetItemRect(infoPtr
, nItem
, &rcItem
)) return FALSE
;
4743 if (bPartial
&& IntersectRect(&rcTemp
, &infoPtr
->rcList
, &rcItem
)) return TRUE
;
4745 if (rcItem
.left
< infoPtr
->rcList
.left
|| rcItem
.right
> infoPtr
->rcList
.right
)
4747 /* scroll left/right, but in LVS_REPORT mode */
4748 if (uView
== LVS_LIST
)
4749 nScrollPosWidth
= infoPtr
->nItemWidth
;
4750 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
4751 nScrollPosWidth
= 1;
4753 if (rcItem
.left
< infoPtr
->rcList
.left
)
4756 if (uView
!= LVS_REPORT
) nHorzDiff
= rcItem
.left
- infoPtr
->rcList
.left
;
4761 if (uView
!= LVS_REPORT
) nHorzDiff
= rcItem
.right
- infoPtr
->rcList
.right
;
4765 if (rcItem
.top
< infoPtr
->rcList
.top
|| rcItem
.bottom
> infoPtr
->rcList
.bottom
)
4767 /* scroll up/down, but not in LVS_LIST mode */
4768 if (uView
== LVS_REPORT
)
4769 nScrollPosHeight
= infoPtr
->nItemHeight
;
4770 else if ((uView
== LVS_ICON
) || (uView
== LVS_SMALLICON
))
4771 nScrollPosHeight
= 1;
4773 if (rcItem
.top
< infoPtr
->rcList
.top
)
4776 if (uView
!= LVS_LIST
) nVertDiff
= rcItem
.top
- infoPtr
->rcList
.top
;
4781 if (uView
!= LVS_LIST
) nVertDiff
= rcItem
.bottom
- infoPtr
->rcList
.bottom
;
4785 if (!nScrollPosWidth
&& !nScrollPosHeight
) return TRUE
;
4787 if (nScrollPosWidth
)
4789 INT diff
= nHorzDiff
/ nScrollPosWidth
;
4790 if (nHorzDiff
% nScrollPosWidth
) diff
+= nHorzAdjust
;
4791 LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
4794 if (nScrollPosHeight
)
4796 INT diff
= nVertDiff
/ nScrollPosHeight
;
4797 if (nVertDiff
% nScrollPosHeight
) diff
+= nVertAdjust
;
4798 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, diff
, 0);
4806 * Searches for an item with specific characteristics.
4809 * [I] hwnd : window handle
4810 * [I] nStart : base item index
4811 * [I] lpFindInfo : item information to look for
4814 * SUCCESS : index of item
4817 static INT
LISTVIEW_FindItemW(LISTVIEW_INFO
*infoPtr
, INT nStart
,
4818 const LVFINDINFOW
*lpFindInfo
)
4820 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
4821 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
4822 BOOL bWrap
= FALSE
, bNearest
= FALSE
;
4823 INT nItem
= nStart
+ 1, nLast
= infoPtr
->nItemCount
, nNearestItem
= -1;
4824 ULONG xdist
, ydist
, dist
, mindist
= 0x7fffffff;
4825 POINT Position
, Destination
;
4828 if (!lpFindInfo
|| nItem
< 0) return -1;
4831 if (lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
))
4833 lvItem
.mask
|= LVIF_TEXT
;
4834 lvItem
.pszText
= szDispText
;
4835 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
4838 if (lpFindInfo
->flags
& LVFI_WRAP
)
4841 if ((lpFindInfo
->flags
& LVFI_NEARESTXY
) &&
4842 (uView
== LVS_ICON
|| uView
==LVS_SMALLICON
))
4847 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
4848 Destination
.x
= lpFindInfo
->pt
.x
- Origin
.x
;
4849 Destination
.y
= lpFindInfo
->pt
.y
- Origin
.y
;
4850 switch(lpFindInfo
->vkDirection
)
4852 case VK_DOWN
: Destination
.y
+= infoPtr
->nItemHeight
; break;
4853 case VK_UP
: Destination
.y
-= infoPtr
->nItemHeight
; break;
4854 case VK_RIGHT
: Destination
.x
+= infoPtr
->nItemWidth
; break;
4855 case VK_LEFT
: Destination
.x
-= infoPtr
->nItemWidth
; break;
4856 case VK_HOME
: Destination
.x
= Destination
.y
= 0; break;
4857 case VK_NEXT
: Destination
.y
+= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
4858 case VK_PRIOR
: Destination
.y
-= infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
; break;
4860 LISTVIEW_GetAreaRect(infoPtr
, &rcArea
);
4861 Destination
.x
= rcArea
.right
;
4862 Destination
.y
= rcArea
.bottom
;
4864 default: ERR("Unknown vkDirection=%d\n", lpFindInfo
->vkDirection
);
4868 else Destination
.x
= Destination
.y
= 0;
4870 /* if LVFI_PARAM is specified, all other flags are ignored */
4871 if (lpFindInfo
->flags
& LVFI_PARAM
)
4873 lvItem
.mask
|= LVIF_PARAM
;
4875 lvItem
.mask
&= ~LVIF_TEXT
;
4879 for (; nItem
< nLast
; nItem
++)
4881 lvItem
.iItem
= nItem
;
4882 lvItem
.iSubItem
= 0;
4883 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
4885 if (lvItem
.mask
& LVIF_PARAM
)
4887 if (lpFindInfo
->lParam
== lvItem
.lParam
)
4893 if (lvItem
.mask
& LVIF_TEXT
)
4895 if (lpFindInfo
->flags
& LVFI_PARTIAL
)
4897 if (strstrW(lvItem
.pszText
, lpFindInfo
->psz
) == NULL
) continue;
4901 if (lstrcmpW(lvItem
.pszText
, lpFindInfo
->psz
) != 0) continue;
4905 if (!bNearest
) return nItem
;
4907 /* This is very inefficient. To do a good job here,
4908 * we need a sorted array of (x,y) item positions */
4909 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
4911 /* compute the distance^2 to the destination */
4912 xdist
= Destination
.x
- Position
.x
;
4913 ydist
= Destination
.y
- Position
.y
;
4914 dist
= xdist
* xdist
+ ydist
* ydist
;
4916 /* remember the distance, and item if it's closer */
4920 nNearestItem
= nItem
;
4927 nLast
= min(nStart
+ 1, infoPtr
->nItemCount
);
4932 return nNearestItem
;
4937 * Searches for an item with specific characteristics.
4940 * [I] hwnd : window handle
4941 * [I] nStart : base item index
4942 * [I] lpFindInfo : item information to look for
4945 * SUCCESS : index of item
4948 static INT
LISTVIEW_FindItemA(LISTVIEW_INFO
*infoPtr
, INT nStart
,
4949 const LVFINDINFOA
*lpFindInfo
)
4951 BOOL hasText
= lpFindInfo
->flags
& (LVFI_STRING
| LVFI_PARTIAL
);
4955 memcpy(&fiw
, lpFindInfo
, sizeof(fiw
));
4956 if (hasText
) fiw
.psz
= textdupTtoW((LPCWSTR
)lpFindInfo
->psz
, FALSE
);
4957 res
= LISTVIEW_FindItemW(infoPtr
, nStart
, &fiw
);
4958 if (hasText
) textfreeT((LPWSTR
)fiw
.psz
, FALSE
);
4964 * Retrieves the background image of the listview control.
4967 * [I] infoPtr : valid pointer to the listview structure
4968 * [O] lpBkImage : background image attributes
4974 /* static BOOL LISTVIEW_GetBkImage(LISTVIEW_INFO *infoPtr, LPLVBKIMAGE lpBkImage) */
4976 /* FIXME (listview, "empty stub!\n"); */
4982 * Retrieves column attributes.
4985 * [I] infoPtr : valid pointer to the listview structure
4986 * [I] nColumn : column index
4987 * [IO] lpColumn : column information
4988 * [I] isW : if TRUE, then lpColumn is a LPLVCOLUMNW
4989 * otherwise it is in fact a LPLVCOLUMNA
4995 static BOOL
LISTVIEW_GetColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
, LPLVCOLUMNW lpColumn
, BOOL isW
)
4997 COLUMN_INFO
*lpColumnInfo
;
5000 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5001 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
5003 /* initialize memory */
5004 ZeroMemory(&hdi
, sizeof(hdi
));
5006 if (lpColumn
->mask
& LVCF_TEXT
)
5008 hdi
.mask
|= HDI_TEXT
;
5009 hdi
.pszText
= lpColumn
->pszText
;
5010 hdi
.cchTextMax
= lpColumn
->cchTextMax
;
5013 if (lpColumn
->mask
& LVCF_IMAGE
)
5014 hdi
.mask
|= HDI_IMAGE
;
5016 if (lpColumn
->mask
& LVCF_ORDER
)
5017 hdi
.mask
|= HDI_ORDER
;
5019 if (!SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_GETITEMW
: HDM_GETITEMA
, nColumn
, (LPARAM
)&hdi
)) return FALSE
;
5021 if (lpColumn
->mask
& LVCF_FMT
)
5022 lpColumn
->fmt
= lpColumnInfo
->fmt
;
5024 if (lpColumn
->mask
& LVCF_WIDTH
)
5025 lpColumn
->cx
= lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
;
5027 if (lpColumn
->mask
& LVCF_IMAGE
)
5028 lpColumn
->iImage
= hdi
.iImage
;
5030 if (lpColumn
->mask
& LVCF_ORDER
)
5031 lpColumn
->iOrder
= hdi
.iOrder
;
5037 static BOOL
LISTVIEW_GetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, LPINT lpiArray
)
5044 /* FIXME: little hack */
5045 for (i
= 0; i
< iCount
; i
++)
5053 * Retrieves the column width.
5056 * [I] infoPtr : valid pointer to the listview structure
5057 * [I] int : column index
5060 * SUCCESS : column width
5063 static INT
LISTVIEW_GetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
)
5065 INT nColumnWidth
= 0;
5068 TRACE("nColumn=%d\n", nColumn
);
5070 /* we have a 'column' in LIST and REPORT mode only */
5071 switch(infoPtr
->dwStyle
& LVS_TYPEMASK
)
5074 nColumnWidth
= infoPtr
->nItemWidth
;
5077 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
5078 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
5079 nColumnWidth
= rcHeader
.right
- rcHeader
.left
;
5083 TRACE("nColumnWidth=%d\n", nColumnWidth
);
5084 return nColumnWidth
;
5089 * In list or report display mode, retrieves the number of items that can fit
5090 * vertically in the visible area. In icon or small icon display mode,
5091 * retrieves the total number of visible items.
5094 * [I] infoPtr : valid pointer to the listview structure
5097 * Number of fully visible items.
5099 static INT
LISTVIEW_GetCountPerPage(LISTVIEW_INFO
*infoPtr
)
5101 switch (infoPtr
->dwStyle
& LVS_TYPEMASK
)
5105 return infoPtr
->nItemCount
;
5107 return LISTVIEW_GetCountPerColumn(infoPtr
);
5109 return LISTVIEW_GetCountPerRow(infoPtr
) * LISTVIEW_GetCountPerColumn(infoPtr
);
5117 * Retrieves an image list handle.
5120 * [I] infoPtr : valid pointer to the listview structure
5121 * [I] nImageList : image list identifier
5124 * SUCCESS : image list handle
5127 static HIMAGELIST
LISTVIEW_GetImageList(LISTVIEW_INFO
*infoPtr
, INT nImageList
)
5131 case LVSIL_NORMAL
: return infoPtr
->himlNormal
;
5132 case LVSIL_SMALL
: return infoPtr
->himlSmall
;
5133 case LVSIL_STATE
: return infoPtr
->himlState
;
5138 /* LISTVIEW_GetISearchString */
5142 * Retrieves item attributes.
5145 * [I] hwnd : window handle
5146 * [IO] lpLVItem : item info
5147 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
5148 * if FALSE, the lpLVItem is a LPLVITEMA.
5151 * This is the internal 'GetItem' interface -- it tries to
5152 * be smart and avoid text copies, if possible, by modifying
5153 * lpLVItem->pszText to point to the text string. Please note
5154 * that this is not always possible (e.g. OWNERDATA), so on
5155 * entry you *must* supply valid values for pszText, and cchTextMax.
5156 * The only difference to the documented interface is that upon
5157 * return, you should use *only* the lpLVItem->pszText, rather than
5158 * the buffer pointer you provided on input. Most code already does
5159 * that, so it's not a problem.
5160 * For the two cases when the text must be copied (that is,
5161 * for LVM_GETITEM, and LVM_GETITEMTEXT), use LISTVIEW_GetItemExtT.
5167 static BOOL
LISTVIEW_GetItemT(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
5169 ITEMHDR callbackHdr
= { LPSTR_TEXTCALLBACKW
, I_IMAGECALLBACK
};
5170 NMLVDISPINFOW dispInfo
;
5176 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
5178 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
5181 if (lpLVItem
->mask
== 0) return TRUE
;
5183 /* make a local copy */
5184 isubitem
= lpLVItem
->iSubItem
;
5186 /* a quick optimization if all we're asked is the focus state
5187 * these queries are worth optimising since they are common,
5188 * and can be answered in constant time, without the heavy accesses */
5189 if ( (lpLVItem
->mask
== LVIF_STATE
) && (lpLVItem
->stateMask
== LVIS_FOCUSED
) &&
5190 !(infoPtr
->uCallbackMask
& LVIS_FOCUSED
) )
5192 lpLVItem
->state
= 0;
5193 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
5194 lpLVItem
->state
|= LVIS_FOCUSED
;
5198 ZeroMemory(&dispInfo
, sizeof(dispInfo
));
5200 /* if the app stores all the data, handle it separately */
5201 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
5203 dispInfo
.item
.state
= 0;
5205 /* apprently, we should not callback for lParam in LVS_OWNERDATA */
5206 if ((lpLVItem
->mask
& ~(LVIF_STATE
| LVIF_PARAM
)) || infoPtr
->uCallbackMask
)
5208 /* NOTE: copy only fields which we _know_ are initialized, some apps
5209 * depend on the uninitialized fields being 0 */
5210 dispInfo
.item
.mask
= lpLVItem
->mask
& ~LVIF_PARAM
;
5211 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
5212 dispInfo
.item
.iSubItem
= isubitem
;
5213 if (lpLVItem
->mask
& LVIF_TEXT
)
5215 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
5216 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
5218 if (lpLVItem
->mask
& LVIF_STATE
)
5219 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
& infoPtr
->uCallbackMask
;
5220 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
5221 dispInfo
.item
.stateMask
= lpLVItem
->stateMask
;
5222 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
5224 /* full size structure expected - _WIN32IE >= 0x560 */
5225 *lpLVItem
= dispInfo
.item
;
5227 else if (lpLVItem
->mask
& LVIF_INDENT
)
5229 /* indent member expected - _WIN32IE >= 0x300 */
5230 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iGroupId
));
5234 /* minimal structure expected */
5235 memcpy(lpLVItem
, &dispInfo
.item
, offsetof( LVITEMW
, iIndent
));
5237 TRACE(" getdispinfo(1):lpLVItem=%s\n", debuglvitem_t(lpLVItem
, isW
));
5240 /* make sure lParam is zeroed out */
5241 if (lpLVItem
->mask
& LVIF_PARAM
) lpLVItem
->lParam
= 0;
5243 /* we store only a little state, so if we're not asked, we're done */
5244 if (!(lpLVItem
->mask
& LVIF_STATE
) || isubitem
) return TRUE
;
5246 /* if focus is handled by us, report it */
5247 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
5249 lpLVItem
->state
&= ~LVIS_FOCUSED
;
5250 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
5251 lpLVItem
->state
|= LVIS_FOCUSED
;
5254 /* and do the same for selection, if we handle it */
5255 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
5257 lpLVItem
->state
&= ~LVIS_SELECTED
;
5258 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
5259 lpLVItem
->state
|= LVIS_SELECTED
;
5265 /* find the item and subitem structures before we proceed */
5266 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, lpLVItem
->iItem
);
5267 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
5272 SUBITEM_INFO
*lpSubItem
= LISTVIEW_GetSubItemPtr(hdpaSubItems
, isubitem
);
5273 pItemHdr
= lpSubItem
? &lpSubItem
->hdr
: &callbackHdr
;
5276 WARN(" iSubItem invalid (%08x), ignored.\n", isubitem
);
5281 pItemHdr
= &lpItem
->hdr
;
5283 /* Do we need to query the state from the app? */
5284 if ((lpLVItem
->mask
& LVIF_STATE
) && infoPtr
->uCallbackMask
&& isubitem
== 0)
5286 dispInfo
.item
.mask
|= LVIF_STATE
;
5287 dispInfo
.item
.stateMask
= infoPtr
->uCallbackMask
;
5290 /* Do we need to enquire about the image? */
5291 if ((lpLVItem
->mask
& LVIF_IMAGE
) && pItemHdr
->iImage
== I_IMAGECALLBACK
&&
5292 (isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
)))
5294 dispInfo
.item
.mask
|= LVIF_IMAGE
;
5295 dispInfo
.item
.iImage
= I_IMAGECALLBACK
;
5298 /* Apps depend on calling back for text if it is NULL or LPSTR_TEXTCALLBACKW */
5299 if ((lpLVItem
->mask
& LVIF_TEXT
) && !is_textW(pItemHdr
->pszText
))
5301 dispInfo
.item
.mask
|= LVIF_TEXT
;
5302 dispInfo
.item
.pszText
= lpLVItem
->pszText
;
5303 dispInfo
.item
.cchTextMax
= lpLVItem
->cchTextMax
;
5304 if (dispInfo
.item
.pszText
&& dispInfo
.item
.cchTextMax
> 0)
5305 *dispInfo
.item
.pszText
= '\0';
5308 /* If we don't have all the requested info, query the application */
5309 if (dispInfo
.item
.mask
!= 0)
5311 dispInfo
.item
.iItem
= lpLVItem
->iItem
;
5312 dispInfo
.item
.iSubItem
= lpLVItem
->iSubItem
; /* yes: the original subitem */
5313 dispInfo
.item
.lParam
= lpItem
->lParam
;
5314 notify_dispinfoT(infoPtr
, LVN_GETDISPINFOW
, &dispInfo
, isW
);
5315 TRACE(" getdispinfo(2):item=%s\n", debuglvitem_t(&dispInfo
.item
, isW
));
5318 /* we should not store values for subitems */
5319 if (isubitem
) dispInfo
.item
.mask
&= ~LVIF_DI_SETITEM
;
5321 /* Now, handle the iImage field */
5322 if (dispInfo
.item
.mask
& LVIF_IMAGE
)
5324 lpLVItem
->iImage
= dispInfo
.item
.iImage
;
5325 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->iImage
== I_IMAGECALLBACK
)
5326 pItemHdr
->iImage
= dispInfo
.item
.iImage
;
5328 else if (lpLVItem
->mask
& LVIF_IMAGE
)
5330 if(isubitem
== 0 || (infoPtr
->dwLvExStyle
& LVS_EX_SUBITEMIMAGES
))
5331 lpLVItem
->iImage
= pItemHdr
->iImage
;
5333 lpLVItem
->iImage
= 0;
5336 /* The pszText field */
5337 if (dispInfo
.item
.mask
& LVIF_TEXT
)
5339 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
) && pItemHdr
->pszText
)
5340 textsetptrT(&pItemHdr
->pszText
, dispInfo
.item
.pszText
, isW
);
5342 lpLVItem
->pszText
= dispInfo
.item
.pszText
;
5344 else if (lpLVItem
->mask
& LVIF_TEXT
)
5346 if (isW
) lpLVItem
->pszText
= pItemHdr
->pszText
;
5347 else textcpynT(lpLVItem
->pszText
, isW
, pItemHdr
->pszText
, TRUE
, lpLVItem
->cchTextMax
);
5350 /* if this is a subitem, we're done */
5351 if (isubitem
) return TRUE
;
5353 /* Next is the lParam field */
5354 if (dispInfo
.item
.mask
& LVIF_PARAM
)
5356 lpLVItem
->lParam
= dispInfo
.item
.lParam
;
5357 if ((dispInfo
.item
.mask
& LVIF_DI_SETITEM
))
5358 lpItem
->lParam
= dispInfo
.item
.lParam
;
5360 else if (lpLVItem
->mask
& LVIF_PARAM
)
5361 lpLVItem
->lParam
= lpItem
->lParam
;
5363 /* ... the state field (this one is different due to uCallbackmask) */
5364 if (lpLVItem
->mask
& LVIF_STATE
)
5366 lpLVItem
->state
= lpItem
->state
;
5367 if (dispInfo
.item
.mask
& LVIF_STATE
)
5369 lpLVItem
->state
&= ~dispInfo
.item
.stateMask
;
5370 lpLVItem
->state
|= (dispInfo
.item
.state
& dispInfo
.item
.stateMask
);
5372 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_FOCUSED
)
5374 lpLVItem
->state
&= ~LVIS_FOCUSED
;
5375 if (infoPtr
->nFocusedItem
== lpLVItem
->iItem
)
5376 lpLVItem
->state
|= LVIS_FOCUSED
;
5378 if ( lpLVItem
->stateMask
& ~infoPtr
->uCallbackMask
& LVIS_SELECTED
)
5380 lpLVItem
->state
&= ~LVIS_SELECTED
;
5381 if (ranges_contain(infoPtr
->selectionRanges
, lpLVItem
->iItem
))
5382 lpLVItem
->state
|= LVIS_SELECTED
;
5386 /* and last, but not least, the indent field */
5387 if (lpLVItem
->mask
& LVIF_INDENT
)
5388 lpLVItem
->iIndent
= lpItem
->iIndent
;
5395 * Retrieves item attributes.
5398 * [I] hwnd : window handle
5399 * [IO] lpLVItem : item info
5400 * [I] isW : if TRUE, then lpLVItem is a LPLVITEMW,
5401 * if FALSE, the lpLVItem is a LPLVITEMA.
5404 * This is the external 'GetItem' interface -- it properly copies
5405 * the text in the provided buffer.
5411 static BOOL
LISTVIEW_GetItemExtT(LISTVIEW_INFO
*infoPtr
, LPLVITEMW lpLVItem
, BOOL isW
)
5416 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iItem
>= infoPtr
->nItemCount
)
5419 pszText
= lpLVItem
->pszText
;
5420 bResult
= LISTVIEW_GetItemT(infoPtr
, lpLVItem
, isW
);
5421 if (bResult
&& lpLVItem
->pszText
!= pszText
)
5422 textcpynT(pszText
, isW
, lpLVItem
->pszText
, isW
, lpLVItem
->cchTextMax
);
5423 lpLVItem
->pszText
= pszText
;
5431 * Retrieves the position (upper-left) of the listview control item.
5432 * Note that for LVS_ICON style, the upper-left is that of the icon
5433 * and not the bounding box.
5436 * [I] infoPtr : valid pointer to the listview structure
5437 * [I] nItem : item index
5438 * [O] lpptPosition : coordinate information
5444 static BOOL
LISTVIEW_GetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPPOINT lpptPosition
)
5446 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5449 TRACE("(nItem=%d, lpptPosition=%p)\n", nItem
, lpptPosition
);
5451 if (!lpptPosition
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5453 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5454 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, lpptPosition
);
5456 if (uView
== LVS_ICON
)
5458 lpptPosition
->x
+= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
5459 lpptPosition
->y
+= ICON_TOP_PADDING
;
5461 lpptPosition
->x
+= Origin
.x
;
5462 lpptPosition
->y
+= Origin
.y
;
5464 TRACE (" lpptPosition=%s\n", debugpoint(lpptPosition
));
5471 * Retrieves the bounding rectangle for a listview control item.
5474 * [I] infoPtr : valid pointer to the listview structure
5475 * [I] nItem : item index
5476 * [IO] lprc : bounding rectangle coordinates
5477 * lprc->left specifies the portion of the item for which the bounding
5478 * rectangle will be retrieved.
5480 * LVIR_BOUNDS Returns the bounding rectangle of the entire item,
5481 * including the icon and label.
5484 * * Experiment shows that native control returns:
5485 * * width = min (48, length of text line)
5486 * * .left = position.x - (width - iconsize.cx)/2
5487 * * .right = .left + width
5488 * * height = #lines of text * ntmHeight + icon height + 8
5489 * * .top = position.y - 2
5490 * * .bottom = .top + height
5491 * * separation between items .y = itemSpacing.cy - height
5492 * * .x = itemSpacing.cx - width
5493 * LVIR_ICON Returns the bounding rectangle of the icon or small icon.
5496 * * Experiment shows that native control returns:
5497 * * width = iconSize.cx + 16
5498 * * .left = position.x - (width - iconsize.cx)/2
5499 * * .right = .left + width
5500 * * height = iconSize.cy + 4
5501 * * .top = position.y - 2
5502 * * .bottom = .top + height
5503 * * separation between items .y = itemSpacing.cy - height
5504 * * .x = itemSpacing.cx - width
5505 * LVIR_LABEL Returns the bounding rectangle of the item text.
5508 * * Experiment shows that native control returns:
5509 * * width = text length
5510 * * .left = position.x - width/2
5511 * * .right = .left + width
5512 * * height = ntmH * linecount + 2
5513 * * .top = position.y + iconSize.cy + 6
5514 * * .bottom = .top + height
5515 * * separation between items .y = itemSpacing.cy - height
5516 * * .x = itemSpacing.cx - width
5517 * LVIR_SELECTBOUNDS Returns the union of the LVIR_ICON and LVIR_LABEL
5518 * rectangles, but excludes columns in report view.
5525 * Note that the bounding rectangle of the label in the LVS_ICON view depends
5526 * upon whether the window has the focus currently and on whether the item
5527 * is the one with the focus. Ensure that the control's record of which
5528 * item has the focus agrees with the items' records.
5530 static BOOL
LISTVIEW_GetItemRect(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
5532 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5533 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5534 BOOL doLabel
= TRUE
, oversizedBox
= FALSE
;
5535 POINT Position
, Origin
;
5539 TRACE("(hwnd=%p, nItem=%d, lprc=%p)\n", infoPtr
->hwndSelf
, nItem
, lprc
);
5541 if (!lprc
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
5543 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
5544 LISTVIEW_GetItemOrigin(infoPtr
, nItem
, &Position
);
5546 /* Be smart and try to figure out the minimum we have to do */
5547 if (lprc
->left
== LVIR_ICON
) doLabel
= FALSE
;
5548 if (uView
== LVS_REPORT
&& lprc
->left
== LVIR_BOUNDS
) doLabel
= FALSE
;
5549 if (uView
== LVS_ICON
&& lprc
->left
!= LVIR_ICON
&&
5550 infoPtr
->bFocus
&& LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_FOCUSED
))
5551 oversizedBox
= TRUE
;
5553 /* get what we need from the item before hand, so we make
5554 * only one request. This can speed up things, if data
5555 * is stored on the app side */
5557 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
5558 if (doLabel
) lvItem
.mask
|= LVIF_TEXT
;
5559 lvItem
.iItem
= nItem
;
5560 lvItem
.iSubItem
= 0;
5561 lvItem
.pszText
= szDispText
;
5562 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5563 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
5564 /* we got the state already up, simulate it here, to avoid a reget */
5565 if (uView
== LVS_ICON
&& (lprc
->left
!= LVIR_ICON
))
5567 lvItem
.mask
|= LVIF_STATE
;
5568 lvItem
.stateMask
= LVIS_FOCUSED
;
5569 lvItem
.state
= (oversizedBox
? LVIS_FOCUSED
: 0);
5572 if (uView
== LVS_REPORT
&& (infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) && lprc
->left
== LVIR_SELECTBOUNDS
)
5573 lprc
->left
= LVIR_BOUNDS
;
5577 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
);
5581 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, NULL
, lprc
);
5585 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
);
5588 case LVIR_SELECTBOUNDS
:
5589 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, &label_rect
);
5590 UnionRect(lprc
, lprc
, &label_rect
);
5594 WARN("Unknown value: %ld\n", lprc
->left
);
5598 OffsetRect(lprc
, Position
.x
+ Origin
.x
, Position
.y
+ Origin
.y
);
5600 TRACE(" rect=%s\n", debugrect(lprc
));
5607 * Retrieves the spacing between listview control items.
5610 * [I] infoPtr : valid pointer to the listview structure
5611 * [IO] lprc : rectangle to receive the output
5612 * on input, lprc->top = nSubItem
5613 * lprc->left = LVIR_ICON | LVIR_BOUNDS | LVIR_LABEL
5615 * NOTE: for subItem = 0, we should return the bounds of the _entire_ item,
5616 * not only those of the first column.
5617 * Fortunately, LISTVIEW_GetItemMetrics does the right thing.
5623 static BOOL
LISTVIEW_GetSubItemRect(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPRECT lprc
)
5627 INT nColumn
= lprc
->top
;
5629 if (!lprc
) return FALSE
;
5631 TRACE("(nItem=%d, nSubItem=%ld)\n", nItem
, lprc
->top
);
5632 /* On WinNT, a subitem of '0' calls LISTVIEW_GetItemRect */
5634 return LISTVIEW_GetItemRect(infoPtr
, nItem
, lprc
);
5636 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) != LVS_REPORT
) return FALSE
;
5638 if (!LISTVIEW_GetItemPosition(infoPtr
, nItem
, &Position
)) return FALSE
;
5640 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
5643 lvItem
.iItem
= nItem
;
5644 lvItem
.iSubItem
= nColumn
;
5646 if (lvItem
.mask
&& !LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return FALSE
;
5650 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, NULL
, NULL
, lprc
, NULL
);
5655 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, lprc
, NULL
, NULL
, NULL
);
5659 ERR("Unknown bounds=%ld\n", lprc
->left
);
5663 OffsetRect(lprc
, Position
.x
, Position
.y
);
5670 * Retrieves the width of a label.
5673 * [I] infoPtr : valid pointer to the listview structure
5676 * SUCCESS : string width (in pixels)
5679 static INT
LISTVIEW_GetLabelWidth(LISTVIEW_INFO
*infoPtr
, INT nItem
)
5681 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
5684 TRACE("(nItem=%d)\n", nItem
);
5686 lvItem
.mask
= LVIF_TEXT
;
5687 lvItem
.iItem
= nItem
;
5688 lvItem
.iSubItem
= 0;
5689 lvItem
.pszText
= szDispText
;
5690 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
5691 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
5693 return LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
5698 * Retrieves the spacing between listview control items.
5701 * [I] infoPtr : valid pointer to the listview structure
5702 * [I] bSmall : flag for small or large icon
5705 * Horizontal + vertical spacing
5707 static LONG
LISTVIEW_GetItemSpacing(LISTVIEW_INFO
*infoPtr
, BOOL bSmall
)
5713 lResult
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
5717 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_ICON
)
5718 lResult
= MAKELONG(DEFAULT_COLUMN_WIDTH
, GetSystemMetrics(SM_CXSMICON
)+HEIGHT_PADDING
);
5720 lResult
= MAKELONG(infoPtr
->nItemWidth
, infoPtr
->nItemHeight
);
5727 * Retrieves the state of a listview control item.
5730 * [I] infoPtr : valid pointer to the listview structure
5731 * [I] nItem : item index
5732 * [I] uMask : state mask
5735 * State specified by the mask.
5737 static UINT
LISTVIEW_GetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uMask
)
5741 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5743 lvItem
.iItem
= nItem
;
5744 lvItem
.iSubItem
= 0;
5745 lvItem
.mask
= LVIF_STATE
;
5746 lvItem
.stateMask
= uMask
;
5747 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return 0;
5749 return lvItem
.state
& uMask
;
5754 * Retrieves the text of a listview control item or subitem.
5757 * [I] hwnd : window handle
5758 * [I] nItem : item index
5759 * [IO] lpLVItem : item information
5760 * [I] isW : TRUE if lpLVItem is Unicode
5763 * SUCCESS : string length
5766 static INT
LISTVIEW_GetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, LPLVITEMW lpLVItem
, BOOL isW
)
5768 if (!lpLVItem
|| nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return 0;
5770 lpLVItem
->mask
= LVIF_TEXT
;
5771 lpLVItem
->iItem
= nItem
;
5772 if (!LISTVIEW_GetItemExtT(infoPtr
, lpLVItem
, isW
)) return 0;
5774 return textlenT(lpLVItem
->pszText
, isW
);
5779 * Searches for an item based on properties + relationships.
5782 * [I] infoPtr : valid pointer to the listview structure
5783 * [I] nItem : item index
5784 * [I] uFlags : relationship flag
5787 * SUCCESS : item index
5790 static INT
LISTVIEW_GetNextItem(LISTVIEW_INFO
*infoPtr
, INT nItem
, UINT uFlags
)
5792 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5794 LVFINDINFOW lvFindInfo
;
5795 INT nCountPerColumn
;
5799 TRACE("nItem=%d, uFlags=%x, nItemCount=%d\n", nItem
, uFlags
, infoPtr
->nItemCount
);
5800 if (nItem
< -1 || nItem
>= infoPtr
->nItemCount
) return -1;
5802 ZeroMemory(&lvFindInfo
, sizeof(lvFindInfo
));
5804 if (uFlags
& LVNI_CUT
)
5807 if (uFlags
& LVNI_DROPHILITED
)
5808 uMask
|= LVIS_DROPHILITED
;
5810 if (uFlags
& LVNI_FOCUSED
)
5811 uMask
|= LVIS_FOCUSED
;
5813 if (uFlags
& LVNI_SELECTED
)
5814 uMask
|= LVIS_SELECTED
;
5816 /* if we're asked for the focused item, that's only one,
5817 * so it's worth optimizing */
5818 if (uFlags
& LVNI_FOCUSED
)
5820 if ((LISTVIEW_GetItemState(infoPtr
, infoPtr
->nFocusedItem
, uMask
) & uMask
) != uMask
) return -1;
5821 return (infoPtr
->nFocusedItem
== nItem
) ? -1 : infoPtr
->nFocusedItem
;
5824 if (uFlags
& LVNI_ABOVE
)
5826 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
5831 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5837 /* Special case for autoarrange - move 'til the top of a list */
5838 if (is_autoarrange(infoPtr
))
5840 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
5841 while (nItem
- nCountPerRow
>= 0)
5843 nItem
-= nCountPerRow
;
5844 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5849 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5850 lvFindInfo
.vkDirection
= VK_UP
;
5851 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5852 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5854 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5859 else if (uFlags
& LVNI_BELOW
)
5861 if ((uView
== LVS_LIST
) || (uView
== LVS_REPORT
))
5863 while (nItem
< infoPtr
->nItemCount
)
5866 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5872 /* Special case for autoarrange - move 'til the bottom of a list */
5873 if (is_autoarrange(infoPtr
))
5875 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
5876 while (nItem
+ nCountPerRow
< infoPtr
->nItemCount
)
5878 nItem
+= nCountPerRow
;
5879 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5884 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5885 lvFindInfo
.vkDirection
= VK_DOWN
;
5886 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5887 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5889 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5894 else if (uFlags
& LVNI_TOLEFT
)
5896 if (uView
== LVS_LIST
)
5898 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
5899 while (nItem
- nCountPerColumn
>= 0)
5901 nItem
-= nCountPerColumn
;
5902 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5906 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
5908 /* Special case for autoarrange - move 'ti the beginning of a row */
5909 if (is_autoarrange(infoPtr
))
5911 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
5912 while (nItem
% nCountPerRow
> 0)
5915 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5920 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5921 lvFindInfo
.vkDirection
= VK_LEFT
;
5922 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5923 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5925 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5930 else if (uFlags
& LVNI_TORIGHT
)
5932 if (uView
== LVS_LIST
)
5934 nCountPerColumn
= LISTVIEW_GetCountPerColumn(infoPtr
);
5935 while (nItem
+ nCountPerColumn
< infoPtr
->nItemCount
)
5937 nItem
+= nCountPerColumn
;
5938 if ((ListView_GetItemState(infoPtr
->hwndSelf
, nItem
, uMask
) & uMask
) == uMask
)
5942 else if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
5944 /* Special case for autoarrange - move 'til the end of a row */
5945 if (is_autoarrange(infoPtr
))
5947 nCountPerRow
= LISTVIEW_GetCountPerRow(infoPtr
);
5948 while (nItem
% nCountPerRow
< nCountPerRow
- 1 )
5951 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5956 lvFindInfo
.flags
= LVFI_NEARESTXY
;
5957 lvFindInfo
.vkDirection
= VK_RIGHT
;
5958 ListView_GetItemPosition(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
.pt
);
5959 while ((nItem
= ListView_FindItemW(infoPtr
->hwndSelf
, nItem
, &lvFindInfo
)) != -1)
5961 if ((LISTVIEW_GetItemState(infoPtr
, nItem
, uMask
) & uMask
) == uMask
)
5970 /* search by index */
5971 for (i
= nItem
; i
< infoPtr
->nItemCount
; i
++)
5973 if ((LISTVIEW_GetItemState(infoPtr
, i
, uMask
) & uMask
) == uMask
)
5981 /* LISTVIEW_GetNumberOfWorkAreas */
5985 * Retrieves the origin coordinates when in icon or small icon display mode.
5988 * [I] infoPtr : valid pointer to the listview structure
5989 * [O] lpptOrigin : coordinate information
5994 static void LISTVIEW_GetOrigin(LISTVIEW_INFO
*infoPtr
, LPPOINT lpptOrigin
)
5996 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
5997 INT nHorzPos
= 0, nVertPos
= 0;
5998 SCROLLINFO scrollInfo
;
6000 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
6001 scrollInfo
.fMask
= SIF_POS
;
6003 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
))
6004 nHorzPos
= scrollInfo
.nPos
;
6005 if (GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
))
6006 nVertPos
= scrollInfo
.nPos
;
6008 TRACE("nHorzPos=%d, nVertPos=%d\n", nHorzPos
, nVertPos
);
6010 lpptOrigin
->x
= infoPtr
->rcList
.left
;
6011 lpptOrigin
->y
= infoPtr
->rcList
.top
;
6012 if (uView
== LVS_LIST
)
6013 nHorzPos
*= infoPtr
->nItemWidth
;
6014 else if (uView
== LVS_REPORT
)
6015 nVertPos
*= infoPtr
->nItemHeight
;
6017 lpptOrigin
->x
-= nHorzPos
;
6018 lpptOrigin
->y
-= nVertPos
;
6020 TRACE(" origin=%s\n", debugpoint(lpptOrigin
));
6025 * Retrieves the width of a string.
6028 * [I] hwnd : window handle
6029 * [I] lpszText : text string to process
6030 * [I] isW : TRUE if lpszText is Unicode, FALSE otherwise
6033 * SUCCESS : string width (in pixels)
6036 static INT
LISTVIEW_GetStringWidthT(LISTVIEW_INFO
*infoPtr
, LPCWSTR lpszText
, BOOL isW
)
6041 if (is_textT(lpszText
, isW
))
6043 HFONT hFont
= infoPtr
->hFont
? infoPtr
->hFont
: infoPtr
->hDefaultFont
;
6044 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
6045 HFONT hOldFont
= SelectObject(hdc
, hFont
);
6048 GetTextExtentPointW(hdc
, lpszText
, lstrlenW(lpszText
), &stringSize
);
6050 GetTextExtentPointA(hdc
, (LPCSTR
)lpszText
, lstrlenA((LPCSTR
)lpszText
), &stringSize
);
6051 SelectObject(hdc
, hOldFont
);
6052 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6054 return stringSize
.cx
;
6059 * Determines which listview item is located at the specified position.
6062 * [I] infoPtr : valid pointer to the listview structure
6063 * [IO] lpht : hit test information
6064 * [I] subitem : fill out iSubItem.
6065 * [I] select : return the index only if the hit selects the item
6068 * (mm 20001022): We must not allow iSubItem to be touched, for
6069 * an app might pass only a structure with space up to iItem!
6070 * (MS Office 97 does that for instance in the file open dialog)
6073 * SUCCESS : item index
6076 static INT
LISTVIEW_HitTest(LISTVIEW_INFO
*infoPtr
, LPLVHITTESTINFO lpht
, BOOL subitem
, BOOL select
)
6078 WCHAR szDispText
[DISP_TEXT_SIZE
] = { '\0' };
6079 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6080 RECT rcBox
, rcBounds
, rcState
, rcIcon
, rcLabel
, rcSearch
;
6081 POINT Origin
, Position
, opt
;
6086 TRACE("(pt=%s, subitem=%d, select=%d)\n", debugpoint(&lpht
->pt
), subitem
, select
);
6090 if (subitem
) lpht
->iSubItem
= 0;
6092 if (infoPtr
->rcList
.left
> lpht
->pt
.x
)
6093 lpht
->flags
|= LVHT_TOLEFT
;
6094 else if (infoPtr
->rcList
.right
< lpht
->pt
.x
)
6095 lpht
->flags
|= LVHT_TORIGHT
;
6097 if (infoPtr
->rcList
.top
> lpht
->pt
.y
)
6098 lpht
->flags
|= LVHT_ABOVE
;
6099 else if (infoPtr
->rcList
.bottom
< lpht
->pt
.y
)
6100 lpht
->flags
|= LVHT_BELOW
;
6102 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
6103 if (lpht
->flags
) return -1;
6105 lpht
->flags
|= LVHT_NOWHERE
;
6107 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6109 /* first deal with the large items */
6110 rcSearch
.left
= lpht
->pt
.x
;
6111 rcSearch
.top
= lpht
->pt
.y
;
6112 rcSearch
.right
= rcSearch
.left
+ 1;
6113 rcSearch
.bottom
= rcSearch
.top
+ 1;
6115 iterator_frameditems(&i
, infoPtr
, &rcSearch
);
6116 iterator_next(&i
); /* go to first item in the sequence */
6118 iterator_destroy(&i
);
6120 TRACE("lpht->iItem=%d\n", iItem
);
6121 if (iItem
== -1) return -1;
6123 lvItem
.mask
= LVIF_STATE
| LVIF_TEXT
;
6124 if (uView
== LVS_REPORT
) lvItem
.mask
|= LVIF_INDENT
;
6125 lvItem
.stateMask
= LVIS_STATEIMAGEMASK
;
6126 if (uView
== LVS_ICON
) lvItem
.stateMask
|= LVIS_FOCUSED
;
6127 lvItem
.iItem
= iItem
;
6128 lvItem
.iSubItem
= 0;
6129 lvItem
.pszText
= szDispText
;
6130 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6131 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) return -1;
6132 if (!infoPtr
->bFocus
) lvItem
.state
&= ~LVIS_FOCUSED
;
6134 LISTVIEW_GetItemMetrics(infoPtr
, &lvItem
, &rcBox
, &rcState
, &rcIcon
, &rcLabel
);
6135 LISTVIEW_GetItemOrigin(infoPtr
, iItem
, &Position
);
6136 opt
.x
= lpht
->pt
.x
- Position
.x
- Origin
.x
;
6137 opt
.y
= lpht
->pt
.y
- Position
.y
- Origin
.y
;
6139 if (uView
== LVS_REPORT
)
6142 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
6143 TRACE("rcBounds=%s\n", debugrect(&rcBounds
));
6144 if (!PtInRect(&rcBounds
, opt
)) return -1;
6146 if (PtInRect(&rcIcon
, opt
))
6147 lpht
->flags
|= LVHT_ONITEMICON
;
6148 else if (PtInRect(&rcLabel
, opt
))
6149 lpht
->flags
|= LVHT_ONITEMLABEL
;
6150 else if (infoPtr
->himlState
&& STATEIMAGEINDEX(lvItem
.state
) && PtInRect(&rcState
, opt
))
6151 lpht
->flags
|= LVHT_ONITEMSTATEICON
;
6152 if (lpht
->flags
& LVHT_ONITEM
)
6153 lpht
->flags
&= ~LVHT_NOWHERE
;
6155 TRACE("lpht->flags=0x%x\n", lpht
->flags
);
6156 if (uView
== LVS_REPORT
&& subitem
)
6160 rcBounds
.right
= rcBounds
.left
;
6161 for (j
= 0; j
< DPA_GetPtrCount(infoPtr
->hdpaColumns
); j
++)
6163 rcBounds
.left
= rcBounds
.right
;
6164 rcBounds
.right
+= LISTVIEW_GetColumnWidth(infoPtr
, j
);
6165 if (PtInRect(&rcBounds
, opt
))
6173 if (select
&& !(uView
== LVS_REPORT
&&
6174 ((infoPtr
->dwLvExStyle
& LVS_EX_FULLROWSELECT
) ||
6175 (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
))))
6177 if (uView
== LVS_REPORT
)
6179 UnionRect(&rcBounds
, &rcIcon
, &rcLabel
);
6180 UnionRect(&rcBounds
, &rcBounds
, &rcState
);
6182 if (!PtInRect(&rcBounds
, opt
)) iItem
= -1;
6184 return lpht
->iItem
= iItem
;
6188 /* LISTVIEW_InsertCompare: callback routine for comparing pszText members of the LV_ITEMS
6189 in a LISTVIEW on insert. Passed to DPA_Sort in LISTVIEW_InsertItem.
6190 This function should only be used for inserting items into a sorted list (LVM_INSERTITEM)
6191 and not during the processing of a LVM_SORTITEMS message. Applications should provide
6192 their own sort proc. when sending LVM_SORTITEMS.
6195 (remarks on LVITEM: LVM_INSERTITEM will insert the new item in the proper sort postion...
6197 LVS_SORTXXX must be specified,
6198 LVS_OWNERDRAW is not set,
6199 <item>.pszText is not LPSTR_TEXTCALLBACK.
6201 (LVS_SORT* flags): "For the LVS_SORTASCENDING... styles, item indices
6202 are sorted based on item text..."
6204 static INT WINAPI
LISTVIEW_InsertCompare( LPVOID first
, LPVOID second
, LPARAM lParam
)
6206 ITEM_INFO
* lv_first
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)first
, 0 );
6207 ITEM_INFO
* lv_second
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)second
, 0 );
6208 INT cmpv
= textcmpWT(lv_first
->hdr
.pszText
, lv_second
->hdr
.pszText
, TRUE
);
6210 /* if we're sorting descending, negate the return value */
6211 return (((LISTVIEW_INFO
*)lParam
)->dwStyle
& LVS_SORTDESCENDING
) ? -cmpv
: cmpv
;
6216 * Inserts a new item in the listview control.
6219 * [I] infoPtr : valid pointer to the listview structure
6220 * [I] lpLVItem : item information
6221 * [I] isW : TRUE if lpLVItem is Unicode, FALSE if it's ANSI
6224 * SUCCESS : new item index
6227 static INT
LISTVIEW_InsertItemT(LISTVIEW_INFO
*infoPtr
, const LVITEMW
*lpLVItem
, BOOL isW
)
6229 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6234 BOOL is_sorted
, has_changed
;
6236 HWND hwndSelf
= infoPtr
->hwndSelf
;
6238 TRACE("(lpLVItem=%s, isW=%d)\n", debuglvitem_t(lpLVItem
, isW
), isW
);
6240 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return infoPtr
->nItemCount
++;
6242 /* make sure it's an item, and not a subitem; cannot insert a subitem */
6243 if (!lpLVItem
|| lpLVItem
->iItem
< 0 || lpLVItem
->iSubItem
) return -1;
6245 if (!is_assignable_item(lpLVItem
, infoPtr
->dwStyle
)) return -1;
6247 if (!(lpItem
= (ITEM_INFO
*)Alloc(sizeof(ITEM_INFO
)))) return -1;
6249 /* insert item in listview control data structure */
6250 if ( !(hdpaSubItems
= DPA_Create(8)) ) goto fail
;
6251 if ( !DPA_SetPtr(hdpaSubItems
, 0, lpItem
) ) assert (FALSE
);
6253 is_sorted
= (infoPtr
->dwStyle
& (LVS_SORTASCENDING
| LVS_SORTDESCENDING
)) &&
6254 !(infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (LPSTR_TEXTCALLBACKW
!= lpLVItem
->pszText
);
6256 nItem
= is_sorted
? infoPtr
->nItemCount
: min(lpLVItem
->iItem
, infoPtr
->nItemCount
);
6257 TRACE(" inserting at %d, sorted=%d, count=%d, iItem=%d\n", nItem
, is_sorted
, infoPtr
->nItemCount
, lpLVItem
->iItem
);
6258 nItem
= DPA_InsertPtr( infoPtr
->hdpaItems
, nItem
, hdpaSubItems
);
6259 if (nItem
== -1) goto fail
;
6260 infoPtr
->nItemCount
++;
6262 /* shift indices first so they don't get tangled */
6263 LISTVIEW_ShiftIndices(infoPtr
, nItem
, 1);
6265 /* set the item attributes */
6266 if (lpLVItem
->mask
& (LVIF_GROUPID
|LVIF_COLUMNS
))
6268 /* full size structure expected - _WIN32IE >= 0x560 */
6271 else if (lpLVItem
->mask
& LVIF_INDENT
)
6273 /* indent member expected - _WIN32IE >= 0x300 */
6274 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iGroupId
));
6278 /* minimal structure expected */
6279 memcpy(&item
, lpLVItem
, offsetof( LVITEMW
, iIndent
));
6282 if (infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) item
.state
&= ~LVIS_STATEIMAGEMASK
;
6283 if (!set_main_item(infoPtr
, &item
, TRUE
, isW
, &has_changed
)) goto undo
;
6285 /* if we're sorted, sort the list, and update the index */
6288 DPA_Sort( infoPtr
->hdpaItems
, LISTVIEW_InsertCompare
, (LPARAM
)infoPtr
);
6289 nItem
= DPA_GetPtrIndex( infoPtr
->hdpaItems
, hdpaSubItems
);
6290 assert(nItem
!= -1);
6293 /* make room for the position, if we are in the right mode */
6294 if ((uView
== LVS_SMALLICON
) || (uView
== LVS_ICON
))
6296 if (DPA_InsertPtr(infoPtr
->hdpaPosX
, nItem
, 0) == -1)
6298 if (DPA_InsertPtr(infoPtr
->hdpaPosY
, nItem
, 0) == -1)
6300 DPA_DeletePtr(infoPtr
->hdpaPosX
, nItem
);
6305 /* send LVN_INSERTITEM notification */
6306 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
6308 nmlv
.lParam
= lpItem
->lParam
;
6309 notify_listview(infoPtr
, LVN_INSERTITEM
, &nmlv
);
6310 if (!IsWindow(hwndSelf
))
6313 /* align items (set position of each item) */
6314 if ((uView
== LVS_SMALLICON
|| uView
== LVS_ICON
))
6318 if (infoPtr
->dwStyle
& LVS_ALIGNLEFT
)
6319 LISTVIEW_NextIconPosLeft(infoPtr
, &pt
);
6321 LISTVIEW_NextIconPosTop(infoPtr
, &pt
);
6323 LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, TRUE
);
6326 /* now is the invalidation fun */
6327 LISTVIEW_ScrollOnInsert(infoPtr
, nItem
, 1);
6331 LISTVIEW_ShiftIndices(infoPtr
, nItem
, -1);
6332 DPA_DeletePtr(infoPtr
->hdpaItems
, nItem
);
6333 infoPtr
->nItemCount
--;
6335 DPA_DeletePtr(hdpaSubItems
, 0);
6336 DPA_Destroy (hdpaSubItems
);
6343 * Redraws a range of items.
6346 * [I] infoPtr : valid pointer to the listview structure
6347 * [I] nFirst : first item
6348 * [I] nLast : last item
6354 static BOOL
LISTVIEW_RedrawItems(LISTVIEW_INFO
*infoPtr
, INT nFirst
, INT nLast
)
6358 if (nLast
< nFirst
|| min(nFirst
, nLast
) < 0 ||
6359 max(nFirst
, nLast
) >= infoPtr
->nItemCount
)
6362 for (i
= nFirst
; i
<= nLast
; i
++)
6363 LISTVIEW_InvalidateItem(infoPtr
, i
);
6370 * Scroll the content of a listview.
6373 * [I] infoPtr : valid pointer to the listview structure
6374 * [I] dx : horizontal scroll amount in pixels
6375 * [I] dy : vertical scroll amount in pixels
6382 * If the control is in report mode (LVS_REPORT) the control can
6383 * be scrolled only in line increments. "dy" will be rounded to the
6384 * nearest number of pixels that are a whole line. Ex: if line height
6385 * is 16 and an 8 is passed, the list will be scrolled by 16. If a 7
6386 * is passed the the scroll will be 0. (per MSDN 7/2002)
6388 * For: (per experimentaion with native control and CSpy ListView)
6389 * LVS_ICON dy=1 = 1 pixel (vertical only)
6391 * LVS_SMALLICON dy=1 = 1 pixel (vertical only)
6393 * LVS_LIST dx=1 = 1 column (horizontal only)
6394 * but will only scroll 1 column per message
6395 * no matter what the value.
6396 * dy must be 0 or FALSE returned.
6397 * LVS_REPORT dx=1 = 1 pixel
6401 static BOOL
LISTVIEW_Scroll(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
6403 switch(infoPtr
->dwStyle
& LVS_TYPEMASK
) {
6405 dy
+= (dy
< 0 ? -1 : 1) * infoPtr
->nItemHeight
/2;
6406 dy
/= infoPtr
->nItemHeight
;
6409 if (dy
!= 0) return FALSE
;
6416 if (dx
!= 0) LISTVIEW_HScroll(infoPtr
, SB_INTERNAL
, dx
, 0);
6417 if (dy
!= 0) LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, dy
, 0);
6424 * Sets the background color.
6427 * [I] infoPtr : valid pointer to the listview structure
6428 * [I] clrBk : background color
6434 static BOOL
LISTVIEW_SetBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrBk
)
6436 TRACE("(clrBk=%lx)\n", clrBk
);
6438 if(infoPtr
->clrBk
!= clrBk
) {
6439 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
6440 infoPtr
->clrBk
= clrBk
;
6441 if (clrBk
== CLR_NONE
)
6442 infoPtr
->hBkBrush
= (HBRUSH
)GetClassLongPtrW(infoPtr
->hwndSelf
, GCLP_HBRBACKGROUND
);
6444 infoPtr
->hBkBrush
= CreateSolidBrush(clrBk
);
6445 LISTVIEW_InvalidateList(infoPtr
);
6451 /* LISTVIEW_SetBkImage */
6453 /*** Helper for {Insert,Set}ColumnT *only* */
6454 static void column_fill_hditem(LISTVIEW_INFO
*infoPtr
, HDITEMW
*lphdi
, INT nColumn
, const LVCOLUMNW
*lpColumn
, BOOL isW
)
6456 if (lpColumn
->mask
& LVCF_FMT
)
6458 /* format member is valid */
6459 lphdi
->mask
|= HDI_FORMAT
;
6461 /* set text alignment (leftmost column must be left-aligned) */
6462 if (nColumn
== 0 || (lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
6463 lphdi
->fmt
|= HDF_LEFT
;
6464 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_RIGHT
)
6465 lphdi
->fmt
|= HDF_RIGHT
;
6466 else if ((lpColumn
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_CENTER
)
6467 lphdi
->fmt
|= HDF_CENTER
;
6469 if (lpColumn
->fmt
& LVCFMT_BITMAP_ON_RIGHT
)
6470 lphdi
->fmt
|= HDF_BITMAP_ON_RIGHT
;
6472 if (lpColumn
->fmt
& LVCFMT_COL_HAS_IMAGES
)
6474 lphdi
->fmt
|= HDF_IMAGE
;
6475 lphdi
->iImage
= I_IMAGECALLBACK
;
6479 if (lpColumn
->mask
& LVCF_WIDTH
)
6481 lphdi
->mask
|= HDI_WIDTH
;
6482 if(lpColumn
->cx
== LVSCW_AUTOSIZE_USEHEADER
)
6484 /* make it fill the remainder of the controls width */
6488 for(item_index
= 0; item_index
< (nColumn
- 1); item_index
++)
6490 LISTVIEW_GetHeaderRect(infoPtr
, item_index
, &rcHeader
);
6491 lphdi
->cxy
+= rcHeader
.right
- rcHeader
.left
;
6494 /* retrieve the layout of the header */
6495 GetClientRect(infoPtr
->hwndSelf
, &rcHeader
);
6496 TRACE("start cxy=%d rcHeader=%s\n", lphdi
->cxy
, debugrect(&rcHeader
));
6498 lphdi
->cxy
= (rcHeader
.right
- rcHeader
.left
) - lphdi
->cxy
;
6501 lphdi
->cxy
= lpColumn
->cx
;
6504 if (lpColumn
->mask
& LVCF_TEXT
)
6506 lphdi
->mask
|= HDI_TEXT
| HDI_FORMAT
;
6507 lphdi
->fmt
|= HDF_STRING
;
6508 lphdi
->pszText
= lpColumn
->pszText
;
6509 lphdi
->cchTextMax
= textlenT(lpColumn
->pszText
, isW
);
6512 if (lpColumn
->mask
& LVCF_IMAGE
)
6514 lphdi
->mask
|= HDI_IMAGE
;
6515 lphdi
->iImage
= lpColumn
->iImage
;
6518 if (lpColumn
->mask
& LVCF_ORDER
)
6520 lphdi
->mask
|= HDI_ORDER
;
6521 lphdi
->iOrder
= lpColumn
->iOrder
;
6528 * Inserts a new column.
6531 * [I] infoPtr : valid pointer to the listview structure
6532 * [I] nColumn : column index
6533 * [I] lpColumn : column information
6534 * [I] isW : TRUE if lpColumn is Unicode, FALSE otherwise
6537 * SUCCESS : new column index
6540 static INT
LISTVIEW_InsertColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
6541 const LVCOLUMNW
*lpColumn
, BOOL isW
)
6543 COLUMN_INFO
*lpColumnInfo
;
6547 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
6549 if (!lpColumn
|| nColumn
< 0) return -1;
6550 nColumn
= min(nColumn
, DPA_GetPtrCount(infoPtr
->hdpaColumns
));
6552 ZeroMemory(&hdi
, sizeof(HDITEMW
));
6553 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
6555 /* insert item in header control */
6556 nNewColumn
= SendMessageW(infoPtr
->hwndHeader
,
6557 isW
? HDM_INSERTITEMW
: HDM_INSERTITEMA
,
6558 (WPARAM
)nColumn
, (LPARAM
)&hdi
);
6559 if (nNewColumn
== -1) return -1;
6560 if (nNewColumn
!= nColumn
) ERR("nColumn=%d, nNewColumn=%d\n", nColumn
, nNewColumn
);
6562 /* create our own column info */
6563 if (!(lpColumnInfo
= Alloc(sizeof(COLUMN_INFO
)))) goto fail
;
6564 if (DPA_InsertPtr(infoPtr
->hdpaColumns
, nNewColumn
, lpColumnInfo
) == -1) goto fail
;
6566 if (lpColumn
->mask
& LVCF_FMT
) lpColumnInfo
->fmt
= lpColumn
->fmt
;
6567 if (!Header_GetItemRect(infoPtr
->hwndHeader
, nNewColumn
, &lpColumnInfo
->rcHeader
)) goto fail
;
6569 /* now we have to actually adjust the data */
6570 if (!(infoPtr
->dwStyle
& LVS_OWNERDATA
) && infoPtr
->nItemCount
> 0)
6572 SUBITEM_INFO
*lpSubItem
;
6576 for (nItem
= 0; nItem
< infoPtr
->nItemCount
; nItem
++)
6578 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, nItem
);
6579 for (i
= 1; i
< DPA_GetPtrCount(hdpaSubItems
); i
++)
6581 lpSubItem
= (SUBITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, i
);
6582 if (lpSubItem
->iSubItem
>= nNewColumn
)
6583 lpSubItem
->iSubItem
++;
6588 /* make space for the new column */
6589 LISTVIEW_ScrollColumns(infoPtr
, nNewColumn
+ 1, lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
6594 if (nNewColumn
!= -1) SendMessageW(infoPtr
->hwndHeader
, HDM_DELETEITEM
, nNewColumn
, 0);
6597 DPA_DeletePtr(infoPtr
->hdpaColumns
, nNewColumn
);
6605 * Sets the attributes of a header item.
6608 * [I] infoPtr : valid pointer to the listview structure
6609 * [I] nColumn : column index
6610 * [I] lpColumn : column attributes
6611 * [I] isW: if TRUE, the lpColumn is a LPLVCOLUMNW, else it is a LPLVCOLUMNA
6617 static BOOL
LISTVIEW_SetColumnT(LISTVIEW_INFO
*infoPtr
, INT nColumn
,
6618 const LVCOLUMNW
*lpColumn
, BOOL isW
)
6620 HDITEMW hdi
, hdiget
;
6623 TRACE("(nColumn=%d, lpColumn=%s, isW=%d)\n", nColumn
, debuglvcolumn_t(lpColumn
, isW
), isW
);
6625 if (!lpColumn
|| nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6627 ZeroMemory(&hdi
, sizeof(HDITEMW
));
6628 if (lpColumn
->mask
& LVCF_FMT
)
6630 hdi
.mask
|= HDI_FORMAT
;
6631 hdiget
.mask
= HDI_FORMAT
;
6632 if (Header_GetItemW(infoPtr
->hwndHeader
, nColumn
, &hdiget
))
6633 hdi
.fmt
= hdiget
.fmt
& HDF_STRING
;
6635 column_fill_hditem(infoPtr
, &hdi
, nColumn
, lpColumn
, isW
);
6637 /* set header item attributes */
6638 bResult
= SendMessageW(infoPtr
->hwndHeader
, isW
? HDM_SETITEMW
: HDM_SETITEMA
, (WPARAM
)nColumn
, (LPARAM
)&hdi
);
6639 if (!bResult
) return FALSE
;
6641 if (lpColumn
->mask
& LVCF_FMT
)
6643 COLUMN_INFO
*lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, nColumn
);
6644 int oldFmt
= lpColumnInfo
->fmt
;
6646 lpColumnInfo
->fmt
= lpColumn
->fmt
;
6647 if ((oldFmt
^ lpColumn
->fmt
) & (LVCFMT_JUSTIFYMASK
| LVCFMT_IMAGE
))
6649 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6650 if (uView
== LVS_REPORT
) LISTVIEW_InvalidateColumn(infoPtr
, nColumn
);
6659 * Sets the column order array
6662 * [I] infoPtr : valid pointer to the listview structure
6663 * [I] iCount : number of elements in column order array
6664 * [I] lpiArray : pointer to column order array
6670 static BOOL
LISTVIEW_SetColumnOrderArray(LISTVIEW_INFO
*infoPtr
, INT iCount
, const INT
*lpiArray
)
6672 FIXME("iCount %d lpiArray %p\n", iCount
, lpiArray
);
6683 * Sets the width of a column
6686 * [I] infoPtr : valid pointer to the listview structure
6687 * [I] nColumn : column index
6688 * [I] cx : column width
6694 static BOOL
LISTVIEW_SetColumnWidth(LISTVIEW_INFO
*infoPtr
, INT nColumn
, INT cx
)
6696 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6697 WCHAR szDispText
[DISP_TEXT_SIZE
] = { 0 };
6701 TRACE("(nColumn=%d, cx=%d\n", nColumn
, cx
);
6703 /* set column width only if in report or list mode */
6704 if (uView
!= LVS_REPORT
&& uView
!= LVS_LIST
) return FALSE
;
6706 /* take care of invalid cx values */
6707 if(uView
== LVS_REPORT
&& cx
< -2) cx
= LVSCW_AUTOSIZE
;
6708 else if (uView
== LVS_LIST
&& cx
< 1) return FALSE
;
6710 /* resize all columns if in LVS_LIST mode */
6711 if(uView
== LVS_LIST
)
6713 infoPtr
->nItemWidth
= cx
;
6714 LISTVIEW_InvalidateList(infoPtr
);
6718 if (nColumn
< 0 || nColumn
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return FALSE
;
6720 if (cx
== LVSCW_AUTOSIZE
|| (cx
== LVSCW_AUTOSIZE_USEHEADER
&& nColumn
< DPA_GetPtrCount(infoPtr
->hdpaColumns
) -1))
6725 lvItem
.mask
= LVIF_TEXT
;
6727 lvItem
.iSubItem
= nColumn
;
6728 lvItem
.pszText
= szDispText
;
6729 lvItem
.cchTextMax
= DISP_TEXT_SIZE
;
6730 for (; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
6732 if (!LISTVIEW_GetItemW(infoPtr
, &lvItem
)) continue;
6733 nLabelWidth
= LISTVIEW_GetStringWidthT(infoPtr
, lvItem
.pszText
, TRUE
);
6734 if (max_cx
< nLabelWidth
) max_cx
= nLabelWidth
;
6736 if (infoPtr
->himlSmall
&& (nColumn
== 0 || (LISTVIEW_GetColumnInfo(infoPtr
, nColumn
)->fmt
& LVCFMT_IMAGE
)))
6737 max_cx
+= infoPtr
->iconSize
.cx
;
6738 max_cx
+= TRAILING_LABEL_PADDING
;
6741 /* autosize based on listview items width */
6742 if(cx
== LVSCW_AUTOSIZE
)
6744 else if(cx
== LVSCW_AUTOSIZE_USEHEADER
)
6746 /* if iCol is the last column make it fill the remainder of the controls width */
6747 if(nColumn
== DPA_GetPtrCount(infoPtr
->hdpaColumns
) - 1)
6752 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
6753 LISTVIEW_GetHeaderRect(infoPtr
, nColumn
, &rcHeader
);
6755 cx
= infoPtr
->rcList
.right
- Origin
.x
- rcHeader
.left
;
6759 /* Despite what the MS docs say, if this is not the last
6760 column, then MS resizes the column to the width of the
6761 largest text string in the column, including headers
6762 and items. This is different from LVSCW_AUTOSIZE in that
6763 LVSCW_AUTOSIZE ignores the header string length. */
6766 /* retrieve header text */
6767 hdi
.mask
= HDI_TEXT
;
6768 hdi
.cchTextMax
= DISP_TEXT_SIZE
;
6769 hdi
.pszText
= szDispText
;
6770 if (Header_GetItemW(infoPtr
->hwndHeader
, nColumn
, (LPARAM
)&hdi
))
6772 HDC hdc
= GetDC(infoPtr
->hwndSelf
);
6773 HFONT old_font
= SelectObject(hdc
, (HFONT
)SendMessageW(infoPtr
->hwndHeader
, WM_GETFONT
, 0, 0));
6776 if (GetTextExtentPoint32W(hdc
, hdi
.pszText
, lstrlenW(hdi
.pszText
), &size
))
6777 cx
= size
.cx
+ TRAILING_HEADER_PADDING
;
6778 /* FIXME: Take into account the header image, if one is present */
6779 SelectObject(hdc
, old_font
);
6780 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
6782 cx
= max (cx
, max_cx
);
6786 if (cx
< 0) return FALSE
;
6788 /* call header to update the column change */
6789 hdi
.mask
= HDI_WIDTH
;
6791 TRACE("hdi.cxy=%d\n", hdi
.cxy
);
6792 return Header_SetItemW(infoPtr
->hwndHeader
, nColumn
, (LPARAM
)&hdi
);
6796 * Creates the checkbox imagelist. Helper for LISTVIEW_SetExtendedListViewStyle
6799 static HIMAGELIST
LISTVIEW_CreateCheckBoxIL(LISTVIEW_INFO
*infoPtr
)
6802 HBITMAP hbm_im
, hbm_mask
, hbm_orig
;
6804 HBRUSH hbr_white
= GetStockObject(WHITE_BRUSH
);
6805 HBRUSH hbr_black
= GetStockObject(BLACK_BRUSH
);
6808 himl
= ImageList_Create(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
),
6809 ILC_COLOR
| ILC_MASK
, 2, 2);
6810 hdc_wnd
= GetDC(infoPtr
->hwndSelf
);
6811 hdc
= CreateCompatibleDC(hdc_wnd
);
6812 hbm_im
= CreateCompatibleBitmap(hdc_wnd
, GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
));
6813 hbm_mask
= CreateBitmap(GetSystemMetrics(SM_CXSMICON
), GetSystemMetrics(SM_CYSMICON
), 1, 1, NULL
);
6814 ReleaseDC(infoPtr
->hwndSelf
, hdc_wnd
);
6816 rc
.left
= rc
.top
= 0;
6817 rc
.right
= GetSystemMetrics(SM_CXSMICON
);
6818 rc
.bottom
= GetSystemMetrics(SM_CYSMICON
);
6820 hbm_orig
= SelectObject(hdc
, hbm_mask
);
6821 FillRect(hdc
, &rc
, hbr_white
);
6822 InflateRect(&rc
, -3, -3);
6823 FillRect(hdc
, &rc
, hbr_black
);
6825 SelectObject(hdc
, hbm_im
);
6826 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
);
6827 SelectObject(hdc
, hbm_orig
);
6828 ImageList_Add(himl
, hbm_im
, hbm_mask
);
6830 SelectObject(hdc
, hbm_im
);
6831 DrawFrameControl(hdc
, &rc
, DFC_BUTTON
, DFCS_BUTTONCHECK
| DFCS_MONO
| DFCS_CHECKED
);
6832 SelectObject(hdc
, hbm_orig
);
6833 ImageList_Add(himl
, hbm_im
, hbm_mask
);
6835 DeleteObject(hbm_mask
);
6836 DeleteObject(hbm_im
);
6844 * Sets the extended listview style.
6847 * [I] infoPtr : valid pointer to the listview structure
6849 * [I] dwStyle : style
6852 * SUCCESS : previous style
6855 static DWORD
LISTVIEW_SetExtendedListViewStyle(LISTVIEW_INFO
*infoPtr
, DWORD dwMask
, DWORD dwStyle
)
6857 DWORD dwOldStyle
= infoPtr
->dwLvExStyle
;
6861 infoPtr
->dwLvExStyle
= (dwOldStyle
& ~dwMask
) | (dwStyle
& dwMask
);
6863 infoPtr
->dwLvExStyle
= dwStyle
;
6865 if((infoPtr
->dwLvExStyle
^ dwOldStyle
) & LVS_EX_CHECKBOXES
)
6867 HIMAGELIST himl
= 0;
6868 if(infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
)
6869 himl
= LISTVIEW_CreateCheckBoxIL(infoPtr
);
6870 LISTVIEW_SetImageList(infoPtr
, LVSIL_STATE
, himl
);
6878 * Sets the new hot cursor used during hot tracking and hover selection.
6881 * [I] infoPtr : valid pointer to the listview structure
6882 * [I] hCursor : the new hot cursor handle
6885 * Returns the previous hot cursor
6887 static HCURSOR
LISTVIEW_SetHotCursor(LISTVIEW_INFO
*infoPtr
, HCURSOR hCursor
)
6889 HCURSOR oldCursor
= infoPtr
->hHotCursor
;
6891 infoPtr
->hHotCursor
= hCursor
;
6899 * Sets the hot item index.
6902 * [I] infoPtr : valid pointer to the listview structure
6903 * [I] iIndex : index
6906 * SUCCESS : previous hot item index
6907 * FAILURE : -1 (no hot item)
6909 static INT
LISTVIEW_SetHotItem(LISTVIEW_INFO
*infoPtr
, INT iIndex
)
6911 INT iOldIndex
= infoPtr
->nHotItem
;
6913 infoPtr
->nHotItem
= iIndex
;
6921 * Sets the amount of time the cursor must hover over an item before it is selected.
6924 * [I] infoPtr : valid pointer to the listview structure
6925 * [I] dwHoverTime : hover time, if -1 the hover time is set to the default
6928 * Returns the previous hover time
6930 static DWORD
LISTVIEW_SetHoverTime(LISTVIEW_INFO
*infoPtr
, DWORD dwHoverTime
)
6932 DWORD oldHoverTime
= infoPtr
->dwHoverTime
;
6934 infoPtr
->dwHoverTime
= dwHoverTime
;
6936 return oldHoverTime
;
6941 * Sets spacing for icons of LVS_ICON style.
6944 * [I] infoPtr : valid pointer to the listview structure
6945 * [I] cx : horizontal spacing (-1 = system spacing, 0 = autosize)
6946 * [I] cy : vertical spacing (-1 = system spacing, 0 = autosize)
6949 * MAKELONG(oldcx, oldcy)
6951 static DWORD
LISTVIEW_SetIconSpacing(LISTVIEW_INFO
*infoPtr
, INT cx
, INT cy
)
6953 DWORD oldspacing
= MAKELONG(infoPtr
->iconSpacing
.cx
, infoPtr
->iconSpacing
.cy
);
6954 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
6956 TRACE("requested=(%d,%d)\n", cx
, cy
);
6958 /* this is supported only for LVS_ICON style */
6959 if (uView
!= LVS_ICON
) return oldspacing
;
6961 /* set to defaults, if instructed to */
6962 if (cx
== -1) cx
= GetSystemMetrics(SM_CXICONSPACING
);
6963 if (cy
== -1) cy
= GetSystemMetrics(SM_CYICONSPACING
);
6965 /* if 0 then compute width
6966 * FIXME: Should scan each item and determine max width of
6967 * icon or label, then make that the width */
6969 cx
= infoPtr
->iconSpacing
.cx
;
6971 /* if 0 then compute height */
6973 cy
= infoPtr
->iconSize
.cy
+ 2 * infoPtr
->ntmHeight
+
6974 ICON_BOTTOM_PADDING
+ ICON_TOP_PADDING
+ LABEL_VERT_PADDING
;
6977 infoPtr
->iconSpacing
.cx
= cx
;
6978 infoPtr
->iconSpacing
.cy
= cy
;
6980 TRACE("old=(%d,%d), new=(%d,%d), iconSize=(%ld,%ld), ntmH=%d\n",
6981 LOWORD(oldspacing
), HIWORD(oldspacing
), cx
, cy
,
6982 infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
,
6983 infoPtr
->ntmHeight
);
6985 /* these depend on the iconSpacing */
6986 LISTVIEW_UpdateItemSize(infoPtr
);
6991 static inline void set_icon_size(SIZE
*size
, HIMAGELIST himl
, BOOL _small
)
6995 if (himl
&& ImageList_GetIconSize(himl
, &cx
, &cy
))
7002 size
->cx
= GetSystemMetrics(_small
? SM_CXSMICON
: SM_CXICON
);
7003 size
->cy
= GetSystemMetrics(_small
? SM_CYSMICON
: SM_CYICON
);
7012 * [I] infoPtr : valid pointer to the listview structure
7013 * [I] nType : image list type
7014 * [I] himl : image list handle
7017 * SUCCESS : old image list
7020 static HIMAGELIST
LISTVIEW_SetImageList(LISTVIEW_INFO
*infoPtr
, INT nType
, HIMAGELIST himl
)
7022 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7023 INT oldHeight
= infoPtr
->nItemHeight
;
7024 HIMAGELIST himlOld
= 0;
7026 TRACE("(nType=%d, himl=%p\n", nType
, himl
);
7031 himlOld
= infoPtr
->himlNormal
;
7032 infoPtr
->himlNormal
= himl
;
7033 if (uView
== LVS_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, FALSE
);
7034 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
7038 himlOld
= infoPtr
->himlSmall
;
7039 infoPtr
->himlSmall
= himl
;
7040 if (uView
!= LVS_ICON
) set_icon_size(&infoPtr
->iconSize
, himl
, TRUE
);
7044 himlOld
= infoPtr
->himlState
;
7045 infoPtr
->himlState
= himl
;
7046 set_icon_size(&infoPtr
->iconStateSize
, himl
, TRUE
);
7047 ImageList_SetBkColor(infoPtr
->himlState
, CLR_NONE
);
7051 ERR("Unknown icon type=%d\n", nType
);
7055 infoPtr
->nItemHeight
= LISTVIEW_CalculateItemHeight(infoPtr
);
7056 if (infoPtr
->nItemHeight
!= oldHeight
)
7057 LISTVIEW_UpdateScroll(infoPtr
);
7064 * Preallocates memory (does *not* set the actual count of items !)
7067 * [I] infoPtr : valid pointer to the listview structure
7068 * [I] nItems : item count (projected number of items to allocate)
7069 * [I] dwFlags : update flags
7075 static BOOL
LISTVIEW_SetItemCount(LISTVIEW_INFO
*infoPtr
, INT nItems
, DWORD dwFlags
)
7077 TRACE("(nItems=%d, dwFlags=%lx)\n", nItems
, dwFlags
);
7079 if (infoPtr
->dwStyle
& LVS_OWNERDATA
)
7081 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7082 INT nOldCount
= infoPtr
->nItemCount
;
7084 if (nItems
< nOldCount
)
7086 RANGE range
= { nItems
, nOldCount
};
7087 ranges_del(infoPtr
->selectionRanges
, range
);
7088 if (infoPtr
->nFocusedItem
>= nItems
)
7090 infoPtr
->nFocusedItem
= -1;
7091 SetRectEmpty(&infoPtr
->rcFocus
);
7095 infoPtr
->nItemCount
= nItems
;
7096 LISTVIEW_UpdateScroll(infoPtr
);
7098 /* the flags are valid only in ownerdata report and list modes */
7099 if (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
) dwFlags
= 0;
7101 if (!(dwFlags
& LVSICF_NOSCROLL
) && infoPtr
->nFocusedItem
!= -1)
7102 LISTVIEW_EnsureVisible(infoPtr
, infoPtr
->nFocusedItem
, FALSE
);
7104 if (!(dwFlags
& LVSICF_NOINVALIDATEALL
))
7105 LISTVIEW_InvalidateList(infoPtr
);
7112 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7113 nFrom
= min(nOldCount
, nItems
);
7114 nTo
= max(nOldCount
, nItems
);
7116 if (uView
== LVS_REPORT
)
7119 rcErase
.top
= nFrom
* infoPtr
->nItemHeight
;
7120 rcErase
.right
= infoPtr
->nItemWidth
;
7121 rcErase
.bottom
= nTo
* infoPtr
->nItemHeight
;
7122 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
7123 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
7124 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
7128 INT nPerCol
= LISTVIEW_GetCountPerColumn(infoPtr
);
7130 rcErase
.left
= (nFrom
/ nPerCol
) * infoPtr
->nItemWidth
;
7131 rcErase
.top
= (nFrom
% nPerCol
) * infoPtr
->nItemHeight
;
7132 rcErase
.right
= rcErase
.left
+ infoPtr
->nItemWidth
;
7133 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
7134 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
7135 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
7136 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
7138 rcErase
.left
= (nFrom
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
7140 rcErase
.right
= (nTo
/ nPerCol
+ 1) * infoPtr
->nItemWidth
;
7141 rcErase
.bottom
= nPerCol
* infoPtr
->nItemHeight
;
7142 OffsetRect(&rcErase
, Origin
.x
, Origin
.y
);
7143 if (IntersectRect(&rcErase
, &rcErase
, &infoPtr
->rcList
))
7144 LISTVIEW_InvalidateRect(infoPtr
, &rcErase
);
7150 /* According to MSDN for non-LVS_OWNERDATA this is just
7151 * a performance issue. The control allocates its internal
7152 * data structures for the number of items specified. It
7153 * cuts down on the number of memory allocations. Therefore
7154 * we will just issue a WARN here
7156 WARN("for non-ownerdata performance option not implemented.\n");
7164 * Sets the position of an item.
7167 * [I] infoPtr : valid pointer to the listview structure
7168 * [I] nItem : item index
7169 * [I] pt : coordinate
7175 static BOOL
LISTVIEW_SetItemPosition(LISTVIEW_INFO
*infoPtr
, INT nItem
, POINT pt
)
7177 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7180 TRACE("(nItem=%d, &pt=%s\n", nItem
, debugpoint(&pt
));
7182 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
||
7183 !(uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)) return FALSE
;
7185 LISTVIEW_GetOrigin(infoPtr
, &Origin
);
7187 /* This point value seems to be an undocumented feature.
7188 * The best guess is that it means either at the origin,
7189 * or at true beginning of the list. I will assume the origin. */
7190 if ((pt
.x
== -1) && (pt
.y
== -1))
7193 if (uView
== LVS_ICON
)
7195 pt
.x
-= (infoPtr
->nItemWidth
- infoPtr
->iconSize
.cx
) / 2;
7196 pt
.y
-= ICON_TOP_PADDING
;
7201 infoPtr
->bAutoarrange
= FALSE
;
7203 return LISTVIEW_MoveIconTo(infoPtr
, nItem
, &pt
, FALSE
);
7208 * Sets the state of one or many items.
7211 * [I] infoPtr : valid pointer to the listview structure
7212 * [I] nItem : item index
7213 * [I] lpLVItem : item or subitem info
7219 static BOOL
LISTVIEW_SetItemState(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
)
7221 BOOL bResult
= TRUE
;
7224 lvItem
.iItem
= nItem
;
7225 lvItem
.iSubItem
= 0;
7226 lvItem
.mask
= LVIF_STATE
;
7227 lvItem
.state
= lpLVItem
->state
;
7228 lvItem
.stateMask
= lpLVItem
->stateMask
;
7229 TRACE("lvItem=%s\n", debuglvitem_t(&lvItem
, TRUE
));
7233 /* apply to all items */
7234 for (lvItem
.iItem
= 0; lvItem
.iItem
< infoPtr
->nItemCount
; lvItem
.iItem
++)
7235 if (!LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
)) bResult
= FALSE
;
7238 bResult
= LISTVIEW_SetItemT(infoPtr
, &lvItem
, TRUE
);
7241 * Update selection mark
7243 * Investigation on windows 2k showed that selection mark was updated
7244 * whenever a new selection was made, but if the selected item was
7245 * unselected it was not updated.
7247 * we are probably still not 100% accurate, but this at least sets the
7248 * proper selection mark when it is needed
7251 if (bResult
&& (lvItem
.state
& lvItem
.stateMask
& LVIS_SELECTED
) &&
7252 ((infoPtr
->nSelectionMark
== -1) || (lvItem
.iItem
<= infoPtr
->nSelectionMark
)))
7255 infoPtr
->nSelectionMark
= -1;
7256 for (i
= 0; i
< infoPtr
->nItemCount
; i
++)
7258 if (infoPtr
->uCallbackMask
& LVIS_SELECTED
)
7260 if (LISTVIEW_GetItemState(infoPtr
, i
, LVIS_SELECTED
))
7262 infoPtr
->nSelectionMark
= i
;
7266 else if (ranges_contain(infoPtr
->selectionRanges
, i
))
7268 infoPtr
->nSelectionMark
= i
;
7279 * Sets the text of an item or subitem.
7282 * [I] hwnd : window handle
7283 * [I] nItem : item index
7284 * [I] lpLVItem : item or subitem info
7285 * [I] isW : TRUE if input is Unicode
7291 static BOOL
LISTVIEW_SetItemTextT(LISTVIEW_INFO
*infoPtr
, INT nItem
, const LVITEMW
*lpLVItem
, BOOL isW
)
7295 if (nItem
< 0 && nItem
>= infoPtr
->nItemCount
) return FALSE
;
7297 lvItem
.iItem
= nItem
;
7298 lvItem
.iSubItem
= lpLVItem
->iSubItem
;
7299 lvItem
.mask
= LVIF_TEXT
;
7300 lvItem
.pszText
= lpLVItem
->pszText
;
7301 lvItem
.cchTextMax
= lpLVItem
->cchTextMax
;
7303 TRACE("(nItem=%d, lpLVItem=%s, isW=%d)\n", nItem
, debuglvitem_t(&lvItem
, isW
), isW
);
7305 return LISTVIEW_SetItemT(infoPtr
, &lvItem
, isW
);
7310 * Set item index that marks the start of a multiple selection.
7313 * [I] infoPtr : valid pointer to the listview structure
7314 * [I] nIndex : index
7317 * Index number or -1 if there is no selection mark.
7319 static INT
LISTVIEW_SetSelectionMark(LISTVIEW_INFO
*infoPtr
, INT nIndex
)
7321 INT nOldIndex
= infoPtr
->nSelectionMark
;
7323 TRACE("(nIndex=%d)\n", nIndex
);
7325 infoPtr
->nSelectionMark
= nIndex
;
7332 * Sets the text background color.
7335 * [I] infoPtr : valid pointer to the listview structure
7336 * [I] clrTextBk : text background color
7342 static BOOL
LISTVIEW_SetTextBkColor(LISTVIEW_INFO
*infoPtr
, COLORREF clrTextBk
)
7344 TRACE("(clrTextBk=%lx)\n", clrTextBk
);
7346 if (infoPtr
->clrTextBk
!= clrTextBk
)
7348 infoPtr
->clrTextBk
= clrTextBk
;
7349 LISTVIEW_InvalidateList(infoPtr
);
7357 * Sets the text foreground color.
7360 * [I] infoPtr : valid pointer to the listview structure
7361 * [I] clrText : text color
7367 static BOOL
LISTVIEW_SetTextColor (LISTVIEW_INFO
*infoPtr
, COLORREF clrText
)
7369 TRACE("(clrText=%lx)\n", clrText
);
7371 if (infoPtr
->clrText
!= clrText
)
7373 infoPtr
->clrText
= clrText
;
7374 LISTVIEW_InvalidateList(infoPtr
);
7382 * Determines which listview item is located at the specified position.
7385 * [I] infoPtr : valid pointer to the listview structure
7386 * [I] hwndNewToolTip : handle to new ToolTip
7391 static HWND
LISTVIEW_SetToolTips( LISTVIEW_INFO
*infoPtr
, HWND hwndNewToolTip
)
7393 HWND hwndOldToolTip
= infoPtr
->hwndToolTip
;
7394 infoPtr
->hwndToolTip
= hwndNewToolTip
;
7395 return hwndOldToolTip
;
7398 /* LISTVIEW_SetUnicodeFormat */
7399 /* LISTVIEW_SetWorkAreas */
7403 * Callback internally used by LISTVIEW_SortItems()
7406 * [I] first : pointer to first ITEM_INFO to compare
7407 * [I] second : pointer to second ITEM_INFO to compare
7408 * [I] lParam : HWND of control
7411 * if first comes before second : negative
7412 * if first comes after second : positive
7413 * if first and second are equivalent : zero
7415 static INT WINAPI
LISTVIEW_CallBackCompare(LPVOID first
, LPVOID second
, LPARAM lParam
)
7417 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)lParam
;
7418 ITEM_INFO
* lv_first
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)first
, 0 );
7419 ITEM_INFO
* lv_second
= (ITEM_INFO
*) DPA_GetPtr( (HDPA
)second
, 0 );
7420 PFNLVCOMPARE CompareFunction
= infoPtr
->pfnCompare
;
7422 /* Forward the call to the client defined callback */
7424 return (CompareFunction
)( lv_first
->lParam
, lv_second
->lParam
, infoPtr
->lParamSort
);
7429 * Sorts the listview items.
7432 * [I] infoPtr : valid pointer to the listview structure
7433 * [I] pfnCompare : application-defined value
7434 * [I] lParamSort : pointer to comparision callback
7440 static BOOL
LISTVIEW_SortItems(LISTVIEW_INFO
*infoPtr
, PFNLVCOMPARE pfnCompare
, LPARAM lParamSort
)
7442 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7445 LPVOID selectionMarkItem
;
7449 TRACE("(pfnCompare=%p, lParamSort=%lx)\n", pfnCompare
, lParamSort
);
7451 if (infoPtr
->dwStyle
& LVS_OWNERDATA
) return FALSE
;
7453 if (!pfnCompare
) return FALSE
;
7454 if (!infoPtr
->hdpaItems
) return FALSE
;
7456 /* if there are 0 or 1 items, there is no need to sort */
7457 if (infoPtr
->nItemCount
< 2) return TRUE
;
7459 if (infoPtr
->nFocusedItem
>= 0)
7461 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nFocusedItem
);
7462 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
7463 if (lpItem
) lpItem
->state
|= LVIS_FOCUSED
;
7465 /* FIXME: go thorugh selected items and mark them so in lpItem->state */
7466 /* clear the lpItem->state for non-selected ones */
7467 /* remove the selection ranges */
7469 infoPtr
->pfnCompare
= pfnCompare
;
7470 infoPtr
->lParamSort
= lParamSort
;
7471 DPA_Sort(infoPtr
->hdpaItems
, LISTVIEW_CallBackCompare
, (LPARAM
)infoPtr
);
7473 /* Adjust selections and indices so that they are the way they should
7474 * be after the sort (otherwise, the list items move around, but
7475 * whatever is at the item's previous original position will be
7478 selectionMarkItem
=(infoPtr
->nSelectionMark
>=0)?DPA_GetPtr(infoPtr
->hdpaItems
, infoPtr
->nSelectionMark
):NULL
;
7479 for (i
=0; i
< infoPtr
->nItemCount
; i
++)
7481 hdpaSubItems
= (HDPA
)DPA_GetPtr(infoPtr
->hdpaItems
, i
);
7482 lpItem
= (ITEM_INFO
*)DPA_GetPtr(hdpaSubItems
, 0);
7484 if (lpItem
->state
& LVIS_SELECTED
)
7486 item
.state
= LVIS_SELECTED
;
7487 item
.stateMask
= LVIS_SELECTED
;
7488 LISTVIEW_SetItemState(infoPtr
, i
, &item
);
7490 if (lpItem
->state
& LVIS_FOCUSED
)
7492 infoPtr
->nFocusedItem
= i
;
7493 lpItem
->state
&= ~LVIS_FOCUSED
;
7496 if (selectionMarkItem
!= NULL
)
7497 infoPtr
->nSelectionMark
= DPA_GetPtrIndex(infoPtr
->hdpaItems
, selectionMarkItem
);
7498 /* I believe nHotItem should be left alone, see LISTVIEW_ShiftIndices */
7500 /* refresh the display */
7501 if (uView
!= LVS_ICON
&& uView
!= LVS_SMALLICON
)
7502 LISTVIEW_InvalidateList(infoPtr
);
7509 * Update theme handle after a theme change.
7512 * [I] infoPtr : valid pointer to the listview structure
7516 * FAILURE : something else
7518 static LRESULT
LISTVIEW_ThemeChanged(LISTVIEW_INFO
*infoPtr
)
7520 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
7521 CloseThemeData(theme
);
7522 OpenThemeData(infoPtr
->hwndSelf
, themeClass
);
7528 * Updates an items or rearranges the listview control.
7531 * [I] infoPtr : valid pointer to the listview structure
7532 * [I] nItem : item index
7538 static BOOL
LISTVIEW_Update(LISTVIEW_INFO
*infoPtr
, INT nItem
)
7540 TRACE("(nItem=%d)\n", nItem
);
7542 if (nItem
< 0 || nItem
>= infoPtr
->nItemCount
) return FALSE
;
7544 /* rearrange with default alignment style */
7545 if (is_autoarrange(infoPtr
))
7546 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
7548 LISTVIEW_InvalidateItem(infoPtr
, nItem
);
7556 * Creates the listview control.
7559 * [I] hwnd : window handle
7560 * [I] lpcs : the create parameters
7566 static LRESULT
LISTVIEW_Create(HWND hwnd
, const CREATESTRUCTW
*lpcs
)
7568 LISTVIEW_INFO
*infoPtr
;
7569 UINT uView
= lpcs
->style
& LVS_TYPEMASK
;
7572 TRACE("(lpcs=%p)\n", lpcs
);
7574 /* initialize info pointer */
7575 infoPtr
= (LISTVIEW_INFO
*)Alloc(sizeof(LISTVIEW_INFO
));
7576 if (!infoPtr
) return -1;
7578 SetWindowLongPtrW(hwnd
, 0, (DWORD_PTR
)infoPtr
);
7580 infoPtr
->hwndSelf
= hwnd
;
7581 infoPtr
->dwStyle
= lpcs
->style
;
7582 /* determine the type of structures to use */
7583 infoPtr
->hwndNotify
= lpcs
->hwndParent
;
7584 infoPtr
->notifyFormat
= SendMessageW(infoPtr
->hwndNotify
, WM_NOTIFYFORMAT
,
7585 (WPARAM
)infoPtr
->hwndSelf
, (LPARAM
)NF_QUERY
);
7587 /* initialize color information */
7588 infoPtr
->clrBk
= CLR_NONE
;
7589 infoPtr
->clrText
= comctl32_color
.clrWindowText
;
7590 infoPtr
->clrTextBk
= CLR_DEFAULT
;
7591 LISTVIEW_SetBkColor(infoPtr
, comctl32_color
.clrWindow
);
7593 /* set default values */
7594 infoPtr
->nFocusedItem
= -1;
7595 infoPtr
->nSelectionMark
= -1;
7596 infoPtr
->nHotItem
= -1;
7597 infoPtr
->bRedraw
= TRUE
;
7598 infoPtr
->bNoItemMetrics
= TRUE
;
7599 infoPtr
->bDoChangeNotify
= TRUE
;
7600 infoPtr
->iconSpacing
.cx
= GetSystemMetrics(SM_CXICONSPACING
);
7601 infoPtr
->iconSpacing
.cy
= GetSystemMetrics(SM_CYICONSPACING
);
7602 infoPtr
->nEditLabelItem
= -1;
7603 infoPtr
->dwHoverTime
= -1; /* default system hover time */
7604 infoPtr
->nMeasureItemHeight
= 0;
7606 /* get default font (icon title) */
7607 SystemParametersInfoW(SPI_GETICONTITLELOGFONT
, 0, &logFont
, 0);
7608 infoPtr
->hDefaultFont
= CreateFontIndirectW(&logFont
);
7609 infoPtr
->hFont
= infoPtr
->hDefaultFont
;
7610 LISTVIEW_SaveTextMetrics(infoPtr
);
7613 infoPtr
->hwndHeader
= CreateWindowW(WC_HEADERW
, NULL
,
7614 WS_CHILD
| HDS_HORZ
| (DWORD
)((LVS_NOSORTHEADER
& lpcs
->style
)?0:HDS_BUTTONS
),
7615 0, 0, 0, 0, hwnd
, NULL
,
7616 lpcs
->hInstance
, NULL
);
7617 if (!infoPtr
->hwndHeader
) goto fail
;
7619 /* set header unicode format */
7620 SendMessageW(infoPtr
->hwndHeader
, HDM_SETUNICODEFORMAT
, (WPARAM
)TRUE
, (LPARAM
)NULL
);
7622 /* set header font */
7623 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, (LPARAM
)TRUE
);
7625 /* allocate memory for the data structure */
7626 if (!(infoPtr
->selectionRanges
= ranges_create(10))) goto fail
;
7627 if (!(infoPtr
->hdpaItems
= DPA_Create(10))) goto fail
;
7628 if (!(infoPtr
->hdpaPosX
= DPA_Create(10))) goto fail
;
7629 if (!(infoPtr
->hdpaPosY
= DPA_Create(10))) goto fail
;
7630 if (!(infoPtr
->hdpaColumns
= DPA_Create(10))) goto fail
;
7632 /* initialize the icon sizes */
7633 set_icon_size(&infoPtr
->iconSize
, infoPtr
->himlNormal
, uView
!= LVS_ICON
);
7634 set_icon_size(&infoPtr
->iconStateSize
, infoPtr
->himlState
, TRUE
);
7636 /* init item size to avoid division by 0 */
7637 LISTVIEW_UpdateItemSize (infoPtr
);
7639 if (uView
== LVS_REPORT
)
7641 if (!(LVS_NOCOLUMNHEADER
& lpcs
->style
))
7643 ShowWindow(infoPtr
->hwndHeader
, SW_SHOWNORMAL
);
7647 /* set HDS_HIDDEN flag to hide the header bar */
7648 SetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
,
7649 GetWindowLongW(infoPtr
->hwndHeader
, GWL_STYLE
) | HDS_HIDDEN
);
7653 OpenThemeData(hwnd
, themeClass
);
7658 DestroyWindow(infoPtr
->hwndHeader
);
7659 ranges_destroy(infoPtr
->selectionRanges
);
7660 DPA_Destroy(infoPtr
->hdpaItems
);
7661 DPA_Destroy(infoPtr
->hdpaPosX
);
7662 DPA_Destroy(infoPtr
->hdpaPosY
);
7663 DPA_Destroy(infoPtr
->hdpaColumns
);
7670 * Destroys the listview control.
7673 * [I] infoPtr : valid pointer to the listview structure
7679 static LRESULT
LISTVIEW_Destroy(LISTVIEW_INFO
*infoPtr
)
7681 HTHEME theme
= GetWindowTheme(infoPtr
->hwndSelf
);
7682 CloseThemeData(theme
);
7688 * Enables the listview control.
7691 * [I] infoPtr : valid pointer to the listview structure
7692 * [I] bEnable : specifies whether to enable or disable the window
7698 static BOOL
LISTVIEW_Enable(LISTVIEW_INFO
*infoPtr
, BOOL bEnable
)
7700 if (infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
)
7701 InvalidateRect(infoPtr
->hwndSelf
, NULL
, TRUE
);
7707 * Erases the background of the listview control.
7710 * [I] infoPtr : valid pointer to the listview structure
7711 * [I] hdc : device context handle
7717 static inline BOOL
LISTVIEW_EraseBkgnd(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
7721 TRACE("(hdc=%p)\n", hdc
);
7723 if (!GetClipBox(hdc
, &rc
)) return FALSE
;
7725 return LISTVIEW_FillBkgnd(infoPtr
, hdc
, &rc
);
7731 * Helper function for LISTVIEW_[HV]Scroll *only*.
7732 * Performs vertical/horizontal scrolling by a give amount.
7735 * [I] infoPtr : valid pointer to the listview structure
7736 * [I] dx : amount of horizontal scroll
7737 * [I] dy : amount of vertical scroll
7739 static void scroll_list(LISTVIEW_INFO
*infoPtr
, INT dx
, INT dy
)
7741 /* now we can scroll the list */
7742 ScrollWindowEx(infoPtr
->hwndSelf
, dx
, dy
, &infoPtr
->rcList
,
7743 &infoPtr
->rcList
, 0, 0, SW_ERASE
| SW_INVALIDATE
);
7744 /* if we have focus, adjust rect */
7745 OffsetRect(&infoPtr
->rcFocus
, dx
, dy
);
7746 UpdateWindow(infoPtr
->hwndSelf
);
7751 * Performs vertical scrolling.
7754 * [I] infoPtr : valid pointer to the listview structure
7755 * [I] nScrollCode : scroll code
7756 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
7757 * [I] hScrollWnd : scrollbar control window handle
7763 * SB_LINEUP/SB_LINEDOWN:
7764 * for LVS_ICON, LVS_SMALLICON is 37 by experiment
7765 * for LVS_REPORT is 1 line
7766 * for LVS_LIST cannot occur
7769 static LRESULT
LISTVIEW_VScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
7770 INT nScrollDiff
, HWND hScrollWnd
)
7772 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7773 INT nOldScrollPos
, nNewScrollPos
;
7774 SCROLLINFO scrollInfo
;
7777 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
7778 debugscrollcode(nScrollCode
), nScrollDiff
);
7780 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
7782 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7783 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
7785 is_an_icon
= ((uView
== LVS_ICON
) || (uView
== LVS_SMALLICON
));
7787 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
)) return 1;
7789 nOldScrollPos
= scrollInfo
.nPos
;
7790 switch (nScrollCode
)
7796 nScrollDiff
= (is_an_icon
) ? -LISTVIEW_SCROLL_ICON_LINE_SIZE
: -1;
7800 nScrollDiff
= (is_an_icon
) ? LISTVIEW_SCROLL_ICON_LINE_SIZE
: 1;
7804 nScrollDiff
= -scrollInfo
.nPage
;
7808 nScrollDiff
= scrollInfo
.nPage
;
7811 case SB_THUMBPOSITION
:
7813 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
7820 /* quit right away if pos isn't changing */
7821 if (nScrollDiff
== 0) return 0;
7823 /* calculate new position, and handle overflows */
7824 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
7825 if (nScrollDiff
> 0) {
7826 if (nNewScrollPos
< nOldScrollPos
||
7827 nNewScrollPos
> scrollInfo
.nMax
)
7828 nNewScrollPos
= scrollInfo
.nMax
;
7830 if (nNewScrollPos
> nOldScrollPos
||
7831 nNewScrollPos
< scrollInfo
.nMin
)
7832 nNewScrollPos
= scrollInfo
.nMin
;
7835 /* set the new position, and reread in case it changed */
7836 scrollInfo
.fMask
= SIF_POS
;
7837 scrollInfo
.nPos
= nNewScrollPos
;
7838 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_VERT
, &scrollInfo
, TRUE
);
7840 /* carry on only if it really changed */
7841 if (nNewScrollPos
== nOldScrollPos
) return 0;
7843 /* now adjust to client coordinates */
7844 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
7845 if (uView
== LVS_REPORT
) nScrollDiff
*= infoPtr
->nItemHeight
;
7847 /* and scroll the window */
7848 scroll_list(infoPtr
, 0, nScrollDiff
);
7855 * Performs horizontal scrolling.
7858 * [I] infoPtr : valid pointer to the listview structure
7859 * [I] nScrollCode : scroll code
7860 * [I] nScrollDiff : units to scroll in SB_INTERNAL mode, 0 otherwise
7861 * [I] hScrollWnd : scrollbar control window handle
7867 * SB_LINELEFT/SB_LINERIGHT:
7868 * for LVS_ICON, LVS_SMALLICON 1 pixel
7869 * for LVS_REPORT is 1 pixel
7870 * for LVS_LIST is 1 column --> which is a 1 because the
7871 * scroll is based on columns not pixels
7874 static LRESULT
LISTVIEW_HScroll(LISTVIEW_INFO
*infoPtr
, INT nScrollCode
,
7875 INT nScrollDiff
, HWND hScrollWnd
)
7877 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7878 INT nOldScrollPos
, nNewScrollPos
;
7879 SCROLLINFO scrollInfo
;
7881 TRACE("(nScrollCode=%d(%s), nScrollDiff=%d)\n", nScrollCode
,
7882 debugscrollcode(nScrollCode
), nScrollDiff
);
7884 if (infoPtr
->hwndEdit
) SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
7886 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7887 scrollInfo
.fMask
= SIF_PAGE
| SIF_POS
| SIF_RANGE
| SIF_TRACKPOS
;
7889 if (!GetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
)) return 1;
7891 nOldScrollPos
= scrollInfo
.nPos
;
7893 switch (nScrollCode
)
7907 nScrollDiff
= -scrollInfo
.nPage
;
7911 nScrollDiff
= scrollInfo
.nPage
;
7914 case SB_THUMBPOSITION
:
7916 nScrollDiff
= scrollInfo
.nTrackPos
- scrollInfo
.nPos
;
7923 /* quit right away if pos isn't changing */
7924 if (nScrollDiff
== 0) return 0;
7926 /* calculate new position, and handle overflows */
7927 nNewScrollPos
= scrollInfo
.nPos
+ nScrollDiff
;
7928 if (nScrollDiff
> 0) {
7929 if (nNewScrollPos
< nOldScrollPos
||
7930 nNewScrollPos
> scrollInfo
.nMax
)
7931 nNewScrollPos
= scrollInfo
.nMax
;
7933 if (nNewScrollPos
> nOldScrollPos
||
7934 nNewScrollPos
< scrollInfo
.nMin
)
7935 nNewScrollPos
= scrollInfo
.nMin
;
7938 /* set the new position, and reread in case it changed */
7939 scrollInfo
.fMask
= SIF_POS
;
7940 scrollInfo
.nPos
= nNewScrollPos
;
7941 nNewScrollPos
= SetScrollInfo(infoPtr
->hwndSelf
, SB_HORZ
, &scrollInfo
, TRUE
);
7943 /* carry on only if it really changed */
7944 if (nNewScrollPos
== nOldScrollPos
) return 0;
7946 if(uView
== LVS_REPORT
)
7947 LISTVIEW_UpdateHeaderSize(infoPtr
, nNewScrollPos
);
7949 /* now adjust to client coordinates */
7950 nScrollDiff
= nOldScrollPos
- nNewScrollPos
;
7951 if (uView
== LVS_LIST
) nScrollDiff
*= infoPtr
->nItemWidth
;
7953 /* and scroll the window */
7954 scroll_list(infoPtr
, nScrollDiff
, 0);
7959 static LRESULT
LISTVIEW_MouseWheel(LISTVIEW_INFO
*infoPtr
, INT wheelDelta
)
7961 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
7962 INT gcWheelDelta
= 0;
7963 INT pulScrollLines
= 3;
7964 SCROLLINFO scrollInfo
;
7966 TRACE("(wheelDelta=%d)\n", wheelDelta
);
7968 SystemParametersInfoW(SPI_GETWHEELSCROLLLINES
,0, &pulScrollLines
, 0);
7969 gcWheelDelta
-= wheelDelta
;
7971 scrollInfo
.cbSize
= sizeof(SCROLLINFO
);
7972 scrollInfo
.fMask
= SIF_POS
;
7979 * listview should be scrolled by a multiple of 37 dependently on its dimension or its visible item number
7980 * should be fixed in the future.
7982 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, (gcWheelDelta
< 0) ?
7983 -LISTVIEW_SCROLL_ICON_LINE_SIZE
: LISTVIEW_SCROLL_ICON_LINE_SIZE
, 0);
7987 if (abs(gcWheelDelta
) >= WHEEL_DELTA
&& pulScrollLines
)
7989 int cLineScroll
= min(LISTVIEW_GetCountPerColumn(infoPtr
), pulScrollLines
);
7990 cLineScroll
*= (gcWheelDelta
/ WHEEL_DELTA
);
7991 LISTVIEW_VScroll(infoPtr
, SB_INTERNAL
, cLineScroll
, 0);
7996 LISTVIEW_HScroll(infoPtr
, (gcWheelDelta
< 0) ? SB_LINELEFT
: SB_LINERIGHT
, 0, 0);
8007 * [I] infoPtr : valid pointer to the listview structure
8008 * [I] nVirtualKey : virtual key
8009 * [I] lKeyData : key data
8014 static LRESULT
LISTVIEW_KeyDown(LISTVIEW_INFO
*infoPtr
, INT nVirtualKey
, LONG lKeyData
)
8016 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
8017 HWND hwndSelf
= infoPtr
->hwndSelf
;
8019 NMLVKEYDOWN nmKeyDown
;
8021 TRACE("(nVirtualKey=%d, lKeyData=%ld)\n", nVirtualKey
, lKeyData
);
8023 /* send LVN_KEYDOWN notification */
8024 nmKeyDown
.wVKey
= nVirtualKey
;
8025 nmKeyDown
.flags
= 0;
8026 notify_hdr(infoPtr
, LVN_KEYDOWN
, &nmKeyDown
.hdr
);
8027 if (!IsWindow(hwndSelf
))
8030 switch (nVirtualKey
)
8033 nItem
= infoPtr
->nFocusedItem
;
8037 if ((infoPtr
->nItemCount
> 0) && (infoPtr
->nFocusedItem
!= -1))
8039 if (!notify(infoPtr
, NM_RETURN
)) return 0;
8040 if (!notify(infoPtr
, LVN_ITEMACTIVATE
)) return 0;
8045 if (infoPtr
->nItemCount
> 0)
8050 if (infoPtr
->nItemCount
> 0)
8051 nItem
= infoPtr
->nItemCount
- 1;
8055 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_TOLEFT
);
8059 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_ABOVE
);
8063 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_TORIGHT
);
8067 nItem
= ListView_GetNextItem(infoPtr
->hwndSelf
, infoPtr
->nFocusedItem
, LVNI_BELOW
);
8071 if (uView
== LVS_REPORT
)
8073 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
8074 if (infoPtr
->nFocusedItem
== topidx
)
8075 nItem
= topidx
- LISTVIEW_GetCountPerColumn(infoPtr
) + 1;
8080 nItem
= infoPtr
->nFocusedItem
- LISTVIEW_GetCountPerColumn(infoPtr
)
8081 * LISTVIEW_GetCountPerRow(infoPtr
);
8082 if(nItem
< 0) nItem
= 0;
8086 if (uView
== LVS_REPORT
)
8088 INT topidx
= LISTVIEW_GetTopIndex(infoPtr
);
8089 INT cnt
= LISTVIEW_GetCountPerColumn(infoPtr
);
8090 if (infoPtr
->nFocusedItem
== topidx
+ cnt
- 1)
8091 nItem
= infoPtr
->nFocusedItem
+ cnt
- 1;
8093 nItem
= topidx
+ cnt
- 1;
8096 nItem
= infoPtr
->nFocusedItem
+ LISTVIEW_GetCountPerColumn(infoPtr
)
8097 * LISTVIEW_GetCountPerRow(infoPtr
);
8098 if(nItem
>= infoPtr
->nItemCount
) nItem
= infoPtr
->nItemCount
- 1;
8102 if ((nItem
!= -1) && (nItem
!= infoPtr
->nFocusedItem
|| nVirtualKey
== VK_SPACE
))
8103 LISTVIEW_KeySelection(infoPtr
, nItem
);
8113 * [I] infoPtr : valid pointer to the listview structure
8118 static LRESULT
LISTVIEW_KillFocus(LISTVIEW_INFO
*infoPtr
)
8122 /* if we did not have the focus, there's nothing to do */
8123 if (!infoPtr
->bFocus
) return 0;
8125 /* send NM_KILLFOCUS notification */
8126 if (!notify(infoPtr
, NM_KILLFOCUS
)) return 0;
8128 /* if we have a focus rectagle, get rid of it */
8129 LISTVIEW_ShowFocusRect(infoPtr
, FALSE
);
8131 /* set window focus flag */
8132 infoPtr
->bFocus
= FALSE
;
8134 /* invalidate the selected items before reseting focus flag */
8135 LISTVIEW_InvalidateSelectedItems(infoPtr
);
8142 * Processes double click messages (left mouse button).
8145 * [I] infoPtr : valid pointer to the listview structure
8146 * [I] wKey : key flag
8147 * [I] x,y : mouse coordinate
8152 static LRESULT
LISTVIEW_LButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8154 LVHITTESTINFO htInfo
;
8156 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
8158 /* send NM_RELEASEDCAPTURE notification */
8159 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
8164 /* send NM_DBLCLK notification */
8165 LISTVIEW_HitTest(infoPtr
, &htInfo
, TRUE
, FALSE
);
8166 if (!notify_click(infoPtr
, NM_DBLCLK
, &htInfo
)) return 0;
8168 /* To send the LVN_ITEMACTIVATE, it must be on an Item */
8169 if(htInfo
.iItem
!= -1) notify_itemactivate(infoPtr
,&htInfo
);
8176 * Processes mouse down messages (left mouse button).
8179 * infoPtr [I ] valid pointer to the listview structure
8180 * wKey [I ] key flag
8181 * x,y [I ] mouse coordinate
8186 static LRESULT
LISTVIEW_LButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8188 LVHITTESTINFO lvHitTestInfo
;
8189 static BOOL bGroupSelect
= TRUE
;
8190 POINT pt
= { x
, y
};
8193 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
8195 /* send NM_RELEASEDCAPTURE notification */
8196 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
8198 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
8200 /* set left button down flag and record the click position */
8201 infoPtr
->bLButtonDown
= TRUE
;
8202 infoPtr
->ptClickPos
= pt
;
8204 lvHitTestInfo
.pt
.x
= x
;
8205 lvHitTestInfo
.pt
.y
= y
;
8207 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
8208 TRACE("at %s, nItem=%d\n", debugpoint(&pt
), nItem
);
8209 infoPtr
->nEditLabelItem
= -1;
8210 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
8212 if ((infoPtr
->dwLvExStyle
& LVS_EX_CHECKBOXES
) && (lvHitTestInfo
.flags
& LVHT_ONITEMSTATEICON
))
8214 DWORD state
= STATEIMAGEINDEX(LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_STATEIMAGEMASK
));
8215 if(state
== 1 || state
== 2)
8219 lvitem
.state
= INDEXTOSTATEIMAGEMASK(state
);
8220 lvitem
.stateMask
= LVIS_STATEIMAGEMASK
;
8221 LISTVIEW_SetItemState(infoPtr
, nItem
, &lvitem
);
8226 if (infoPtr
->dwStyle
& LVS_SINGLESEL
)
8228 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
8229 infoPtr
->nEditLabelItem
= nItem
;
8231 LISTVIEW_SetSelection(infoPtr
, nItem
);
8235 if ((wKey
& MK_CONTROL
) && (wKey
& MK_SHIFT
))
8239 if (!LISTVIEW_AddGroupSelection(infoPtr
, nItem
)) return 0;
8240 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
8241 infoPtr
->nSelectionMark
= nItem
;
8247 item
.state
= LVIS_SELECTED
| LVIS_FOCUSED
;
8248 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
8250 LISTVIEW_SetItemState(infoPtr
,nItem
,&item
);
8251 infoPtr
->nSelectionMark
= nItem
;
8254 else if (wKey
& MK_CONTROL
)
8258 bGroupSelect
= (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
) == 0);
8260 item
.state
= (bGroupSelect
? LVIS_SELECTED
: 0) | LVIS_FOCUSED
;
8261 item
.stateMask
= LVIS_SELECTED
| LVIS_FOCUSED
;
8262 LISTVIEW_SetItemState(infoPtr
, nItem
, &item
);
8263 infoPtr
->nSelectionMark
= nItem
;
8265 else if (wKey
& MK_SHIFT
)
8267 LISTVIEW_SetGroupSelection(infoPtr
, nItem
);
8271 if (LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
8272 infoPtr
->nEditLabelItem
= nItem
;
8274 /* set selection (clears other pre-existing selections) */
8275 LISTVIEW_SetSelection(infoPtr
, nItem
);
8281 /* remove all selections */
8282 LISTVIEW_DeselectAll(infoPtr
);
8291 * Processes mouse up messages (left mouse button).
8294 * infoPtr [I ] valid pointer to the listview structure
8295 * wKey [I ] key flag
8296 * x,y [I ] mouse coordinate
8301 static LRESULT
LISTVIEW_LButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8303 LVHITTESTINFO lvHitTestInfo
;
8305 TRACE("(key=%hu, X=%hu, Y=%hu)\n", wKey
, x
, y
);
8307 if (!infoPtr
->bLButtonDown
) return 0;
8309 lvHitTestInfo
.pt
.x
= x
;
8310 lvHitTestInfo
.pt
.y
= y
;
8312 /* send NM_CLICK notification */
8313 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
8314 if (!notify_click(infoPtr
, NM_CLICK
, &lvHitTestInfo
)) return 0;
8316 /* set left button flag */
8317 infoPtr
->bLButtonDown
= FALSE
;
8319 /* if we clicked on a selected item, edit the label */
8320 if(lvHitTestInfo
.iItem
== infoPtr
->nEditLabelItem
&& (lvHitTestInfo
.flags
& LVHT_ONITEMLABEL
))
8321 LISTVIEW_EditLabelT(infoPtr
, lvHitTestInfo
.iItem
, TRUE
);
8328 * Destroys the listview control (called after WM_DESTROY).
8331 * [I] infoPtr : valid pointer to the listview structure
8336 static LRESULT
LISTVIEW_NCDestroy(LISTVIEW_INFO
*infoPtr
)
8340 /* delete all items */
8341 LISTVIEW_DeleteAllItems(infoPtr
);
8343 /* destroy data structure */
8344 DPA_Destroy(infoPtr
->hdpaItems
);
8345 DPA_Destroy(infoPtr
->hdpaPosX
);
8346 DPA_Destroy(infoPtr
->hdpaPosY
);
8347 DPA_Destroy(infoPtr
->hdpaColumns
);
8348 ranges_destroy(infoPtr
->selectionRanges
);
8350 /* destroy image lists */
8351 if (!(infoPtr
->dwStyle
& LVS_SHAREIMAGELISTS
))
8353 if (infoPtr
->himlNormal
)
8354 ImageList_Destroy(infoPtr
->himlNormal
);
8355 if (infoPtr
->himlSmall
)
8356 ImageList_Destroy(infoPtr
->himlSmall
);
8357 if (infoPtr
->himlState
)
8358 ImageList_Destroy(infoPtr
->himlState
);
8361 /* destroy font, bkgnd brush */
8363 if (infoPtr
->hDefaultFont
) DeleteObject(infoPtr
->hDefaultFont
);
8364 if (infoPtr
->clrBk
!= CLR_NONE
) DeleteObject(infoPtr
->hBkBrush
);
8366 SetWindowLongPtrW(infoPtr
->hwndSelf
, 0, 0);
8368 /* free listview info pointer*/
8376 * Handles notifications from header.
8379 * [I] infoPtr : valid pointer to the listview structure
8380 * [I] nCtrlId : control identifier
8381 * [I] lpnmh : notification information
8386 static LRESULT
LISTVIEW_HeaderNotification(LISTVIEW_INFO
*infoPtr
, const NMHEADERW
*lpnmh
)
8388 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
8389 HWND hwndSelf
= infoPtr
->hwndSelf
;
8391 TRACE("(lpnmh=%p)\n", lpnmh
);
8393 if (!lpnmh
|| lpnmh
->iItem
< 0 || lpnmh
->iItem
>= DPA_GetPtrCount(infoPtr
->hdpaColumns
)) return 0;
8395 switch (lpnmh
->hdr
.code
)
8397 case HDN_ITEMCHANGINGW
:
8398 case HDN_ITEMCHANGINGA
:
8399 return notify_forward_header(infoPtr
, lpnmh
);
8400 case HDN_ITEMCHANGEDW
:
8401 case HDN_ITEMCHANGEDA
:
8402 notify_forward_header(infoPtr
, lpnmh
);
8403 if (!IsWindow(hwndSelf
))
8409 COLUMN_INFO
*lpColumnInfo
;
8412 if (!lpnmh
->pitem
|| !(lpnmh
->pitem
->mask
& HDI_WIDTH
))
8416 hdi
.mask
= HDI_WIDTH
;
8417 if (!Header_GetItemW(infoPtr
->hwndHeader
, lpnmh
->iItem
, (LPARAM
)&hdi
)) return 0;
8421 cxy
= lpnmh
->pitem
->cxy
;
8423 /* determine how much we change since the last know position */
8424 lpColumnInfo
= LISTVIEW_GetColumnInfo(infoPtr
, lpnmh
->iItem
);
8425 dx
= cxy
- (lpColumnInfo
->rcHeader
.right
- lpColumnInfo
->rcHeader
.left
);
8428 lpColumnInfo
->rcHeader
.right
+= dx
;
8429 LISTVIEW_ScrollColumns(infoPtr
, lpnmh
->iItem
+ 1, dx
);
8430 LISTVIEW_UpdateItemSize(infoPtr
);
8431 if (uView
== LVS_REPORT
&& is_redrawing(infoPtr
))
8434 RECT rcCol
= lpColumnInfo
->rcHeader
;
8436 LISTVIEW_GetOrigin(infoPtr
, &ptOrigin
);
8437 OffsetRect(&rcCol
, ptOrigin
.x
, 0);
8439 rcCol
.top
= infoPtr
->rcList
.top
;
8440 rcCol
.bottom
= infoPtr
->rcList
.bottom
;
8442 /* resizing left-aligned columns leaves most of the left side untouched */
8443 if ((lpColumnInfo
->fmt
& LVCFMT_JUSTIFYMASK
) == LVCFMT_LEFT
)
8445 INT nMaxDirty
= infoPtr
->nEllipsisWidth
+ infoPtr
->ntmMaxCharWidth
+ dx
;
8446 rcCol
.left
= max (rcCol
.left
, rcCol
.right
- nMaxDirty
);
8449 LISTVIEW_InvalidateRect(infoPtr
, &rcCol
);
8455 case HDN_ITEMCLICKW
:
8456 case HDN_ITEMCLICKA
:
8458 /* Handle sorting by Header Column */
8461 ZeroMemory(&nmlv
, sizeof(NMLISTVIEW
));
8463 nmlv
.iSubItem
= lpnmh
->iItem
;
8464 notify_listview(infoPtr
, LVN_COLUMNCLICK
, &nmlv
);
8468 case HDN_DIVIDERDBLCLICKW
:
8469 case HDN_DIVIDERDBLCLICKA
:
8470 LISTVIEW_SetColumnWidth(infoPtr
, lpnmh
->iItem
, LVSCW_AUTOSIZE
);
8479 * Paint non-client area of control.
8482 * [I] infoPtr : valid pointer to the listview structureof the sender
8483 * [I] region : update region
8486 * TRUE - frame was painted
8487 * FALSE - call default window proc
8489 static BOOL
LISTVIEW_NCPaint(LISTVIEW_INFO
*infoPtr
, HRGN region
)
8491 HTHEME theme
= GetWindowTheme (infoPtr
->hwndSelf
);
8495 int cxEdge
= GetSystemMetrics (SM_CXEDGE
),
8496 cyEdge
= GetSystemMetrics (SM_CYEDGE
);
8498 if (!theme
) return FALSE
;
8500 GetWindowRect(infoPtr
->hwndSelf
, &r
);
8502 cliprgn
= CreateRectRgn (r
.left
+ cxEdge
, r
.top
+ cyEdge
,
8503 r
.right
- cxEdge
, r
.bottom
- cyEdge
);
8504 if (region
!= (HRGN
)1)
8505 CombineRgn (cliprgn
, cliprgn
, region
, RGN_AND
);
8506 OffsetRect(&r
, -r
.left
, -r
.top
);
8508 dc
= GetDCEx(infoPtr
->hwndSelf
, region
, DCX_WINDOW
|DCX_INTERSECTRGN
);
8509 OffsetRect(&r
, -r
.left
, -r
.top
);
8511 if (IsThemeBackgroundPartiallyTransparent (theme
, 0, 0))
8512 DrawThemeParentBackground(infoPtr
->hwndSelf
, dc
, &r
);
8513 DrawThemeBackground (theme
, dc
, 0, 0, &r
, 0);
8514 ReleaseDC(infoPtr
->hwndSelf
, dc
);
8516 /* Call default proc to get the scrollbars etc. painted */
8517 DefWindowProcW (infoPtr
->hwndSelf
, WM_NCPAINT
, (WPARAM
)cliprgn
, 0);
8524 * Determines the type of structure to use.
8527 * [I] infoPtr : valid pointer to the listview structureof the sender
8528 * [I] hwndFrom : listview window handle
8529 * [I] nCommand : command specifying the nature of the WM_NOTIFYFORMAT
8534 static LRESULT
LISTVIEW_NotifyFormat(LISTVIEW_INFO
*infoPtr
, HWND hwndFrom
, INT nCommand
)
8536 TRACE("(hwndFrom=%p, nCommand=%d)\n", hwndFrom
, nCommand
);
8538 if (nCommand
!= NF_REQUERY
) return 0;
8540 infoPtr
->notifyFormat
= SendMessageW(hwndFrom
, WM_NOTIFYFORMAT
, (WPARAM
)infoPtr
->hwndSelf
, NF_QUERY
);
8547 * Paints/Repaints the listview control.
8550 * [I] infoPtr : valid pointer to the listview structure
8551 * [I] hdc : device context handle
8556 static LRESULT
LISTVIEW_Paint(LISTVIEW_INFO
*infoPtr
, HDC hdc
)
8558 TRACE("(hdc=%p)\n", hdc
);
8560 if (infoPtr
->bNoItemMetrics
&& infoPtr
->nItemCount
)
8562 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
8564 infoPtr
->bNoItemMetrics
= FALSE
;
8565 LISTVIEW_UpdateItemSize(infoPtr
);
8566 if (uView
== LVS_ICON
|| uView
== LVS_SMALLICON
)
8567 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8568 LISTVIEW_UpdateScroll(infoPtr
);
8571 LISTVIEW_Refresh(infoPtr
, hdc
);
8576 hdc
= BeginPaint(infoPtr
->hwndSelf
, &ps
);
8578 if (ps
.fErase
) LISTVIEW_FillBkgnd(infoPtr
, hdc
, &ps
.rcPaint
);
8579 LISTVIEW_Refresh(infoPtr
, hdc
);
8580 EndPaint(infoPtr
->hwndSelf
, &ps
);
8589 * Paints/Repaints the listview control.
8592 * [I] infoPtr : valid pointer to the listview structure
8593 * [I] hdc : device context handle
8594 * [I] options : drawing options
8599 static LRESULT
LISTVIEW_PrintClient(LISTVIEW_INFO
*infoPtr
, HDC hdc
, DWORD options
)
8601 FIXME("Partial Stub: (hdc=%p options=0x%08lx)\n", hdc
, options
);
8603 if ((options
& PRF_CHECKVISIBLE
) && !IsWindowVisible(infoPtr
->hwndSelf
))
8606 if (options
& PRF_ERASEBKGND
)
8607 LISTVIEW_EraseBkgnd(infoPtr
, hdc
);
8609 if (options
& PRF_CLIENT
)
8610 LISTVIEW_Paint(infoPtr
, hdc
);
8618 * Processes double click messages (right mouse button).
8621 * [I] infoPtr : valid pointer to the listview structure
8622 * [I] wKey : key flag
8623 * [I] x,y : mouse coordinate
8628 static LRESULT
LISTVIEW_RButtonDblClk(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8630 LVHITTESTINFO lvHitTestInfo
;
8632 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
8634 /* send NM_RELEASEDCAPTURE notification */
8635 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
8637 /* send NM_RDBLCLK notification */
8638 lvHitTestInfo
.pt
.x
= x
;
8639 lvHitTestInfo
.pt
.y
= y
;
8640 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
8641 notify_click(infoPtr
, NM_RDBLCLK
, &lvHitTestInfo
);
8648 * Processes mouse down messages (right mouse button).
8651 * [I] infoPtr : valid pointer to the listview structure
8652 * [I] wKey : key flag
8653 * [I] x,y : mouse coordinate
8658 static LRESULT
LISTVIEW_RButtonDown(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8660 LVHITTESTINFO lvHitTestInfo
;
8663 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
8665 /* send NM_RELEASEDCAPTURE notification */
8666 if (!notify(infoPtr
, NM_RELEASEDCAPTURE
)) return 0;
8668 /* make sure the listview control window has the focus */
8669 if (!infoPtr
->bFocus
) SetFocus(infoPtr
->hwndSelf
);
8671 /* set right button down flag */
8672 infoPtr
->bRButtonDown
= TRUE
;
8674 /* determine the index of the selected item */
8675 lvHitTestInfo
.pt
.x
= x
;
8676 lvHitTestInfo
.pt
.y
= y
;
8677 nItem
= LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, TRUE
);
8679 if ((nItem
>= 0) && (nItem
< infoPtr
->nItemCount
))
8681 LISTVIEW_SetItemFocus(infoPtr
, nItem
);
8682 if (!((wKey
& MK_SHIFT
) || (wKey
& MK_CONTROL
)) &&
8683 !LISTVIEW_GetItemState(infoPtr
, nItem
, LVIS_SELECTED
))
8684 LISTVIEW_SetSelection(infoPtr
, nItem
);
8688 LISTVIEW_DeselectAll(infoPtr
);
8696 * Processes mouse up messages (right mouse button).
8699 * [I] infoPtr : valid pointer to the listview structure
8700 * [I] wKey : key flag
8701 * [I] x,y : mouse coordinate
8706 static LRESULT
LISTVIEW_RButtonUp(LISTVIEW_INFO
*infoPtr
, WORD wKey
, INT x
, INT y
)
8708 LVHITTESTINFO lvHitTestInfo
;
8711 TRACE("(key=%hu,X=%hu,Y=%hu)\n", wKey
, x
, y
);
8713 if (!infoPtr
->bRButtonDown
) return 0;
8715 /* set button flag */
8716 infoPtr
->bRButtonDown
= FALSE
;
8718 /* Send NM_RClICK notification */
8719 lvHitTestInfo
.pt
.x
= x
;
8720 lvHitTestInfo
.pt
.y
= y
;
8721 LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, TRUE
, FALSE
);
8722 if (!notify_click(infoPtr
, NM_RCLICK
, &lvHitTestInfo
)) return 0;
8724 /* Change to screen coordinate for WM_CONTEXTMENU */
8725 pt
= lvHitTestInfo
.pt
;
8726 ClientToScreen(infoPtr
->hwndSelf
, &pt
);
8728 /* Send a WM_CONTEXTMENU message in response to the RBUTTONUP */
8729 SendMessageW(infoPtr
->hwndSelf
, WM_CONTEXTMENU
,
8730 (WPARAM
)infoPtr
->hwndSelf
, MAKELPARAM(pt
.x
, pt
.y
));
8741 * [I] infoPtr : valid pointer to the listview structure
8742 * [I] hwnd : window handle of window containing the cursor
8743 * [I] nHittest : hit-test code
8744 * [I] wMouseMsg : ideintifier of the mouse message
8747 * TRUE if cursor is set
8750 static BOOL
LISTVIEW_SetCursor(LISTVIEW_INFO
*infoPtr
, HWND hwnd
, UINT nHittest
, UINT wMouseMsg
)
8752 LVHITTESTINFO lvHitTestInfo
;
8754 if(!(infoPtr
->dwLvExStyle
& LVS_EX_TRACKSELECT
)) return FALSE
;
8756 if(!infoPtr
->hHotCursor
) return FALSE
;
8758 GetCursorPos(&lvHitTestInfo
.pt
);
8759 if (LISTVIEW_HitTest(infoPtr
, &lvHitTestInfo
, FALSE
, FALSE
) < 0) return FALSE
;
8761 SetCursor(infoPtr
->hHotCursor
);
8771 * [I] infoPtr : valid pointer to the listview structure
8772 * [I] hwndLoseFocus : handle of previously focused window
8777 static LRESULT
LISTVIEW_SetFocus(LISTVIEW_INFO
*infoPtr
, HWND hwndLoseFocus
)
8779 TRACE("(hwndLoseFocus=%p)\n", hwndLoseFocus
);
8781 /* if we have the focus already, there's nothing to do */
8782 if (infoPtr
->bFocus
) return 0;
8784 /* send NM_SETFOCUS notification */
8785 if (!notify(infoPtr
, NM_SETFOCUS
)) return 0;
8787 /* set window focus flag */
8788 infoPtr
->bFocus
= TRUE
;
8790 /* put the focus rect back on */
8791 LISTVIEW_ShowFocusRect(infoPtr
, TRUE
);
8793 /* redraw all visible selected items */
8794 LISTVIEW_InvalidateSelectedItems(infoPtr
);
8804 * [I] infoPtr : valid pointer to the listview structure
8805 * [I] fRedraw : font handle
8806 * [I] fRedraw : redraw flag
8811 static LRESULT
LISTVIEW_SetFont(LISTVIEW_INFO
*infoPtr
, HFONT hFont
, WORD fRedraw
)
8813 HFONT oldFont
= infoPtr
->hFont
;
8815 TRACE("(hfont=%p,redraw=%hu)\n", hFont
, fRedraw
);
8817 infoPtr
->hFont
= hFont
? hFont
: infoPtr
->hDefaultFont
;
8818 if (infoPtr
->hFont
== oldFont
) return 0;
8820 LISTVIEW_SaveTextMetrics(infoPtr
);
8822 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_REPORT
)
8823 SendMessageW(infoPtr
->hwndHeader
, WM_SETFONT
, (WPARAM
)hFont
, MAKELPARAM(fRedraw
, 0));
8825 if (fRedraw
) LISTVIEW_InvalidateList(infoPtr
);
8832 * Message handling for WM_SETREDRAW.
8833 * For the Listview, it invalidates the entire window (the doc specifies otherwise)
8836 * [I] infoPtr : valid pointer to the listview structure
8837 * [I] bRedraw: state of redraw flag
8840 * DefWinProc return value
8842 static LRESULT
LISTVIEW_SetRedraw(LISTVIEW_INFO
*infoPtr
, BOOL bRedraw
)
8844 TRACE("infoPtr->bRedraw=%d, bRedraw=%d\n", infoPtr
->bRedraw
, bRedraw
);
8846 /* we cannot use straight equality here because _any_ non-zero value is TRUE */
8847 if ((infoPtr
->bRedraw
&& bRedraw
) || (!infoPtr
->bRedraw
&& !bRedraw
)) return 0;
8849 infoPtr
->bRedraw
= bRedraw
;
8851 if(!bRedraw
) return 0;
8853 if (is_autoarrange(infoPtr
))
8854 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8855 LISTVIEW_UpdateScroll(infoPtr
);
8857 /* despite what the WM_SETREDRAW docs says, apps expect us
8858 * to invalidate the listview here... stupid! */
8859 LISTVIEW_InvalidateList(infoPtr
);
8866 * Resizes the listview control. This function processes WM_SIZE
8867 * messages. At this time, the width and height are not used.
8870 * [I] infoPtr : valid pointer to the listview structure
8871 * [I] Width : new width
8872 * [I] Height : new height
8877 static LRESULT
LISTVIEW_Size(LISTVIEW_INFO
*infoPtr
, int Width
, int Height
)
8879 RECT rcOld
= infoPtr
->rcList
;
8881 TRACE("(width=%d, height=%d)\n", Width
, Height
);
8883 LISTVIEW_UpdateSize(infoPtr
);
8884 if (EqualRect(&rcOld
, &infoPtr
->rcList
)) return 0;
8886 /* do not bother with display related stuff if we're not redrawing */
8887 if (!is_redrawing(infoPtr
)) return 0;
8889 if (is_autoarrange(infoPtr
))
8890 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
8892 LISTVIEW_UpdateScroll(infoPtr
);
8894 /* refresh all only for lists whose height changed significantly */
8895 if ((infoPtr
->dwStyle
& LVS_TYPEMASK
) == LVS_LIST
&&
8896 (rcOld
.bottom
- rcOld
.top
) / infoPtr
->nItemHeight
!=
8897 (infoPtr
->rcList
.bottom
- infoPtr
->rcList
.top
) / infoPtr
->nItemHeight
)
8898 LISTVIEW_InvalidateList(infoPtr
);
8905 * Sets the size information.
8908 * [I] infoPtr : valid pointer to the listview structure
8913 static void LISTVIEW_UpdateSize(LISTVIEW_INFO
*infoPtr
)
8915 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
8917 TRACE("uView=%d, rcList(old)=%s\n", uView
, debugrect(&infoPtr
->rcList
));
8919 GetClientRect(infoPtr
->hwndSelf
, &infoPtr
->rcList
);
8921 if (uView
== LVS_LIST
)
8923 /* Apparently the "LIST" style is supposed to have the same
8924 * number of items in a column even if there is no scroll bar.
8925 * Since if a scroll bar already exists then the bottom is already
8926 * reduced, only reduce if the scroll bar does not currently exist.
8927 * The "2" is there to mimic the native control. I think it may be
8928 * related to either padding or edges. (GLA 7/2002)
8930 if (!(GetWindowLongW(infoPtr
->hwndSelf
, GWL_STYLE
) & WS_HSCROLL
))
8931 infoPtr
->rcList
.bottom
-= GetSystemMetrics(SM_CYHSCROLL
);
8932 infoPtr
->rcList
.bottom
= max (infoPtr
->rcList
.bottom
- 2, 0);
8934 else if (uView
== LVS_REPORT
&& !(infoPtr
->dwStyle
& LVS_NOCOLUMNHEADER
))
8939 hl
.prc
= &infoPtr
->rcList
;
8941 Header_Layout(infoPtr
->hwndHeader
, &hl
);
8943 SetWindowPos(wp
.hwnd
, wp
.hwndInsertAfter
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
8945 infoPtr
->rcList
.top
= max(wp
.cy
, 0);
8948 TRACE(" rcList=%s\n", debugrect(&infoPtr
->rcList
));
8953 * Processes WM_STYLECHANGED messages.
8956 * [I] infoPtr : valid pointer to the listview structure
8957 * [I] wStyleType : window style type (normal or extended)
8958 * [I] lpss : window style information
8963 static INT
LISTVIEW_StyleChanged(LISTVIEW_INFO
*infoPtr
, WPARAM wStyleType
,
8964 const STYLESTRUCT
*lpss
)
8966 UINT uNewView
= lpss
->styleNew
& LVS_TYPEMASK
;
8967 UINT uOldView
= lpss
->styleOld
& LVS_TYPEMASK
;
8969 TRACE("(styletype=%x, styleOld=0x%08lx, styleNew=0x%08lx)\n",
8970 wStyleType
, lpss
->styleOld
, lpss
->styleNew
);
8972 if (wStyleType
!= GWL_STYLE
) return 0;
8974 /* FIXME: if LVS_NOSORTHEADER changed, update header */
8975 /* what if LVS_OWNERDATA changed? */
8976 /* or LVS_SINGLESEL */
8977 /* or LVS_SORT{AS,DES}CENDING */
8979 infoPtr
->dwStyle
= lpss
->styleNew
;
8981 if (((lpss
->styleOld
& WS_HSCROLL
) != 0)&&
8982 ((lpss
->styleNew
& WS_HSCROLL
) == 0))
8983 ShowScrollBar(infoPtr
->hwndSelf
, SB_HORZ
, FALSE
);
8985 if (((lpss
->styleOld
& WS_VSCROLL
) != 0)&&
8986 ((lpss
->styleNew
& WS_VSCROLL
) == 0))
8987 ShowScrollBar(infoPtr
->hwndSelf
, SB_VERT
, FALSE
);
8989 if (uNewView
!= uOldView
)
8991 SIZE oldIconSize
= infoPtr
->iconSize
;
8994 SendMessageW(infoPtr
->hwndEdit
, WM_KILLFOCUS
, 0, 0);
8995 ShowWindow(infoPtr
->hwndHeader
, SW_HIDE
);
8997 ShowScrollBar(infoPtr
->hwndSelf
, SB_BOTH
, FALSE
);
8998 SetRectEmpty(&infoPtr
->rcFocus
);
9000 himl
= (uNewView
== LVS_ICON
? infoPtr
->himlNormal
: infoPtr
->himlSmall
);
9001 set_icon_size(&infoPtr
->iconSize
, himl
, uNewView
!= LVS_ICON
);
9003 if (uNewView
== LVS_ICON
)
9005 if ((infoPtr
->iconSize
.cx
!= oldIconSize
.cx
) || (infoPtr
->iconSize
.cy
!= oldIconSize
.cy
))
9007 TRACE("icon old size=(%ld,%ld), new size=(%ld,%ld)\n",
9008 oldIconSize
.cx
, oldIconSize
.cy
, infoPtr
->iconSize
.cx
, infoPtr
->iconSize
.cy
);
9009 LISTVIEW_SetIconSpacing(infoPtr
, 0, 0);
9012 else if (uNewView
== LVS_REPORT
)
9017 hl
.prc
= &infoPtr
->rcList
;
9019 Header_Layout(infoPtr
->hwndHeader
, &hl
);
9020 SetWindowPos(infoPtr
->hwndHeader
, infoPtr
->hwndSelf
, wp
.x
, wp
.y
, wp
.cx
, wp
.cy
, wp
.flags
);
9023 LISTVIEW_UpdateItemSize(infoPtr
);
9026 if (uNewView
== LVS_REPORT
)
9027 ShowWindow(infoPtr
->hwndHeader
, (lpss
->styleNew
& LVS_NOCOLUMNHEADER
) ? SW_HIDE
: SW_SHOWNORMAL
);
9029 if ( (uNewView
== LVS_ICON
|| uNewView
== LVS_SMALLICON
) &&
9030 (uNewView
!= uOldView
|| ((lpss
->styleNew
^ lpss
->styleOld
) & LVS_ALIGNMASK
)) )
9031 LISTVIEW_Arrange(infoPtr
, LVA_DEFAULT
);
9033 /* update the size of the client area */
9034 LISTVIEW_UpdateSize(infoPtr
);
9036 /* add scrollbars if needed */
9037 LISTVIEW_UpdateScroll(infoPtr
);
9039 /* invalidate client area + erase background */
9040 LISTVIEW_InvalidateList(infoPtr
);
9047 * Window procedure of the listview control.
9050 static LRESULT WINAPI
9051 LISTVIEW_WindowProc(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
9053 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(hwnd
, 0);
9055 TRACE("(uMsg=%x wParam=%x lParam=%lx)\n", uMsg
, wParam
, lParam
);
9057 if (!infoPtr
&& (uMsg
!= WM_CREATE
))
9058 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
9062 case LVM_APPROXIMATEVIEWRECT
:
9063 return LISTVIEW_ApproximateViewRect(infoPtr
, (INT
)wParam
,
9064 LOWORD(lParam
), HIWORD(lParam
));
9066 return LISTVIEW_Arrange(infoPtr
, (INT
)wParam
);
9068 /* case LVM_CANCELEDITLABEL: */
9070 case LVM_CREATEDRAGIMAGE
:
9071 return (LRESULT
)LISTVIEW_CreateDragImage(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
9073 case LVM_DELETEALLITEMS
:
9074 return LISTVIEW_DeleteAllItems(infoPtr
);
9076 case LVM_DELETECOLUMN
:
9077 return LISTVIEW_DeleteColumn(infoPtr
, (INT
)wParam
);
9079 case LVM_DELETEITEM
:
9080 return LISTVIEW_DeleteItem(infoPtr
, (INT
)wParam
);
9082 case LVM_EDITLABELW
:
9083 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, TRUE
);
9085 case LVM_EDITLABELA
:
9086 return (LRESULT
)LISTVIEW_EditLabelT(infoPtr
, (INT
)wParam
, FALSE
);
9088 /* case LVM_ENABLEGROUPVIEW: */
9090 case LVM_ENSUREVISIBLE
:
9091 return LISTVIEW_EnsureVisible(infoPtr
, (INT
)wParam
, (BOOL
)lParam
);
9094 return LISTVIEW_FindItemW(infoPtr
, (INT
)wParam
, (LPLVFINDINFOW
)lParam
);
9097 return LISTVIEW_FindItemA(infoPtr
, (INT
)wParam
, (LPLVFINDINFOA
)lParam
);
9099 case LVM_GETBKCOLOR
:
9100 return infoPtr
->clrBk
;
9102 /* case LVM_GETBKIMAGE: */
9104 case LVM_GETCALLBACKMASK
:
9105 return infoPtr
->uCallbackMask
;
9107 case LVM_GETCOLUMNA
:
9108 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
9110 case LVM_GETCOLUMNW
:
9111 return LISTVIEW_GetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
9113 case LVM_GETCOLUMNORDERARRAY
:
9114 return LISTVIEW_GetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
9116 case LVM_GETCOLUMNWIDTH
:
9117 return LISTVIEW_GetColumnWidth(infoPtr
, (INT
)wParam
);
9119 case LVM_GETCOUNTPERPAGE
:
9120 return LISTVIEW_GetCountPerPage(infoPtr
);
9122 case LVM_GETEDITCONTROL
:
9123 return (LRESULT
)infoPtr
->hwndEdit
;
9125 case LVM_GETEXTENDEDLISTVIEWSTYLE
:
9126 return infoPtr
->dwLvExStyle
;
9128 /* case LVM_GETGROUPINFO: */
9130 /* case LVM_GETGROUPMETRICS: */
9133 return (LRESULT
)infoPtr
->hwndHeader
;
9135 case LVM_GETHOTCURSOR
:
9136 return (LRESULT
)infoPtr
->hHotCursor
;
9138 case LVM_GETHOTITEM
:
9139 return infoPtr
->nHotItem
;
9141 case LVM_GETHOVERTIME
:
9142 return infoPtr
->dwHoverTime
;
9144 case LVM_GETIMAGELIST
:
9145 return (LRESULT
)LISTVIEW_GetImageList(infoPtr
, (INT
)wParam
);
9147 /* case LVM_GETINSERTMARK: */
9149 /* case LVM_GETINSERTMARKCOLOR: */
9151 /* case LVM_GETINSERTMARKRECT: */
9153 case LVM_GETISEARCHSTRINGA
:
9154 case LVM_GETISEARCHSTRINGW
:
9155 FIXME("LVM_GETISEARCHSTRING: unimplemented\n");
9159 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
9162 return LISTVIEW_GetItemExtT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
9164 case LVM_GETITEMCOUNT
:
9165 return infoPtr
->nItemCount
;
9167 case LVM_GETITEMPOSITION
:
9168 return LISTVIEW_GetItemPosition(infoPtr
, (INT
)wParam
, (LPPOINT
)lParam
);
9170 case LVM_GETITEMRECT
:
9171 return LISTVIEW_GetItemRect(infoPtr
, (INT
)wParam
, (LPRECT
)lParam
);
9173 case LVM_GETITEMSPACING
:
9174 return LISTVIEW_GetItemSpacing(infoPtr
, (BOOL
)wParam
);
9176 case LVM_GETITEMSTATE
:
9177 return LISTVIEW_GetItemState(infoPtr
, (INT
)wParam
, (UINT
)lParam
);
9179 case LVM_GETITEMTEXTA
:
9180 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
9182 case LVM_GETITEMTEXTW
:
9183 return LISTVIEW_GetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
9185 case LVM_GETNEXTITEM
:
9186 return LISTVIEW_GetNextItem(infoPtr
, (INT
)wParam
, LOWORD(lParam
));
9188 case LVM_GETNUMBEROFWORKAREAS
:
9189 FIXME("LVM_GETNUMBEROFWORKAREAS: unimplemented\n");
9193 if (!lParam
) return FALSE
;
9194 LISTVIEW_GetOrigin(infoPtr
, (LPPOINT
)lParam
);
9197 /* case LVM_GETOUTLINECOLOR: */
9199 /* case LVM_GETSELECTEDCOLUMN: */
9201 case LVM_GETSELECTEDCOUNT
:
9202 return LISTVIEW_GetSelectedCount(infoPtr
);
9204 case LVM_GETSELECTIONMARK
:
9205 return infoPtr
->nSelectionMark
;
9207 case LVM_GETSTRINGWIDTHA
:
9208 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, FALSE
);
9210 case LVM_GETSTRINGWIDTHW
:
9211 return LISTVIEW_GetStringWidthT(infoPtr
, (LPCWSTR
)lParam
, TRUE
);
9213 case LVM_GETSUBITEMRECT
:
9214 return LISTVIEW_GetSubItemRect(infoPtr
, (UINT
)wParam
, (LPRECT
)lParam
);
9216 case LVM_GETTEXTBKCOLOR
:
9217 return infoPtr
->clrTextBk
;
9219 case LVM_GETTEXTCOLOR
:
9220 return infoPtr
->clrText
;
9222 /* case LVM_GETTILEINFO: */
9224 /* case LVM_GETTILEVIEWINFO: */
9226 case LVM_GETTOOLTIPS
:
9227 if( !infoPtr
->hwndToolTip
)
9228 infoPtr
->hwndToolTip
= COMCTL32_CreateToolTip( hwnd
);
9229 return (LRESULT
)infoPtr
->hwndToolTip
;
9231 case LVM_GETTOPINDEX
:
9232 return LISTVIEW_GetTopIndex(infoPtr
);
9234 /*case LVM_GETUNICODEFORMAT:
9235 FIXME("LVM_GETUNICODEFORMAT: unimplemented\n");
9238 /* case LVM_GETVIEW: */
9240 case LVM_GETVIEWRECT
:
9241 return LISTVIEW_GetViewRect(infoPtr
, (LPRECT
)lParam
);
9243 case LVM_GETWORKAREAS
:
9244 FIXME("LVM_GETWORKAREAS: unimplemented\n");
9247 /* case LVM_HASGROUP: */
9250 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, FALSE
, FALSE
);
9252 case LVM_INSERTCOLUMNA
:
9253 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
9255 case LVM_INSERTCOLUMNW
:
9256 return LISTVIEW_InsertColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
9258 /* case LVM_INSERTGROUP: */
9260 /* case LVM_INSERTGROUPSORTED: */
9262 case LVM_INSERTITEMA
:
9263 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
9265 case LVM_INSERTITEMW
:
9266 return LISTVIEW_InsertItemT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
9268 /* case LVM_INSERTMARKHITTEST: */
9270 /* case LVM_ISGROUPVIEWENABLED: */
9272 /* case LVM_MAPIDTOINDEX: */
9274 /* case LVM_MAPINDEXTOID: */
9276 /* case LVM_MOVEGROUP: */
9278 /* case LVM_MOVEITEMTOGROUP: */
9280 case LVM_REDRAWITEMS
:
9281 return LISTVIEW_RedrawItems(infoPtr
, (INT
)wParam
, (INT
)lParam
);
9283 /* case LVM_REMOVEALLGROUPS: */
9285 /* case LVM_REMOVEGROUP: */
9288 return LISTVIEW_Scroll(infoPtr
, (INT
)wParam
, (INT
)lParam
);
9290 case LVM_SETBKCOLOR
:
9291 return LISTVIEW_SetBkColor(infoPtr
, (COLORREF
)lParam
);
9293 /* case LVM_SETBKIMAGE: */
9295 case LVM_SETCALLBACKMASK
:
9296 infoPtr
->uCallbackMask
= (UINT
)wParam
;
9299 case LVM_SETCOLUMNA
:
9300 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, FALSE
);
9302 case LVM_SETCOLUMNW
:
9303 return LISTVIEW_SetColumnT(infoPtr
, (INT
)wParam
, (LPLVCOLUMNW
)lParam
, TRUE
);
9305 case LVM_SETCOLUMNORDERARRAY
:
9306 return LISTVIEW_SetColumnOrderArray(infoPtr
, (INT
)wParam
, (LPINT
)lParam
);
9308 case LVM_SETCOLUMNWIDTH
:
9309 return LISTVIEW_SetColumnWidth(infoPtr
, (INT
)wParam
, (short)LOWORD(lParam
));
9311 case LVM_SETEXTENDEDLISTVIEWSTYLE
:
9312 return LISTVIEW_SetExtendedListViewStyle(infoPtr
, (DWORD
)wParam
, (DWORD
)lParam
);
9314 /* case LVM_SETGROUPINFO: */
9316 /* case LVM_SETGROUPMETRICS: */
9318 case LVM_SETHOTCURSOR
:
9319 return (LRESULT
)LISTVIEW_SetHotCursor(infoPtr
, (HCURSOR
)lParam
);
9321 case LVM_SETHOTITEM
:
9322 return LISTVIEW_SetHotItem(infoPtr
, (INT
)wParam
);
9324 case LVM_SETHOVERTIME
:
9325 return LISTVIEW_SetHoverTime(infoPtr
, (DWORD
)wParam
);
9327 case LVM_SETICONSPACING
:
9328 return LISTVIEW_SetIconSpacing(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
9330 case LVM_SETIMAGELIST
:
9331 return (LRESULT
)LISTVIEW_SetImageList(infoPtr
, (INT
)wParam
, (HIMAGELIST
)lParam
);
9333 /* case LVM_SETINFOTIP: */
9335 /* case LVM_SETINSERTMARK: */
9337 /* case LVM_SETINSERTMARKCOLOR: */
9340 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, FALSE
);
9343 return LISTVIEW_SetItemT(infoPtr
, (LPLVITEMW
)lParam
, TRUE
);
9345 case LVM_SETITEMCOUNT
:
9346 return LISTVIEW_SetItemCount(infoPtr
, (INT
)wParam
, (DWORD
)lParam
);
9348 case LVM_SETITEMPOSITION
:
9351 pt
.x
= (short)LOWORD(lParam
);
9352 pt
.y
= (short)HIWORD(lParam
);
9353 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, pt
);
9356 case LVM_SETITEMPOSITION32
:
9357 if (lParam
== 0) return FALSE
;
9358 return LISTVIEW_SetItemPosition(infoPtr
, (INT
)wParam
, *((POINT
*)lParam
));
9360 case LVM_SETITEMSTATE
:
9361 return LISTVIEW_SetItemState(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
);
9363 case LVM_SETITEMTEXTA
:
9364 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, FALSE
);
9366 case LVM_SETITEMTEXTW
:
9367 return LISTVIEW_SetItemTextT(infoPtr
, (INT
)wParam
, (LPLVITEMW
)lParam
, TRUE
);
9369 /* case LVM_SETOUTLINECOLOR: */
9371 /* case LVM_SETSELECTEDCOLUMN: */
9373 case LVM_SETSELECTIONMARK
:
9374 return LISTVIEW_SetSelectionMark(infoPtr
, (INT
)lParam
);
9376 case LVM_SETTEXTBKCOLOR
:
9377 return LISTVIEW_SetTextBkColor(infoPtr
, (COLORREF
)lParam
);
9379 case LVM_SETTEXTCOLOR
:
9380 return LISTVIEW_SetTextColor(infoPtr
, (COLORREF
)lParam
);
9382 /* case LVM_SETTILEINFO: */
9384 /* case LVM_SETTILEVIEWINFO: */
9386 /* case LVM_SETTILEWIDTH: */
9388 case LVM_SETTOOLTIPS
:
9389 return (LRESULT
)LISTVIEW_SetToolTips(infoPtr
, (HWND
)lParam
);
9391 /* case LVM_SETUNICODEFORMAT: */
9393 /* case LVM_SETVIEW: */
9395 /* case LVM_SETWORKAREAS: */
9397 /* case LVM_SORTGROUPS: */
9400 return LISTVIEW_SortItems(infoPtr
, (PFNLVCOMPARE
)lParam
, (LPARAM
)wParam
);
9402 /* LVM_SORTITEMSEX: */
9404 case LVM_SUBITEMHITTEST
:
9405 return LISTVIEW_HitTest(infoPtr
, (LPLVHITTESTINFO
)lParam
, TRUE
, FALSE
);
9408 return LISTVIEW_Update(infoPtr
, (INT
)wParam
);
9411 return LISTVIEW_ProcessLetterKeys( infoPtr
, wParam
, lParam
);
9414 return LISTVIEW_Command(infoPtr
, wParam
, lParam
);
9417 return LISTVIEW_Create(hwnd
, (LPCREATESTRUCTW
)lParam
);
9420 return LISTVIEW_Destroy(infoPtr
);
9423 return LISTVIEW_Enable(infoPtr
, (BOOL
)wParam
);
9426 return LISTVIEW_EraseBkgnd(infoPtr
, (HDC
)wParam
);
9429 return DLGC_WANTCHARS
| DLGC_WANTARROWS
;
9432 return (LRESULT
)infoPtr
->hFont
;
9435 return LISTVIEW_HScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
9438 return LISTVIEW_KeyDown(infoPtr
, (INT
)wParam
, (LONG
)lParam
);
9441 return LISTVIEW_KillFocus(infoPtr
);
9443 case WM_LBUTTONDBLCLK
:
9444 return LISTVIEW_LButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9446 case WM_LBUTTONDOWN
:
9447 return LISTVIEW_LButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9450 return LISTVIEW_LButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9453 return LISTVIEW_MouseMove (infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9456 return LISTVIEW_MouseHover(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9459 return LISTVIEW_NCDestroy(infoPtr
);
9462 if (LISTVIEW_NCPaint(infoPtr
, (HRGN
)wParam
))
9467 if (lParam
&& ((LPNMHDR
)lParam
)->hwndFrom
== infoPtr
->hwndHeader
)
9468 return LISTVIEW_HeaderNotification(infoPtr
, (LPNMHEADERW
)lParam
);
9471 case WM_NOTIFYFORMAT
:
9472 return LISTVIEW_NotifyFormat(infoPtr
, (HWND
)wParam
, (INT
)lParam
);
9474 case WM_PRINTCLIENT
:
9475 return LISTVIEW_PrintClient(infoPtr
, (HDC
)wParam
, (DWORD
)lParam
);
9478 return LISTVIEW_Paint(infoPtr
, (HDC
)wParam
);
9480 case WM_RBUTTONDBLCLK
:
9481 return LISTVIEW_RButtonDblClk(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9483 case WM_RBUTTONDOWN
:
9484 return LISTVIEW_RButtonDown(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9487 return LISTVIEW_RButtonUp(infoPtr
, (WORD
)wParam
, (SHORT
)LOWORD(lParam
), (SHORT
)HIWORD(lParam
));
9490 if(LISTVIEW_SetCursor(infoPtr
, (HWND
)wParam
, LOWORD(lParam
), HIWORD(lParam
)))
9495 return LISTVIEW_SetFocus(infoPtr
, (HWND
)wParam
);
9498 return LISTVIEW_SetFont(infoPtr
, (HFONT
)wParam
, (WORD
)lParam
);
9501 return LISTVIEW_SetRedraw(infoPtr
, (BOOL
)wParam
);
9504 return LISTVIEW_Size(infoPtr
, (short)LOWORD(lParam
), (short)HIWORD(lParam
));
9506 case WM_STYLECHANGED
:
9507 return LISTVIEW_StyleChanged(infoPtr
, wParam
, (LPSTYLESTRUCT
)lParam
);
9509 case WM_SYSCOLORCHANGE
:
9510 COMCTL32_RefreshSysColors();
9513 /* case WM_TIMER: */
9514 case WM_THEMECHANGED
:
9515 return LISTVIEW_ThemeChanged(infoPtr
);
9518 return LISTVIEW_VScroll(infoPtr
, (INT
)LOWORD(wParam
), 0, (HWND
)lParam
);
9521 if (wParam
& (MK_SHIFT
| MK_CONTROL
))
9522 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
9523 return LISTVIEW_MouseWheel(infoPtr
, (short int)HIWORD(wParam
));
9525 case WM_WINDOWPOSCHANGED
:
9526 if (!(((WINDOWPOS
*)lParam
)->flags
& SWP_NOSIZE
))
9528 UINT uView
= infoPtr
->dwStyle
& LVS_TYPEMASK
;
9529 SetWindowPos(infoPtr
->hwndSelf
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOACTIVATE
|
9530 SWP_NOZORDER
| SWP_NOMOVE
| SWP_NOSIZE
);
9532 if ((infoPtr
->dwStyle
& LVS_OWNERDRAWFIXED
) && (uView
== LVS_REPORT
))
9534 MEASUREITEMSTRUCT mis
;
9535 mis
.CtlType
= ODT_LISTVIEW
;
9536 mis
.CtlID
= GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_ID
);
9540 mis
.itemHeight
= infoPtr
->nItemHeight
;
9541 SendMessageW(infoPtr
->hwndNotify
, WM_MEASUREITEM
, mis
.CtlID
, (LPARAM
)&mis
);
9542 if (infoPtr
->nItemHeight
!= max(mis
.itemHeight
, 1))
9543 infoPtr
->nMeasureItemHeight
= infoPtr
->nItemHeight
= max(mis
.itemHeight
, 1);
9546 LISTVIEW_UpdateSize(infoPtr
);
9547 LISTVIEW_UpdateScroll(infoPtr
);
9549 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
9551 /* case WM_WININICHANGE: */
9554 if ((uMsg
>= WM_USER
) && (uMsg
< WM_APP
))
9555 ERR("unknown msg %04x wp=%08x lp=%08lx\n", uMsg
, wParam
, lParam
);
9558 /* call default window procedure */
9559 return DefWindowProcW(hwnd
, uMsg
, wParam
, lParam
);
9566 * Registers the window class.
9574 void LISTVIEW_Register(void)
9578 ZeroMemory(&wndClass
, sizeof(WNDCLASSW
));
9579 wndClass
.style
= CS_GLOBALCLASS
| CS_DBLCLKS
;
9580 wndClass
.lpfnWndProc
= LISTVIEW_WindowProc
;
9581 wndClass
.cbClsExtra
= 0;
9582 wndClass
.cbWndExtra
= sizeof(LISTVIEW_INFO
*);
9583 wndClass
.hCursor
= LoadCursorW(0, (LPWSTR
)IDC_ARROW
);
9584 wndClass
.hbrBackground
= (HBRUSH
)(COLOR_WINDOW
+ 1);
9585 wndClass
.lpszClassName
= WC_LISTVIEWW
;
9586 RegisterClassW(&wndClass
);
9591 * Unregisters the window class.
9599 void LISTVIEW_Unregister(void)
9601 UnregisterClassW(WC_LISTVIEWW
, NULL
);
9606 * Handle any WM_COMMAND messages
9609 * [I] infoPtr : valid pointer to the listview structure
9610 * [I] wParam : the first message parameter
9611 * [I] lParam : the second message parameter
9616 static LRESULT
LISTVIEW_Command(LISTVIEW_INFO
*infoPtr
, WPARAM wParam
, LPARAM lParam
)
9618 switch (HIWORD(wParam
))
9623 * Adjust the edit window size
9626 HDC hdc
= GetDC(infoPtr
->hwndEdit
);
9627 HFONT hFont
, hOldFont
= 0;
9632 if (!infoPtr
->hwndEdit
|| !hdc
) return 0;
9633 len
= GetWindowTextW(infoPtr
->hwndEdit
, buffer
, sizeof(buffer
)/sizeof(buffer
[0]));
9634 GetWindowRect(infoPtr
->hwndEdit
, &rect
);
9636 /* Select font to get the right dimension of the string */
9637 hFont
= (HFONT
)SendMessageW(infoPtr
->hwndEdit
, WM_GETFONT
, 0, 0);
9640 hOldFont
= SelectObject(hdc
, hFont
);
9643 if (GetTextExtentPoint32W(hdc
, buffer
, lstrlenW(buffer
), &sz
))
9645 TEXTMETRICW textMetric
;
9647 /* Add Extra spacing for the next character */
9648 GetTextMetricsW(hdc
, &textMetric
);
9649 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
9657 rect
.bottom
- rect
.top
,
9658 SWP_DRAWFRAME
|SWP_NOMOVE
);
9661 SelectObject(hdc
, hOldFont
);
9663 ReleaseDC(infoPtr
->hwndEdit
, hdc
);
9669 return SendMessageW (infoPtr
->hwndNotify
, WM_COMMAND
, wParam
, lParam
);
9678 * Subclassed edit control windproc function
9681 * [I] hwnd : the edit window handle
9682 * [I] uMsg : the message that is to be processed
9683 * [I] wParam : first message parameter
9684 * [I] lParam : second message parameter
9685 * [I] isW : TRUE if input is Unicode
9690 static LRESULT
EditLblWndProcT(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
, BOOL isW
)
9692 LISTVIEW_INFO
*infoPtr
= (LISTVIEW_INFO
*)GetWindowLongPtrW(GetParent(hwnd
), 0);
9693 BOOL cancel
= FALSE
;
9695 TRACE("(hwnd=%p, uMsg=%x, wParam=%x, lParam=%lx, isW=%d)\n",
9696 hwnd
, uMsg
, wParam
, lParam
, isW
);
9701 return DLGC_WANTARROWS
| DLGC_WANTALLKEYS
;
9708 WNDPROC editProc
= infoPtr
->EditWndProc
;
9709 infoPtr
->EditWndProc
= 0;
9710 SetWindowLongPtrW(hwnd
, GWLP_WNDPROC
, (DWORD_PTR
)editProc
);
9711 return CallWindowProcT(editProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
9715 if (VK_ESCAPE
== (INT
)wParam
)
9720 else if (VK_RETURN
== (INT
)wParam
)
9724 return CallWindowProcT(infoPtr
->EditWndProc
, hwnd
, uMsg
, wParam
, lParam
, isW
);
9728 if (infoPtr
->hwndEdit
)
9730 LPWSTR buffer
= NULL
;
9732 infoPtr
->hwndEdit
= 0;
9735 DWORD len
= isW
? GetWindowTextLengthW(hwnd
) : GetWindowTextLengthA(hwnd
);
9739 if ( (buffer
= Alloc((len
+1) * (isW
? sizeof(WCHAR
) : sizeof(CHAR
)))) )
9741 if (isW
) GetWindowTextW(hwnd
, buffer
, len
+1);
9742 else GetWindowTextA(hwnd
, (CHAR
*)buffer
, len
+1);
9746 LISTVIEW_EndEditLabelT(infoPtr
, buffer
, isW
);
9748 if (buffer
) Free(buffer
);
9752 SendMessageW(hwnd
, WM_CLOSE
, 0, 0);
9758 * Subclassed edit control Unicode windproc function
9761 * [I] hwnd : the edit window handle
9762 * [I] uMsg : the message that is to be processed
9763 * [I] wParam : first message parameter
9764 * [I] lParam : second message parameter
9768 LRESULT CALLBACK
EditLblWndProcW(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
9770 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, TRUE
);
9775 * Subclassed edit control ANSI windproc function
9778 * [I] hwnd : the edit window handle
9779 * [I] uMsg : the message that is to be processed
9780 * [I] wParam : first message parameter
9781 * [I] lParam : second message parameter
9785 LRESULT CALLBACK
EditLblWndProcA(HWND hwnd
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
9787 return EditLblWndProcT(hwnd
, uMsg
, wParam
, lParam
, FALSE
);
9792 * Creates a subclassed edit cotrol
9795 * [I] infoPtr : valid pointer to the listview structure
9796 * [I] text : initial text for the edit
9797 * [I] style : the window style
9798 * [I] isW : TRUE if input is Unicode
9802 static HWND
CreateEditLabelT(LISTVIEW_INFO
*infoPtr
, LPCWSTR text
, DWORD style
,
9803 INT x
, INT y
, INT width
, INT height
, BOOL isW
)
9805 WCHAR editName
[5] = { 'E', 'd', 'i', 't', '\0' };
9810 TEXTMETRICW textMetric
;
9811 HINSTANCE hinst
= (HINSTANCE
)GetWindowLongPtrW(infoPtr
->hwndSelf
, GWLP_HINSTANCE
);
9813 TRACE("(text=%s, ..., isW=%d)\n", debugtext_t(text
, isW
), isW
);
9815 style
|= WS_CHILDWINDOW
|WS_CLIPSIBLINGS
|ES_LEFT
|ES_AUTOHSCROLL
|WS_BORDER
;
9816 hdc
= GetDC(infoPtr
->hwndSelf
);
9818 /* Select the font to get appropriate metric dimensions */
9819 if(infoPtr
->hFont
!= 0)
9820 hOldFont
= SelectObject(hdc
, infoPtr
->hFont
);
9822 /*Get String Length in pixels */
9823 if(!GetTextExtentPoint32W(hdc
, text
, lstrlenW(text
), &sz
))
9826 /*Add Extra spacing for the next character */
9827 GetTextMetricsW(hdc
, &textMetric
);
9828 sz
.cx
+= (textMetric
.tmMaxCharWidth
* 2);
9830 if(infoPtr
->hFont
!= 0)
9831 SelectObject(hdc
, hOldFont
);
9833 ReleaseDC(infoPtr
->hwndSelf
, hdc
);
9835 hedit
= CreateWindowW(editName
, text
, style
, x
, y
, sz
.cx
, height
, infoPtr
->hwndSelf
, 0, hinst
, 0);
9837 hedit
= CreateWindowA("Edit", (LPCSTR
)text
, style
, x
, y
, sz
.cx
, height
, infoPtr
->hwndSelf
, 0, hinst
, 0);
9839 if (!hedit
) return 0;
9841 infoPtr
->EditWndProc
= (WNDPROC
)
9842 (isW
? SetWindowLongPtrW(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcW
) :
9843 SetWindowLongPtrA(hedit
, GWLP_WNDPROC
, (DWORD_PTR
)EditLblWndProcA
) );
9845 SendMessageW(hedit
, WM_SETFONT
, (WPARAM
)infoPtr
->hFont
, FALSE
);